Skip to content

Commit

Permalink
perf(build): minify/ng-annotate on prepare
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Reed committed Apr 3, 2015
1 parent ff2f9b0 commit 5ec1101
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 101 deletions.
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@
<icon src="resources/ios/icon/icon-small@2x.png" width="58" height="58"/>
</platform>
<icon src="resources/android/icon/drawable-xhdpi-icon.png"/>
</widget>
</widget>
163 changes: 93 additions & 70 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,106 +1,129 @@
var gulp = require('gulp');
var gutil = require('gulp-util');

var bower = require('bower');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var jasmine = require('gulp-jasmine');
var jshint = require('gulp-jshint');
var karma = require('gulp-karma');
var minifyCss = require('gulp-minify-css');
var ngAnnotate = require('gulp-ng-annotate');
var rename = require('gulp-rename');
var rev = require('gulp-rev');
var sass = require('gulp-sass');
var sh = require('shelljs');
var jshint = require('gulp-jshint');
var jasmine = require('gulp-jasmine');
var karma = require('gulp-karma');
var uglify = require('gulp-uglify');
var usemin = require('gulp-usemin');

require('gulp-changelog-release')(gulp);

var paths = {
sass: './scss/*.scss',
sassIncludes: './scss/includes/*.scss',
opennms: './www/scripts/opennms/**/*.js',
spec: './spec/*.js'
sass: './scss/*.scss',
sassIncludes: './scss/includes/*.scss',
opennms: './www/scripts/opennms/**/*.js',
spec: './spec/*.js'
};

gulp.task('default', ['sass', 'lint', 'test']);

gulp.task('sass', function(done) {
gulp.src([paths.sass])
.pipe(sass())
.pipe(gulp.dest('./www/css/'))
.pipe(minifyCss({
keepSpecialComments: 0
}))
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest('./www/css/'))
.on('end', done);
gulp.src([paths.sass])
.pipe(sass())
.pipe(gulp.dest('./www/css/'))
.pipe(minifyCss({
keepSpecialComments: 0
}))
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest('./www/css/'))
.on('end', done);
});

gulp.task('lint', function() {
return gulp.src([paths.opennms, paths.spec])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
return gulp.src([paths.opennms, paths.spec])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
});

gulp.task('watch', function() {
gulp.watch([paths.sass, paths.sassIncludes], ['sass']);
gulp.watch([paths.sass, paths.sassIncludes], ['sass']);
});

gulp.task('prepare', function() {
return gulp.src('www/index.html')
.pipe(usemin({
shim: [uglify(), rev()],
thirdparty: [uglify(), rev()],
ipv6: [uglify(), rev()],
angular: [ngAnnotate(), uglify(), rev()],
charts: [uglify(), rev()],
models: [uglify(), rev()],
opennms: [ngAnnotate(), uglify(), rev()],
}))
.pipe(gulp.dest('platforms/android/assets/www'))
.pipe(gulp.dest('platforms/ios/www'));
});

gulp.task('install', ['git-check'], function() {
return bower.commands.install()
.on('log', function(data) {
gutil.log('bower', gutil.colors.cyan(data.id), data.message);
});
return bower.commands.install()
.on('log', function(data) {
gutil.log('bower', gutil.colors.cyan(data.id), data.message);
});
});

gulp.task('git-check', function(done) {
if (!sh.which('git')) {
console.log(
' ' + gutil.colors.red('Git is not installed.'),
'\n Git, the version control system, is required to download Ionic.',
'\n Download git here:', gutil.colors.cyan('http://git-scm.com/downloads') + '.',
'\n Once git is installed, run \'' + gutil.colors.cyan('gulp install') + '\' again.'
);
process.exit(1);
}
done();
if (!sh.which('git')) {
console.log(
' ' + gutil.colors.red('Git is not installed.'),
'\n Git, the version control system, is required to download Ionic.',
'\n Download git here:', gutil.colors.cyan('http://git-scm.com/downloads') + '.',
'\n Once git is installed, run \'' + gutil.colors.cyan('gulp install') + '\' again.'
);
process.exit(1);
}
done();
});

