Revert "gulp4 ftw"

This reverts commit 8aa0614cde30f648cc796ef8cc4b68ea01ea3e10.
This commit is contained in:
Tim Lancina
2015-07-22 09:11:09 -05:00
parent ccb86e6c4b
commit becfac3b60
2 changed files with 208 additions and 198 deletions

View File

@ -53,224 +53,243 @@ var tscReporter = {
} }
}; };
// Framework gulp.task('clean.build', function() {
gulp.task('transpile', transpileTask); runSequence(
gulp.task('bundle.js', bundleJsTask); 'clean',
gulp.task('sass', sassTask); 'transpile',
gulp.task('fonts', fontsTask); //'bundle.deps',
'bundle.js',
'examples',
'sass',
'fonts',
'vendor',
'copy-scripts');
})
// Karma testing gulp.task('build', function() {
gulp.task('tests', testsTask); runSequence(
gulp.task('karma', karmaTask); 'transpile',
gulp.task('karma-watch', karmaWatchTask); 'bundle.js',
'examples',
'sass',
'fonts',
'vendor',
'copy-scripts');
})
// e2e testing gulp.task('watch', function() {
gulp.task('e2e.copy', e2eCopyTask);
gulp.task('e2e.template', e2eHTMLTemplateTask);
gulp.task('e2e.transpile', e2eTranspileTask);
gulp.task('e2e.tests', e2eTestsTask);
gulp.task('e2e', gulp.parallel('e2e.copy', 'e2e.template', 'e2e.transpile', 'e2e.tests'));
// Utility runSequence(
gulp.task('clean', cleanTask); 'transpile',
gulp.task('vendor', vendorTask); 'bundle.js',
gulp.task('copy-scripts', copyScriptsTask); 'examples',
gulp.task('serve', serveTask); 'sass',
gulp.task('watch-task', watchTask); 'fonts',
gulp.task('watch', gulp.series('serve', 'watch-task')); 'vendor',
gulp.task('examples', gulp.parallel('e2e.copy', 'e2e.template', 'e2e.transpile')); 'copy-scripts',
'serve',
// Build function() {
gulp.task('build', gulp.parallel( watch(
gulp.series('transpile', 'bundle.js', 'copy-scripts'), [
'sass', 'ionic/**/*.js',
'fonts', 'ionic/**/*.ts',
'vendor' '!ionic/components/*/test/**/*',
)) '!ionic/util/test/*'
],
function() {
runSequence(
'transpile',
'bundle.js',
'examples'
)
}
);
gulp.task('clean.build', gulp.series( watch('ionic/components/*/test/**/*', function() {
'clean', gulp.start('examples');
'build' });
));
gulp.task('build.watch', gulp.series( watch('ionic/**/*.scss', function() {
gulp.parallel('build', 'examples'), gulp.start('sass');
'serve', });
'watch-task' })
)) });
/*****************************************************************************/ gulp.task('serve', function() {
function watchTask(done) {
watch([
'ionic/**/*.js',
'ionic/**/*.ts',
'!ionic/components/*/test/**/*',
'!ionic/util/test/*'
],
gulp.series('transpile', 'bundle.js')
);
watch('ionic/components/*/test/**/*.ts', e2eTranspileTask);
watch('scripts/e2e/e2e.template.html', e2eHTMLTemplateTask);
watch([
'ionic/components/*/test/**/*',
'!ionic/components/*/test/**/*.ts'
],
e2eCopyTask
);
watch('ionic/**/*.scss', sassTask);
done();
}
function serveTask(done) {
connect.server({ connect.server({
root: 'dist', root: 'dist',
port: 8000, port: 8000,
livereload: false livereload: false
}); });
done(); });
}
function cleanTask(done) { gulp.task('clean', function(done) {
del(['dist/'], done); del(['dist/'], done);
} });
function transpileTask() { gulp.task('transpile', function() {
var stream = gulp.src([ var stream = gulp.src(
'ionic/**/*.ts', [
'ionic/**/*.js', 'ionic/**/*.ts',
'!ionic/components/*/test/**/*', 'ionic/**/*.js',
'!ionic/init.js', '!ionic/components/*/test/**/*',
'!ionic/util/test/*' '!ionic/init.js',
]) '!ionic/util/test/*'
.pipe(cache('transpile', { optimizeMemory: true })) ]
.pipe(tsc(tscOptions, null, tscReporter)) )
.on('error', function(error) { .pipe(cache('transpile', { optimizeMemory: true }))
stream.emit('end'); .pipe(tsc(tscOptions, null, tscReporter))
}) .on('error', function(error) {
.pipe(gulp.dest('dist/js/es6/ionic')) stream.emit('end');
.pipe(babel(getBabelOptions('ionic'))) })
.on('error', function (err) { .pipe(gulp.dest('dist/js/es6/ionic'))
console.log("ERROR: " + err.message); .pipe(babel(getBabelOptions('ionic')))
this.emit('end'); .on('error', function (err) {
}) console.log("ERROR: " + err.message);
.pipe(gulp.dest('dist/js/es5/ionic')) this.emit('end');
})
.pipe(gulp.dest('dist/js/es5/ionic'))
return stream; return stream;
} });
function bundleJsTask() { gulp.task('bundle.js', function() {
return gulp.src(['dist/js/es5/ionic/**/*.js', 'ionic/init.js']) return gulp.src(['dist/js/es5/ionic/**/*.js', 'ionic/init.js'])
.pipe(concat('ionic.bundle.js')) .pipe(concat('ionic.bundle.js'))
.pipe(gulp.dest('dist/js/')); .pipe(gulp.dest('dist/js/'));
} });
function testsTask() { gulp.task('tests', function() {
return gulp.src('ionic/components/*/test/*/**/*.spec.ts') return gulp.src('ionic/components/*/test/*/**/*.spec.ts')
.pipe(tsc(tscOptions, null, tscReporter)) .pipe(tsc(tscOptions, null, tscReporter))
.pipe(babel(getBabelOptions('tests'))) .pipe(babel(getBabelOptions('tests')))
.pipe(rename(function(file) { .pipe(rename(function(file) {
file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep) file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep)
})) }))
.pipe(gulp.dest('dist/tests')) .pipe(gulp.dest('dist/tests'))
} })
function copyScriptsTask() { gulp.task('examples', function() {
return gulp.src([ var buildTest = lazypipe()
'scripts/resources/*.js', .pipe(tsc, tscOptions, null, tscReporter)
'config.js', .pipe(babel, getBabelOptions('examples'))
'dist/js/ionic.bundle.js',
'dist/vendor/web-animations-js/web-animations.min.js'
])
.pipe(gulp.dest('dist/lib'));
}
// Get each test folder with gulp.src
function e2eCopyTask() { return gulp.src(['ionic/components/*/test/*/**/*', '!ionic/components/*/test/*/**/*.spec.ts'])
return gulp.src([ .pipe(cache('examples', { optimizeMemory: true }))
'ionic/components/*/test/*/**/*', .pipe(gulpif(/.ts$/, buildTest()))
'!ionic/components/*/test/*/**/*.ts'
])
.pipe(rename(function(file) {
file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep)
}))
.pipe(gulp.dest('dist/e2e'))
}
function e2eTranspileTask() {
return gulp.src([
'ionic/components/*/test/*/**/*.ts',
'!ionic/components/*/test/*/**/*.spec.ts',
'!ionic/components/*/test/*/**/e2e.ts'
])
.pipe(cache('e2e.transpile', { optimizeMemory: true }))
.pipe(tsc(tscOptions, null, tscReporter))
.pipe(babel(getBabelOptions('e2e')))
.on('error', function (err) { .on('error', function (err) {
console.log("ERROR: " + err.message); console.log("ERROR: " + err.message);
this.emit('end'); this.emit('end');
}) })
.pipe(gulpif(/index.js$/, createIndexHTML())) //TSC changes .ts to .js
.pipe(rename(function(file) { .pipe(rename(function(file) {
file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep) file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep)
})) }))
.pipe(gulp.dest('dist/e2e/')) .pipe(gulp.dest('dist/examples/'))
}
function e2eHTMLTemplateTask() { function createIndexHTML() {
var HTMLTemplate = _.template( var template = _.template(
fs.readFileSync('scripts/e2e/e2e.template.html') fs.readFileSync('scripts/e2e/example.template.html')
)({ )({
buildConfig: buildConfig buildConfig: buildConfig
}); });
return through2.obj(function(file, enc, next) {
var self = this;
// we won't actually do anything with index.ts, we just know that this is the
// location index.html should be
return gulp.src('ionic/components/*/test/*/**/index.ts')
.pipe(cache('e2e.html.template', { optimizeMemory: true }))
.pipe(through2.obj(function(file, enc, next) {
var module = path.dirname(file.path) var module = path.dirname(file.path)
.replace(__dirname, '') .replace(__dirname, '')
.replace('/ionic/components/', 'e2e/') .replace('/ionic/components/', 'examples/')
.replace('/test/', '/') + .replace('/test/', '/') +
'/index'; '/index';
var templateContents = HTMLTemplate.replace('{{MODULE}}', module); var indexContents = template.replace('{{MODULE}}', module);
var indexFile = new VinylFile({
base: file.base, self.push(new VinylFile({
contents: new Buffer(templateContents), base: file.base,
path: path.join(path.dirname(file.path), 'index.html'), contents: new Buffer(indexContents),
}) path: path.join(path.dirname(file.path), 'index.html'),
next(null, indexFile); }));
})) next(null, file);
.pipe(rename(function(file) { });
file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep) }
})) });
.pipe(gulp.dest('dist/e2e/'))
} gulp.task('copy-scripts', function(){
gulp.src(['scripts/resources/*.js', 'config.js', 'dist/js/ionic.bundle.js',
'dist/vendor/web-animations-js/web-animations.min.js'])
.pipe(gulp.dest('dist/lib'));
})
gulp.task('e2e', ['copy-scripts'], function() {
var buildTest = lazypipe()
//.pipe(traceur, traceurOptions)
.pipe(tsc, tscOptions, null, tscReporter)
.pipe(babel, getBabelOptions('e2e'))
var buildE2ETest = lazypipe()
//.pipe(traceur, traceurOptions)
.pipe(tsc, tscOptions, null, tscReporter)
.pipe(babel)
var indexTemplate = _.template(
fs.readFileSync('scripts/e2e/e2e.template.html')
)({
buildConfig: buildConfig
})
var testTemplate = _.template( fs.readFileSync('scripts/e2e/e2e.template.js') )
function e2eTestsTask() {
var testTemplate = _.template(fs.readFileSync('scripts/e2e/e2e.template.js'));
var platforms = [ var platforms = [
'android', 'android',
'core', 'core',
'ios', 'ios',
]; ];
return gulp.src('ionic/components/*/test/*/**/e2e.ts') // Get each test folder with gulp.src
.pipe(cache('e2e.tests', { optimizeMemory: true })) return gulp.src(['ionic/components/*/test/*/**/*', '!ionic/components/*/test/*/**/*.spec.ts'])
.pipe(tsc(tscOptions, null, tscReporter)) .pipe(cache('e2e', { optimizeMemory: true }))
.pipe(babel()) .pipe(gulpif(/e2e.ts$/, buildE2ETest()))
.pipe(gulpif(/.ts$/, buildTest()))
.on('error', function (err) { .on('error', function (err) {
console.log("ERROR: " + err.message); console.log("ERROR: " + err.message);
this.emit('end'); this.emit('end');
}) })
.pipe(gulpif(/index.js$/, createIndexHTML())) //TSC changes .ts to .js
.pipe(rename(function(file) { .pipe(rename(function(file) {
file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep) file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep)
})) }))
.pipe(through2.obj(function(file, enc, next) { .pipe(gulpif(/e2e.js$/, createPlatformTests()))
.pipe(gulp.dest('dist/e2e/'))
function createIndexHTML() {
return through2.obj(function(file, enc, next) {
var self = this; var self = this;
var relativePath = path.dirname(file.path.replace(/^.*?ionic(\/|\\)components(\/|\\)/, ''));
var contents = file.contents.toString(); var module = path.dirname(file.path)
.replace(__dirname, '')
.replace('/ionic/components/', 'e2e/')
.replace('/test/', '/') +
'/index';
var indexContents = indexTemplate.replace('{{MODULE}}', module);
self.push(new VinylFile({
base: file.base,
contents: new Buffer(indexContents),
path: path.join(path.dirname(file.path), 'index.html'),
}));
next(null, file);
});
}
function createPlatformTests(file) {
return through2.obj(function(file, enc, next) {
var self = this
var relativePath = path.dirname(file.path.replace(/^.*?ionic(\/|\\)components(\/|\\)/, ''))
var contents = file.contents.toString()
platforms.forEach(function(platform) { platforms.forEach(function(platform) {
var platformContents = testTemplate({ var platformContents = testTemplate({
contents: contents, contents: contents,
@ -285,11 +304,11 @@ function e2eTestsTask() {
})) }))
}) })
next() next()
})) })
.pipe(gulp.dest('dist/e2e/')) }
} });
function sassTask() { gulp.task('sass', function() {
return gulp.src('ionic/ionic.scss') return gulp.src('ionic/ionic.scss')
.pipe(sass({ .pipe(sass({
onError: function(err) { onError: function(err) {
@ -298,25 +317,25 @@ function sassTask() {
})) }))
.pipe(autoprefixer(buildConfig.autoprefixer)) .pipe(autoprefixer(buildConfig.autoprefixer))
.pipe(gulp.dest('dist/css/')); .pipe(gulp.dest('dist/css/'));
} });
function fontsTask() { gulp.task('fonts', function() {
return gulp.src('ionic/components/icon/fonts/**/*') return gulp.src('ionic/components/icon/fonts/**/*')
.pipe(gulp.dest('dist/fonts')); .pipe(gulp.dest('dist/fonts'));
} });
function vendorTask() { gulp.task('vendor', function() {
return gulp.src(['scripts/vendor/**/*']) return gulp.src(['scripts/vendor/**/*'])
.pipe(gulp.dest('dist/vendor')); .pipe(gulp.dest('dist/vendor'));
} });
function karmaTask() {
return karma.start({ configFile: __dirname + '/scripts/test/karma.conf.js' })
}
function karmaWatchTask() {
return karma.start({ configFile: __dirname + '/scripts/test/karma-watch.conf.js' })
}
// snapshot tasks
require('./scripts/snapshot/snapshot.task')(gulp, argv, buildConfig); require('./scripts/snapshot/snapshot.task')(gulp, argv, buildConfig);
gulp.task('karma', function() {
return karma.start({ configFile: __dirname + '/scripts/test/karma.conf.js' })
//return karma.start({ configFile: __dirname + '/karma.conf.js' })
});
gulp.task('karma-watch', function() {
return karma.start({ configFile: __dirname + '/scripts/test/karma-watch.conf.js' })
});

View File

@ -14,24 +14,16 @@ module.exports = function(gulp, argv, buildConfig) {
var protractorHttpServer; var protractorHttpServer;
var snapshotValues = _.merge(snapshotConfig.platformDefauls, argv); var snapshotValues = _.merge(snapshotConfig.platformDefauls, argv);
gulp.task('protractor-server', protractorServerTask); gulp.task('protractor-server', function() {
gulp.task('snapshot-task', snapshotTask);
gulp.task('snapshot', gulp.series(
gulp.parallel('build', 'e2e', 'protractor-server'),
'snapshot-task'
));
function protractorServerTask(done) {
var app = connect().use(serveStatic(projectRoot)); // serve everything that is static var app = connect().use(serveStatic(projectRoot)); // serve everything that is static
protractorHttpServer = http.createServer(app).listen(buildConfig.protractorPort); protractorHttpServer = http.createServer(app).listen(buildConfig.protractorPort);
console.log('Serving `dist` on http://localhost:' + buildConfig.protractorPort); console.log('Serving `dist` on http://localhost:' + buildConfig.protractorPort);
done(); });
}
function snapshotTask(done) { gulp.task('snapshot', ['e2e', 'protractor-server'], function(done) {
var protractorConfigFile = path.resolve(projectRoot, 'scripts/snapshot/protractor.config.js'); var protractorConfigFile = path.resolve(projectRoot, 'scripts/snapshot/protractor.config.js');
snapshot(done, protractorConfigFile); snapshot(done, protractorConfigFile);
} });
function snapshot(done, protractorConfigFile) { function snapshot(done, protractorConfigFile) {
snapshotValues.params.test_id = uuid.v4().split('-')[0]; snapshotValues.params.test_id = uuid.v4().split('-')[0];
@ -49,13 +41,12 @@ module.exports = function(gulp, argv, buildConfig) {
return _.template(argument, snapshotValues); return _.template(argument, snapshotValues);
}); });
// e2ePublish(snapshotValues.params.test_id); e2ePublish(snapshotValues.params.test_id);
return protractor(done, [protractorConfigFile].concat(protractorArgs)); return protractor(done, [protractorConfigFile].concat(protractorArgs));
} }
function protractor(done, args) { function protractor(done, args) {
debugger;
var child = cp.spawn('protractor', args, { var child = cp.spawn('protractor', args, {
stdio: [process.stdin, process.stdout, 'pipe'] stdio: [process.stdin, process.stdout, 'pipe']
}); });