Skip to content

Commit

Permalink
Upgrade ADF CLI to latest Commander library (#9473)
Browse files Browse the repository at this point in the history
* build(deps-dev): bump commander from 6.2.1 to 12.0.0

Bumps [commander](https://github.com/tj/commander.js) from 6.2.1 to 12.0.0.
- [Release notes](https://github.com/tj/commander.js/releases)
- [Changelog](https://github.com/tj/commander.js/blob/master/CHANGELOG.md)
- [Commits](tj/commander.js@v6.2.1...v12.0.0)

---
updated-dependencies:
- dependency-name: commander
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore: migrate CLI to latest commander library

* chore: migrate CLI to latest commander library [ci:force]

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
DenysVuika and dependabot[bot] committed Mar 26, 2024
1 parent 7cca017 commit 9d76088
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 143 deletions.
17 changes: 13 additions & 4 deletions lib/cli/scripts/audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ import * as ejs from 'ejs';
import * as path from 'path';
import * as fs from 'fs';
import { argv, exit } from 'node:process';
import program from 'commander';
import { Command } from 'commander';

const program = new Command();

interface AuditCommandArgs {
package?: string;
outDir?: string;
}

/**
* Audit report command
Expand All @@ -44,10 +51,12 @@ export default function main(_args: string[], workingDir: string) {
exit(0);
}

const options = program.opts<AuditCommandArgs>();

let packagePath = path.resolve(workingDir, 'package.json');

if (program.package) {
packagePath = path.resolve(program.package);
if (options.package) {
packagePath = path.resolve(options.package);
}

if (!fs.existsSync(packagePath)) {
Expand Down Expand Up @@ -82,7 +91,7 @@ export default function main(_args: string[], workingDir: string) {
console.error(err);
reject(err);
} else {
const outputPath = path.resolve(program.outDir || workingDir);
const outputPath = path.resolve(options.outDir || workingDir);
const outputFile = path.join(outputPath, `audit-info-${packageJson.version}.md`);

fs.writeFileSync(outputFile, mdText);
Expand Down
10 changes: 7 additions & 3 deletions lib/cli/scripts/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import { argv, exit } from 'node:process';
import * as shell from 'shelljs';
import * as path from 'path';
import program from 'commander';
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;
Expand Down Expand Up @@ -167,8 +169,10 @@ export default function main(_args: string[], workingDir: string) {
exit(0);
}

const dir = path.resolve(program.dir || workingDir);
const { range, skip, max, format, output, exclude } = program;
const options = program.opts();

const dir = path.resolve(options.dir || workingDir);
const { range, skip, max, format, output, exclude } = options;

const remote = getRemote(dir);

Expand Down
29 changes: 21 additions & 8 deletions lib/cli/scripts/check-cs-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@

import { AlfrescoApi /*, NodesApi, UploadApi*/ } from '@alfresco/js-api';
import { argv, exit } from 'node:process';
// import { Buffer } from 'node:buffer';
const program = require('commander');
import { Command } from 'commander';
import { logger } from './logger';

interface CheckCsEnvArgs {
host?: string;
username?: string;
password?: string;
time?: number;
retry?: number;
}

const program = new Command();
const MAX_RETRY = 3;
const TIMEOUT = 20000;

let counter = 0;
let alfrescoJsApi: AlfrescoApi;

Expand All @@ -40,32 +50,35 @@ export default async function main() {
.option('-r, --retry [type]', 'retry ')
.parse(argv);

await checkEnv();
const opts = program.opts<CheckCsEnvArgs>();
await checkEnv(opts);
// TODO: https://alfresco.atlassian.net/browse/ACS-5873
// await checkDiskSpaceFullEnv();
}

/**
* Check environment
*
* @param opts command options
*/
async function checkEnv() {
async function checkEnv(opts?: CheckCsEnvArgs) {
try {
alfrescoJsApi = new AlfrescoApi({
provider: 'ECM',
hostEcm: program.host,
hostEcm: opts.host,
contextRoot: 'alfresco'
});

await alfrescoJsApi.login(program.username, program.password);
await alfrescoJsApi.login(opts.username, opts.password);
} catch (error) {
if (error?.error?.code === 'ETIMEDOUT') {
logger.error('The env is not reachable. Terminating');
exit(1);
}
logger.error('Login error environment down or inaccessible');
counter++;
const retry = program.retry || MAX_RETRY;
const time = program.time || TIMEOUT;
const retry = opts.retry || MAX_RETRY;
const time = opts.time || TIMEOUT;
if (retry === counter) {
logger.error('Give up');
exit(1);
Expand Down
58 changes: 38 additions & 20 deletions lib/cli/scripts/check-plugin-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,25 @@
*/

import { argv } from 'node:process';
import { PluginTarget } from './plugins/plugin-model';
import { CheckEnv } from './plugins/check-env';
import program = require('commander');
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 {
host?: string;
pluginName?: 'processService' | 'processAutomation' | 'governance';
clientId?: string;
appName?: string;
username?: string;
password?: string;
uiName?: string;
}

/**
* Check environment plugin
*/
Expand All @@ -40,30 +50,34 @@ export default async function main() {
.option('--ui, --uiName [type]', 'uiName', 'Deployed app UI type on activiti-cloud')
.parse(argv);

pluginEnv = new CheckEnv(program.host, program.username, program.password, program.clientId);
const options = program.opts<CheckPluginArgs>();

pluginEnv = new CheckEnv(options.host, options.username, options.password, options.clientId);
await pluginEnv.checkEnv();

if (program.pluginName === PluginTarget.processService) {
await checkProcessServicesPlugin();
if (options.pluginName === 'processService') {
await checkProcessServicesPlugin(options);
}

if (program.pluginName === PluginTarget.processAutomation) {
await checkProcessAutomationPlugin();
if (options.pluginName === 'processAutomation') {
await checkProcessAutomationPlugin(options);
}

if (program.pluginName === PluginTarget.governance) {
await checkGovernancePlugin();
if (options.pluginName === 'governance') {
await checkGovernancePlugin(options);
}
}

/**
* Check PS plugin
*
* @param options program arguments
*/
async function checkProcessServicesPlugin() {
async function checkProcessServicesPlugin(options: CheckPluginArgs) {
const processServiceCheckPlugin = new ProcessServiceCheckPlugin(
{
host: program.host,
name: PluginTarget.processService
host: options.host,
name: 'processService'
},
pluginEnv.alfrescoJsApi
);
Expand All @@ -72,14 +86,16 @@ async function checkProcessServicesPlugin() {

/**
* Check APA plugin
*
* @param options program arguments
*/
async function checkProcessAutomationPlugin() {
async function checkProcessAutomationPlugin(options: CheckPluginArgs) {
const processAutomationCheckPlugin = new ProcessAutomationCheckPlugin(
{
host: program.host,
name: PluginTarget.processAutomation,
appName: program.appName,
uiName: program.uiName
host: options.host,
name: 'processAutomation',
appName: options.appName,
uiName: options.uiName
},
pluginEnv.alfrescoJsApi
);
Expand All @@ -88,12 +104,14 @@ async function checkProcessAutomationPlugin() {

/**
* Check AGS plugin
*
* @param options program arguments
*/
async function checkGovernancePlugin() {
async function checkGovernancePlugin(options: CheckPluginArgs) {
const governancePluginCheck = new GovernanceCheckPlugin(
{
host: program.host,
name: PluginTarget.governance
host: options.host,
name: 'governance'
},
pluginEnv.alfrescoJsApi
);
Expand Down
4 changes: 3 additions & 1 deletion lib/cli/scripts/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

import { argv, exit } from 'node:process';
import { exec } from './exec';
import program from 'commander';
import { Command } from 'commander';
import { logger } from './logger';
import { resolve } from 'path';

const program = new Command();

// eslint-disable-next-line no-shadow
enum TARGETS {
publish = 'publish',
Expand Down
34 changes: 20 additions & 14 deletions lib/cli/scripts/init-aae-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@
* limitations under the License.
*/

import program from 'commander';
import { Command } from 'commander';
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;
let alfrescoJsApiDevops: AlfrescoApi;
let args: ConfigArgs;
let isValid = true;

export interface ConfigArgs {
modelerUsername: string;
modelerPassword: string;
Expand Down Expand Up @@ -424,7 +427,7 @@ function deploy(model: any) {
* @param options token options
* @returns options
*/
function initializeDefaultToken(options: any): any {
function initializeDefaultToken(options: ConfigArgs): any {
options.tokenEndpoint = options.tokenEndpoint.replace('${clientId}', options.clientId);
return options;
}
Expand Down Expand Up @@ -680,18 +683,21 @@ async function getFileFromRemote(url: string, name: string): Promise<void> {
}
return response;
})
.then((response) => new Promise<void>((resolve, reject) => {
const outputFile = fs.createWriteStream(`${name}.zip`);
response.body.pipe(outputFile);
outputFile.on('finish', () => {
logger.info(`The file is finished downloading.`);
resolve();
});
outputFile.on('error', (error) => {
logger.error(`Not possible to download the project form remote`);
reject(error);
});
}))
.then(
(response) =>
new Promise<void>((resolve, reject) => {
const outputFile = fs.createWriteStream(`${name}.zip`);
response.body.pipe(outputFile);
outputFile.on('finish', () => {
logger.info(`The file is finished downloading.`);
resolve();
});
outputFile.on('error', (error) => {
logger.error(`Not possible to download the project form remote`);
reject(error);
});
})
)
.catch((error) => {
logger.error(`Failed to fetch file from remote: ${error.message}`);
throw error;
Expand Down

0 comments on commit 9d76088

Please sign in to comment.