1
0
mirror of synced 2025-11-08 21:07:23 +00:00

feat(CLI): begin adding extra configuration options

This commit is contained in:
Jason Dreyzehner
2018-03-11 04:33:45 -04:00
parent c93c9dbb9d
commit ee930cc8e9
3 changed files with 89 additions and 31 deletions

View File

@@ -4,7 +4,7 @@ import { Runner, TypescriptStarterUserOptions, validateName } from './utils';
export async function inquire(): Promise<TypescriptStarterUserOptions> {
const packageNameQuestion: Question = {
filter: (answer: string) => answer.trim(),
message: 'Enter the new package name:',
message: '📦 Enter the new package name:',
name: 'projectName',
type: 'input',
validate: validateName
@@ -19,14 +19,14 @@ export async function inquire(): Promise<TypescriptStarterUserOptions> {
{ name: 'Node.js application', value: ProjectType.Node },
{ name: 'Javascript library', value: ProjectType.Library }
],
message: 'What are you making?',
message: '🔨 What are you making?',
name: 'type',
type: 'list'
};
const packageDescriptionQuestion: Question = {
filter: (answer: string) => answer.trim(),
message: 'Enter the package description:',
message: '💬 Enter the package description:',
name: 'description',
type: 'input',
validate: (answer: string) => answer.length > 0
@@ -37,71 +37,109 @@ export async function inquire(): Promise<TypescriptStarterUserOptions> {
{ name: 'npm', value: Runner.Npm },
{ name: 'yarn', value: Runner.Yarn }
],
message: 'Will this project use npm or yarn?',
message: '🚄 Will this project use npm or yarn?',
name: 'runner',
type: 'list'
};
enum TypeDefinitions {
none = 'none',
Node = 'node',
DOM = 'dom',
NodeAndDOM = 'both'
node = 'node',
dom = 'dom',
nodeAndDom = 'both'
}
const typeDefsQuestion: Question = {
choices: [
{
name: `None — the library won't use any globals or modules from Node.js or the DOM`,
value: '0'
value: TypeDefinitions.none
},
{
name: `Node.js — parts of the library require access to Node.js globals or built-in modules`,
value: '1'
value: TypeDefinitions.node
},
{
name: `DOM — parts of the library require access to the Document Object Model (DOM)`,
value: '2'
value: TypeDefinitions.dom
},
{
name: `Both Node.js and DOM — some parts of the library require Node.js, other parts require DOM access`,
value: '3'
value: TypeDefinitions.nodeAndDom
}
],
message: 'Which global type definitions do you want to include?',
message: '📚 Which global type definitions do you want to include?',
name: 'definitions',
type: 'list',
when: (answers: any) => answers.type === ProjectType.Library
};
enum Extras {
strict = 'strict',
immutable = 'immutable',
vscode = 'vscode'
}
const extrasQuestion: Question = {
choices: [
{
name: 'Enable stricter type-checking',
value: Extras.strict
},
{
checked: true,
name: 'Enable tslint-immutable',
value: Extras.immutable
},
{
checked: true,
name: 'Include VS Code debugging config',
value: Extras.vscode
}
],
message: '🚀 More fun stuff:',
name: 'extras',
type: 'checkbox'
};
return prompt([
packageNameQuestion,
projectTypeQuestion,
packageDescriptionQuestion,
runnerQuestion,
typeDefsQuestion
typeDefsQuestion,
extrasQuestion
]).then(answers => {
const { definitions, description, projectName, runner } = answers as {
const {
definitions,
description,
extras,
projectName,
runner
} = answers as {
readonly definitions?: TypeDefinitions;
readonly description: string;
readonly extras: ReadonlyArray<string>;
readonly projectName: string;
readonly runner: Runner;
};
return {
description,
domDefinitions: definitions
? [TypeDefinitions.DOM, TypeDefinitions.NodeAndDOM].includes(
? [TypeDefinitions.dom, TypeDefinitions.nodeAndDom].includes(
definitions
)
: false,
immutable: extras.includes(Extras.immutable),
install: true,
nodeDefinitions: definitions
? [TypeDefinitions.Node, TypeDefinitions.NodeAndDOM].includes(
? [TypeDefinitions.node, TypeDefinitions.nodeAndDom].includes(
definitions
)
: false,
projectName,
runner
runner,
strict: extras.includes(Extras.strict),
vscode: extras.includes(Extras.vscode)
};
});
}