2016-01-23 03:47:28 +00:00
|
|
|
import gulp from 'gulp';
|
|
|
|
import del from 'del';
|
|
|
|
import sourcemaps from 'gulp-sourcemaps';
|
|
|
|
import webpack from 'webpack-stream';
|
|
|
|
import babel from 'gulp-babel';
|
|
|
|
import runSequence from 'run-sequence';
|
2016-01-23 04:29:40 +00:00
|
|
|
import path from 'path';
|
2016-01-23 18:02:23 +00:00
|
|
|
import eslint from 'gulp-eslint';
|
2016-01-24 17:10:28 +00:00
|
|
|
import mocha from 'gulp-mocha';
|
2016-02-01 07:23:29 +00:00
|
|
|
import istanbul from 'gulp-istanbul';
|
2016-01-29 16:31:27 +00:00
|
|
|
import shellJs from 'shelljs';
|
2016-01-23 04:29:40 +00:00
|
|
|
|
2016-01-23 04:42:09 +00:00
|
|
|
const PATHS = setUpPaths();
|
2016-01-23 04:29:40 +00:00
|
|
|
|
2016-01-23 03:47:28 +00:00
|
|
|
gulp.task('default', ['build']);
|
|
|
|
|
|
|
|
gulp.task('build', callback => {
|
2016-01-28 14:36:34 +00:00
|
|
|
runSequence('clean', ['build-cli', 'build-app', 'build-tests'], callback);
|
2016-01-23 03:47:28 +00:00
|
|
|
});
|
|
|
|
|
2016-01-23 04:29:40 +00:00
|
|
|
gulp.task('build-app', ['build-static'], () => {
|
|
|
|
return gulp.src(PATHS.APP_MAIN_JS)
|
|
|
|
.pipe(webpack(require(PATHS.WEBPACK_CONFIG)))
|
|
|
|
.pipe(gulp.dest(PATHS.APP_DEST));
|
2016-01-23 03:47:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('clean', callback => {
|
2016-01-23 04:29:40 +00:00
|
|
|
del(PATHS.CLI_DEST).then(() => {
|
|
|
|
del(PATHS.APP_DEST).then(() => {
|
2016-01-28 14:36:34 +00:00
|
|
|
del(PATHS.TEST_DEST).then(() => {
|
|
|
|
callback();
|
|
|
|
});
|
2016-01-23 03:47:28 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-01-23 04:29:40 +00:00
|
|
|
gulp.task('build-cli', done => {
|
|
|
|
return gulp.src(PATHS.CLI_SRC_JS)
|
2016-01-23 03:47:28 +00:00
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
.pipe(babel())
|
2016-01-23 04:29:40 +00:00
|
|
|
.on('error', done)
|
2016-01-23 03:47:28 +00:00
|
|
|
.pipe(sourcemaps.write('.'))
|
|
|
|
.pipe(gulp.dest('lib'));
|
|
|
|
});
|
|
|
|
|
2016-01-25 04:43:55 +00:00
|
|
|
gulp.task('build-static', ['build-static-js', 'build-static-not-js']);
|
|
|
|
|
|
|
|
gulp.task('build-static-not-js', () => {
|
|
|
|
return gulp.src([PATHS.APP_STATIC_ALL, '!**/*.js'])
|
|
|
|
.pipe(gulp.dest(PATHS.APP_STATIC_DEST));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('build-static-js', done => {
|
|
|
|
return gulp.src(PATHS.APP_STATIC_JS)
|
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
.pipe(babel())
|
|
|
|
.on('error', done)
|
|
|
|
.pipe(sourcemaps.write('.'))
|
2016-01-23 04:29:40 +00:00
|
|
|
.pipe(gulp.dest(PATHS.APP_STATIC_DEST));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('watch', ['build'], () => {
|
2016-01-23 18:02:23 +00:00
|
|
|
var handleError = function(error) {
|
2016-01-23 04:29:40 +00:00
|
|
|
console.error(error);
|
|
|
|
};
|
|
|
|
gulp.watch(PATHS.APP_ALL, ['build-app'])
|
|
|
|
.on('error', handleError);
|
|
|
|
|
|
|
|
gulp.watch(PATHS.CLI_SRC_JS, ['build-cli'])
|
|
|
|
.on('error', handleError);
|
2016-01-28 14:36:34 +00:00
|
|
|
|
|
|
|
gulp.watch(PATHS.TEST_SRC_JS, ['build-tests'])
|
|
|
|
.on('error', handleError);
|
2016-01-23 03:47:28 +00:00
|
|
|
});
|
2016-01-23 04:42:09 +00:00
|
|
|
|
2016-01-23 08:01:58 +00:00
|
|
|
gulp.task('publish', done => {
|
2016-01-29 16:42:47 +00:00
|
|
|
shellExec('npm publish', false, done);
|
2016-01-23 08:01:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('release', callback => {
|
2016-01-25 01:14:49 +00:00
|
|
|
return runSequence('test', 'lint', 'build', 'publish', callback);
|
2016-01-23 08:01:58 +00:00
|
|
|
});
|
|
|
|
|
2016-01-24 17:10:28 +00:00
|
|
|
gulp.task('lint', () => {
|
2016-02-20 02:39:59 +00:00
|
|
|
return gulp.src(['**/*.js', '!node_modules/**', '!app/node_modules/**', '!app/lib/**', '!lib/**', '!built-tests/**', '!coverage/**'])
|
2016-01-23 18:02:23 +00:00
|
|
|
.pipe(eslint())
|
|
|
|
.pipe(eslint.format())
|
|
|
|
.pipe(eslint.failAfterError());
|
|
|
|
});
|
|
|
|
|
2016-01-27 02:24:02 +00:00
|
|
|
gulp.task('build-tests', done => {
|
|
|
|
return gulp.src(PATHS.TEST_SRC_JS)
|
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
.pipe(babel())
|
|
|
|
.on('error', done)
|
|
|
|
.pipe(sourcemaps.write('.'))
|
|
|
|
.pipe(gulp.dest(PATHS.TEST_DEST));
|
|
|
|
});
|
|
|
|
|
2016-01-29 16:31:27 +00:00
|
|
|
gulp.task('prune', done => {
|
2016-01-29 16:42:47 +00:00
|
|
|
shellExec('npm prune', true, done);
|
2016-01-29 16:31:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('test', callback => {
|
|
|
|
return runSequence('prune', 'mocha', callback);
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('mocha', ['build'], () => {
|
2016-02-01 07:23:29 +00:00
|
|
|
return gulp.src(PATHS.CLI_DEST_JS)
|
|
|
|
.pipe(istanbul({includeUntested: true}))
|
|
|
|
.on('finish', () => {
|
|
|
|
return gulp.src(PATHS.TEST_DEST_JS, {read: false})
|
|
|
|
.pipe(mocha())
|
|
|
|
.pipe(istanbul.writeReports({
|
|
|
|
dir: './coverage',
|
|
|
|
reporters: ['lcov'],
|
|
|
|
reportOpts: {dir: './coverage'}
|
|
|
|
}));
|
|
|
|
});
|
2016-01-24 17:10:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('ci', callback => {
|
|
|
|
return runSequence('test', 'lint', callback);
|
|
|
|
});
|
2016-01-23 18:02:23 +00:00
|
|
|
|
2016-01-23 04:42:09 +00:00
|
|
|
function setUpPaths() {
|
|
|
|
const paths = {
|
|
|
|
WEBPACK_CONFIG: './webpack.config.js',
|
|
|
|
APP_SRC: 'app/src',
|
|
|
|
APP_DEST: 'app/lib',
|
|
|
|
CLI_SRC: 'src',
|
2016-01-27 02:24:02 +00:00
|
|
|
CLI_DEST: 'lib',
|
|
|
|
TEST_SRC: 'test',
|
|
|
|
TEST_DEST: 'built-tests'
|
2016-01-23 04:42:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
paths.APP_MAIN_JS = path.join(paths.APP_SRC, '/main.js');
|
|
|
|
paths.APP_ALL = paths.APP_SRC + '/**/*';
|
|
|
|
paths.APP_STATIC_ALL = path.join(paths.APP_SRC, 'static') + '/**/*';
|
2016-01-25 04:43:55 +00:00
|
|
|
paths.APP_STATIC_JS = path.join(paths.APP_SRC, 'static') + '/**/*.js';
|
2016-01-23 04:42:09 +00:00
|
|
|
paths.APP_STATIC_DEST = path.join(paths.APP_DEST, 'static');
|
|
|
|
paths.CLI_SRC_JS = paths.CLI_SRC + '/**/*.js';
|
2016-02-01 07:23:29 +00:00
|
|
|
paths.CLI_DEST_JS = paths.CLI_DEST + '/**/*.js';
|
2016-01-28 03:47:40 +00:00
|
|
|
paths.TEST_SRC_JS = paths.TEST_SRC + '/**/*.js';
|
2016-01-27 02:24:02 +00:00
|
|
|
paths.TEST_DEST_JS = paths.TEST_DEST + '/**/*.js';
|
2016-01-23 04:42:09 +00:00
|
|
|
|
|
|
|
return paths;
|
|
|
|
}
|
2016-01-29 16:31:27 +00:00
|
|
|
|
2016-01-29 16:42:47 +00:00
|
|
|
function shellExec(cmd, silent, callback) {
|
|
|
|
shellJs.exec(cmd, {silent: silent}, (code, stdout, stderr) => {
|
2016-01-29 16:31:27 +00:00
|
|
|
if (code) {
|
|
|
|
callback(JSON.stringify({code, stdout, stderr}));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|