Files
vue-cli/packages/@vue/cli/lib/util/loadPresetFromDir.js
T

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
}