generated from salesforcecli/plugin-template-sf
-
Notifications
You must be signed in to change notification settings - Fork 3
/
discover.ts
62 lines (51 loc) · 2.18 KB
/
discover.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* 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 { EOL } from 'node:os';
import { SfCommand, StandardColors } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import shared, { DiscoverResult } from '../../shared/discoverQuery.js';
import { packages } from '../../shared/plugins.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
const messages = Messages.loadMessages('@salesforce/plugin-marketplace', 'plugins.discover');
export type DiscoverResults = DiscoverResult[];
export default class PluginsDiscover extends SfCommand<DiscoverResults> {
public static readonly summary = messages.getMessage('summary');
public static readonly examples = messages.getMessages('examples');
public async run(): Promise<DiscoverResults> {
await this.parse(PluginsDiscover);
const results = shared.transform(await shared.query(packages)).map(limitJson);
this.table(results.map(formatRow).map(colorizeRow), {
name: { header: 'Package' },
description: { header: 'Description' },
homepage: { header: 'Homepage' },
downloads: { header: 'DL/Wk' },
published: { header: 'Published' },
});
this.log(); // Add a blank line before the disclaimer
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, published }: DiscoverResult): DiscoverResult => ({
name,
description,
homepage,
downloads,
published,
});
const formatRow = (dr: DiscoverResult): DiscoverResult => ({
...dr,
name: dr.name.split('/').join(`/${EOL} `),
description: shared.descriptionTransform(dr.description),
});
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);