Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
HAWKULAR-197: Added sourcemaps and improved performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Viliam Rockai committed May 15, 2015
1 parent 64e3729 commit 46a8ae6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 34 deletions.
66 changes: 32 additions & 34 deletions ui/console/src/main/scripts/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ var gulp = require('gulp'),
path = require('path'),
size = require('gulp-size'),
s = require('underscore.string'),
tslint = require('gulp-tslint');
tslint = require('gulp-tslint'),
jsString;

var plugins = gulpLoadPlugins({});
var pkg = require('./package.json');
Expand Down Expand Up @@ -86,19 +87,26 @@ gulp.task('clean-defs', function () {
});

gulp.task('git-sha', function(cb) {
plugins.git.exec({args : 'log -n 1 --oneline'}, function (err, stdout) {
if (err) throw err;
var versionFile = 'version.js';
var gitSha = stdout.slice(0, -1);
var jsString = 'var HawkularVersion = \'' + gitSha + '\';';
var versionFile = 'version.js';

if(!jsString) {
plugins.git.exec({args: 'log -n 1 --oneline'}, function (err, stdout) {
if (err) throw err;
var gitSha = stdout.slice(0, -1);
jsString = 'var HawkularVersion = \'' + gitSha + '\';';
fs.writeFileSync(versionFile, jsString);
cb();
});
} else {
fs.writeFileSync(versionFile, jsString);
cb();
});
}
});

var gulpTsc = function() {
var gulpTsc = function(done) {
var cwd = process.cwd();
var tsResult = gulp.src(config.ts)
.pipe(plugins.sourcemaps.init())
.pipe(plugins.typescript(config.tsProject))
.on('error', plugins.notify.onError({
message: '#{ error.message }',
Expand All @@ -108,6 +116,7 @@ var gulpTsc = function() {
return eventStream.merge(
tsResult.js
.pipe(plugins.concat('compiled.js'))
.pipe(plugins.sourcemaps.write())
.pipe(gulp.dest('.')),
tsResult.dts
.pipe(gulp.dest('d.ts')))
Expand All @@ -118,15 +127,17 @@ var gulpTsc = function() {
var relative = path.relative(cwd, filename);
fs.appendFileSync('defs.d.ts', '/// <reference path="' + relative + '"/>\n');
return buf;
}));
})).on('end', function(){
done && done();
});
};

gulp.task('tsc', ['clean-defs'], function () {
gulpTsc();
gulp.task('tsc', ['clean-defs'], function (done) {
gulpTsc(done);
});

gulp.task('tsc-live', ['copy-sources','clean-defs'], function () {
gulpTsc();
gulp.task('tsc-live', ['copy-sources','clean-defs'], function (done) {
gulpTsc(done);
});

gulp.task('tslint', function () {
Expand Down Expand Up @@ -160,11 +171,11 @@ var gulpTemplate = function(){
.pipe(gulp.dest('.'));
};

gulp.task('template', ['tsc', 'less'], function () {
gulp.task('template', ['tsc'], function () {
return gulpTemplate();
});

gulp.task('template-live', ['tsc', 'less-live', 'copy-sources'], function () {
gulp.task('template-live', ['tsc-live', 'copy-sources'], function () {
return gulpTemplate();
});

Expand All @@ -190,17 +201,19 @@ var gulpConcat = function() {
var gZipSize = size(gZippedSizeOptions);

return gulp.src(['compiled.js', 'templates.js', 'version.js'])
.pipe(plugins.sourcemaps.init({loadMaps: true}))
.pipe(plugins.concat(config.js))
.pipe(plugins.sourcemaps.write())
.pipe(gulp.dest(config.dist))
.pipe(size(normalSizeOptions))
.pipe(gZipSize);
};

gulp.task('concat', ['template', 'git-sha'], function () {
gulp.task('concat', ['template', 'tsc', 'git-sha'], function () {
return gulpConcat();
});

gulp.task('concat-live', ['template-live', 'git-sha'], function () {
gulp.task('concat-live', ['template-live', 'tsc-live', 'git-sha'], function () {
return gulpConcat();
});

Expand Down Expand Up @@ -237,20 +250,5 @@ gulp.task('copy-kettle-css', ['less-live'] , function() {
.pipe(gulp.dest(config.serverPath));
});

gulp.task('connect', ['watch'], function () {
plugins.connect.server({
root: '.',
livereload: true,
port: 2772,
fallback: 'index.html'
});
});

gulp.task('reload', function () {
gulp.src('.')
.pipe(plugins.connect.reload());
});

gulp.task('build', ['bower', 'path-adjust', 'tslint', 'tsc', 'template', 'concat', 'clean']);
gulp.task('build-live', ['copy-sources', 'bower', 'path-adjust', 'tslint-watch', 'tsc', 'template-live', 'concat-live']);
gulp.task('default', ['connect']);
gulp.task('build', ['bower', 'path-adjust', 'tslint', 'tsc', 'less', 'template', 'concat', 'clean']);
gulp.task('build-live', ['copy-sources', 'bower', 'path-adjust', 'tslint-watch', 'tsc-live', 'less-live', 'template-live', 'concat-live']);
1 change: 1 addition & 0 deletions ui/console/src/main/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"gulp-notify": "^2.1.0",
"gulp-replace": "0.5.3",
"gulp-size": "^1.2.0",
"gulp-sourcemaps": "1.5.0",
"gulp-tslint": "^1.4.2",
"gulp-typescript": "^2.3.0",
"gulp-watch": "^3.0.0",
Expand Down

0 comments on commit 46a8ae6

Please sign in to comment.