Skip to content

Commit

Permalink
refactor: resolve packageJS one time
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkdo committed Aug 31, 2018
1 parent 4ad1528 commit fe2dd22
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions build/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export default class Package extends EventEmitter {

this.rootDir = this.rootDir || process.cwd()
this.distDir = this.resolvePath(this.distDir)
this.packagePath = this.resolvePath('package.json')
this.packageJS = this.resolvePath('package.js')
this.packageJSON = this.resolvePath('package.json')

// Initialize
this.init()
Expand All @@ -41,13 +42,12 @@ export default class Package extends EventEmitter {
}

_readPackage() {
this.packageObj = readJSONSync(this.packagePath)
this.packageObj = readJSONSync(this.packageJSON)
}

_loadPackageJS() {
const packageJS = this.resolvePath(this.rootDir, 'package.js')
if (existsSync(packageJS)) {
let fn = require(packageJS)
if (existsSync(this.packageJS)) {
let fn = require(this.packageJS)
fn = fn.default || fn
if (typeof fn === 'function') {
fn(this, {
Expand All @@ -60,8 +60,8 @@ export default class Package extends EventEmitter {
}

writePackage() {
consola.debug('Writing', this.packagePath)
writeFileSync(this.packagePath, JSON.stringify(this.packageObj, null, 2) + '\n')
consola.debug('Writing', this.packageJSON)
writeFileSync(this.packageJSON, JSON.stringify(this.packageObj, null, 2) + '\n')
}

generateVersion() {
Expand Down

0 comments on commit fe2dd22

Please sign in to comment.