Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
var gulp = require('gulp');
var runSequence = require('run-sequence');
var del = require('del');
var vinylPaths = require('vinyl-paths');
var to5 = require('gulp-6to5');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var yuidoc = require("gulp-yuidoc");
var changelog = require('conventional-changelog');
var assign = Object.assign || require('object.assign');
var fs = require('fs');
var bump = require('gulp-bump');
var browserSync = require('browser-sync');
var changed = require('gulp-changed');
var plumber = require('gulp-plumber');
var tools = require('aurelia-tools');
var protractor = require("gulp-protractor").protractor;
var webdriver_update = require('gulp-protractor').webdriver_update;
var sourcemaps = require('gulp-sourcemaps');
var path = {
source: 'src/**/*.js',
html: 'src/**/*.html',
style: 'styles/**/*.css',
output: 'dist/',
doc: './doc',
e2eSpecsSrc: 'test/e2e/src/*.js',
e2eSpecsDist: 'test/e2e/dist/'
};
var compilerOptions = {
filename: '',
filenameRelative: '',
blacklist: [],
whitelist: [],
modules: '',
sourceMap: true,
//sourceMapName: '',
//sourceFileName: '',
sourceRoot: '',
moduleRoot: '',
moduleIds: false,
experimental: false,
format: {
comments: false,
compact: false,
indent: {
parentheses: true,
adjustMultilineComment: true,
style: " ",
base: 0
}
}
};
var jshintConfig = {esnext: true};
gulp.task('clean', function () {
return gulp.src([path.output])
.pipe(vinylPaths(del));
});
gulp.task('build-system', function () {
return gulp.src(path.source)
.pipe(plumber())
.pipe(changed(path.output, {extension: '.js'}))
.pipe(sourcemaps.init())
.pipe(to5(assign({}, compilerOptions, {modules: 'system'})))
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest(path.output));
});
gulp.task('build-html', function () {
return gulp.src(path.html)
.pipe(changed(path.output, {extension: '.html'}))
.pipe(gulp.dest(path.output));
});
gulp.task('lint', function () {
return gulp.src(path.source)
.pipe(jshint(jshintConfig))
.pipe(jshint.reporter(stylish));
});
gulp.task('doc-generate', function () {
return gulp.src(path.source)
.pipe(yuidoc.parser(null, 'api.json'))
.pipe(gulp.dest(path.doc));
});
gulp.task('doc', ['doc-generate'], function () {
tools.transformAPIModel(path.doc);
});
gulp.task('bump-version', function () {
return gulp.src(['./package.json'])
.pipe(bump({type: 'patch'})) //major|minor|patch|prerelease
.pipe(gulp.dest('./'));
});
gulp.task('changelog', function (callback) {
var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));
return changelog({
repository: pkg.repository.url,
version: pkg.version,
file: path.doc + '/CHANGELOG.md'
}, function (err, log) {
fs.writeFileSync(path.doc + '/CHANGELOG.md', log);
});
});
gulp.task('build', function (callback) {
return runSequence(
'clean',
['build-system', 'build-html'],
callback
);
});
gulp.task('webdriver_update', webdriver_update);
gulp.task('build-e2e', function () {
return gulp.src(path.e2eSpecsSrc)
.pipe(plumber())
.pipe(to5())
.pipe(gulp.dest(path.e2eSpecsDist));
});
gulp.task('e2e', ['webdriver_update', 'build-e2e'], function (cb) {
return gulp.src(path.e2eSpecsDist + "/*.js")
.pipe(protractor({
configFile: "protractor.conf.js",
args: ['--baseUrl', 'http://127.0.0.1:9000']
}))
.on('error', function (e) {
throw e;
});
});
gulp.task('update-own-deps', function () {
tools.updateOwnDependenciesFromLocalRepositories();
});
gulp.task('build-dev-env', function () {
tools.buildDevEnv();
});
gulp.task('serve', ['build'], function (done) {
browserSync({
open: false,
port: 9000,
server: {
baseDir: ['.'],
middleware: function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
next();
}
}
}, done);
});
function reportChange(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
}
gulp.task('watch', ['serve'], function () {
gulp.watch(path.source, ['build-system', browserSync.reload]).on('change', reportChange);
gulp.watch(path.html, ['build-html', browserSync.reload]).on('change', reportChange);
gulp.watch(path.style, browserSync.reload).on('change', reportChange);
});
gulp.task('prepare-release', function (callback) {
return runSequence(
'build',
'lint',
'bump-version',
'doc',
'changelog',
callback
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment