mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-05-02 18:09:38 -05:00
23 lines
702 B
JavaScript
23 lines
702 B
JavaScript
const path = require('path')
|
|
const fs = require('fs-extra')
|
|
|
|
module.exports = async function loadPresetFromDir (dir) {
|
|
const presetPath = path.join(dir, 'preset.json')
|
|
if (!fs.existsSync(presetPath)) {
|
|
throw new Error('remote / local preset does not contain preset.json!')
|
|
}
|
|
const preset = await fs.readJson(presetPath)
|
|
|
|
// if the preset dir contains generator.js, we will inject it as a hidden
|
|
// plugin so it will be invoked by the generator.
|
|
const generatorPath = path.join(dir, 'generator.js')
|
|
if (fs.existsSync(generatorPath)) {
|
|
(preset.plugins || (preset.plugins = {}))[dir.replace(/[\/]$/, '')] = {
|
|
_isPreset: true,
|
|
prompts: true
|
|
}
|
|
}
|
|
|
|
return preset
|
|
}
|