Skip to content

feat: use oclif/core v4 #1111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions messages/repositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,35 @@ For more information on the list of repositories, visit https://github.com/sales
- <%= config.bin %> <%= command.id %> --columns=url --filter='Name=sfdx-core' --no-header | xargs open

- <%= config.bin %> <%= command.id %> --json | jq -r '.result[] | select(.name=="sfdx-core") | .packages[] | .url

# flags.columns.summary

Only show provided columns (comma-separated).

# flags.csv.summary

Output is csv format.

# flags.extended.summary

Show extra columns.

# flags.filter.summary

Filter property by partial string matching, ex: name=foo.

# flags.no-header.summary

Hide table header from output.

# flags.no-truncate.summary

Do not truncate output to fit screen.

# flags.output.summary

Output in a more machine friendly format.

# flags.sort.summary

Property to sort by (prepend '-' for descending).
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"sf-release": "bin/run.js"
},
"dependencies": {
"@oclif/core": "^3.26.4",
"@oclif/core": "^4",
"@octokit/core": "^4.2.4",
"@octokit/plugin-paginate-rest": "^6.1.2",
"@octokit/plugin-throttling": "^5.2.3",
Expand All @@ -18,7 +18,7 @@
"@salesforce/kit": "^3.1.2",
"@salesforce/plugin-command-reference": "^3.0.83",
"@salesforce/plugin-trust": "^3.7.0",
"@salesforce/sf-plugins-core": "^9.1.1",
"@salesforce/sf-plugins-core": "^10.0.0",
"@salesforce/ts-types": "^2.0.9",
"aws-sdk": "^2.1632.0",
"chalk": "^5.3.0",
Expand All @@ -34,7 +34,7 @@
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^5.2.0",
"@salesforce/dev-scripts": "^9.1.2",
"@salesforce/dev-scripts": "^10",
"@salesforce/ts-sinon": "1.4.19",
"@types/semver": "^7.5.8",
"@types/shelljs": "^0.8.15",
Expand Down
17 changes: 9 additions & 8 deletions src/commands/cli/install/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import path from 'node:path';
import os from 'node:os';
import fs from 'node:fs/promises';
import shelljs from 'shelljs';
import { ux } from '@oclif/core';
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
import { Flags, SfCommand, Ux } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import { ensure } from '@salesforce/ts-types';
import got from 'got';
Expand All @@ -21,6 +20,8 @@ import { AmazonS3, download } from '../../../amazonS3.js';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-release-management', 'cli.install.test');

const ux = new Ux();

type Results = Record<string, Record<CLI, boolean>>;

namespace Method {
Expand All @@ -35,7 +36,7 @@ namespace Method {
channel: Channel;
method: Type;
directory: string;
}
};

export abstract class Base {
private static TEST_TARGETS = {
Expand Down Expand Up @@ -175,15 +176,15 @@ class Tarball extends Method.Base {
const dir = path.join(this.options.directory, path.basename(file).replace(/\./g, '-'));
await fs.mkdir(dir, { recursive: true });
return new Promise((resolve, reject) => {
ux.action.start(`Unpacking ${chalk.cyan(path.basename(file))} to ${dir}`);
ux.spinner.start(`Unpacking ${chalk.cyan(path.basename(file))} to ${dir}`);
const cmd =
process.platform === 'win32'
? `tar -xf ${file} -C ${dir} --strip-components 1 --exclude node_modules/.bin`
: `tar -xf ${file} -C ${dir} --strip-components 1`;
const opts = process.platform === 'win32' ? { shell: 'powershell.exe' } : {};
shelljs.exec(cmd, { ...opts, silent: true }, (code: number, stdout: string, stderr: string) => {
if (code === 0) {
ux.action.stop();
ux.spinner.stop();
ux.log(stdout);
resolve(dir);
} else {
Expand Down Expand Up @@ -261,18 +262,18 @@ class Npm extends Method.Base {
}

private async install(): Promise<void> {
ux.action.start(`Installing: ${chalk.cyan(this.package)}`);
ux.spinner.start(`Installing: ${chalk.cyan(this.package)}`);
return new Promise((resolve, reject) => {
shelljs.exec(
`npm install ${this.package}`,
{ silent: true, cwd: this.options.directory },
(code, stdout, stderr) => {
if (code === 0) {
ux.action.stop();
ux.spinner.stop();
ux.log(stdout);
resolve();
} else {
ux.action.stop('Failed');
ux.spinner.stop('Failed');
ux.log(stdout);
ux.log(stderr);
reject();
Expand Down
76 changes: 53 additions & 23 deletions src/commands/repositories/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
* 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';
/* eslint-disable sf-plugin/no-hardcoded-messages-flags */

import { Flags, SfCommand, Ux } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import { ux } from '@oclif/core';
import { RepositoryInfo, retrieveKnownRepositories } from '../../repositories.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
Expand All @@ -19,35 +20,64 @@ export default class Repositories extends SfCommand<RepositoryResult> {
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
public static readonly flags = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...(ux.table.flags() as any),
columns: Flags.string({
summary: messages.getMessage('flags.columns.summary'),
exclusive: ['extended'],
}),
csv: Flags.boolean({
summary: messages.getMessage('flags.csv.summary'),
exclusive: ['no-truncate'],
}),
extended: Flags.boolean({
char: 'x',
summary: messages.getMessage('flags.extended.summary'),
exclusive: ['columns'],
}),
filter: Flags.string({
summary: messages.getMessage('flags.filter.summary'),
}),
'no-header': Flags.boolean({
summary: messages.getMessage('flags.no-header.summary'),
exclusive: ['csv'],
}),
'no-truncate': Flags.boolean({
summary: messages.getMessage('flags.no-truncate.summary'),
exclusive: ['csv'],
}),
output: Flags.string({
summary: messages.getMessage('flags.output.summary'),
exclusive: ['no-truncate', 'csv'],
options: ['csv', 'json', 'yaml'],
}),
sort: Flags.string({
summary: messages.getMessage('flags.sort.summary'),
}),
};

public async run(): Promise<RepositoryResult> {
const { flags } = await this.parse(Repositories);
const repositories = await retrieveKnownRepositories();
const ux = new Ux({ jsonEnabled: flags.json ?? false });

if (!flags.json) {
ux.table(
repositories,
{
organization: {},
name: {},
url: {},
packages: {
get: (row: RepositoryInfo): string => row.packages.map((pkg) => `${pkg.type} ${pkg.name}`).join('\n'),
extended: true,
},
ux.table(
repositories,
{
organization: {},
name: {},
url: {},
packages: {
get: (row: RepositoryInfo): string => row.packages.map((pkg) => `${pkg.type} ${pkg.name}`).join('\n'),
extended: true,
},
{
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
printLine: this.log.bind(this),
...flags, // parsed flags
}
);
}
},
{
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
printLine: this.log.bind(this),
...flags, // parsed flags
}
);

return repositories;
}
}
6 changes: 3 additions & 3 deletions src/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { Env } from '@salesforce/kit';
import { OutputFlags } from '@oclif/core/lib/interfaces/parser.js';
import { OutputFlags } from '@oclif/core/parser';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type Flags = OutputFlags<any>;
Expand All @@ -16,14 +16,14 @@ type Dependency = {
name: string;
type: DependencyType;
condition?: ConditionFn;
}
};

type Result = {
name: string;
type: DependencyType;
passed: boolean;
message?: string;
}
};

const DEPENDENCIES: Dependency[] = [
{
Expand Down
Loading
Loading