var testSource = [
'./www/lib/modernizr/modernizr.js',
'./www/lib/es5-shim/es5-shim.js',
'./www/lib/blob-util/dist/blob-util.min.js',
'./www/lib/jquery/dist/jquery.min.js',
'./www/lib/jquery-visible/jquery.visible.min.js',
'./www/lib/async/lib/async.js',
'./www/lib/angular/angular.min.js',
'./www/lib/angular-animate/angular-animate.min.js',
'./www/lib/angular-cookies/angular-cookies.min.js',
'./www/lib/angular-sanitize/angular-sanitize.min.js',
'./www/lib/angular-ui-router/release/angular-ui-router.min.js',
'./www/lib/angular-mocks/angular-mocks.js',
'./www/lib/ionic/release/js/ionic.min.js',
'./www/lib/ionic/release/js/ionic-angular.min.js',
'./www/lib/angularLocalStorage/src/angularLocalStorage.js',
'./www/lib/angular-queue/angular-queue.js',
'./www/lib/ng-resize/ngresize.min.js',
'./www/lib/ngCordova/dist/ng-cordova-mocks.js',
'./www/lib/momentjs/moment.js',
paths.opennms,
paths.spec
'./www/lib/modernizr/modernizr.js',
'./www/lib/es5-shim/es5-shim.js',
'./www/lib/blob-util/dist/blob-util.min.js',
'./www/lib/jquery/dist/jquery.min.js',
'./www/lib/jquery-visible/jquery.visible.min.js',
'./www/lib/async/lib/async.js',
'./www/lib/angular/angular.min.js',
'./www/lib/angular-animate/angular-animate.min.js',
'./www/lib/angular-cookies/angular-cookies.min.js',
'./www/lib/angular-sanitize/angular-sanitize.min.js',
'./www/lib/angular-ui-router/release/angular-ui-router.min.js',
'./www/lib/angular-mocks/angular-mocks.js',
'./www/lib/ionic/release/js/ionic.min.js',
'./www/lib/ionic/release/js/ionic-angular.min.js',
'./www/lib/angularLocalStorage/src/angularLocalStorage.js',
'./www/lib/angular-queue/angular-queue.js',
'./www/lib/ng-resize/ngresize.min.js',
'./www/lib/ngCordova/dist/ng-cordova-mocks.js',
'./www/lib/momentjs/moment.js',
paths.opennms,
paths.spec
];

gulp.task('test', ['lint'], function(done) {
gulp.src(testSource)
.pipe(karma({
configFile: 'karma.conf.js',
action: 'run'
}))
.on('error', function(err) {
throw err;
});
gulp.src(testSource)
.pipe(karma({
configFile: 'karma.conf.js',
action: 'run'
}))
.on('error', function(err) {
throw err;
});
});

gulp.task('continuous', function() {
gulp.src(testSource)
.pipe(karma({
configFile: 'karma.conf.js',
action: 'watch'
}));
gulp.src(testSource)
.pipe(karma({
configFile: 'karma.conf.js',
action: 'watch'
}));
});

9 changes: 9 additions & 0 deletions hooks/after_prepare/zzz_minify_javascript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node

var exec = require('child_process').exec;

var rootdir = process.argv[2];

