Skip to content

Commit

Permalink
feat: add config option when pack
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoler.gl committed Nov 19, 2018
1 parent cc57202 commit 19c1e82
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/bin/apfe-pack-pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const TEMP_PATH = path.join(ROOT_PATH, TEMP_DIR)
const program = new Command('apfe pack')
program
.usage(' ')
.option('-c, --config [file]', 'apfe config')
.parse(process.argv)

/**
Expand Down Expand Up @@ -127,31 +128,33 @@ function archiving (subapp, cb) {

/**
* entry
* 1. preCheck package.json exist
* 1. preCheck config file (package.json as default) exist
* 2. render build config
* 3. invoke packSubapp @see packSubapp
* @name entry
* @function
* @access public
*/
function entry () {
if (!fs.pathExistsSync('package.json')) {
console.log(chalk.red('\r\nMissing package.json'))
const configPath = program.config || 'package.json'

if (!fs.pathExistsSync(configPath)) {
console.log(chalk.red(`\r\nMissing ${configPath}`))
return
}

try {
const pkg = fs.readJSONSync('package.json')
const pkg = fs.readJSONSync(configPath)
const version = pkg.version
const config = Object.assign({ version }, pkg.subapp)

if (!('subapp' in pkg)) {
console.log(chalk.red('\r\nMissing `subapp` config in package.json'))
console.log(chalk.red(`\r\nMissing \`subapp\` config in ${configPath}`))
return
}

if (!config.id) {
console.log(chalk.red('\r\nMissing `subapp.id` config in package.json'))
console.log(chalk.red(`\r\nMissing \`subapp.id\` config in ${configPath}`))
return
}

Expand Down

0 comments on commit 19c1e82

Please sign in to comment.