mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ACS-5987] improved security for shell scripts (#8889)
* improved security for node process functions * improved security for node process functions * remove unused file from demo shell * restore regex * fix regex * update escaping * lint fixes * fix typo * fix export * fix exports * fix lint * fix lint
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { argv } from 'node:process';
|
||||
import program from 'commander';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
@@ -46,8 +47,8 @@ function parseAlfrescoLibs(workingDir: string): PackageInfo {
|
||||
const json = require(packagePath);
|
||||
const isAlfrescoLib = (key: string) => key.startsWith('@alfresco');
|
||||
|
||||
dependencies = Object.keys((json.dependencies || [])).filter(isAlfrescoLib);
|
||||
devDependencies = Object.keys((json.devDependencies || [])).filter(isAlfrescoLib);
|
||||
dependencies = Object.keys(json.dependencies || []).filter(isAlfrescoLib);
|
||||
devDependencies = Object.keys(json.devDependencies || []).filter(isAlfrescoLib);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -57,10 +58,7 @@ function parseAlfrescoLibs(workingDir: string): PackageInfo {
|
||||
}
|
||||
|
||||
function formatNpmCommand(deps: string[], tag: string): string {
|
||||
return [
|
||||
'npm i -E',
|
||||
deps.map(name => `${name}@${tag}`).join(' ')
|
||||
].join(' ');
|
||||
return ['npm i -E', deps.map((name) => `${name}@${tag}`).join(' ')].join(' ');
|
||||
}
|
||||
|
||||
function runNpmCommand(command: string, workingDir: string) {
|
||||
@@ -72,23 +70,17 @@ function runNpmCommand(command: string, workingDir: string) {
|
||||
|
||||
function updateLibs(pkg: PackageInfo, tag: string, workingDir: string) {
|
||||
if (pkg.dependencies && pkg.dependencies.length > 0) {
|
||||
runNpmCommand(
|
||||
formatNpmCommand(pkg.dependencies, tag),
|
||||
workingDir
|
||||
);
|
||||
runNpmCommand(formatNpmCommand(pkg.dependencies, tag), workingDir);
|
||||
}
|
||||
|
||||
if (pkg.devDependencies && pkg.devDependencies.length > 0) {
|
||||
runNpmCommand(
|
||||
formatNpmCommand(pkg.devDependencies, tag) + ' -D',
|
||||
workingDir
|
||||
);
|
||||
runNpmCommand(formatNpmCommand(pkg.devDependencies, tag) + ' -D', workingDir);
|
||||
}
|
||||
}
|
||||
|
||||
function parseTag(args: UpdateArgs): string {
|
||||
if (args.alpha) {
|
||||
return 'alpha';
|
||||
return 'alpha';
|
||||
}
|
||||
|
||||
if (args.beta) {
|
||||
@@ -100,17 +92,19 @@ function parseTag(args: UpdateArgs): string {
|
||||
|
||||
export default function main(args: UpdateArgs, workingDir: string) {
|
||||
program
|
||||
.description('This command allows you to update the adf dependencies and js-api with different versions\n\n' +
|
||||
'Update adf libs and js-api with latest alpha\n\n' +
|
||||
'adf-cli update-version --alpha')
|
||||
.description(
|
||||
'This command allows you to update the adf dependencies and js-api with different versions\n\n' +
|
||||
'Update adf libs and js-api with latest alpha\n\n' +
|
||||
'adf-cli update-version --alpha'
|
||||
)
|
||||
.option('--pathPackage [dir]', 'Directory that contains package.json file', 'current directory')
|
||||
.option('--alpha', 'use alpha')
|
||||
.option('--beta', 'use beta')
|
||||
.option('--version [tag]', 'use specific version can be also alpha/beta/latest', 'latest')
|
||||
.option('--vjs [tag]', 'Upgrade only JS-API to a specific version')
|
||||
.parse(process.argv);
|
||||
.parse(argv);
|
||||
|
||||
if (process.argv.includes('-h') || process.argv.includes('--help')) {
|
||||
if (argv.includes('-h') || argv.includes('--help')) {
|
||||
program.outputHelp();
|
||||
return;
|
||||
}
|
||||
@@ -118,9 +112,7 @@ export default function main(args: UpdateArgs, workingDir: string) {
|
||||
workingDir = args.pathPackage || workingDir;
|
||||
|
||||
const tag = args.vjs || parseTag(args);
|
||||
const pkg = args.vjs
|
||||
? { dependencies: ['@alfresco/js-api'] }
|
||||
: parseAlfrescoLibs(workingDir);
|
||||
const pkg = args.vjs ? { dependencies: ['@alfresco/js-api'] } : parseAlfrescoLibs(workingDir);
|
||||
|
||||
updateLibs(pkg, tag, workingDir);
|
||||
}
|
||||
|
Reference in New Issue
Block a user