From 1b604423d90e3cb00b3152121d3443ad3b0e3ca0 Mon Sep 17 00:00:00 2001 From: Fangzhou Li Date: Sun, 5 May 2019 18:07:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=89=93=E5=8C=85=20zip=20?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=20(#69)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/pack.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/build/pack.js b/build/pack.js index b969aa4..99435ca 100644 --- a/build/pack.js +++ b/build/pack.js @@ -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()