Skip to content

Commit ffce61d

Browse files
author
Steve Orvell
committed
Merge pull request #1522 from Polymer/0.9-testable-builds
Add commands to test build
2 parents 1426afc + 95be50e commit ffce61d

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

gulpfile.js

+45-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
var gulp = require('gulp');
22
var replace = require('gulp-replace');
33
var shell = require('gulp-shell');
4+
var rename = require('gulp-rename');
5+
var runseq = require('run-sequence');
46
var del = require('del');
57
var fs = require('fs');
68
var path = require('path');
@@ -13,7 +15,6 @@ function vulcanize(filename, dstdir, excludes) {
1315
excludes.forEach(function(exclude) {
1416
cmd = cmd + ' --exclude ' + exclude;
1517
});
16-
cmd = cmd + ' --implicit-strip';
1718
}
1819
cmd = cmd + ' --strip-comments';
1920
cmd = cmd + ' ' + filename + ' > ' + path.join(dstdir, filename);
@@ -30,7 +31,7 @@ gulp.task('mini', ['mkdir'], shell.task(vulcanize(mini, workdir, [micro])));
3031
gulp.task('max', ['mkdir'], shell.task(vulcanize(max, workdir, [mini, micro])));
3132

3233
gulp.task('strip', ['micro', 'mini', 'max'], function() {
33-
return gulp.src(['dist/'+micro, 'dist/' + mini, 'dist/' + max])
34+
return gulp.src(['dist/' + micro, 'dist/' + mini, 'dist/' + max])
3435
.pipe(polyclean.cleanJsComments())
3536
// Collapse newlines
3637
.pipe(replace(/\n\s*\n/g, '\n'))
@@ -40,16 +41,13 @@ gulp.task('strip', ['micro', 'mini', 'max'], function() {
4041
.pipe(replace('</head><body>\n</body></html>', ''))
4142
// Collapse leading spaces+tabs.
4243
.pipe(replace(/^[ \t]+/gm, ''))
43-
// Restore important newlines
44-
.pipe(replace(/(-->|<script>)/g, '$1\n'))
45-
.pipe(replace(/<\/script>/g, '\n$1'))
4644
// put the out
4745
.pipe(gulp.dest('dist'))
4846
;
4947
});
5048

5149
gulp.task('clean', function(cb) {
52-
del([workdir+'/'+micro, workdir+'/'+mini, workdir+'/'+max], cb);
50+
del(workdir, cb);
5351
});
5452

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

6159
// Default Task
6260
gulp.task('default', ['strip']);
61+
62+
// switch src and build for testing
63+
gulp.task('save-src', function() {
64+
return gulp.src([mini, micro, max])
65+
.pipe(rename(function (p) {
66+
p.extname += '.bak';
67+
}))
68+
.pipe(gulp.dest('.'))
69+
;
70+
});
71+
72+
gulp.task('restore-src', function() {
73+
return gulp.src([mini + '.bak', micro + '.bak', max + '.bak'])
74+
.pipe(rename(function (p) {
75+
p.extname = '';
76+
}))
77+
.pipe(gulp.dest('.'))
78+
;
79+
});
80+
81+
gulp.task('cleanup-switch', function(cb) {
82+
del([mini + '.bak', micro + '.bak', max + '.bak'], cb);
83+
});
84+
85+
gulp.task('switch-build', function() {
86+
return gulp.src(['dist/' + mini, 'dist/' + micro, 'dist/' + max])
87+
.pipe(gulp.dest('.'));
88+
});
89+
90+
gulp.task('restore-build', function() {
91+
return gulp.src([mini, micro, max])
92+
.pipe(gulp.dest('dist'));
93+
});
94+
95+
gulp.task('switch', ['default'], function(cb) {
96+
runseq('save-src', 'switch-build', cb);
97+
});
98+
99+
gulp.task('restore', ['clean'], function(cb) {
100+
runseq('restore-build', 'restore-src', 'cleanup-switch', cb);
101+
});

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010
"devDependencies": {
1111
"del": "^1.1.1",
1212
"gulp": "^3.8.11",
13+
"gulp-rename": "^1.2.2",
1314
"gulp-replace": "^0.5.3",
1415
"gulp-shell": "^0.4.0",
1516
"polyclean": "0.0.1",
17+
"run-sequence": "^1.1.0",
1618
"vulcanize": "^1.4.0"
1719
},
1820
"scripts": {
1921
"build": "node_modules/gulp/bin/gulp.js",
20-
"test": "wct"
22+
"test": "wct",
23+
"test-build": "node_modules/gulp/bin/gulp.js switch && wct && node_modules/gulp/bin/gulp.js restore"
2124
},
2225
"repository": {
2326
"type": "git",

0 commit comments

Comments
 (0)