if (rootdir) {
exec('gulp prepare');
}
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"name": "OpenNMS",
"version": "2.0.0",
"description": "OpenNMS Compass",
"repository": {
"type": "git",
"url": "http://github.com/OpenNMS/opennms-compass.git"
},
"dependencies": {
"gulp": "*",
"gulp-concat": "*",
Expand All @@ -15,13 +19,18 @@
"commonmark": "*",
"cordova-android": "*",
"fs.extra": "*",
"gulp-bytediff": "^0.2.1",
"grunt-conventional-changelog": "^1.2.1",
"gulp-changelog-release": "0.0.11",
"gulp-grunt": "^0.5.2",
"gulp-jasmine": "*",
"gulp-jshint": "*",
"gulp-karma": "*",
"gulp-minify-css": "^1.0.0",
"gulp-ng-annotate": "^0.5.2",
"gulp-rev": "^3.0.1",
"gulp-sourcemaps": "^1.5.0",
"gulp-uglify": "^1.1.0",
"gulp-usemin": "^0.3.11",
"jshint": "*",
"jshint-stylish": "*",
"karma": "*",
Expand Down
53 changes: 24 additions & 29 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@
<meta name="format-detection" content="telephone=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />

<!-- build:css(.tmp) styles/3rdparty.css -->
<!-- endbuild -->

<!-- build:css(.tmp) styles/cm.css -->
<link rel="stylesheet" href="css/opennms.css" />
<!-- endbuild -->
<link rel="stylesheet" href="css/opennms.min.css" />

<style>
[ng\:cloak], [ng-cloak], .ng-cloak {
Expand All @@ -35,45 +30,45 @@
<body class="antialiased off-canvas hide-extras" ng-class="themeType" ng-cloak animation="no-animation">
<ion-nav-view></ion-nav-view>

<!-- build:js scripts/shim.js -->
<!-- build:shim scripts/shim.js -->
<script src="lib/modernizr/modernizr.js"></script>
<script src="lib/classlist/classList.min.js"></script>
<script src="lib/es5-shim/es5-shim.min.js"></script>
<script src="lib/classlist/classList.js"></script>
<script src="lib/es5-shim/es5-shim.js"></script>
<!-- endbuild -->

<!-- build:js scripts/3rdparty.js -->
<script src="lib/jquery/dist/jquery.min.js"></script>
<script src="lib/jquery-visible/jquery.visible.min.js"></script>
<!-- build:thirdparty scripts/3rdparty.js -->
<script src="lib/jquery/dist/jquery.js"></script>
<script src="lib/jquery-visible/jquery.visible.js"></script>
<script src="lib/async/lib/async.js"></script>
<script src="lib/momentjs/min/moment.min.js"></script>
<script src="lib/x2js/xml2json.min.js"></script>
<script src="lib/momentjs/moment.js"></script>
<script src="lib/x2js/xml2json.js"></script>
<!-- endbuild -->

<!-- build:js scripts/ipv6.js -->
<!-- build:ipv6 scripts/ipv6.js -->
<script src="lib/ipv6/lib/browser/jsbn.js"></script>
<script src="lib/ipv6/lib/browser/jsbn2.js"></script>
<script src="lib/ipv6/lib/browser/sprintf.js"></script>
<script src="lib/ipv6/ipv6.js"></script>
<!-- endbuild -->

<!-- build:js scripts/angular.js -->
<script src="lib/angular/angular.min.js"></script>
<script src="lib/angular-animate/angular-animate.min.js"></script>
<script src="lib/angular-cookies/angular-cookies.min.js"></script>
<script src="lib/angular-sanitize/angular-sanitize.min.js"></script>
<script src="lib/angular-ui-router/release/angular-ui-router.min.js"></script>
<script src="lib/ionic/release/js/ionic.min.js"></script>
<script src="lib/ionic/release/js/ionic-angular.min.js"></script>
<!-- build:angular scripts/angular.js -->
<script src="lib/angular/angular.js"></script>
<script src="lib/angular-animate/angular-animate.js"></script>
<script src="lib/angular-cookies/angular-cookies.js"></script>
<script src="lib/angular-sanitize/angular-sanitize.js"></script>
<script src="lib/angular-ui-router/release/angular-ui-router.js"></script>
<script src="lib/ionic/release/js/ionic.js"></script>
<script src="lib/ionic/release/js/ionic-angular.js"></script>
<script src="lib/angularLocalStorage/src/angularLocalStorage.js"></script>
<script src="lib/ng-resize/ngresize.min.js"></script>
<script src="lib/ng-resize/ngresize.js"></script>
<!-- endbuild -->

<!-- build.js scripts/charts.js -->
<script src="lib/d3/d3.min.js"></script>
<script src="lib/d3pie/d3pie/d3pie.min.js"></script>
<!-- build:charts scripts/charts.js -->
<script src="lib/d3/d3.js"></script>
<script src="lib/d3pie/d3pie/d3pie.js"></script>
<!-- endbuild -->

<!-- build:js scripts/models.js -->
<!-- build:models scripts/models.js -->
<script src="scripts/opennms/models/Array.js"></script>
<script src="scripts/opennms/models/String.js"></script>
<script src="scripts/opennms/models/Alarm.js"></script>
Expand All @@ -96,7 +91,7 @@
<script src="scripts/opennms/models/RestError.js"></script>
<!-- endbuild -->

<!-- build:js scripts/cm.js -->
<!-- build:opennms scripts/opennms.js -->
<script src="scripts/opennms/main.js"></script>
<script src="scripts/opennms/controllers/Alarms.js"></script>
<script src="scripts/opennms/controllers/Dashboard.js"></script>
Expand Down

0 comments on commit 5ec1101

Please sign in to comment.