Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add commands to test build #1522

Merged
merged 1 commit into from
May 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var gulp = require('gulp');
var replace = require('gulp-replace');
var shell = require('gulp-shell');
var rename = require('gulp-rename');
var runseq = require('run-sequence');
var del = require('del');
var fs = require('fs');
var path = require('path');
Expand All @@ -13,7 +15,6 @@ function vulcanize(filename, dstdir, excludes) {
excludes.forEach(function(exclude) {
cmd = cmd + ' --exclude ' + exclude;
});
cmd = cmd + ' --implicit-strip';
}
cmd = cmd + ' --strip-comments';
cmd = cmd + ' ' + filename + ' > ' + path.join(dstdir, filename);
Expand All @@ -30,7 +31,7 @@ gulp.task('mini', ['mkdir'], shell.task(vulcanize(mini, workdir, [micro])));
gulp.task('max', ['mkdir'], shell.task(vulcanize(max, workdir, [mini, micro])));

gulp.task('strip', ['micro', 'mini', 'max'], function() {
return gulp.src(['dist/'+micro, 'dist/' + mini, 'dist/' + max])
return gulp.src(['dist/' + micro, 'dist/' + mini, 'dist/' + max])
.pipe(polyclean.cleanJsComments())
// Collapse newlines
.pipe(replace(/\n\s*\n/g, '\n'))
Expand All @@ -40,16 +41,13 @@ gulp.task('strip', ['micro', 'mini', 'max'], function() {
.pipe(replace('</head><body>\n</body></html>', ''))
// Collapse leading spaces+tabs.
.pipe(replace(/^[ \t]+/gm, ''))
// Restore important newlines
.pipe(replace(/(-->|<script>)/g, '$1\n'))
.pipe(replace(/<\/script>/g, '\n$1'))
// put the out
.pipe(gulp.dest('dist'))
;
});

gulp.task('clean', function(cb) {
del([workdir+'/'+micro, workdir+'/'+mini, workdir+'/'+max], cb);
del(workdir, cb);
});

gulp.task('mkdir', ['clean'], function(cb) {
Expand All @@ -60,3 +58,44 @@ gulp.task('mkdir', ['clean'], function(cb) {

// Default Task
gulp.task('default', ['strip']);

// switch src and build for testing
gulp.task('save-src', function() {
return gulp.src([mini, micro, max])
.pipe(rename(function (p) {
p.extname += '.bak';
}))
.pipe(gulp.dest('.'))
;
});

gulp.task('restore-src', function() {
return gulp.src([mini + '.bak', micro + '.bak', max + '.bak'])
.pipe(rename(function (p) {
p.extname = '';
}))
.pipe(gulp.dest('.'))
;
});

gulp.task('cleanup-switch', function(cb) {
del([mini + '.bak', micro + '.bak', max + '.bak'], cb);
});

gulp.task('switch-build', function() {
return gulp.src(['dist/' + mini, 'dist/' + micro, 'dist/' + max])
.pipe(gulp.dest('.'));
});

gulp.task('restore-build', function() {
return gulp.src([mini, micro, max])
.pipe(gulp.dest('dist'));
});

gulp.task('switch', ['default'], function(cb) {
runseq('save-src', 'switch-build', cb);
});

gulp.task('restore', ['clean'], function(cb) {
runseq('restore-build', 'restore-src', 'cleanup-switch', cb);
});
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
"devDependencies": {
"del": "^1.1.1",
"gulp": "^3.8.11",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.3",
"gulp-shell": "^0.4.0",
"polyclean": "0.0.1",
"run-sequence": "^1.1.0",
"vulcanize": "^1.4.0"
},
"scripts": {
"build": "node_modules/gulp/bin/gulp.js",
"test": "wct"
"test": "wct",
"test-build": "node_modules/gulp/bin/gulp.js switch && wct && node_modules/gulp/bin/gulp.js restore"
},
"repository": {
"type": "git",
Expand Down