mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-01-25 00:29:06 -06:00
22 lines
476 B
JavaScript
22 lines
476 B
JavaScript
const fs = require('fs')
|
|
const path = require('path')
|
|
|
|
module.exports = function getPackageJson (projectPath) {
|
|
const packagePath = path.join(projectPath, 'package.json')
|
|
|
|
let packageJson
|
|
try {
|
|
packageJson = fs.readFileSync(packagePath, 'utf-8')
|
|
} catch (err) {
|
|
throw new Error(`${packagePath} not exist`)
|
|
}
|
|
|
|
try {
|
|
packageJson = JSON.parse(packageJson)
|
|
} catch (err) {
|
|
throw new Error('The package.json is malformed')
|
|
}
|
|
|
|
return packageJson
|
|
}
|