Skip to content

Commit

Permalink
改进打包 zip 脚本 (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
riophae authored and LitoMore committed May 5, 2019
1 parent 40fc9ee commit 1b60442
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions build/pack.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
/* eslint no-console: 0 */

const path = require('path')
const cp = require('child_process')
const chalk = require('chalk')
const timestamp = require('tinydate')('{YYYY}/{MM}/{DD} {HH}:{mm}:{ss}')
const manifest = require('../static/manifest')

function zip() {
function log(message) {
console.log(`[${chalk.cyan(timestamp())}] ${message}`)
}

function pack() {
const version = manifest.version_name || manifest.version
const zipName = `space-fanfou-${version}.zip`
const outPath = path.join(__dirname, '..', zipName)
const distPath = path.join(__dirname, '..', 'dist')
const command = `rm -f ${outPath} && cd ${distPath} && zip -r ${outPath} ./*`
const pkgRootPath = path.join(__dirname, '..')
const outPath = path.join(pkgRootPath, zipName)
const distPath = path.join(pkgRootPath, 'dist')
const command = `rm -f ${JSON.stringify(outPath)} && cd ${JSON.stringify(distPath)} && zip -r ${JSON.stringify(outPath)} *`

log(`正在创建:${chalk.green(zipName)}`)

cp.execSync(command)
// eslint-disable-next-line no-console
console.log(`创建成功:${chalk.green(zipName)}`)
cp.exec(command, error => {
if (error) {
log(chalk.red('创建失败'))
console.log(error)
} else {
log(chalk.green('创建成功'))
}
})
}
zip()
pack()

0 comments on commit 1b60442

Please sign in to comment.