Skip to content

Commit

Permalink
Merge pull request #530 from Sikora00/feature/directory-option
Browse files Browse the repository at this point in the history
feat(cli): add directory option to the application schematic
  • Loading branch information
kamilmysliwiec committed Jan 13, 2020
2 parents 184c6c9 + 4a2ee3b commit 44b4ac5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 14 additions & 2 deletions actions/new.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { AbstractAction } from './abstract.action';

export class NewAction extends AbstractAction {
public async handle(inputs: Input[], options: Input[]) {
const directoryOption = options.find(option => option.name === 'directory');
const dryRunOption = options.find(option => option.name === 'dry-run');
const isDryRunEnabled = dryRunOption && dryRunOption.value;

Expand All @@ -38,8 +39,9 @@ export class NewAction extends AbstractAction {
const shouldSkipGit = options.some(
option => option.name === 'skip-git' && option.value === true,
);
const projectDirectory = dasherize(
getApplicationNameInput(inputs)!.value as string,
const projectDirectory = getProjectDirectory(
getApplicationNameInput(inputs)!,
directoryOption,
);

if (!shouldSkipInstall) {
Expand All @@ -64,6 +66,16 @@ export class NewAction extends AbstractAction {
const getApplicationNameInput = (inputs: Input[]) =>
inputs.find(input => input.name === 'name');

const getProjectDirectory = (
applicationName: Input,
directoryOption?: Input,
): string => {
return (
(directoryOption && (directoryOption.value as string)) ||
dasherize(applicationName.value as string)
);
};

const askForMissingInformation = async (inputs: Input[]) => {
console.info(MESSAGES.PROJECT_INFORMATION_START);
console.info();
Expand Down
2 changes: 2 additions & 0 deletions commands/new.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class NewCommand extends AbstractCommand {
.command('new [name]')
.alias('n')
.description('Generate Nest application.')
.option('--directory [directory]', 'Specify the destination directory')
.option(
'-d, --dry-run',
'Report actions that would be performed without writing out results.',
Expand All @@ -29,6 +30,7 @@ export class NewCommand extends AbstractCommand {
)
.action(async (name: string, command: Command) => {
const options: Input[] = [];
options.push({ name: 'directory', value: command.directory });
options.push({ name: 'dry-run', value: !!command.dryRun });
options.push({ name: 'skip-git', value: !!command.skipGit });
options.push({ name: 'skip-install', value: !!command.skipInstall });
Expand Down

0 comments on commit 44b4ac5

Please sign in to comment.