From 15a7304e1b6040fc6f8252ddfbbf5cf6033cadfe Mon Sep 17 00:00:00 2001 From: Jia Hao Date: Sat, 30 Jan 2016 00:31:27 +0800 Subject: [PATCH] Run npm prune before running tests, use shelljs instead of child process --- gulpfile.babel.js | 26 ++++++++++++++++++++++---- package.json | 1 + 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 680f336..e988e10 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -5,9 +5,9 @@ import webpack from 'webpack-stream'; import babel from 'gulp-babel'; import runSequence from 'run-sequence'; import path from 'path'; -import childProcess from 'child_process'; import eslint from 'gulp-eslint'; import mocha from 'gulp-mocha'; +import shellJs from 'shelljs'; const PATHS = setUpPaths(); @@ -73,8 +73,7 @@ gulp.task('watch', ['build'], () => { }); gulp.task('publish', done => { - childProcess.spawn('npm', ['publish'], {stdio: 'inherit'}) - .on('close', done); + shellExec('npm publish', done); }); gulp.task('release', callback => { @@ -97,7 +96,15 @@ gulp.task('build-tests', done => { .pipe(gulp.dest(PATHS.TEST_DEST)); }); -gulp.task('test', ['build'], () => { +gulp.task('prune', done => { + shellExec('npm prune', done); +}); + +gulp.task('test', callback => { + return runSequence('prune', 'mocha', callback); +}); + +gulp.task('mocha', ['build'], () => { return gulp.src(PATHS.TEST_DEST_JS, {read: false}) .pipe(mocha()); }); @@ -128,3 +135,14 @@ function setUpPaths() { return paths; } + +function shellExec(cmd, callback) { + shellJs.exec(cmd, {silent: true}, (code, stdout, stderr) => { + if (code) { + callback(JSON.stringify({code, stdout, stderr})); + return; + } + callback(); + }); +} + diff --git a/package.json b/package.json index 1beb5dc..cee702c 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "gulp-sourcemaps": "^1.6.0", "lodash": "^4.0.0", "run-sequence": "^1.1.5", + "shelljs": "^0.5.3", "tmp": "0.0.28", "webpack-stream": "^3.1.0" }