Skip to content

Commit

Permalink
feat: enhance shotHash
Browse files Browse the repository at this point in the history
  • Loading branch information
xudafeng committed Aug 31, 2018
1 parent d7ade8e commit 5cff39b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apfe-cli",
"version": "1.3.1",
"version": "1.3.2",
"description": "Alipay+ Subapp ToolKit",
"keywords": [
"ToolKit",
Expand Down Expand Up @@ -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",
Expand Down
62 changes: 35 additions & 27 deletions src/bin/apfe-pack-pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit 5cff39b

Please sign in to comment.