generated from salesforcecli/plugin-template-sf
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
270 additions
and
555 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
[ | ||
{ | ||
"command": "hello:world", | ||
"plugin": "@salesforce/plugin-template-sf", | ||
"flags": ["json", "name"], | ||
"command": "plugins:discover", | ||
"plugin": "@salesforce/plugin-marketplace", | ||
"flags": ["json"], | ||
"alias": [], | ||
"flagChars": ["n"], | ||
"flagChars": [], | ||
"flagAliases": [] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
# summary | ||
|
||
Summary of a command. | ||
See a list of sf plugins you can install. | ||
|
||
# description | ||
|
||
Description of a command. | ||
|
||
# flags.name.summary | ||
|
||
Description of a flag. | ||
|
||
# examples | ||
|
||
- <%= config.bin %> <%= command.id %> | ||
|
||
# disclaimer | ||
|
||
These plugins are not created by Salesforce. Ensure that you trust the creator of the plugin or have reviewed the code. Install at your own risk. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$ref": "#/definitions/DiscoverResults", | ||
"definitions": { | ||
"DiscoverResults": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/DiscoverResult" | ||
} | ||
}, | ||
"DiscoverResult": { | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"date": { | ||
"type": "string" | ||
}, | ||
"downloads": { | ||
"type": "string" | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"description": { | ||
"type": "string" | ||
}, | ||
"homepage": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["date", "description", "downloads", "homepage", "name"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import got from 'got'; | ||
|
||
export type NpmInfo = { | ||
name: string; | ||
// version: string; | ||
description: string; | ||
homepage: string; | ||
// repository: { url: string }; | ||
}; | ||
|
||
export type StarInfo = { | ||
downloads: string; | ||
// package: string; | ||
}; | ||
|
||
export type SearchInfo = { | ||
objects: Array<{ | ||
package: { | ||
name: string; | ||
date: string; | ||
}; | ||
}>; | ||
}; | ||
|
||
export type DiscoverResult = NpmInfo & StarInfo & { date: string }; | ||
|
||
type QueryResult = [NpmInfo, StarInfo, SearchInfo]; | ||
|
||
export const query = async (packages: string[]): Promise<Array<[NpmInfo, StarInfo, SearchInfo]>> => | ||
Promise.all( | ||
packages.map((pkg) => | ||
Promise.all([ | ||
got<NpmInfo>(`https://registry.npmjs.org/${pkg}/latest`).json<NpmInfo>(), | ||
got<StarInfo>(`https://api.npmjs.org/downloads/point/last-week/${pkg}`).json<StarInfo>(), | ||
// use yarn to spread the load around some | ||
got<SearchInfo>(`https://registry.yarnpkg.com/-/v1/search?text=${pkg}`).json<SearchInfo>(), | ||
]) | ||
) | ||
); | ||
|
||
export const transform = (queryResult: QueryResult[]): DiscoverResult[] => | ||
queryResult | ||
.map((y) => ({ ...y[0], ...y[1], date: dateFromSearchObjects(y[0].name, y[2]) })) | ||
.sort((a, b) => (b.downloads > a.downloads ? 1 : -1)) | ||
.map((y) => ({ | ||
...y, | ||
description: descriptionTransform(y.description), | ||
homepage: y.homepage.replace('https://github.com/https://github.com', 'https://github.com'), | ||
})); | ||
|
||
const dateFromSearchObjects = (pkgName: string, searchInfo: SearchInfo): string => | ||
searchInfo.objects.find((o) => o.package.name === pkgName)?.package.date.split('T')[0] ?? ''; | ||
|
||
/** word wrap inside the description. Also removes line empty lines and markdown dividers */ | ||
export const descriptionTransform = (description: string): string => | ||
( | ||
description | ||
// line dividers | ||
.replace(/={2,}/g, '') | ||
.trim() | ||
// separate into shorter lines | ||
.match(/(.{1,50})(?:\s|$)/g) | ||
?.map((line) => line.trim()) | ||
.join('\n') ?? '' | ||
) | ||
// remove empty lines | ||
.replace(/\n{2,}/gm, '\n'); |
Oops, something went wrong.