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 Nov 14, 2019
1 parent 2652ab6 commit 6fb189a
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,8 +1,10 @@
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const debug = require('debug')
const execa = require('execa')
const inquirer = require('inquirer')
const readPkg = require('read-pkg')
const semver = require('semver')
const EventEmitter = require('events')
const Generator = require('./Generator')
Expand Down Expand Up @@ -139,12 +141,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 @@ -512,6 +509,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 @@ -50,6 +50,7 @@
"lodash.clonedeep": "^4.5.0",
"lru-cache": "^5.1.1",
"minimist": "^1.2.0",
"read-pkg": "^5.1.1",
"recast": "^0.18.1",
"request": "^2.87.0",
"request-promise-native": "^1.0.7",
Expand Down

0 comments on commit 6fb189a

Please sign in to comment.