Skip to content

Commit

Permalink
feat: respect existing package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
zyy7259 committed Dec 5, 2019
1 parent 6c24964 commit 6b6f6c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
25 changes: 19 additions & 6 deletions packages/@vue/cli/lib/Creator.js
@@ -1,6 +1,8 @@
const fs = require('fs')
const path = require('path')
const debug = require('debug')
const inquirer = require('inquirer')
const readPkg = require('read-pkg')
const EventEmitter = require('events')
const Generator = require('./Generator')
const cloneDeep = require('lodash.clonedeep')
Expand Down Expand Up @@ -142,12 +144,7 @@ module.exports = class Creator extends EventEmitter {
latestMinor = current
}
// generate package.json with plugin dependencies
const pkg = {
name,
version: '0.1.0',
private: true,
devDependencies: {}
}
const pkg = this.resolvePkg()
const deps = Object.keys(preset.plugins)
deps.forEach(dep => {
if (preset.plugins[dep]._isPreset) {
Expand Down Expand Up @@ -515,6 +512,22 @@ module.exports = class Creator extends EventEmitter {
return prompts
}

resolvePkg () {
let existingPkg = {}
if (fs.existsSync(path.join(this.context, 'package.json'))) {
existingPkg = readPkg.sync({ cwd: this.context })
}
const { name, version, devDependencies, ...more } = existingPkg
const pkg = {
name: name || this.name,
version: version || '0.1.0',
private: true,
devDependencies: devDependencies || {},
...more
}
return pkg
}

shouldInitGit (cliOptions) {
if (!hasGit()) {
return false
Expand Down
1 change: 1 addition & 0 deletions packages/@vue/cli/package.json
Expand Up @@ -48,6 +48,7 @@
"lodash.clonedeep": "^4.5.0",
"lru-cache": "^5.1.1",
"minimist": "^1.2.0",
"read-pkg": "^5.1.1",
"recast": "^0.18.1",
"resolve": "^1.13.1",
"shortid": "^2.2.15",
Expand Down

0 comments on commit 6b6f6c3

Please sign in to comment.