-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(wip): support new options #37
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as inquirer from 'inquirer'; | ||
|
||
export async function promptInput({ | ||
name, message, defaultAnswer, | ||
}: {name: string; message: string; defaultAnswer: string}): Promise<inquirer.Answers> { | ||
return inquirer.createPromptModule()([{type: 'input', name, message, default: defaultAnswer}]); | ||
} | ||
|
||
export async function promptSelect({ | ||
name, message, choices, defaultAnswer, | ||
}: {name: string; message: string; choices: string[]; defaultAnswer: string}): Promise<inquirer.Answers> { | ||
return inquirer.createPromptModule({})([{type: 'select', name, message, choices, default: defaultAnswer}]); | ||
} | ||
Comment on lines
+1
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To remove |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {GenericRunner} from './generic.runner'; | ||
|
||
export class NestJsRunner extends GenericRunner { | ||
private static getNestJsCliPath(): string { | ||
return require.resolve( | ||
'@nestjs/cli/bin/nest.js', | ||
{paths: module.paths}, | ||
); | ||
} | ||
|
||
// private static formatNewOptions(options: string[]): string { | ||
// const formattedOptions = options.filter(Boolean).join(' '); | ||
// if (options.includes('--skip-install')) { | ||
// return formattedOptions; | ||
// } | ||
// | ||
// return `${formattedOptions} --skip-install`; | ||
// } | ||
// | ||
Comment on lines
+11
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To remove |
||
constructor() { | ||
super('node'); | ||
} | ||
|
||
public async generateNestApplication(name: string, options: string[]) { | ||
if (!options.includes('--skip-install')) { | ||
options.push('--skip-install'); | ||
} | ||
|
||
const args = ['new', name, ...options].filter(Boolean); | ||
console.log(args); | ||
await super.run({command: NestJsRunner.getNestJsCliPath(), args, stdio: 'inherit'}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
function removeDashesFrom(args: string[], initialIndex: number): string[] { | ||
return args.map((arg, index) => { | ||
if (index < initialIndex) { | ||
return arg; | ||
} | ||
|
||
return arg.replace(/^--|^-/, ''); | ||
}); | ||
} | ||
|
||
export function removeDashes(args: string[]): string[] { | ||
const command = args[2]; | ||
const parsingStrategies: Record<string, () => string[]> = { | ||
new() { | ||
return removeDashesFrom(args, 2); | ||
}, | ||
generate() { | ||
return removeDashesFrom(args, 5); | ||
}, | ||
default() { | ||
return args; | ||
}, | ||
}; | ||
|
||
return (parsingStrategies[command] || parsingStrategies.default)(); | ||
} | ||
|
||
export function addDashes(args: string[]): string[] { | ||
return args.map(arg => `--${arg}`); | ||
} | ||
Comment on lines
+28
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To remove |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To remove