2019-09-28 10:15:54 -04:00
|
|
|
/* eslint-env es6 */
|
2019-09-14 13:49:24 -04:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const gulp = require('gulp');
|
|
|
|
const bump = require('gulp-bump');
|
|
|
|
const changelog = require('gulp-conventional-changelog');
|
|
|
|
const tag = require('gulp-tag-version');
|
|
|
|
const sequence = require('run-sequence');
|
|
|
|
const gutil = require('gulp-util');
|
|
|
|
const pkg = require('./package.json');
|
|
|
|
const exec = require('child_process').exec;
|
|
|
|
|
|
|
|
const shellExec = (command, callback) => {
|
|
|
|
const args = process.argv.slice(3).join(' '),
|
|
|
|
proc = exec(command + ' ' + args, (err, stdout, stderr) => {
|
|
|
|
callback(err, stdout, stderr, proc);
|
|
|
|
});
|
|
|
|
|
|
|
|
proc.stdout.on('data', data => process.stdout.write(data));
|
|
|
|
proc.stderr.on('data', data => process.stderr.write(data));
|
|
|
|
};
|
|
|
|
|
|
|
|
const shell = command => (callback => { shellExec(command, callback); });
|
|
|
|
|
|
|
|
const hint = command => (callback => {
|
|
|
|
gutil.log(gutil.colors.red('Error'), 'use', gutil.colors.yellow(command), 'instead.');
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('default', hint('npm run build'));
|
|
|
|
gulp.task('dev', hint('npm run dev'));
|
|
|
|
gulp.task('build', hint('npm run build'));
|
|
|
|
gulp.task('test', hint('npm run test'));
|
|
|
|
gulp.task('lint', hint('npm run lint'));
|
2015-11-29 09:27:38 -05:00
|
|
|
|
2019-09-14 13:49:24 -04:00
|
|
|
gulp.task('doc', callback => {
|
2019-09-15 14:50:51 -04:00
|
|
|
shellExec(`yuidoc --config yuidoc.json --project-version ${pkg.version}`, callback);
|
2019-09-14 13:49:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('bump', () => {
|
|
|
|
return gulp.src(['package.json', 'bower.json'])
|
|
|
|
.pipe(bump({ type: process.argv[4] || 'minor' }))
|
|
|
|
.pipe(gulp.dest('.'));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('tag', () => {
|
|
|
|
return gulp.src('package.json')
|
|
|
|
.pipe(tag({ prefix: '' }));
|
|
|
|
});
|
2015-11-29 09:27:38 -05:00
|
|
|
|
2019-09-14 13:49:24 -04:00
|
|
|
gulp.task('changelog', () => {
|
|
|
|
return gulp.src('CHANGELOG.md')
|
|
|
|
.pipe(changelog())
|
|
|
|
.pipe(gulp.dest('.'));
|
2015-12-05 11:34:48 -05:00
|
|
|
});
|
2015-11-29 09:27:38 -05:00
|
|
|
|
2019-09-14 13:49:24 -04:00
|
|
|
gulp.task('release', callback => {
|
|
|
|
shellExec('git status --porcelain', (err, stdout) => {
|
2016-04-19 07:18:33 -04:00
|
|
|
if (stdout && stdout.trim()) {
|
|
|
|
throw new gutil.PluginError({
|
|
|
|
plugin: 'release',
|
|
|
|
message: 'cannot build release as there are uncomitted changes'
|
|
|
|
});
|
|
|
|
} else {
|
2019-09-14 14:31:31 -04:00
|
|
|
sequence(
|
|
|
|
'release:lint', 'bump', 'release:build', 'release:test',
|
|
|
|
'doc', 'changelog', callback
|
|
|
|
);
|
2016-04-19 07:18:33 -04:00
|
|
|
}
|
|
|
|
});
|
2015-11-29 09:27:38 -05:00
|
|
|
});
|
|
|
|
|
2019-09-14 14:31:31 -04:00
|
|
|
gulp.task('release:lint', shell('npm run lint'));
|
2019-09-14 13:49:24 -04:00
|
|
|
gulp.task('release:build', shell('npm run build'));
|
2019-09-14 14:31:31 -04:00
|
|
|
gulp.task('release:test', shell('TEST_BUILD=true npm run test'));
|
2019-09-15 15:22:44 -04:00
|
|
|
gulp.task('release:push:git', shell('git push origin && git push origin --tags'));
|
2019-09-14 13:49:24 -04:00
|
|
|
gulp.task('release:push:npm', shell('npm publish'));
|
|
|
|
|
|
|
|
gulp.task('release:push', callback => {
|
|
|
|
shellExec('git status --porcelain', (err, stdout) => {
|
2016-04-19 07:18:33 -04:00
|
|
|
if (stdout && stdout.trim()) {
|
|
|
|
throw new gutil.PluginError({
|
|
|
|
plugin: 'release',
|
|
|
|
message: 'cannot push release as it has not yet been committed'
|
|
|
|
});
|
|
|
|
} else {
|
2016-11-03 20:14:50 -04:00
|
|
|
sequence('tag', 'release:push:git', 'release:push:npm', callback);
|
2016-04-19 07:18:33 -04:00
|
|
|
}
|
|
|
|
});
|
2016-01-14 18:44:04 -05:00
|
|
|
});
|