Skip to content

feat(cli): allow local .json files for presets (#1068) #1201

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

Merged
merged 2 commits into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/@vue/cli/lib/Creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const writeFileTree = require('./util/writeFileTree')
const formatFeatures = require('./util/formatFeatures')
const setupDevProject = require('./util/setupDevProject')
const fetchRemotePreset = require('./util/fetchRemotePreset')
const readLocalPreset = require('./util/readLocalPreset')

const {
defaults,
Expand Down Expand Up @@ -238,6 +239,8 @@ module.exports = class Creator {
error(`Failed fetching remote preset ${chalk.cyan(name)}:`)
throw e
}
} else if (name.endsWith('.json')) {
preset = await readLocalPreset(this.context, name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can directly use fs-extra here so it's just JSON.parse(await fs.readFile()) here, I don't think it's necessary to split into a separate file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could even just be preset = await fs.readJson(path.join(this.context, name))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good. I just followed the pattern for reading remote presets, even though it felt like overkill at the time. Will update PR

} else {
preset = savedPresets[name]
}
Expand Down
8 changes: 8 additions & 0 deletions packages/@vue/cli/lib/util/readLocalPreset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const fs = require('fs')
const { promisify } = require('util')
const read = promisify(fs.readFile)

module.exports = async function readLocalPreset (dir, preset) {
const json = await read(preset)
return JSON.parse(json)
}