Skip to content

Commit

Permalink
feat: support custom paths in tar file
Browse files Browse the repository at this point in the history
  • Loading branch information
antife-yinyue committed Nov 19, 2018
1 parent 4eb6da7 commit f247c73
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 66 deletions.
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,50 +45,50 @@
"babel-preset-es2015": "^6.24.1",
"babel-runtime": "^6.26.0",
"camelcase": "^5.0.0",
"commander": "^2.17.1",
"commander": "^2.19.0",
"consolidate": "^0.15.1",
"debug": "^3.1.0",
"deepmerge": "^2.1.1",
"fs-extra": "^7.0.0",
"debug": "^4.1.0",
"deepmerge": "^2.2.1",
"fs-extra": "^7.0.1",
"git-branch": "^2.0.1",
"git-clone": "^0.1.0",
"globby": "^8.0.1",
"gulp": "^3.9.1",
"gulp-tar": "~2.1.0",
"gulp-zip": "^4.2.0",
"handlebars": "^4.0.11",
"handlebars": "^4.0.12",
"inquirer": "^6.2.0",
"ios-simulator": "^1.0.15",
"last-commit-log": "^1.0.12",
"last-commit-log": "^1.0.13",
"map-stream": "^0.1.0",
"metalsmith": "^2.3.0",
"minimatch": "^3.0.4",
"multimatch": "^2.1.0",
"node-forge": "^0.7.6",
"ora": "^3.0.0",
"ramda": "^0.25.0",
"ramda": "^0.26.0",
"ramda-fantasy": "^0.8.0",
"read-metadata": "^1.0.0",
"request": "^2.88.0",
"rimraf": "^2.6.2",
"semver": "^5.5.1",
"shelljs": "^0.8.2",
"semver": "^5.6.0",
"shelljs": "^0.8.3",
"user-home": "^2.0.0",
"validate-npm-package-name": "^3.0.0",
"win-spawn": "^2.0.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-eslint": "^9.0.0",
"chai": "^4.1.2",
"babel-eslint": "^10.0.1",
"chai": "^4.2.0",
"chai-fs": "^2.0.0",
"chalk": "^2.4.1",
"eslint": "^5.4.0",
"eslint": "^5.9.0",
"eslint-config-antife": "^1.0.3",
"eslint-plugin-babel": "^5.1.0",
"eslint-plugin-babel": "^5.3.0",
"eslint-watch": "^4.0.2",
"git-contributor": "^1.0.8",
"husky": "^1.0.0-rc.13",
"husky": "^1.1.4",
"istanbul": "^0.4.5",
"mocha": "^5.2.0"
},
Expand Down
98 changes: 46 additions & 52 deletions src/bin/apfe-pack-pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import zip from 'gulp-zip'
import map from 'map-stream'
import sign from '../lib/sign'
import home from 'user-home'
// import globby from 'globby'
import { Command } from 'commander'
import LCL from 'last-commit-log'

Expand All @@ -19,12 +18,11 @@ const ROOT_PATH = process.cwd()
const PACKAGE_DIR = './_packages'
const TEMP_DIR = './._temp'
const TEMP_PATH = path.join(ROOT_PATH, TEMP_DIR)
// const HOOK_PATH = path.join(ROOT_PATH, './.hook.js')

const program = new Command('apfe pack')
program
.usage(' ')
.option('-c, --config [file]', 'apfe config')
.option('-c, --config [file]', 'offline-package config')
.parse(process.argv)

/**
Expand All @@ -48,79 +46,75 @@ function archiving (subapp, cb) {
fs.removeSync(TEMP_PATH)
}

let distSrc = ['./dist/**/*'] // Defaults include all filse in dist dir
const tarFiles = []
let sourceSrc = ['./dist/**/*'] // Defaults include all filse in dist dir

// parse include files
if (Array.isArray(subapp.includes) && subapp.includes.length > 0) {
distSrc = subapp.includes
sourceSrc = subapp.includes
}

// ignore subapp.ignores configuration
if (Array.isArray(subapp.ignores)) {
subapp.ignores.forEach((v) => {
distSrc.push('!' + v)
sourceSrc.push('!' + v)
})
}

// define gulp tasks
gulp.task('tar', () => {
// console.log('Start gulp task: tar')

const _tarPath = `${TEMP_DIR}/_tar`
return gulp
.src(distSrc.map(_ => `${TEMP_DIR}/_tar/${_}`))
.src(sourceSrc.map(_ => `${_tarPath}/${_}`))
.on('end', () => {
if (fs.existsSync(_tarPath)) fs.removeSync(_tarPath)
})
.pipe(tar(subapp.id + '.tar'))
.pipe(gulp.dest(TEMP_DIR))
})

gulp.task('cert', ['tar'], () => {
// console.log('Start gulp task: cert')

const _tarPath = TEMP_PATH + '/_tar'
if (fs.existsSync(_tarPath)) {
fs.removeSync(_tarPath)
}

const rtv = gulp.src(TEMP_DIR + '/**/*')
function scanPipe (files) {
function fn (file, cb) {
const tarFiles = []
const scanPipe = (files) => {
return map((file) => {
!file.isDirectory() && files.push(file.relative)
}
return map(fn)
})
}
rtv.pipe(scanPipe(tarFiles))
rtv.on('end', () => {
signTar(TEMP_PATH, tarFiles, () => {
const _options = {
tar: true,
}
gulpPkg(_options, subapp, cb)

return gulp
.src(TEMP_DIR + '/**/*')
.on('end', () => {
signTar(TEMP_PATH, tarFiles, () => gulpPkg({ tar: true }, subapp, cb))
})
})
return rtv
.pipe(scanPipe(tarFiles))
})

gulp.task('dist', () => {
// console.log('Start gulp task: dist')

const src = gulp.src(distSrc).on('end', () => {
// build Manifest.xml
buildManifestSync(subapp, TEMP_PATH, true)
let tarRootPath = ''
if (subapp.rootPath) {
tarRootPath = subapp.rootPath.replace('[id]', subapp.id) + '/'
if (tarRootPath.indexOf('.') !== -1) {
tarRootPath = tarRootPath.replace(/\./g, '_')
}
}

setTimeout(() => {
gulp.start('cert')
}, 500)
})
gulp
.src(sourceSrc)
.on('end', () => {
// build Manifest.xml
createManifestFile(subapp, TEMP_PATH, true)

src.pipe(
gulp.dest((file) => {
let distDir = TEMP_DIR + '/_tar'
if (file.base.indexOf(ROOT_PATH) > -1) {
distDir += file.base.replace(ROOT_PATH, '')
}
return distDir
}),
)
setTimeout(() => gulp.start('cert'), 500)
})
.pipe(
gulp.dest((file) => {
let destDir = TEMP_DIR + '/_tar'
if (file.base.indexOf(ROOT_PATH) > -1) {
destDir += file.base.replace(ROOT_PATH, '')
}
destDir += tarRootPath
return destDir
})
)
})

gulp.start('dist')
Expand Down Expand Up @@ -189,16 +183,16 @@ function packSubapp (config) {
}

/**
* buildManifestSync
* createManifestFile
* generate Manifest.xml
*
* @name buildManifestSync
* @name createManifestFile
* @function
* @access public
* @param {Object} subapp package.json config
* @param {String} manifestDir output path
*/
function buildManifestSync (subapp, manifestDir) {
function createManifestFile (subapp, manifestDir) {
try {
const out = []
out.push('<?xml version="1.0" encoding="utf-8"?>')
Expand Down

0 comments on commit f247c73

Please sign in to comment.