2016-10-25 03:14:45 +03:00
|
|
|
const gulp = require('gulp');
|
|
|
|
const gulpMerge = require('merge2');
|
|
|
|
const gulpRunSequence = require('run-sequence');
|
|
|
|
const gulpConcat = require('gulp-concat');
|
|
|
|
|
|
|
|
const tsc = require('gulp-typescript');
|
|
|
|
const karma = require('karma');
|
|
|
|
const gulpClean = require('gulp-clean');
|
|
|
|
const path = require('path');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
|
|
|
|
let isTestRun = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inline the templates and styles, and the compile to javascript.
|
|
|
|
*/
|
|
|
|
gulp.task(':build:app', () => {
|
2016-10-25 21:33:19 +03:00
|
|
|
const tsProject = tsc.createProject('tsconfig.json', {
|
|
|
|
module: isTestRun ? 'commonjs' : 'es2015',
|
|
|
|
});
|
2016-10-25 03:14:45 +03:00
|
|
|
|
2016-10-25 21:33:19 +03:00
|
|
|
gulp.src(['./src/**/*.ts'])
|
|
|
|
.pipe(tsProject())
|
|
|
|
.pipe(gulp.dest('./dist'));
|
2016-10-25 03:14:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleans the build folder
|
|
|
|
*/
|
|
|
|
gulp.task('clean', () => gulp.src('dist', { read: false }).pipe(gulpClean(null)));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the main framework to the build folder
|
|
|
|
*/
|
|
|
|
gulp.task('build', (cb) => gulpRunSequence(
|
2016-10-25 21:33:19 +03:00
|
|
|
'clean',
|
|
|
|
[
|
|
|
|
':build:app',
|
|
|
|
],
|
|
|
|
cb
|
2016-10-25 03:14:45 +03:00
|
|
|
));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bundles vendor files for test access
|
|
|
|
*/
|
|
|
|
gulp.task(':test:vendor', function () {
|
2016-10-25 21:33:19 +03:00
|
|
|
const npmVendorFiles = [
|
|
|
|
'@angular', 'core-js/client', 'rxjs', 'systemjs/dist', 'zone.js/dist'
|
|
|
|
];
|
2016-10-25 03:14:45 +03:00
|
|
|
|
2016-10-25 21:33:19 +03:00
|
|
|
return gulpMerge(npmVendorFiles.map(function (root) {
|
|
|
|
const glob = path.join(root, '**/*.+(js|js.map)');
|
2016-10-25 03:14:45 +03:00
|
|
|
|
2016-10-25 21:33:19 +03:00
|
|
|
return gulp.src(path.join('node_modules', glob))
|
|
|
|
.pipe(gulp.dest(path.join('dist/vendor', root)));
|
|
|
|
}));
|
2016-10-25 03:14:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bundles systemjs files
|
|
|
|
*/
|
|
|
|
gulp.task(':test:system', () => {
|
2016-10-25 21:33:19 +03:00
|
|
|
gulp.src('test/bin/**.*')
|
|
|
|
.pipe(tsc())
|
|
|
|
.pipe(gulp.dest('dist/bin'));
|
2016-10-25 03:14:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pre-test setup task
|
|
|
|
*/
|
|
|
|
gulp.task(':test:deps', (cb) => {
|
2016-10-25 21:33:19 +03:00
|
|
|
isTestRun = true;
|
|
|
|
gulpRunSequence(
|
|
|
|
'clean',
|
|
|
|
[
|
|
|
|
':test:system',
|
|
|
|
':test:vendor',
|
|
|
|
':build:app',
|
|
|
|
],
|
|
|
|
cb
|
|
|
|
);
|
2016-10-25 03:14:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Karma unit-testing
|
|
|
|
*/
|
|
|
|
gulp.task('test', [':test:deps'], (done) => {
|
2016-10-25 21:33:19 +03:00
|
|
|
new karma.Server({
|
|
|
|
configFile: path.join(process.cwd(), 'test/karma.confloader.js')
|
|
|
|
}, done).start();
|
2016-10-25 03:14:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task(':demo:clean', () => gulp.src('demo/dist', { read: false }).pipe(gulpClean(null)));
|
|
|
|
|
|
|
|
gulp.task(':demo:build:ts', (cb) => {
|
2016-10-25 21:33:19 +03:00
|
|
|
webpack(require('./demo/webpack.config.js'), cb);
|
2016-10-25 03:14:45 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('demo', (cb) => gulpRunSequence(
|
2016-10-25 21:33:19 +03:00
|
|
|
':demo:clean',
|
|
|
|
[
|
|
|
|
':demo:build:ts',
|
|
|
|
],
|
|
|
|
cb
|
2016-10-25 03:14:45 +03:00
|
|
|
));
|
|
|
|
|