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 uglify = require('gulp-uglify');
|
|
|
|
var rename = require('gulp-rename');
|
2015-10-03 11:54:09 +03:00
|
|
|
|
2016-01-06 18:21:33 +03:00
|
|
|
paths.redocBuilt = path.join(paths.output, paths.outputName) + '.js';
|
2015-10-03 11:54:09 +03:00
|
|
|
gulp.task('build', function (callback) {
|
|
|
|
return runSequence(
|
|
|
|
'clean',
|
2016-01-09 17:20:20 +03:00
|
|
|
'bundleProd',
|
2015-10-03 11:54:09 +03:00
|
|
|
callback
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-01-06 18:21:33 +03:00
|
|
|
gulp.task('bundle', ['bundleSfx', 'concatDeps', 'uglify']);
|
2016-01-09 17:20:20 +03:00
|
|
|
gulp.task('bundleProd', ['bundle', 'uglify']);
|
2015-10-14 23:59:39 +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-01-06 18:21:33 +03:00
|
|
|
// produces minimized verstion of sfx bundle
|
|
|
|
gulp.task('uglify', ['concatDeps'], function() {
|
|
|
|
return gulp.src(paths.redocBuilt)
|
|
|
|
.pipe(sourcemaps.init())
|
|
|
|
.pipe(uglify())
|
|
|
|
.pipe(rename(paths.outputName + '.min.js'))
|
|
|
|
.pipe(sourcemaps.write('./'))
|
|
|
|
.pipe(gulp.dest(paths.output));
|
|
|
|
});
|
|
|
|
|
2015-10-14 23:59:39 +03:00
|
|
|
var JS_DEV_DEPS = [
|
2015-11-03 02:12:08 +03:00
|
|
|
'node_modules/zone.js/dist/zone-microtask.js',
|
|
|
|
'node_modules/reflect-metadata/Reflect.js'
|
2015-10-14 23:59:39 +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: './' })
|
2015-11-22 14:49:31 +03:00
|
|
|
.pipe(sass.sync().on('error', sass.logError))
|
|
|
|
.pipe(gulp.dest(paths.tmp));
|
|
|
|
});
|
|
|
|
|
2015-10-14 23:59:39 +03:00
|
|
|
// concatenate angular2 deps
|
|
|
|
gulp.task('concatDeps', ['bundleSfx'], function() {
|
|
|
|
gulp.src(JS_DEV_DEPS.concat([paths.redocBuilt]))
|
|
|
|
.pipe(sourcemaps.init({loadMaps: true}))
|
2016-01-06 18:21:33 +03:00
|
|
|
.pipe(concat(paths.outputName + '.js'))
|
2015-10-26 22:17:26 +03:00
|
|
|
.pipe(sourcemaps.write('.'))
|
2015-10-14 23:59:39 +03:00
|
|
|
.pipe(gulp.dest(paths.output))
|
|
|
|
});
|
|
|
|
|
2015-10-03 12:50:35 +03:00
|
|
|
gulp.task('bundleSfx', ['inlineTemplates'], function(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
|
|
|
builder.config({
|
|
|
|
separateCSS: true
|
|
|
|
});
|
|
|
|
|
2015-10-03 11:54:09 +03:00
|
|
|
builder
|
2015-10-03 12:50:35 +03:00
|
|
|
.buildStatic(path.join(paths.tmp, paths.sourceEntryPoint),
|
2015-10-14 23:59:39 +03:00
|
|
|
paths.redocBuilt,
|
2015-12-30 11:16:36 +03:00
|
|
|
{ format:'amd', sourceMaps: true, lowResSourceMaps: true }
|
2015-10-07 10:18:02 +03:00
|
|
|
)
|
2015-10-03 11:54:09 +03:00
|
|
|
.then(function() {
|
|
|
|
cb();
|
|
|
|
})
|
|
|
|
.catch(function(err) {
|
|
|
|
cb(new Error(err));
|
|
|
|
});
|
|
|
|
});
|