-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): create modules, preset/feature selection
- Loading branch information
Guillaume Chau
committed
Dec 30, 2018
1 parent
a3eb078
commit c8ebcb7
Showing
8 changed files
with
192 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** @typedef {import('./Creator')} Creator */ | ||
/** @typedef {import('inquirer').ChoiceType} ChoiceType */ | ||
/** @typedef {import('inquirer').Question} Question */ | ||
/** @typedef {import('./Creator').Preset} Preset */ | ||
|
||
module.exports = class CreateModuleAPI { | ||
/** | ||
* @param {Creator} creator | ||
*/ | ||
constructor (creator) { | ||
this.creator = creator | ||
} | ||
|
||
/** | ||
* @param {ChoiceType} feature | ||
*/ | ||
injectFeature (feature) { | ||
this.creator.featurePrompt.choices.push(feature) | ||
} | ||
|
||
/** | ||
* @param {Question} prompt | ||
*/ | ||
injectPrompt (prompt) { | ||
this.creator.injectedPrompts.push(prompt) | ||
} | ||
|
||
/** | ||
* @param {(answers: any, preset: Preset) => void | Promise.<void>} cb | ||
*/ | ||
onPromptComplete (cb) { | ||
this.creator.promptCompleteCbs.push(cb) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** @type {import('../Creator').CreateModule} */ | ||
module.exports = api => { | ||
api.injectFeature({ | ||
name: 'Babel', | ||
value: 'babel', | ||
}) | ||
|
||
api.onPromptComplete((answers, preset) => { | ||
if (answers.features.includes('ts')) { | ||
if (!answers.useTsWithBabel) { | ||
return | ||
} | ||
} else if (!answers.features.includes('babel')) { | ||
return | ||
} | ||
// @ts-ignore | ||
preset.plugins['@nodepack/plugin-babel'] = '' | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
exports.getPromptModules = () => { | ||
return [ | ||
'babel', | ||
'typescript', | ||
].map(file => require(`./${file}`)) | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/@nodepack/cli/src/lib/createModules/typescript.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** @type {import('../Creator').CreateModule} */ | ||
module.exports = api => { | ||
api.injectFeature({ | ||
name: 'Typescript', | ||
value: 'ts', | ||
}) | ||
|
||
api.injectPrompt({ | ||
name: 'useTsWithBabel', | ||
when: answers => answers.features.includes('ts'), | ||
type: 'confirm', | ||
message: 'Use Babel alongside TypeScript for auto-detected polyfills?', | ||
default: answers => answers.features.includes('babel'), | ||
}) | ||
|
||
api.onPromptComplete((answers, preset) => { | ||
if (answers.features.includes('ts')) { | ||
// @ts-ignore | ||
preset.plugins['@nodepack/plugin-typescript'] = '' | ||
} | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** @typedef {import('@nodepack/utils').Preset} Preset */ | ||
|
||
const { | ||
chalk, | ||
toShortPluginId, | ||
} = require('@nodepack/utils') | ||
|
||
/** | ||
* @param {Preset} preset | ||
*/ | ||
exports.getFeatures = (preset) => { | ||
const features = [] | ||
const plugins = Object.keys(preset.plugins || []).filter(dep => { | ||
return dep !== '@nodepack/service' | ||
}) | ||
features.push.apply(features, plugins) | ||
return features | ||
} | ||
|
||
/** | ||
* @param {Preset} preset | ||
* @param {string} lead | ||
* @param {string} joiner | ||
*/ | ||
exports.formatFeatures = (preset, lead = '', joiner = ', ') => { | ||
const features = exports.getFeatures(preset) | ||
return features.map(dep => { | ||
dep = toShortPluginId(dep) | ||
return `${lead}${chalk.yellow(dep)}` | ||
}).join(joiner) | ||
} |