Skip to content

Commit

Permalink
feat: prep for release
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Aug 16, 2023
1 parent c7bed7c commit 8dce356
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 555 deletions.
8 changes: 4 additions & 4 deletions command-snapshot.json
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": []
}
]
10 changes: 5 additions & 5 deletions messages/plugins.discover.md
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.
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"name": "@salesforce/plugin-marketplace",
"description": "A template repository for sf plugins",
"description": "Find sf plugins",
"version": "0.0.1",
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^2.11.7",
"@salesforce/core": "^4.3.7",
"@salesforce/kit": "^3.0.8",
"@salesforce/core": "^5.2.0",
"@salesforce/kit": "^3.0.9",
"@salesforce/sf-plugins-core": "^3.1.14",
"tslib": "^2"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^4.0.11",
"@salesforce/cli-plugins-testkit": "^4.2.8",
"@salesforce/cli-plugins-testkit": "^4.2.9",
"@salesforce/dev-config": "^4.0.1",
"@salesforce/dev-scripts": "^5.4.3",
"@salesforce/plugin-command-reference": "^3.0.21",
"@salesforce/plugin-command-reference": "^3.0.25",
"@salesforce/prettier-config": "^0.0.3",
"@salesforce/ts-sinon": "1.4.8",
"@swc/core": "1.3.39",
Expand All @@ -32,18 +32,18 @@
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jsdoc": "^43.0.5",
"eslint-plugin-sf-plugin": "^1.16.1",
"eslint-plugin-sf-plugin": "^1.16.2",
"husky": "^7.0.4",
"mocha": "^9.2.2",
"nyc": "^15.1.0",
"oclif": "^3.9.1",
"oclif": "^3.11.3",
"prettier": "^2.8.8",
"pretty-quick": "^3.1.3",
"shx": "0.3.4",
"sinon": "10.0.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.5",
"wireit": "^0.9.5"
"typescript": "^5.1.6",
"wireit": "^0.10.0"
},
"engines": {
"node": ">=16.0.0"
Expand Down Expand Up @@ -76,8 +76,9 @@
"@salesforce/plugin-command-reference"
],
"topics": {
"hello": {
"description": "Commands to say hello."
"plugins": {
"external": true,
"description": "Find and manage plugins"
}
}
},
Expand Down
19 changes: 0 additions & 19 deletions schemas/hello-world.json

This file was deleted.

34 changes: 34 additions & 0 deletions schemas/plugins-discover.json
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"]
}
}
}
69 changes: 30 additions & 39 deletions src/commands/plugins/discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,64 @@
* 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 { SfCommand } from '@salesforce/sf-plugins-core';
import { SfCommand, StandardColors } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import got from 'got';
import { query, DiscoverResult, transform } from '../../shared/discoverQuery';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-marketplace', 'plugins.discover');

type NpmInfo = {
name: string;
version: string;
description: string;
homepage: string;
repository: { url: string };
};
export type DiscoverResults = DiscoverResult[];

type StarInfo = {
downloads: string;
package: string;
};

export default class PluginsDiscover extends SfCommand<void> {
export default class PluginsDiscover extends SfCommand<DiscoverResults> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');

// eslint-disable-next-line class-methods-use-this
public async run(): Promise<void> {
public async run(): Promise<DiscoverResults> {
const packages = [
'@muenzpraeger/sfdx-plugin',
'sfdx-waw-plugin',
'mo-dx-plugin',
'sfdx-hardis',
'sfdx-affirm',
'expereo-sfdx-plugin',
'heat-sfdx-cli',
'bmsfdx',
'shane-sfdx-plugins',
'sfdx-cmdt-plugin',
'etcopydata',
'sfdx-migration-automatic',
'sfdx-devhub-pool',
'@dx-cli-toolbox/sfdx-toolbox-package-utils',
'@dxatscale/sfpowerscripts',
'soqlx-opener',
'sfdx-git-packager',
'texei-sfdx-plugin',
];

const npmData = await 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>(),
])
)
);

const combined = npmData
.map((y) => ({ ...y[0], ...y[1] }))
.sort((a, b) => (b.downloads > a.downloads ? 1 : -1))
.map((y) => ({ ...y, description: `${y.description.match(/(.{1,100})(?:\s|$)/g)?.join('\n')}` }));
const results = transform(await query(packages))
.map(limitJson)
.map(colorizeRow);

this.table(combined, {
this.table(results, {
name: { header: 'Package' },
description: { header: 'Description' },
homepage: { header: 'Homepage' },
downloads: { header: 'Weekly Downloads' },
downloads: { header: 'Downloads/Week' },
date: { header: 'Published' },
});

this.warn(messages.getMessage('disclaimer'));
return results;
}
}

/* there's a LOT more properties outside out types coming back from the APIs that we don't want people to build dependencies on */
const limitJson = ({ name, description, homepage, downloads, date }: DiscoverResult): DiscoverResult => ({
name,
description,
homepage,
downloads,
date,
});

const colorizeRow = (row: DiscoverResult, index: number): DiscoverResult =>
index % 2 === 0
? row
: (Object.fromEntries(
Object.entries(row).map(([key, value]) => [key, StandardColors.info(value)])
) as DiscoverResult);
73 changes: 73 additions & 0 deletions src/shared/discoverQuery.ts
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');
Loading

0 comments on commit 8dce356

Please sign in to comment.