From 5cff39b0154c4343c5ac1ccffb11cbadb003d7ca Mon Sep 17 00:00:00 2001 From: xdf Date: Fri, 31 Aug 2018 18:27:32 +0800 Subject: [PATCH] feat: enhance shotHash --- package.json | 3 +- src/bin/apfe-pack-pack.js | 62 ++++++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index e3aef57..3896e13 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apfe-cli", - "version": "1.3.1", + "version": "1.3.2", "description": "Alipay+ Subapp ToolKit", "keywords": [ "ToolKit", @@ -58,6 +58,7 @@ "handlebars": "^4.0.11", "inquirer": "^6.2.0", "ios-simulator": "^1.0.15", + "last-commit-log": "^1.0.12", "map-stream": "^0.1.0", "metalsmith": "^2.3.0", "minimatch": "^3.0.4", diff --git a/src/bin/apfe-pack-pack.js b/src/bin/apfe-pack-pack.js index 67105c3..3454aa4 100755 --- a/src/bin/apfe-pack-pack.js +++ b/src/bin/apfe-pack-pack.js @@ -11,6 +11,9 @@ import sign from '../lib/sign' import home from 'user-home' // import globby from 'globby' import { Command } from 'commander' +import LCL from 'last-commit-log' + +const lcl = new LCL() const ROOT_PATH = process.cwd() const PACKAGE_DIR = './_packages' @@ -265,36 +268,41 @@ function signTar (distPath, files, cb) { * @param {Function} cb callback */ function gulpPkg (options, subapp, cb) { - let amrFilename = `${subapp.id}_${subapp.version}` - - // Custom offline-package filename - if (subapp.filename) { - amrFilename = subapp.filename - .replace('[id]', subapp.id) - .replace('[version]', subapp.version) - .replace('[random]', Math.random().toString(36).substr(2, 6)) - } + const handlePack = shortHash => { + let amrFilename = `${subapp.id}_${subapp.version}` + + // Custom offline-package filename + if (subapp.filename) { + amrFilename = subapp.filename + .replace('[id]', subapp.id) + .replace('[version]', subapp.version) + .replace('[random]', shortHash || Math.random().toString(36).substr(2, 7)) + } - amrFilename += '.amr' + amrFilename += '.amr' - const amrPath = path.join(ROOT_PATH, PACKAGE_DIR, amrFilename) - const srcPath = TEMP_DIR + '/**/*' + const amrPath = path.join(ROOT_PATH, PACKAGE_DIR, amrFilename) + const srcPath = TEMP_DIR + '/**/*' - gulp.task('zip', () => { - return gulp - .src(srcPath) - .pipe(zip(amrFilename)) - .pipe(gulp.dest(PACKAGE_DIR)) - }) - gulp.task('pack', ['zip'], () => { - console.log(chalk.yellow('# packed successfully at'), chalk.green(amrPath.replace(home, '~'))) - const pkgInfo = { - file: PACKAGE_DIR + '/' + amrFilename, - config: subapp, - } - cb && cb(options.all, pkgInfo) - }) - gulp.start('pack') + gulp.task('zip', () => { + return gulp + .src(srcPath) + .pipe(zip(amrFilename)) + .pipe(gulp.dest(PACKAGE_DIR)) + }) + gulp.task('pack', ['zip'], () => { + console.log(chalk.yellow('# packed successfully at'), chalk.green(amrPath.replace(home, '~'))) + const pkgInfo = { + file: PACKAGE_DIR + '/' + amrFilename, + config: subapp, + } + cb && cb(options.all, pkgInfo) + }) + gulp.start('pack') + } + lcl.getLastCommit() + .then(lastCommit => handlePack(lastCommit.shortHash)) + .catch(() => handlePack()) } function preCheck () {