arcade-machine/gulpfile.js

164 строки
3.6 KiB
JavaScript
Исходник Постоянная ссылка Обычный вид История

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');
2016-12-13 00:17:55 +03:00
const exec = require('child_process').exec;
2016-10-25 03:14:45 +03:00
let isTestRun = false;
/**
2016-12-13 00:17:55 +03:00
* Copy the tsconfig to the staging folder
2016-10-25 03:14:45 +03:00
*/
2016-12-13 00:17:55 +03:00
gulp.task(':build:copy', () => {
return gulp
.src('./tsconfig.json')
.pipe(gulp.dest('./staging'));
2016-10-25 03:14:45 +03:00
});
2016-12-13 00:17:55 +03:00
/**
* Inline styles and templates and output the result into staging
*/
gulp.task(':build:inline', () => {
return gulp.src(['./src/**/*.ts', '!./src/**/*.spec.ts'])
.pipe(gulp.dest('./staging/src'))
})
/**
* Compile typescrypt using ngc.
*/
gulp.task(':build:ngc', (cb) => {
exec('npm run ngc', function (err, stdout, stderr) {
if (err && err.message.includes('npm ERR!')) {
console.log(stdout);
cb(new Error(err.message.substring(0, err.message.indexOf('npm ERR!')).trim()));
return;
}
cb(err);
});
})
/**
* Remove the staging folder
*/
gulp.task(':build:clean', () => gulp.src('staging', { read: false }).pipe(gulpClean(null)));
/**
* Copy compiled code into the dist folder, excluding the typescript source.
*/
gulp.task(':build:copyFinal', () => {
return gulp
.src(['./staging/src/**/*', '!./staging/src/**/*.ts'])
.pipe(gulp.dest('./dist'));
})
/**
* Copy the typedefs to dist, this was missing in :build:copyFinal.
*/
gulp.task(':build:typeDefs', () => {
return gulp
.src(['./staging/src/**/*.d.ts'])
.pipe(gulp.dest('./dist'));
})
/**
* Inline and then compile the lib.
*/
gulp.task(':build:app', (cb) => gulpRunSequence(
':build:inline',
':build:copy',
':build:ngc',
[
':build:copyFinal',
':build:typeDefs',
],
cb
));
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-12-13 00:17:55 +03:00
[
'clean',
':build:clean',
],
[
':build:app',
],
':build:clean',
cb
2016-10-25 03:14:45 +03:00
));
/**
2016-12-13 00:17:55 +03:00
* Inline the templates and styles, and the compile to javascript.
2016-10-25 03:14:45 +03:00
*/
2016-12-13 00:17:55 +03:00
gulp.task(':test:build', () => {
const tsProject = tsc.createProject('tsconfig.json', {
module: 'commonjs',
});
const src = ['./src/**/*.ts'];
2016-10-25 03:14:45 +03:00
2016-12-13 00:17:55 +03:00
return gulp.src(src)
.pipe(tsProject())
.pipe(gulp.dest('./dist'));
});
2016-10-25 03:14:45 +03:00
2016-12-13 00:17:55 +03:00
/**
* Bundles vendor files for test access
*/
gulp.task(':test:vendor', function () {
const npmVendorFiles = [
'@angular', 'core-js/client', 'rxjs', 'systemjs/dist', 'zone.js/dist'
];
return gulpMerge(
npmVendorFiles.map(root =>
gulp.src(path.join('node_modules', path.join(root, '**/*.+(js|js.map)')))
.pipe(gulp.dest(path.join('dist/vendor', root)))
));
2016-10-25 03:14:45 +03:00
});
/**
* Bundles systemjs files
*/
gulp.task(':test:system', () => {
2016-12-13 00:17:55 +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-12-13 00:17:55 +03:00
isTestRun = true;
gulpRunSequence(
'clean',
[
':test:system',
':test:vendor',
':test:build',
],
cb
);
2016-10-25 03:14:45 +03:00
});
/**
* Karma unit-testing
*/
gulp.task('test', [':test:deps'], (done) => {
2016-12-13 00:17:55 +03:00
new karma.Server({
configFile: path.join(process.cwd(), 'test/karma.conf.js')
2016-12-13 00:17:55 +03:00
}, done).start();
2016-10-25 03:14:45 +03:00
});