Skip to content

Commit

Permalink
Merge pull request #1810 from z3bra5hax/feature/add-action-skip-install
Browse files Browse the repository at this point in the history
feat(cli): allow skip-install for add
  • Loading branch information
kamilmysliwiec committed Oct 27, 2022
2 parents cc779d8 + 76b282e commit 3fac85c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion actions/add.action.ts
Expand Up @@ -14,6 +14,7 @@ import { MESSAGES } from '../lib/ui';
import { loadConfiguration } from '../lib/utils/load-configuration';
import {
askForProjectName,
hasValidOptionFlag,
moveDefaultProjectToStart,
shouldAskForProject
} from '../lib/utils/project-utils';
Expand All @@ -27,7 +28,8 @@ export class AddAction extends AbstractAction {
const packageName = this.getPackageName(libraryName);
const collectionName = this.getCollectionName(libraryName, packageName);
const tagName = this.getTagName(packageName);
const packageInstallSuccess = await this.installPackage(
const skipInstall = hasValidOptionFlag('skip-install', options);
const packageInstallSuccess = skipInstall || await this.installPackage(
collectionName,
tagName,
);
Expand Down
2 changes: 2 additions & 0 deletions commands/add.command.ts
Expand Up @@ -13,11 +13,13 @@ export class AddCommand extends AbstractCommand {
'-d, --dry-run',
'Report actions that would be performed without writing out results.',
)
.option('-s, --skip-install', 'Skip package installation.', false)
.option('-p, --project [project]', 'Project in which to generate files.')
.usage('<library> [options] [library-specific-options]')
.action(async (library: string, command: Command) => {
const options: Input[] = [];
options.push({ name: 'dry-run', value: !!command.dryRun });
options.push({ name: 'skip-install', value: command.skipInstall });
options.push({
name: 'project',
value: command.project,
Expand Down
7 changes: 7 additions & 0 deletions lib/utils/project-utils.ts
@@ -1,5 +1,6 @@
import * as inquirer from 'inquirer';
import { Answers, Question } from 'inquirer';
import { Input } from '../../commands';
import { getValueOrDefault } from '../compiler/helpers/get-value-or-default';
import { Configuration, ProjectConfiguration } from '../configuration';
import { generateSelect } from '../questions/questions';
Expand Down Expand Up @@ -93,3 +94,9 @@ export function moveDefaultProjectToStart(
projects.unshift(defaultProjectName);
return projects;
}

export function hasValidOptionFlag(queriedOptionName: string, options: Input[], queriedValue: string|number|boolean = true): boolean {
return options.some(
(option: Input) => option.name === queriedOptionName && option.value === queriedValue
);
}

0 comments on commit 3fac85c

Please sign in to comment.