10 examples of 'npm commander' in JavaScript

Every line of 'npm commander' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
6module.exports = function npm(command, args, options, runOptions) {
7 function constructCommand(_command, _args, _options) {
8 let cmd = 'npm ';
9 const arg = _args.join(' ');
10 const cmdOptions = Object.assign({}, _options, {
11 // loglevel: 'error',
12 });
13
14 cmd += `${_command} ${arg}`;
15
16 _.forEach(cmdOptions, (value, key) => {
17 if (!value) {
18 cmd += ` --${key} ${value}`;
19 } else {
20 cmd += ` --${key}`;
21 }
22 });
23 return cmd;
24 }
25
26 const cmd = constructCommand(command, args, options);
27 const cmdRunOptions = {};
28
29 if (runOptions && runOptions.dir) {
30 cmdRunOptions.cwd = runOptions.dir;
31 }
32
33 return exec(cmd, cmdRunOptions);
34};
45async function npm(command,dir){
46 if(dir)
47 await exec(`npm --prefix ${dir} ${command}`);
48 else
49 await exec(`npm ${command}`);
50}
30function setCommandOptions(command: commander.Command) {
31 return command
32 .version(version, "-v, --version")
33 .usage("[options] files...")
34 .option("-f, --fix-in-place", "Fix the file in-place.")
35 .option("--provideRoots ", "Root namespaces to provide separated by comma.", list)
36 .option("--namespaceMethods ", "DEPRECATED: Use --namespaces", list)
37 .option("--namespaces ", "Provided namespaces separated by comma.", list)
38 .option(
39 "--replaceMap ",
40 'Methods or properties to namespaces mapping like "before1:after1,before2:after2".',
41 map
42 )
43 .option(
44 "--useForwardDeclare",
45 "Use goog.forwardDeclare() instead of goog.requireType().",
46 false
47 )
48 .option("--config ", ".fixclosurerc file path.")
49 .option("--depsJs ", "deps.js file paths separated by comma.", list)
50 .option("--showSuccess", "Show success ouput.", false)
51 .option("--no-color", "Disable color highlight.");
52}
135export function npmRun({ dir }: NpmOperationOptions, command: string): Promise {
136 return exec(dir, `npm run ${command}`);
137}
424function runCommandNpm(packageDir, args) {
425 return Promise.resolve()
426 .then(() => withPatchedPackageJson(packageDir, () => {
427 return npm(packageDir, args.join(' '));
428 }));
429}
8export function npmLinkCommand({project, local, deep, verbose, yarn, here}) {
9 const noDeepLinking = deep === false;
10 // 1. clean dist folders
11 // 2.1 merge pkg json
12 // 2.2 validate pkg (main, module, types)
13 // 2.3 write pkg
14 // 3. compile ts
15 return findSubmodules(project, {local})
16 .then((opts: TsmOptions[]) => new Listr([
17 {
18 title: 'Link all submodules',
19 task: () => {
20 const linkingTasks = new Listr(
21 opts.map(opt => ({
22 title: `npm link ${opt.pkg.name} (from: ${opt.dist})`,
23 task: () => npmLink({yarn, cwd: opt.dist})
24 }))
25 );
26
27 if (noDeepLinking) {
28 return linkingTasks;
29 }
30
31 opts.filter(opt => opt.cross.length > 0)
32 .forEach(opt => opt.cross
33 .forEach(crossName => linkingTasks.add(
34 {
35 title: `npm link ${crossName} to ${opt.pkg.name} (${opt.src})`,
36 task: () => npmLink({yarn, cwd: opt.dist, module: crossName})
37 }
38 )));
39 return linkingTasks;
40 }
41 },
42 {
43 title: 'Link submodules to local project',
44 task: () => new Listr(
45 opts.map(opt => ({
46 title: `npm link ${opt.pkg.name}`,
47 task: () => npmLink({yarn, module: opt.pkg.name, cwd: '.'})
48 }))
49 ),
50 skip: () => here !== true
51
52 }
53 ], {renderer: verbose ? 'verbose' : 'default'}));
54}
18function cli(args) {
19 const { _: [command] } = args;
20 return getModule(command).default(args)
21 .catch(err => {
22 getModule('input').emitError(err.message);
23 process.exit(1);
24 });
25}
3export function npmLink(project:string, to: string = '') {
4 return execa.shell(`cd ${project} && npm link ${to}`, [], {preferLocal: true});
5}
18public register(commander: CommanderStatic): void {
19 const logger = new WinstonLogger();
20 const command = commander
21 .command("validator")
22 .description("Start lodestar validator")
23 .action(async (options) => {
24 // library is not awaiting this method so don't allow error propagation
25 // (unhandled promise rejections)
26 try {
27 await this.action(options, logger);
28 } catch (e) {
29 logger.error(e.message + "\n" + e.stack);
30 }
31 });
32 generateCommanderOptions(command, validatorClientCliConfiguration);
33}
9constructor() {
10 program.version(embark.version);
11}

Related snippets