-
-
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: guijs plugin & refactor to
defaultTemplate
- Loading branch information
Guillaume Chau
committed
Jul 27, 2019
1 parent
400ebed
commit 655e265
Showing
18 changed files
with
475 additions
and
93 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
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
34 changes: 31 additions & 3 deletions
34
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 |
---|---|---|
@@ -1,22 +1,50 @@ | ||
/** @type {import('../ProjectCreateJob').CreateModule} */ | ||
module.exports = api => { | ||
const featureName = 'Typescript' | ||
|
||
api.injectFeature({ | ||
name: 'Typescript', | ||
name: featureName, | ||
value: 'ts', | ||
// @ts-ignore | ||
description: 'Add support for the TypeScript language', | ||
link: 'https://github.com/Akryum/nodepack/tree/dev/packages/%40nodepack/plugin-typescript', | ||
}) | ||
|
||
api.injectPrompt({ | ||
name: 'useTsWithBabel', | ||
when: answers => answers.features.includes('ts'), | ||
when: answers => answers.features.includes('ts') && answers.features.includes('babel'), | ||
type: 'confirm', | ||
message: 'Use Babel alongside TypeScript for auto-detected polyfills?', | ||
default: answers => answers.features.includes('babel'), | ||
// @ts-ignore | ||
description: 'It will output ES2015 and delegate the rest to Babel for auto polyfill based on compilation targets.', | ||
default: true, | ||
// @ts-ignore | ||
group: featureName, | ||
}) | ||
|
||
api.injectPrompt({ | ||
name: 'useTsLint', | ||
when: answers => answers.features.includes('ts'), | ||
type: 'confirm', | ||
message: 'Use TS Lint', | ||
// @ts-ignore | ||
description: 'Checks for code quality and style.', | ||
default: true, | ||
// @ts-ignore | ||
group: featureName, | ||
}) | ||
|
||
api.onPromptComplete((answers, preset) => { | ||
if (answers.features.includes('ts')) { | ||
// @ts-ignore | ||
preset.plugins['@nodepack/plugin-typescript'] = '' | ||
} | ||
|
||
const appMigrations = preset.appMigrations['@nodepack/plugin-typescript'] = { | ||
defaultTemplate: {}, | ||
} | ||
if (answers.useTsLint) { | ||
appMigrations.defaultTemplate.tslint = true | ||
} | ||
}) | ||
} |
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,9 @@ | ||
const { | ||
loadGlobalOptions, | ||
defaultGlobalOptions, | ||
} = require('@nodepack/utils') | ||
|
||
exports.getPresets = function () { | ||
const savedOptions = loadGlobalOptions() | ||
return Object.assign({}, savedOptions.presets, defaultGlobalOptions.presets) | ||
} |
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,86 @@ | ||
/** @typedef {import('@nodepack/utils').Preset} Preset */ | ||
|
||
const path = require('path') | ||
const loadLocalPreset = require('./loadLocalPreset') | ||
const loadRemotePreset = require('./loadRemotePreset') | ||
const { | ||
loadGlobalOptions, | ||
saveGlobalOptions, | ||
logWithSpinner, | ||
stopSpinner, | ||
log, | ||
error, | ||
chalk, | ||
defaultPreset, | ||
} = require('@nodepack/utils') | ||
|
||
/** | ||
* @param {string} presetName | ||
* @param {boolean} clone | ||
*/ | ||
exports.resolvePreset = async function (presetName, clone = false) { | ||
let preset = null | ||
const savedPresets = loadGlobalOptions().presets || {} | ||
|
||
if (presetName in savedPresets) { | ||
preset = savedPresets[presetName] | ||
} else if (presetName.endsWith('.json') || /^\./.test(presetName) || path.isAbsolute(presetName)) { | ||
preset = await loadLocalPreset(path.resolve(presetName)) | ||
} else if (presetName.includes('/')) { | ||
logWithSpinner(`Fetching remote preset ${chalk.cyan(presetName)}...`) | ||
try { | ||
preset = await loadRemotePreset(presetName, clone) | ||
stopSpinner() | ||
} catch (e) { | ||
stopSpinner() | ||
error(`Failed fetching remote preset ${chalk.cyan(presetName)}:`) | ||
throw e | ||
} | ||
} | ||
|
||
// use default preset if user has not overwritten it | ||
if (presetName === 'default' && !preset) { | ||
preset = defaultPreset | ||
} | ||
if (!preset) { | ||
error(`preset "${presetName}" not found.`) | ||
const presets = Object.keys(savedPresets) | ||
if (presets.length) { | ||
log() | ||
log(`available presets:\n${presets.join(`\n`)}`) | ||
} else { | ||
log(`you don't seem to have any saved preset.`) | ||
log(`run 'nodepack create' in manual mode to create a preset.`) | ||
} | ||
process.exit(1) | ||
} | ||
return preset | ||
} | ||
|
||
exports.getPresetFromAnswers = async function (answers, promptCompleteCbs) { | ||
if (answers.packageManager) { | ||
saveGlobalOptions({ | ||
packageManager: answers.packageManager, | ||
}) | ||
} | ||
|
||
/** @type {Preset?} */ | ||
let preset | ||
if (answers.preset && answers.preset !== '__manual__') { | ||
preset = await exports.resolvePreset(answers.preset) | ||
} else { | ||
// manual | ||
preset = { | ||
useConfigFiles: answers.useConfigFiles === 'files', | ||
plugins: {}, | ||
appMigrations: {}, | ||
} | ||
answers.features = answers.features || [] | ||
// run cb registered by prompt modules to finalize the preset | ||
for (const cb of promptCompleteCbs) { | ||
await cb(answers, preset) | ||
} | ||
} | ||
|
||
return preset | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
{ | ||
"name": "@nodepack/guijs-plugin", | ||
"version": "0.2.0", | ||
"description": "Nodepack plugin for guijs", | ||
"author": "Guillaume Chau <[email protected]>", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Akryum/nodepack.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/Akryum/nodepack/issues" | ||
}, | ||
"homepage": "https://github.com/Akryum/nodepack#readme", | ||
"main": "./src/index.js", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"engines": { | ||
"node": ">=8.12" | ||
}, | ||
"scripts": { | ||
"test": "yarn test:lint", | ||
"test:lint": "eslint src" | ||
}, | ||
"dependencies": { | ||
"@nodepack/cli": "^0.2.0", | ||
"@nodepack/utils": "^0.2.0", | ||
"execa": "^1.0.0" | ||
} | ||
} |
Oops, something went wrong.