AAE-39314 Break dependencies on the "commander" lib in the CLI (#11299)

This commit is contained in:
Denys Vuika
2025-10-23 12:22:40 -04:00
committed by GitHub
parent 1c8af0467e
commit e202c693c1
11 changed files with 502 additions and 132 deletions
+30 -12
View File
@@ -22,9 +22,7 @@ import * as ejs from 'ejs';
import * as path from 'path';
import * as fs from 'fs';
import { argv, exit } from 'node:process';
import { Command } from 'commander';
const program = new Command();
import { parseArgs } from 'node:util';
interface AuditCommandArgs {
package?: string;
@@ -39,19 +37,39 @@ interface AuditCommandArgs {
* @returns void
*/
export default function main(_args: string[], workingDir: string) {
program
.description('Generate an audit report')
.usage('audit [options]')
.option('-p, --package <path>', 'Path to package file (default: package.json in working directory)')
.option('-d, --outDir <dir>', 'Ouput directory (default: working directory)')
.parse(argv);
if (argv.includes('-h') || argv.includes('--help')) {
program.outputHelp();
console.log(`
Usage: audit [options]
Generate an audit report
Options:
-p, --package <path> Path to package file (default: package.json in working directory)
-d, --outDir <dir> Output directory (default: working directory)
-h, --help Display help for command
`);
exit(0);
}
const options: AuditCommandArgs = program.opts();
const { values } = parseArgs({
args: argv.slice(2),
options: {
package: {
type: 'string',
short: 'p'
},
outDir: {
type: 'string',
short: 'd'
}
},
allowPositionals: true
});
const options: AuditCommandArgs = {
package: values.package as string | undefined,
outDir: values.outDir as string | undefined
};
let packagePath = path.resolve(workingDir, 'package.json');
+64 -20
View File
@@ -20,15 +20,13 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { argv, exit } from 'node:process';
import { parseArgs } from 'node:util';
import * as shell from 'shelljs';
import * as path from 'path';
import { Command } from 'commander';
import { logger } from './logger';
import * as fs from 'fs';
import * as ejs from 'ejs';
const program = new Command();
interface Commit {
hash: string;
author: string;
@@ -151,28 +149,74 @@ function commitAuthorAllowed(commit: Commit, authorFilter: string): boolean {
* @returns void
*/
export default function main(_args: string[], workingDir: string) {
program
.description('Generate changelog report for two branches of git repository')
.version('0.0.1', '-v, --version')
.usage('changelog [options]')
.option('-r, --range <range>', 'Commit range, e.g. origin/master..develop', 'origin/master..develop')
.option('-d, --dir <dir>', 'Working directory (default: working directory)')
.option('-m, --max <number>', 'Limit the number of commits to output')
.option('-o, --output <dir>', 'Output directory, will use console output if not defined')
.option('--skip <number>', 'Skip number commits before starting to show the commit output')
.option('-f, --format <format>', 'Output format (md, html)', 'md')
.option('-e --exclude <string>', 'Exclude authors from the output, comma-delimited list')
.parse(argv);
if (argv.includes('-h') || argv.includes('--help')) {
program.outputHelp();
console.log(`
Usage: changelog [options]
Generate changelog report for two branches of git repository
Options:
-v, --version Output the version number
-r, --range <range> Commit range, e.g. origin/master..develop (default: "origin/master..develop")
-d, --dir <dir> Working directory (default: working directory)
-m, --max <number> Limit the number of commits to output
-o, --output <dir> Output directory, will use console output if not defined
--skip <number> Skip number commits before starting to show the commit output
-f, --format <format> Output format (md, html) (default: "md")
-e, --exclude <string> Exclude authors from the output, comma-delimited list
-h, --help Display help for command
`);
exit(0);
}
const options = program.opts();
if (argv.includes('-v') || argv.includes('--version')) {
console.log('0.0.1');
exit(0);
}
const dir = path.resolve(options.dir || workingDir);
const { range, skip, max, format, output, exclude } = options;
const { values } = parseArgs({
args: argv.slice(2),
options: {
range: {
type: 'string',
short: 'r',
default: 'origin/master..develop'
},
dir: {
type: 'string',
short: 'd'
},
max: {
type: 'string',
short: 'm'
},
output: {
type: 'string',
short: 'o'
},
skip: {
type: 'string'
},
format: {
type: 'string',
short: 'f',
default: 'md'
},
exclude: {
type: 'string',
short: 'e'
}
},
allowPositionals: true
});
const dir = path.resolve((values.dir as string) || workingDir);
const range = values.range as string;
const skip = values.skip ? parseInt(values.skip as string, 10) : undefined;
const max = values.max ? parseInt(values.max as string, 10) : undefined;
const format = values.format as string;
const output = values.output as string | undefined;
const exclude = values.exclude as string | undefined;
const remote = getRemote(dir);
+57 -14
View File
@@ -17,7 +17,7 @@
import { AlfrescoApi /*, NodesApi, UploadApi*/ } from '@alfresco/js-api';
import { argv, exit } from 'node:process';
import { Command } from 'commander';
import { parseArgs } from 'node:util';
import { logger } from './logger';
interface CheckCsEnvArgs {
@@ -27,8 +27,6 @@ interface CheckCsEnvArgs {
time?: number;
retry?: number;
}
const program = new Command();
const MAX_RETRY = 3;
const TIMEOUT = 20000;
@@ -39,18 +37,63 @@ let alfrescoJsApi: AlfrescoApi;
* Check CS environment command
*/
export default async function main() {
program
.version('0.1.0')
.description('Check Content service is up ')
.usage('check-cs-env [options]')
.option('--host [type]', 'Remote environment host adf.lab.com ')
.option('-p, --password [type]', 'password ')
.option('-u, --username [type]', 'username ')
.option('-t, --time [type]', 'time ')
.option('-r, --retry [type]', 'retry ')
.parse(argv);
if (argv.includes('-h') || argv.includes('--help')) {
console.log(`
Usage: check-cs-env [options]
Check Content service is up
Options:
-v, --version Output the version number
--host <host> Remote environment host adf.lab.com
-p, --password <pass> Password
-u, --username <user> Username
-t, --time <ms> Time in milliseconds
-r, --retry <num> Retry count
-h, --help Display help for command
`);
exit(0);
}
if (argv.includes('-v') || argv.includes('--version')) {
console.log('0.1.0');
exit(0);
}
const { values } = parseArgs({
args: argv.slice(2),
options: {
host: {
type: 'string'
},
password: {
type: 'string',
short: 'p'
},
username: {
type: 'string',
short: 'u'
},
time: {
type: 'string',
short: 't'
},
retry: {
type: 'string',
short: 'r'
}
},
allowPositionals: true
});
const opts: CheckCsEnvArgs = {
host: values.host as string | undefined,
username: values.username as string | undefined,
password: values.password as string | undefined,
time: values.time ? parseInt(values.time as string, 10) : undefined,
retry: values.retry ? parseInt(values.retry as string, 10) : undefined
};
const opts = program.opts();
await checkEnv(opts);
// TODO: https://alfresco.atlassian.net/browse/ACS-5873
// await checkDiskSpaceFullEnv();
+69 -14
View File
@@ -15,14 +15,13 @@
* limitations under the License.
*/
import { argv } from 'node:process';
import { argv, exit } from 'node:process';
import { parseArgs } from 'node:util';
import { CheckEnv } from './plugins/check-env';
import { Command } from 'commander';
import { ProcessServiceCheckPlugin } from './plugins/process-service-check-plugin';
import { ProcessAutomationCheckPlugin } from './plugins/process-automation-check-plugin';
import { GovernanceCheckPlugin } from './plugins/governance-check-plugin';
const program = new Command();
let pluginEnv: CheckEnv;
interface CheckPluginArgs {
@@ -39,18 +38,74 @@ interface CheckPluginArgs {
* Check environment plugin
*/
export default async function main() {
program
.version('0.1.0')
.option('--host [type]', 'Remote environment host')
.option('--pluginName [type]', 'pluginName')
.option('--clientId [type]', 'sso client', 'alfresco')
.option('--appName [type]', 'appName ', 'Deployed appName on activiti-cloud')
.option('-p, --password [type]', 'password ')
.option('-u, --username [type]', 'username ')
.option('--ui, --uiName [type]', 'uiName', 'Deployed app UI type on activiti-cloud')
.parse(argv);
if (argv.includes('-h') || argv.includes('--help')) {
console.log(`
Usage: check-plugin-env [options]
const options = program.opts();
Check plugin status
Options:
-v, --version Output the version number
--host <host> Remote environment host
--pluginName <name> Plugin name (processService, processAutomation, governance)
--clientId <id> SSO client (default: "alfresco")
--appName <name> Deployed appName on activiti-cloud
-p, --password <pass> Password
-u, --username <user> Username
--ui, --uiName <name> Deployed app UI type on activiti-cloud
-h, --help Display help for command
`);
exit(0);
}
if (argv.includes('-v') || argv.includes('--version')) {
console.log('0.1.0');
exit(0);
}
const { values } = parseArgs({
args: argv.slice(2),
options: {
host: {
type: 'string'
},
pluginName: {
type: 'string'
},
clientId: {
type: 'string',
default: 'alfresco'
},
appName: {
type: 'string'
},
password: {
type: 'string',
short: 'p'
},
username: {
type: 'string',
short: 'u'
},
ui: {
type: 'string'
},
uiName: {
type: 'string'
}
},
allowPositionals: true
});
const options: CheckPluginArgs = {
host: values.host as string | undefined,
pluginName: values.pluginName as 'processService' | 'processAutomation' | 'governance' | undefined,
clientId: values.clientId as string | undefined,
appName: values.appName as string | undefined,
username: values.username as string | undefined,
password: values.password as string | undefined,
uiName: (values.ui || values.uiName) as string | undefined
};
pluginEnv = new CheckEnv(options.host, options.username, options.password, options.clientId);
await pluginEnv.checkEnv();
+94 -25
View File
@@ -17,14 +17,12 @@
* limitations under the License.
*/
import { Command } from 'commander';
import { parseArgs } from 'node:util';
import fetch from 'node-fetch';
import * as fs from 'fs';
import { logger } from './logger';
import { AlfrescoApi, AlfrescoApiConfig } from '@alfresco/js-api';
import { argv, exit } from 'node:process';
const program = new Command();
const ACTIVITI_CLOUD_APPS = require('./resources').ACTIVITI_CLOUD_APPS;
let alfrescoJsApiModeler: AlfrescoApi;
@@ -730,32 +728,103 @@ async function sleep(time: number) {
* Init AAE environment command
*/
export default async function main() {
program
.version('0.1.0')
.description(
'The following command is in charge of Initializing the activiti cloud env with the default apps' +
'adf-cli init-aae-env --host "gateway_env" --modelerUsername "modelerusername" --modelerPassword "modelerpassword" --devopsUsername "devevopsusername" --devopsPassword "devopspassword"'
)
.option('-h, --host [type]', 'Host gateway')
.option('--oauth [type]', 'SSO host')
.option('--clientId [type]', 'sso client')
.option('--secret [type]', 'sso secret', '')
.option('--scope [type]', 'sso scope', 'openid')
.option('--tokenEndpoint [type]', 'discovery token Endpoint', 'auth/realms/${clientId}/protocol/openid-connect/token')
.option('--modelerUsername [type]', 'username of a user with role ACTIVIT_MODELER')
.option('--modelerPassword [type]', 'modeler password')
.option('--devopsUsername [type]', 'username of a user with role ACTIVIT_DEVOPS')
.option('--devopsPassword [type]', 'devops password')
.option('--tag [type]', 'tag name of the codebase')
.option('--envs [type...]', 'environment ids of the envs where to deploy the app')
.parse(argv);
if (argv.includes('--help')) {
console.log(`
Usage: init-aae-env [options]
if (argv.includes('-h') || argv.includes('--help')) {
program.outputHelp();
Initialize the activiti cloud env with the default apps
Example:
adf-cli init-aae-env --host "gateway_env" --modelerUsername "modelerusername" \\
--modelerPassword "modelerpassword" --devopsUsername "devopsusername" \\
--devopsPassword "devopspassword"
Options:
-v, --version Output the version number
-h, --host <host> Host gateway
--oauth <host> SSO host
--clientId <id> SSO client
--secret <secret> SSO secret (default: "")
--scope <scope> SSO scope (default: "openid")
--tokenEndpoint <endpoint> Discovery token endpoint (default: "auth/realms/\${clientId}/protocol/openid-connect/token")
--modelerUsername <username> Username of a user with role ACTIVIT_MODELER
--modelerPassword <password> Modeler password
--devopsUsername <username> Username of a user with role ACTIVIT_DEVOPS
--devopsPassword <password> Devops password
--tag <tag> Tag name of the codebase
--envs <envs...> Environment ids of the envs where to deploy the app
--help Display help for command
`);
return;
}
const options = initializeDefaultToken(program.opts() as ConfigArgs);
if (argv.includes('-v') || argv.includes('--version')) {
console.log('0.1.0');
exit(0);
}
const { values } = parseArgs({
args: argv.slice(2),
options: {
host: {
type: 'string',
short: 'h'
},
oauth: {
type: 'string'
},
clientId: {
type: 'string'
},
secret: {
type: 'string',
default: ''
},
scope: {
type: 'string',
default: 'openid'
},
tokenEndpoint: {
type: 'string',
default: 'auth/realms/${clientId}/protocol/openid-connect/token'
},
modelerUsername: {
type: 'string'
},
modelerPassword: {
type: 'string'
},
devopsUsername: {
type: 'string'
},
devopsPassword: {
type: 'string'
},
tag: {
type: 'string'
},
envs: {
type: 'string',
multiple: true
}
},
allowPositionals: true
});
const options = initializeDefaultToken({
host: values.host as string,
oauth: values.oauth as string,
clientId: values.clientId as string,
secret: values.secret as string,
scope: values.scope as string,
tokenEndpoint: values.tokenEndpoint as string,
modelerUsername: values.modelerUsername as string,
modelerPassword: values.modelerPassword as string,
devopsUsername: values.devopsUsername as string,
devopsPassword: values.devopsPassword as string,
tag: values.tag as string,
envs: (values.envs as string[]) || []
} as ConfigArgs);
args = {
host: options.host,
+51 -11
View File
@@ -17,7 +17,7 @@
import { AlfrescoApi, SharedlinksApi, FavoritesApi, NodesApi, UploadApi, NodeEntry } from '@alfresco/js-api';
import { exit, argv } from 'node:process';
import { Command } from 'commander';
import { parseArgs } from 'node:util';
import { createReadStream } from 'fs';
import * as path from 'path';
import { logger } from './logger';
@@ -28,8 +28,6 @@ interface InitAcsEnvArgs {
username?: string;
password?: string;
}
const program = new Command();
const MAX_RETRY = 10;
let counter = 0;
const TIMEOUT = 6000;
@@ -41,15 +39,57 @@ let alfrescoJsApi: AlfrescoApi;
* Init ACS environment command
*/
export default async function main() {
program
.version('0.1.0')
.option('--host [type]', 'Remote environment host')
.option('--clientId [type]', 'sso client', 'alfresco')
.option('-p, --password [type]', 'password ')
.option('-u, --username [type]', 'username ')
.parse(argv);
if (argv.includes('-h') || argv.includes('--help')) {
console.log(`
Usage: init-acs-env [options]
Initialize ACS environment
Options:
-v, --version Output the version number
--host <host> Remote environment host
--clientId <id> SSO client (default: "alfresco")
-p, --password <pass> Password
-u, --username <user> Username
-h, --help Display help for command
`);
exit(0);
}
if (argv.includes('-v') || argv.includes('--version')) {
console.log('0.1.0');
exit(0);
}
const { values } = parseArgs({
args: argv.slice(2),
options: {
host: {
type: 'string'
},
clientId: {
type: 'string',
default: 'alfresco'
},
password: {
type: 'string',
short: 'p'
},
username: {
type: 'string',
short: 'u'
}
},
allowPositionals: true
});
const opts: InitAcsEnvArgs = {
host: values.host as string | undefined,
clientId: values.clientId as string | undefined,
username: values.username as string | undefined,
password: values.password as string | undefined
};
const opts = program.opts();
await checkEnv(opts);
logger.info(`***** Step initialize ACS *****`);
+59 -16
View File
@@ -26,12 +26,11 @@ import {
AppDefinitionUpdateResultRepresentation
} from '@alfresco/js-api';
import { argv, exit } from 'node:process';
import { parseArgs } from 'node:util';
import { spawnSync } from 'node:child_process';
import { createReadStream } from 'node:fs';
import { Command } from 'commander';
import * as path from 'path';
import { logger } from './logger';
import { throwError } from 'rxjs';
interface InitApsEnvArgs {
host?: string;
@@ -40,8 +39,6 @@ interface InitApsEnvArgs {
password?: string;
license?: string;
}
const program = new Command();
const MAX_RETRY = 10;
let counter = 0;
const TIMEOUT = 6000;
@@ -56,16 +53,62 @@ let alfrescoJsApi: AlfrescoApi;
* Init APS command
*/
export default async function main() {
program
.version('0.1.0')
.option('--host [type]', 'Remote environment host')
.option('--clientId [type]', 'sso client', 'alfresco')
.option('-p, --password [type]', 'password ')
.option('-u, --username [type]', 'username ')
.option('--license [type]', 'APS license S3 path ')
.parse(argv);
if (argv.includes('-h') || argv.includes('--help')) {
console.log(`
Usage: init-aps-env [options]
Initialize APS environment
Options:
-v, --version Output the version number
--host <host> Remote environment host
--clientId <id> SSO client (default: "alfresco")
-p, --password <pass> Password
-u, --username <user> Username
--license <path> APS license S3 path
-h, --help Display help for command
`);
exit(0);
}
if (argv.includes('-v') || argv.includes('--version')) {
console.log('0.1.0');
exit(0);
}
const { values } = parseArgs({
args: argv.slice(2),
options: {
host: {
type: 'string'
},
clientId: {
type: 'string',
default: 'alfresco'
},
password: {
type: 'string',
short: 'p'
},
username: {
type: 'string',
short: 'u'
},
license: {
type: 'string'
}
},
allowPositionals: true
});
const opts: InitApsEnvArgs = {
host: values.host as string | undefined,
clientId: values.clientId as string | undefined,
username: values.username as string | undefined,
password: values.password as string | undefined,
license: values.license as string | undefined
};
const opts = program.opts();
await checkEnv(opts);
logger.info(`***** Step 1 - Check License *****`);
@@ -207,9 +250,9 @@ async function hasDefaultTenant(tenantId: number, tenantName: string): Promise<b
logger.info(`Aps: has default tenantId: ${tenantId} and name ${tenantName}`);
return true;
} else {
logger.info(`Wrong configuration. Another tenant has been created with id ${tenant.id} and name ${tenant.name}`);
throwError(`Wrong configuration. Another tenant has been created with id ${tenant.id} and name ${tenant.name}`);
return false;
const errorMessage = `Wrong configuration. Another tenant has been created with id ${tenant.id} and name ${tenant.name}`;
logger.error(errorMessage);
throw new Error(errorMessage);
}
}
+31 -12
View File
@@ -18,14 +18,12 @@
*/
import { argv, exit } from 'node:process';
import { parseArgs } from 'node:util';
import * as path from 'path';
import * as fs from 'fs';
import * as checker from 'license-checker';
import * as licenseList from 'spdx-license-list';
import * as ejs from 'ejs';
import { Command } from 'commander';
const program = new Command();
interface LicensesCommandArgs {
package?: string;
@@ -103,19 +101,40 @@ function getPackageFile(packagePath: string): PackageInfo {
* @returns void function
*/
export default function main(_args: string[], workingDir: string) {
program
.description('Generate a licences report')
.usage('licenses [options]')
.option('-p, --package <path>', 'Path to package file (default: package.json in working directory)')
.option('-d, --outDir <dir>', 'Ouput directory (default: working directory)')
.parse(argv);
if (argv.includes('-h') || argv.includes('--help')) {
program.outputHelp();
console.log(`
Usage: licenses [options]
Generate a licenses report
Options:
-p, --package <path> Path to package file (default: package.json in working directory)
-d, --outDir <dir> Output directory (default: working directory)
-h, --help Display help for command
`);
exit(0);
}
const options: LicensesCommandArgs = program.opts();
const { values } = parseArgs({
args: argv.slice(2),
options: {
package: {
type: 'string',
short: 'p'
},
outDir: {
type: 'string',
short: 'd'
}
},
allowPositionals: true
});
const options: LicensesCommandArgs = {
package: values.package as string | undefined,
outDir: values.outDir as string | undefined
};
let packagePath = path.resolve(workingDir, 'package.json');
if (options.package) {