Skip to content

Commit

Permalink
feat: read existing files during plugin invocation (close #873)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Mar 5, 2018
1 parent dbbc96b commit de60d9f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/@vue/cli/lib/invoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require('fs')
const path = require('path')
const execa = require('execa')
const chalk = require('chalk')
const globby = require('globby')
const resolve = require('resolve')
const inquirer = require('inquirer')
const Generator = require('./Generator')
Expand All @@ -27,6 +28,20 @@ function load (request, context) {
}
}

async function readFiles (context) {
const files = await globby(['**'], {
cwd: context,
onlyFiles: true,
gitignore: true,
ignore: ['**node_modules**']
})
const res = {}
for (const file of files) {
res[file] = fs.readFileSync(path.resolve(context, file), 'utf-8')
}
return res
}

async function invoke (pluginName, options = {}, context = process.cwd()) {
delete options._
const pkgPath = path.resolve(context, 'package.json')
Expand Down Expand Up @@ -84,6 +99,7 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
const generator = new Generator(context, {
pkg,
plugins: [plugin],
files: await readFiles(context),
completeCbs: createCompleteCbs
})

Expand Down

0 comments on commit de60d9f

Please sign in to comment.