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('transpile', transpileTask);
gulp.task('bundle.js', bundleJsTask);
gulp.task('sass', sassTask);
gulp.task('fonts', fontsTask);
gulp.task('clean.build', function() {
runSequence(
'clean',
'transpile',
//'bundle.deps',
'bundle.js',
'examples',
'sass',
'fonts',
'vendor',
'copy-scripts');
})
// Karma testing
gulp.task('tests', testsTask);
gulp.task('karma', karmaTask);
gulp.task('karma-watch', karmaWatchTask);
gulp.task('build', function() {
runSequence(
'transpile',
'bundle.js',
'examples',
'sass',
'fonts',
'vendor',
'copy-scripts');
})
// e2e testing
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'));
gulp.task('watch', function() {
// Utility
gulp.task('clean', cleanTask);
gulp.task('vendor', vendorTask);
gulp.task('copy-scripts', copyScriptsTask);
gulp.task('serve', serveTask);
gulp.task('watch-task', watchTask);
gulp.task('watch', gulp.series('serve', 'watch-task'));
gulp.task('examples', gulp.parallel('e2e.copy', 'e2e.template', 'e2e.transpile'));
runSequence(
'transpile',
'bundle.js',
'examples',
'sass',
'fonts',
'vendor',
'copy-scripts',
'serve',
// Build
gulp.task('build', gulp.parallel(
gulp.series('transpile', 'bundle.js', 'copy-scripts'),
'sass',
'fonts',
'vendor'
))
function() {
watch(
[
'ionic/**/*.js',
'ionic/**/*.ts',
'!ionic/components/*/test/**/*',
'!ionic/util/test/*'
],
function() {
runSequence(
'transpile',
'bundle.js',
'examples'
)
}
);
gulp.task('clean.build', gulp.series(
'clean',
'build'
));
watch('ionic/components/*/test/**/*', function() {
gulp.start('examples');
});
gulp.task('build.watch', gulp.series(
gulp.parallel('build', 'examples'),
'serve',
'watch-task'
))
watch('ionic/**/*.scss', function() {
gulp.start('sass');
});
})
});
/*****************************************************************************/
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) {
gulp.task('serve', function() {
connect.server({
root: 'dist',
port: 8000,
livereload: false
});
done();
}
});
function cleanTask(done) {
gulp.task('clean', function(done) {
del(['dist/'], done);
}
});
function transpileTask() {
var stream = gulp.src([
'ionic/**/*.ts',
'ionic/**/*.js',
'!ionic/components/*/test/**/*',
'!ionic/init.js',
'!ionic/util/test/*'
])
.pipe(cache('transpile', { optimizeMemory: true }))
.pipe(tsc(tscOptions, null, tscReporter))
.on('error', function(error) {
stream.emit('end');
})
.pipe(gulp.dest('dist/js/es6/ionic'))
.pipe(babel(getBabelOptions('ionic')))
.on('error', function (err) {
console.log("ERROR: " + err.message);
this.emit('end');
})
.pipe(gulp.dest('dist/js/es5/ionic'))
gulp.task('transpile', function() {
var stream = gulp.src(
[
'ionic/**/*.ts',
'ionic/**/*.js',
'!ionic/components/*/test/**/*',
'!ionic/init.js',
'!ionic/util/test/*'
]
)
.pipe(cache('transpile', { optimizeMemory: true }))
.pipe(tsc(tscOptions, null, tscReporter))
.on('error', function(error) {
stream.emit('end');
})
.pipe(gulp.dest('dist/js/es6/ionic'))
.pipe(babel(getBabelOptions('ionic')))
.on('error', function (err) {
console.log("ERROR: " + err.message);
this.emit('end');
})
.pipe(gulp.dest('dist/js/es5/ionic'))
return stream;
}
});
function bundleJsTask() {
gulp.task('bundle.js', function() {
return gulp.src(['dist/js/es5/ionic/**/*.js', 'ionic/init.js'])
.pipe(concat('ionic.bundle.js'))
.pipe(gulp.dest('dist/js/'));
}
.pipe(concat('ionic.bundle.js'))
.pipe(gulp.dest('dist/js/'));
});
function testsTask() {
gulp.task('tests', function() {
return gulp.src('ionic/components/*/test/*/**/*.spec.ts')
.pipe(tsc(tscOptions, null, tscReporter))
.pipe(babel(getBabelOptions('tests')))
.pipe(rename(function(file) {
file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep)
}))
.pipe(gulp.dest('dist/tests'))
}
.pipe(tsc(tscOptions, null, tscReporter))
.pipe(babel(getBabelOptions('tests')))
.pipe(rename(function(file) {
file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep)
}))
.pipe(gulp.dest('dist/tests'))
})
function copyScriptsTask() {
return 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('examples', function() {
var buildTest = lazypipe()
.pipe(tsc, tscOptions, null, tscReporter)
.pipe(babel, getBabelOptions('examples'))
function e2eCopyTask() {
return gulp.src([
'ionic/components/*/test/*/**/*',
'!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')))
// Get each test folder with gulp.src
return gulp.src(['ionic/components/*/test/*/**/*', '!ionic/components/*/test/*/**/*.spec.ts'])
.pipe(cache('examples', { optimizeMemory: true }))
.pipe(gulpif(/.ts$/, buildTest()))
.on('error', function (err) {
console.log("ERROR: " + err.message);
this.emit('end');
})
.pipe(gulpif(/index.js$/, createIndexHTML())) //TSC changes .ts to .js
.pipe(rename(function(file) {
file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep)
}))
.pipe(gulp.dest('dist/e2e/'))
}
.pipe(gulp.dest('dist/examples/'))
function e2eHTMLTemplateTask() {
var HTMLTemplate = _.template(
fs.readFileSync('scripts/e2e/e2e.template.html')
)({
buildConfig: buildConfig
});
function createIndexHTML() {
var template = _.template(
fs.readFileSync('scripts/e2e/example.template.html')
)({
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)
.replace(__dirname, '')
.replace('/ionic/components/', 'e2e/')
.replace('/ionic/components/', 'examples/')
.replace('/test/', '/') +
'/index';
var templateContents = HTMLTemplate.replace('{{MODULE}}', module);
var indexFile = new VinylFile({
base: file.base,
contents: new Buffer(templateContents),
path: path.join(path.dirname(file.path), 'index.html'),
})
next(null, indexFile);
}))
.pipe(rename(function(file) {
file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep)
}))
.pipe(gulp.dest('dist/e2e/'))
}
var indexContents = template.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);
});
}
});
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 = [
'android',
'core',
'ios',
];
return gulp.src('ionic/components/*/test/*/**/e2e.ts')
.pipe(cache('e2e.tests', { optimizeMemory: true }))
.pipe(tsc(tscOptions, null, tscReporter))
.pipe(babel())
// Get each test folder with gulp.src
return gulp.src(['ionic/components/*/test/*/**/*', '!ionic/components/*/test/*/**/*.spec.ts'])
.pipe(cache('e2e', { optimizeMemory: true }))
.pipe(gulpif(/e2e.ts$/, buildE2ETest()))
.pipe(gulpif(/.ts$/, buildTest()))
.on('error', function (err) {
console.log("ERROR: " + err.message);
this.emit('end');
})
.pipe(gulpif(/index.js$/, createIndexHTML())) //TSC changes .ts to .js
.pipe(rename(function(file) {
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 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) {
var platformContents = testTemplate({
contents: contents,
@ -285,11 +304,11 @@ function e2eTestsTask() {
}))
})
next()
}))
.pipe(gulp.dest('dist/e2e/'))
}
})
}
});
function sassTask() {
gulp.task('sass', function() {
return gulp.src('ionic/ionic.scss')
.pipe(sass({
onError: function(err) {
@ -298,25 +317,25 @@ function sassTask() {
}))
.pipe(autoprefixer(buildConfig.autoprefixer))
.pipe(gulp.dest('dist/css/'));
}
});
function fontsTask() {
gulp.task('fonts', function() {
return gulp.src('ionic/components/icon/fonts/**/*')
.pipe(gulp.dest('dist/fonts'));
}
});
function vendorTask() {
gulp.task('vendor', function() {
return gulp.src(['scripts/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);
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 snapshotValues = _.merge(snapshotConfig.platformDefauls, argv);
gulp.task('protractor-server', protractorServerTask);
gulp.task('snapshot-task', snapshotTask);
gulp.task('snapshot', gulp.series(
gulp.parallel('build', 'e2e', 'protractor-server'),
'snapshot-task'
));
function protractorServerTask(done) {
gulp.task('protractor-server', function() {
var app = connect().use(serveStatic(projectRoot)); // serve everything that is static
protractorHttpServer = http.createServer(app).listen(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');
snapshot(done, protractorConfigFile);
}
});
function snapshot(done, protractorConfigFile) {
snapshotValues.params.test_id = uuid.v4().split('-')[0];
@ -49,13 +41,12 @@ module.exports = function(gulp, argv, buildConfig) {
return _.template(argument, snapshotValues);
});
// e2ePublish(snapshotValues.params.test_id);
e2ePublish(snapshotValues.params.test_id);
return protractor(done, [protractorConfigFile].concat(protractorArgs));
}
function protractor(done, args) {
debugger;
var child = cp.spawn('protractor', args, {
stdio: [process.stdin, process.stdout, 'pipe']
});