2015-10-03 11:54:09 +03:00
|
|
|
var gulp = require('gulp');
|
|
|
|
var runSequence = require('run-sequence');
|
|
|
|
var Builder = require('systemjs-builder');
|
2015-10-03 12:50:35 +03:00
|
|
|
var inlineNg2Template = require('gulp-inline-ng2-template');
|
2015-10-03 11:54:09 +03:00
|
|
|
var path = require('path');
|
2015-10-14 23:59:39 +03:00
|
|
|
var sourcemaps = require('gulp-sourcemaps');
|
2015-10-03 11:54:09 +03:00
|
|
|
var paths = require('../paths');
|
2015-10-03 12:50:35 +03:00
|
|
|
var fs= require('fs');
|
2015-10-14 23:59:39 +03:00
|
|
|
var concat = require('gulp-concat');
|
2015-11-22 14:49:31 +03:00
|
|
|
var gulp = require('gulp');
|
|
|
|
var sass = require('gulp-sass');
|
|
|
|
var replace = require('gulp-replace');
|
2016-01-06 18:21:33 +03:00
|
|
|
var rename = require('gulp-rename');
|
2016-05-18 22:18:06 +03:00
|
|
|
var argv = require('yargs').argv;
|
2016-05-20 20:12:54 +03:00
|
|
|
var gulpIf = require('gulp-if');
|
2015-10-03 11:54:09 +03:00
|
|
|
|
|
|
|
gulp.task('build', function (callback) {
|
2016-05-18 22:18:06 +03:00
|
|
|
if (argv.skipRebuild) {
|
|
|
|
console.log('>>> Rebuild skipped')
|
|
|
|
return callback();
|
|
|
|
}
|
2015-10-03 11:54:09 +03:00
|
|
|
return runSequence(
|
|
|
|
'clean',
|
2016-05-18 22:18:06 +03:00
|
|
|
'concatPrism',
|
2016-01-09 23:23:49 +03:00
|
|
|
'bundle',
|
2016-05-18 22:18:06 +03:00
|
|
|
'concatDeps',
|
2016-01-09 23:23:49 +03:00
|
|
|
callback
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-05-18 22:39:21 +03:00
|
|
|
gulp.task('rebuild', function(done) {
|
|
|
|
return runSequence(
|
|
|
|
'bundle',
|
|
|
|
'concatDeps',
|
2016-05-19 10:03:48 +03:00
|
|
|
done
|
2016-05-18 22:39:21 +03:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2015-11-22 14:49:31 +03:00
|
|
|
gulp.task('inlineTemplates', ['sass'], function() {
|
2015-10-03 12:50:35 +03:00
|
|
|
return gulp.src(paths.source, { base: './' })
|
2015-11-22 14:49:31 +03:00
|
|
|
.pipe(replace(/'(.*?\.css)'/g, '\'.tmp/$1\''))
|
2015-10-03 12:50:35 +03:00
|
|
|
.pipe(inlineNg2Template({ base: '/' }))
|
|
|
|
.pipe(gulp.dest(paths.tmp));
|
|
|
|
});
|
|
|
|
|
2016-05-18 22:18:06 +03:00
|
|
|
var JS_DEPS = argv.prod ? [
|
2016-05-20 19:27:47 +03:00
|
|
|
'lib/utils/browser-update.js',
|
|
|
|
'node_modules/zone.js/dist/zone.min.js',
|
|
|
|
'node_modules/reflect-metadata/Reflect.js',
|
|
|
|
'node_modules/babel-polyfill/dist/polyfill.min.js'
|
|
|
|
]: [
|
2016-02-18 00:45:27 +03:00
|
|
|
'lib/utils/browser-update.js',
|
2016-03-27 18:25:46 +03:00
|
|
|
'node_modules/zone.js/dist/zone.js',
|
2016-05-06 00:48:41 +03:00
|
|
|
'node_modules/zone.js/dist/long-stack-trace-zone.js',
|
2016-01-17 14:51:02 +03:00
|
|
|
'node_modules/reflect-metadata/Reflect.js',
|
|
|
|
'node_modules/babel-polyfill/dist/polyfill.js'
|
2016-05-18 22:18:06 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
var outputFileName = paths.redocBuilt + (argv.prod ? '.min.js' : '.js');
|
2016-01-12 01:23:29 +03:00
|
|
|
|
2015-11-22 14:49:31 +03:00
|
|
|
gulp.task('sass', function () {
|
2015-11-22 15:08:28 +03:00
|
|
|
return gulp.src(paths.scss, { base: './' })
|
2016-01-23 15:19:22 +03:00
|
|
|
.pipe(sass.sync({outputStyle: 'compressed'}).on('error', sass.logError))
|
2015-11-22 14:49:31 +03:00
|
|
|
.pipe(gulp.dest(paths.tmp));
|
|
|
|
});
|
|
|
|
|
2015-10-14 23:59:39 +03:00
|
|
|
// concatenate angular2 deps
|
2016-05-18 22:18:06 +03:00
|
|
|
gulp.task('concatDeps', function() {
|
|
|
|
return gulp.src(JS_DEPS.concat([outputFileName]))
|
2016-05-20 20:12:54 +03:00
|
|
|
.pipe(gulpIf(!argv.prod, sourcemaps.init({loadMaps: true})))
|
2016-05-18 22:18:06 +03:00
|
|
|
.pipe(concat(outputFileName))
|
2016-05-20 20:12:54 +03:00
|
|
|
.pipe(gulpIf(!argv.prod, sourcemaps.write('.')))
|
2016-05-18 22:18:06 +03:00
|
|
|
.pipe(gulp.dest('.'))
|
2016-01-12 01:23:29 +03:00
|
|
|
});
|
|
|
|
|
2016-05-18 22:18:06 +03:00
|
|
|
gulp.task('bundle', ['inlineTemplates'], function bundle(cb) {
|
2015-10-26 22:34:32 +03:00
|
|
|
fs.existsSync('dist') || fs.mkdirSync('dist');
|
2015-10-03 11:54:09 +03:00
|
|
|
var builder = new Builder('./', 'system.config.js');
|
2015-10-26 22:34:32 +03:00
|
|
|
|
2015-10-03 11:54:09 +03:00
|
|
|
builder
|
2015-10-03 12:50:35 +03:00
|
|
|
.buildStatic(path.join(paths.tmp, paths.sourceEntryPoint),
|
2016-05-18 22:18:06 +03:00
|
|
|
outputFileName,
|
|
|
|
{ format:'umd', sourceMaps: !argv.prod, lowResSourceMaps: true, minify: argv.prod }
|
2015-10-07 10:18:02 +03:00
|
|
|
)
|
2015-10-03 11:54:09 +03:00
|
|
|
.then(function() {
|
2016-04-09 02:25:23 +03:00
|
|
|
// wait some time to allow flush
|
|
|
|
setTimeout(() => cb(), 500);
|
2015-10-03 11:54:09 +03:00
|
|
|
})
|
|
|
|
.catch(function(err) {
|
|
|
|
cb(new Error(err));
|
|
|
|
});
|
2016-05-18 22:18:06 +03:00
|
|
|
});
|
2016-04-28 22:21:08 +03:00
|
|
|
|
|
|
|
gulp.task('concatPrism', function() {
|
|
|
|
require('../../system.config.js');
|
|
|
|
var prismFolder = System.normalizeSync('prismjs').substring(8);
|
|
|
|
prismFolder = prismFolder.substring(0, prismFolder.length -3);
|
|
|
|
var prismFiles = [
|
|
|
|
'prism.js',
|
|
|
|
'components/prism-actionscript.js',
|
|
|
|
'components/prism-c.js',
|
|
|
|
'components/prism-cpp.js',
|
|
|
|
'components/prism-csharp.js',
|
|
|
|
'components/prism-php.js',
|
|
|
|
'components/prism-coffeescript.js',
|
|
|
|
'components/prism-go.js',
|
|
|
|
'components/prism-haskell.js',
|
|
|
|
'components/prism-java.js',
|
|
|
|
'components/prism-lua.js',
|
|
|
|
'components/prism-matlab.js',
|
|
|
|
'components/prism-perl.js',
|
|
|
|
'components/prism-python.js',
|
|
|
|
'components/prism-r.js',
|
|
|
|
'components/prism-ruby.js',
|
|
|
|
'components/prism-bash.js',
|
|
|
|
'components/prism-swift.js',
|
|
|
|
'components/prism-objectivec.js',
|
|
|
|
'components/prism-scala.js'
|
|
|
|
].map(file => path.join(prismFolder, file));
|
|
|
|
|
2016-05-18 22:18:06 +03:00
|
|
|
return gulp.src(prismFiles)
|
|
|
|
.pipe(concat(path.join(paths.tmp, 'prismjs-bundle.js')))
|
|
|
|
.pipe(gulp.dest('.'))
|
2016-04-28 22:21:08 +03:00
|
|
|
});
|