From 5d70435b9450227532307e9f575309e11f777da9 Mon Sep 17 00:00:00 2001 From: Swagata Prateek Date: Thu, 23 Jun 2016 14:47:53 +0600 Subject: [PATCH 1/5] #73, production build script on the way, need to minify this --- .gitignore | 2 ++ gulpfile.js | 59 +++++++++++++++++++++++++++++++++++++++------------- package.json | 3 ++- 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 1e9bcb2..9ed485e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ tests/**/*.js.map dist/ npm-debug.log typings/ +tmp/ +outfile.js diff --git a/gulpfile.js b/gulpfile.js index 066eb5d..b0e8312 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,6 +5,7 @@ const del = require('del'); const runSequence = require('run-sequence'); const minimist = require('minimist'); var args = minimist(process.argv.slice(2)); +var Builder = require('systemjs-builder'); // Loading typescript requirements const typescript = require('gulp-typescript'); @@ -19,8 +20,8 @@ var install = require("gulp-install"); /** * Remove dist directory. */ -gulp.task('clean', function (cb) { - del(["dist"]).then(function (paths) { +gulp.task('clean', function(cb) { + del(["dist"]).then(function(paths) { console.log('Deleted files and folders:\n', paths.join('\n')); cb(); }); @@ -29,7 +30,7 @@ gulp.task('clean', function (cb) { /** * Compile TypeScript sources and create sourcemaps in build directory. */ -gulp.task('compile', function () { +gulp.task('compile', function() { var tsProject = typescript.createProject('tsconfig.json'); return tsProject .src(['app/**/*.ts', 'tests/**/*.ts']) @@ -42,7 +43,7 @@ gulp.task('compile', function () { /** * Lint all custom TypeScript files. */ -gulp.task('tslint', function () { +gulp.task('tslint', function() { return gulp.src('app/**/*.ts') .pipe(tslint()) .pipe(tslint.report('verbose')); @@ -51,7 +52,7 @@ gulp.task('tslint', function () { // copy dependencies from node_modules // we are just mimicking the dev environment now, but for production a // lot more has to be done -gulp.task('copy:libs', function () { +gulp.task('copy:libs', function() { return gulp.src([ 'bootstrap/dist/css/bootstrap.min.css', 'bootstrap/dist/css/bootstrap.min.css.map', @@ -79,7 +80,7 @@ gulp.task('copy:libs', function () { // copy dependencies from node_modules // we are just mimicking the dev environment now, but for production a lot more has to be done -gulp.task('copy:test-libs', function () { +gulp.task('copy:test-libs', function() { return gulp.src([ 'jasmine-core/lib/jasmine-core/jasmine.css', 'jasmine-core/lib/jasmine-core/jasmine.js', @@ -92,12 +93,12 @@ gulp.task('copy:test-libs', function () { /** * copy static assets - i.e. non TypeScript compiled source */ -gulp.task('copy:assets', function () { +gulp.task('copy:assets', function() { return gulp.src(['app/**/*', 'assets/**/*', 'systemjs.config.js', 'config.js', 'package.json', 'index.html', 'styles.css', '!app/**/*.ts'], { base: './' }) .pipe(gulp.dest('dist')); }); -gulp.task('copy:test-assets', function () { +gulp.task('copy:test-assets', function() { return gulp.src(['test/**/*', 'test.html', '!test/**/*.ts'], { base: './' }) .pipe(gulp.dest('dist')); }); @@ -105,7 +106,7 @@ gulp.task('copy:test-assets', function () { /** * Watch for changes in HTML and CSS files. */ -gulp.task('watch', function () { +gulp.task('watch', function() { return gulp.src('', { base: "./" }) .pipe(watch(["app/**/*.html", "app/**/*.css", "assets/**/*", "styles.css", "index.html", "test.html", "systemjs.config.js"], { base: "./" })) .pipe(gulp.dest("./dist")); @@ -114,27 +115,57 @@ gulp.task('watch', function () { /** * Watch for changes in TypeScript files. */ -gulp.task('watch-ts', function () { +gulp.task('watch-ts', function() { gulp.watch(['app/**/*.ts', 'tests/**/*.ts'], ['compile']); }); /** - * The build script + * The development build script */ -gulp.task('build', function (callback) { +gulp.task('build', function(callback) { runSequence('clean', 'compile', ['copy:assets', 'copy:test-assets', 'copy:libs', 'copy:test-libs'], callback); }); +/** + * The system-js builder build script + */ + +gulp.task('build-systemjs', function(done) { + var builder = new Builder("./dist", "systemjs.config.js"); + + builder.bundle('./dist/app/main.js', 'outfile.js') + .then(function() { + console.log('Build complete'); + }) + .catch(function(err) { + console.log('Build error'); + console.log(err); + }); +}); + + +/** + * The production build script + */ + +gulp.task('build:prod', function(callback) { + runSequence('clean', + 'compile', + ['copy:assets', 'copy:test-assets', 'copy:libs', 'copy:test-libs'], + callback); +}); + + /** * The deploy script */ -gulp.task('deploy', function () { +gulp.task('deploy', function() { var conn = ftp.create({ host: args.host, user: args.user, @@ -148,7 +179,7 @@ gulp.task('deploy', function () { .pipe(conn.dest('site/wwwroot')); }); -gulp.task('default', ['build'], function () { +gulp.task('default', ['build'], function() { console.log("Building WebCat ..."); }); diff --git a/package.json b/package.json index 78fd979..59ed2f0 100644 --- a/package.json +++ b/package.json @@ -56,9 +56,10 @@ "lite-server": "^2.2.0", "minimist": "^1.2.0", "run-sequence": "^1.2.1", + "systemjs-builder": "^0.15.23", "tslint": "^3.10.2", "typescript": "^1.8.10", "typings": "^0.8.1", "vinyl-ftp": "^0.4.5" } -} \ No newline at end of file +} From 736f9102213f54d5612d93fd1ef598fbb2342920 Mon Sep 17 00:00:00 2001 From: Swagata Prateek Date: Thu, 23 Jun 2016 15:27:43 +0600 Subject: [PATCH 2/5] prod-build failing still, need to move the tmp bundle to prod folder --- .gitignore | 1 + gulpfile.js | 76 ++++++++++++++++++++++++++++++++++++++++++++++------ package.json | 4 +++ 3 files changed, 73 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 9ed485e..02584e8 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ npm-debug.log typings/ tmp/ outfile.js +prod diff --git a/gulpfile.js b/gulpfile.js index b0e8312..e689f39 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,7 +5,10 @@ const del = require('del'); const runSequence = require('run-sequence'); const minimist = require('minimist'); var args = minimist(process.argv.slice(2)); -var Builder = require('systemjs-builder'); +var systemBuilder = require('systemjs-builder'); +var useref = require('gulp-useref'); +var gulpif = require('gulp-if'); +var cssnano = require('gulp-cssnano'); // Loading typescript requirements const typescript = require('gulp-typescript'); @@ -27,6 +30,16 @@ gulp.task('clean', function(cb) { }); }); +/** + * Remove prod directory. + */ +gulp.task('clean:prod', function(cb) { + del(["prod"]).then(function(paths) { + console.log('Deleted files and folders:\n', paths.join('\n')); + cb(); + }); +}); + /** * Compile TypeScript sources and create sourcemaps in build directory. */ @@ -136,18 +149,62 @@ gulp.task('build', function(callback) { */ gulp.task('build-systemjs', function(done) { - var builder = new Builder("./dist", "systemjs.config.js"); - - builder.bundle('./dist/app/main.js', 'outfile.js') + var builder = new systemBuilder("./dist", "systemjs.config.js"); + + builder.buildStatic('app/main.js', 'tmp/bundle.js', { + normalize: true, + minify: true, + mangle: true, + runtime: false, + globalDefs: { DEBUG: false, ENV: 'production' } + } + ) .then(function() { console.log('Build complete'); + done(); }) - .catch(function(err) { - console.log('Build error'); - console.log(err); + .catch(function(ex) { + console.log('error', ex); + done('Build failed.'); }); }); +/** + * The production asset move script + */ +gulp.task('build:prod-asset', function(callback) { + gulp.src('app/**/*.html', { + base: 'app/' + }) + .pipe(gulp.dest('prod/')); + + gulp.src('*.css', { + base: '' + }) + .pipe(cssnano()) + .pipe(gulp.dest('prod/')); + + gulp.src('app/' + '**/*.css', { + base: 'app/' + }) + .pipe(cssnano()) + .pipe(gulp.dest('prod/')); + + gulp.src('assets/' + '**/*.*', { + base: 'assets/' + }) + .pipe(gulp.dest('prod/assets/')); + + gulp.src('index.html') + .pipe(userref()) + .pipe(gulpif('*.css', cssnano())) + .pipe(gulpif('!*.html', rev())) + .pipe(revReplace()) + .pipe(gulp.dest('prod/')) + .on('finish', done); + +}) + /** * The production build script @@ -155,8 +212,11 @@ gulp.task('build-systemjs', function(done) { gulp.task('build:prod', function(callback) { runSequence('clean', + 'clean:prod', 'compile', - ['copy:assets', 'copy:test-assets', 'copy:libs', 'copy:test-libs'], + 'copy:libs', + 'build-systemjs', + 'build:prod-asset', callback); }); diff --git a/package.json b/package.json index 59ed2f0..f90993d 100644 --- a/package.json +++ b/package.json @@ -43,13 +43,17 @@ "concurrently": "^2.0.0", "del": "^2.1.0", "gulp": "^3.9.0", + "gulp-cssnano": "^2.1.2", "gulp-debug": "^2.1.2", + "gulp-if": "^2.0.1", "gulp-inject": "^4.1.0", "gulp-install": "^0.6.0", + "gulp-rev": "^7.1.0", "gulp-rimraf": "^0.2.0", "gulp-sourcemaps": "^1.6.0", "gulp-tslint": "^5.0.0", "gulp-typescript": "^2.8.0", + "gulp-useref": "^3.1.0", "gulp-util": "^3.0.7", "gulp-watch": "^4.3.6", "jasmine-core": "^2.4.1", From f867a244baf35fa2a33a279b8634bcdddf8b3be9 Mon Sep 17 00:00:00 2001 From: Swagata Prateek Date: Thu, 23 Jun 2016 15:46:00 +0600 Subject: [PATCH 3/5] prod-build is passing now #73, need to add the refs to the system now --- gulpfile.js | 27 +++++++++++---------------- package.json | 1 + 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index e689f39..1e1292c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -9,6 +9,8 @@ var systemBuilder = require('systemjs-builder'); var useref = require('gulp-useref'); var gulpif = require('gulp-if'); var cssnano = require('gulp-cssnano'); +var rev = require('gulp-rev'); +var revReplace = require('gulp-rev-replace'); // Loading typescript requirements const typescript = require('gulp-typescript'); @@ -151,7 +153,7 @@ gulp.task('build', function(callback) { gulp.task('build-systemjs', function(done) { var builder = new systemBuilder("./dist", "systemjs.config.js"); - builder.buildStatic('app/main.js', 'tmp/bundle.js', { + builder.buildStatic('app/main.js', 'prod/app/bundle.js', { normalize: true, minify: true, mangle: true, @@ -172,31 +174,24 @@ gulp.task('build-systemjs', function(done) { /** * The production asset move script */ -gulp.task('build:prod-asset', function(callback) { - gulp.src('app/**/*.html', { - base: 'app/' - }) +gulp.task('build:prod-asset', function(done) { + + gulp.src(['app/**/*.html'], { base: './' }) .pipe(gulp.dest('prod/')); - gulp.src('*.css', { - base: '' - }) + gulp.src(['*.css'], { base: './' }) .pipe(cssnano()) .pipe(gulp.dest('prod/')); - gulp.src('app/' + '**/*.css', { - base: 'app/' - }) + gulp.src('app/**/*.css', { base: './' }) .pipe(cssnano()) .pipe(gulp.dest('prod/')); - gulp.src('assets/' + '**/*.*', { - base: 'assets/' - }) - .pipe(gulp.dest('prod/assets/')); + gulp.src('assets/' + '**/*.*', { base: './' }) + .pipe(gulp.dest('prod/')); gulp.src('index.html') - .pipe(userref()) + .pipe(useref()) .pipe(gulpif('*.css', cssnano())) .pipe(gulpif('!*.html', rev())) .pipe(revReplace()) diff --git a/package.json b/package.json index f90993d..46c5857 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "bootstrap": "^3.3.6", "es6-shim": "^0.35.0", "font-awesome": "^4.6.3", + "gulp-rev-replace": "^0.4.3", "jquery": "^2.2.3", "moment": "^2.13.0", "ng2-bootstrap": "^1.0.16", From 8c7d688431c2d4029725490976e7c93497edb0d0 Mon Sep 17 00:00:00 2001 From: Swagata Prateek Date: Thu, 23 Jun 2016 16:22:12 +0600 Subject: [PATCH 4/5] prod-build, need to add the bundle file somehow and a lot of css missing, still promising --- gulpfile.js | 3 ++- index.html | 34 ++++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 1e1292c..2d11757 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -190,7 +190,7 @@ gulp.task('build:prod-asset', function(done) { gulp.src('assets/' + '**/*.*', { base: './' }) .pipe(gulp.dest('prod/')); - gulp.src('index.html') + gulp.src('dist/index.html') .pipe(useref()) .pipe(gulpif('*.css', cssnano())) .pipe(gulpif('!*.html', rev())) @@ -210,6 +210,7 @@ gulp.task('build:prod', function(callback) { 'clean:prod', 'compile', 'copy:libs', + 'copy:assets', 'build-systemjs', 'build:prod-asset', callback); diff --git a/index.html b/index.html index bb6ff9f..923f366 100644 --- a/index.html +++ b/index.html @@ -11,6 +11,8 @@ Loading .. + + @@ -19,7 +21,14 @@ + + + + + + + @@ -29,33 +38,30 @@ - - - - - + + + + + + + + + Loading... - - - - - - - From 241b6bec35b0a34e149b34fe80f470dc846d27f7 Mon Sep 17 00:00:00 2001 From: Swagata Prateek Date: Thu, 23 Jun 2016 21:02:46 +0600 Subject: [PATCH 5/5] #73, basic prod build making done, other issues would be solved in other tickets --- gulpfile.js | 56 ++++++++++++++++++++++++++------------------- index.html | 8 ++++--- package.json | 1 + prod-bs-config.json | 7 ++++++ 4 files changed, 46 insertions(+), 26 deletions(-) create mode 100644 prod-bs-config.json diff --git a/gulpfile.js b/gulpfile.js index 2d11757..75a81da 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -18,15 +18,15 @@ const tscConfig = require('./tsconfig.json'); const sourcemaps = require('gulp-sourcemaps'); const tslint = require('gulp-tslint'); var watch = require('gulp-watch'); - +var inject = require('gulp-inject'); // npm var install = require("gulp-install"); /** * Remove dist directory. */ -gulp.task('clean', function(cb) { - del(["dist"]).then(function(paths) { +gulp.task('clean', function (cb) { + del(["dist"]).then(function (paths) { console.log('Deleted files and folders:\n', paths.join('\n')); cb(); }); @@ -35,8 +35,8 @@ gulp.task('clean', function(cb) { /** * Remove prod directory. */ -gulp.task('clean:prod', function(cb) { - del(["prod"]).then(function(paths) { +gulp.task('clean:prod', function (cb) { + del(["prod"]).then(function (paths) { console.log('Deleted files and folders:\n', paths.join('\n')); cb(); }); @@ -45,7 +45,7 @@ gulp.task('clean:prod', function(cb) { /** * Compile TypeScript sources and create sourcemaps in build directory. */ -gulp.task('compile', function() { +gulp.task('compile', function () { var tsProject = typescript.createProject('tsconfig.json'); return tsProject .src(['app/**/*.ts', 'tests/**/*.ts']) @@ -58,7 +58,7 @@ gulp.task('compile', function() { /** * Lint all custom TypeScript files. */ -gulp.task('tslint', function() { +gulp.task('tslint', function () { return gulp.src('app/**/*.ts') .pipe(tslint()) .pipe(tslint.report('verbose')); @@ -67,7 +67,7 @@ gulp.task('tslint', function() { // copy dependencies from node_modules // we are just mimicking the dev environment now, but for production a // lot more has to be done -gulp.task('copy:libs', function() { +gulp.task('copy:libs', function () { return gulp.src([ 'bootstrap/dist/css/bootstrap.min.css', 'bootstrap/dist/css/bootstrap.min.css.map', @@ -95,7 +95,7 @@ gulp.task('copy:libs', function() { // copy dependencies from node_modules // we are just mimicking the dev environment now, but for production a lot more has to be done -gulp.task('copy:test-libs', function() { +gulp.task('copy:test-libs', function () { return gulp.src([ 'jasmine-core/lib/jasmine-core/jasmine.css', 'jasmine-core/lib/jasmine-core/jasmine.js', @@ -108,12 +108,12 @@ gulp.task('copy:test-libs', function() { /** * copy static assets - i.e. non TypeScript compiled source */ -gulp.task('copy:assets', function() { +gulp.task('copy:assets', function () { return gulp.src(['app/**/*', 'assets/**/*', 'systemjs.config.js', 'config.js', 'package.json', 'index.html', 'styles.css', '!app/**/*.ts'], { base: './' }) .pipe(gulp.dest('dist')); }); -gulp.task('copy:test-assets', function() { +gulp.task('copy:test-assets', function () { return gulp.src(['test/**/*', 'test.html', '!test/**/*.ts'], { base: './' }) .pipe(gulp.dest('dist')); }); @@ -121,7 +121,7 @@ gulp.task('copy:test-assets', function() { /** * Watch for changes in HTML and CSS files. */ -gulp.task('watch', function() { +gulp.task('watch', function () { return gulp.src('', { base: "./" }) .pipe(watch(["app/**/*.html", "app/**/*.css", "assets/**/*", "styles.css", "index.html", "test.html", "systemjs.config.js"], { base: "./" })) .pipe(gulp.dest("./dist")); @@ -130,7 +130,7 @@ gulp.task('watch', function() { /** * Watch for changes in TypeScript files. */ -gulp.task('watch-ts', function() { +gulp.task('watch-ts', function () { gulp.watch(['app/**/*.ts', 'tests/**/*.ts'], ['compile']); }); @@ -139,7 +139,7 @@ gulp.task('watch-ts', function() { * The development build script */ -gulp.task('build', function(callback) { +gulp.task('build', function (callback) { runSequence('clean', 'compile', ['copy:assets', 'copy:test-assets', 'copy:libs', 'copy:test-libs'], @@ -150,7 +150,7 @@ gulp.task('build', function(callback) { * The system-js builder build script */ -gulp.task('build-systemjs', function(done) { +gulp.task('build-systemjs', function (done) { var builder = new systemBuilder("./dist", "systemjs.config.js"); builder.buildStatic('app/main.js', 'prod/app/bundle.js', { @@ -161,11 +161,11 @@ gulp.task('build-systemjs', function(done) { globalDefs: { DEBUG: false, ENV: 'production' } } ) - .then(function() { + .then(function () { console.log('Build complete'); done(); }) - .catch(function(ex) { + .catch(function (ex) { console.log('error', ex); done('Build failed.'); }); @@ -174,7 +174,7 @@ gulp.task('build-systemjs', function(done) { /** * The production asset move script */ -gulp.task('build:prod-asset', function(done) { +gulp.task('build:prod-asset', function (done) { gulp.src(['app/**/*.html'], { base: './' }) .pipe(gulp.dest('prod/')); @@ -190,6 +190,9 @@ gulp.task('build:prod-asset', function(done) { gulp.src('assets/' + '**/*.*', { base: './' }) .pipe(gulp.dest('prod/')); + gulp.src(['dist/lib/font-awesome/fonts/*.*']) + .pipe(gulp.dest('prod/fonts')); + gulp.src('dist/index.html') .pipe(useref()) .pipe(gulpif('*.css', cssnano())) @@ -197,15 +200,21 @@ gulp.task('build:prod-asset', function(done) { .pipe(revReplace()) .pipe(gulp.dest('prod/')) .on('finish', done); +}); -}) - +gulp.task('build:inject-index', function (done) { + var bundleSources = gulp.src('./prod/app/bundle.js', { read: false }); + gulp.src('./prod/index.html') + .pipe(inject(bundleSources, {ignorePath: 'prod'})) + .pipe(gulp.dest('prod/')) + .on('finish', done); +}); /** * The production build script */ -gulp.task('build:prod', function(callback) { +gulp.task('build:prod', function (callback) { runSequence('clean', 'clean:prod', 'compile', @@ -213,6 +222,7 @@ gulp.task('build:prod', function(callback) { 'copy:assets', 'build-systemjs', 'build:prod-asset', + 'build:inject-index', callback); }); @@ -221,7 +231,7 @@ gulp.task('build:prod', function(callback) { * The deploy script */ -gulp.task('deploy', function() { +gulp.task('deploy', function () { var conn = ftp.create({ host: args.host, user: args.user, @@ -235,7 +245,7 @@ gulp.task('deploy', function() { .pipe(conn.dest('site/wwwroot')); }); -gulp.task('default', ['build'], function() { +gulp.task('default', ['build'], function () { console.log("Building WebCat ..."); }); diff --git a/index.html b/index.html index 923f366..e19e2fa 100644 --- a/index.html +++ b/index.html @@ -26,6 +26,7 @@ + @@ -42,11 +43,12 @@ + + - - - + + diff --git a/package.json b/package.json index 46c5857..1ae6cc8 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "build": "gulp build", "prestart": "npm run build", "start": "concurrently --kill-others \"gulp watch\" \"gulp watch-ts\" \"lite-server\"", + "prod": "gulp build:prod && lite-server -c prod-bs-config.json", "lite": "lite-server", "postinstall": "typings install", "tsc": "tsc", diff --git a/prod-bs-config.json b/prod-bs-config.json new file mode 100644 index 0000000..848a5da --- /dev/null +++ b/prod-bs-config.json @@ -0,0 +1,7 @@ +{ + "server": { + "baseDir": [ + "./prod" + ] + } +}