Rollback of "Split TensorBoard gulpfile into per-task files.
Gulp task changes: "compile.all" -> "compile" "tslint-strict" -> "tslint" "tslint-permissive" -> "tslint.permissive" gulp watch will run tslint and compile in parallel rather than in sequence (faster)" Change: 115630394
This commit is contained in:
parent
7dd05309b3
commit
045e086764
@ -13,11 +13,26 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
|
|
||||||
|
// Based on the gulpfile provided by angular team
|
||||||
|
// (https://github.com/angular/ts2dart/blob/master/gulpfile.js)
|
||||||
var gulp = require('gulp');
|
var gulp = require('gulp');
|
||||||
|
var tester = require('web-component-tester').test;
|
||||||
|
var ts = require('gulp-typescript');
|
||||||
|
var typescript = require('typescript');
|
||||||
|
var gutil = require('gulp-util');
|
||||||
|
var tslint = require('gulp-tslint');
|
||||||
var server = require('gulp-server-livereload');
|
var server = require('gulp-server-livereload');
|
||||||
|
var merge = require('merge2');
|
||||||
|
var gulpFilter = require('gulp-filter');
|
||||||
|
var vulcanize = require('gulp-vulcanize');
|
||||||
var minimist = require('minimist');
|
var minimist = require('minimist');
|
||||||
var constants = require('./gulp_tasks/constants.js');
|
var replace = require('gulp-replace');
|
||||||
|
var rename = require('gulp-rename');
|
||||||
|
var header = require('gulp-header');
|
||||||
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
|
var typings = require('gulp-typings');
|
||||||
|
var bower = require('gulp-bower');
|
||||||
var options = minimist(process.argv.slice(2), {
|
var options = minimist(process.argv.slice(2), {
|
||||||
default: {
|
default: {
|
||||||
p: 8000, // port for gulp server
|
p: 8000, // port for gulp server
|
||||||
@ -25,32 +40,105 @@ var options = minimist(process.argv.slice(2), {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function getTask(task) {
|
var tsProject = ts.createProject('tsconfig.json', {
|
||||||
return require('./gulp_tasks/' + task);
|
typescript: typescript,
|
||||||
}
|
noExternalResolve: true, // opt-in for faster compilation!
|
||||||
|
|
||||||
gulp.task('compile', getTask('compile'));
|
|
||||||
gulp.task('typings', getTask('typings'));
|
|
||||||
gulp.task('tslint', getTask('tslint')(true));
|
|
||||||
// tslint.permissive warns without failing.
|
|
||||||
gulp.task('tslint.permissive', getTask('tslint')(false));
|
|
||||||
gulp.task('first-compile', ['typings'], getTask('compile'));
|
|
||||||
gulp.task('test.onlytest', getTask('test')); // if you don't want to lint, etc
|
|
||||||
gulp.task('test', ['tslint', 'compile'], getTask('test'));
|
|
||||||
|
|
||||||
gulp.task('watch', [], function() {
|
|
||||||
// Avoid watching generated .d.ts in the build (aka output) directory.
|
|
||||||
return gulp.watch(constants.all_typescript,
|
|
||||||
{ignoreInitial: true},
|
|
||||||
['compile', 'tslint.permissive']);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var hasError;
|
||||||
|
var failOnError = true; // Is set to false when watching.
|
||||||
|
|
||||||
// Do first-compile before turning on server, to avoid spamming
|
var onError = function(err) {
|
||||||
// livereload info
|
hasError = true;
|
||||||
// TODO(danmane): Disconnect this once we can get livereload to
|
gutil.log(err.message);
|
||||||
// no longer spam.
|
if (failOnError) {
|
||||||
gulp.task('server', ['first-compile'], function() {
|
process.exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// These constants should always be in sync with the path in the .gitignore
|
||||||
|
// file.
|
||||||
|
var TF_COMPONENTS_PREFIX = 'tf-';
|
||||||
|
var TF_COMPONENTS_TYPESCRIPT_GLOB = 'components/' + TF_COMPONENTS_PREFIX +
|
||||||
|
'*/**/*.ts';
|
||||||
|
|
||||||
|
var TF_LIB_TYPESCRIPT_GLOB = 'lib/js/**/*.ts';
|
||||||
|
|
||||||
|
gulp.task('typings', function() {
|
||||||
|
// This task will create a typings directory at root level, with all typings
|
||||||
|
// installed in it.
|
||||||
|
return gulp.src('./typings.json')
|
||||||
|
.pipe(typings());
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO(danmane): Wire this up once bower.json specifies all resolutions
|
||||||
|
gulp.task('bower', function() {
|
||||||
|
return bower();
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('compile.all', ['typings'], function() {
|
||||||
|
hasError = false;
|
||||||
|
var isComponent = gulpFilter(['components/**/*.js']);
|
||||||
|
var isLib = gulpFilter(['lib/js/**/*.js']);
|
||||||
|
var isApp = gulpFilter(['app/**/*.js']);
|
||||||
|
|
||||||
|
var tsResult = tsProject.src()
|
||||||
|
.pipe(ts(tsProject))
|
||||||
|
.on('error', onError);
|
||||||
|
return merge([
|
||||||
|
// Duplicate all component code to live next to the ts file
|
||||||
|
// (makes polymer imports very clean)
|
||||||
|
tsResult.js
|
||||||
|
.pipe(isComponent)
|
||||||
|
.pipe(gulp.dest('.')),
|
||||||
|
tsResult.js
|
||||||
|
.pipe(isLib)
|
||||||
|
.pipe(gulp.dest('.')),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('test', ['tslint-strict', 'compile.all'], function(done) {
|
||||||
|
tester({suites: ['components/tf-test/'],
|
||||||
|
plugins: {local: {}, sauce: false}}, function(error) {
|
||||||
|
if (error) {
|
||||||
|
// Pretty error for gulp.
|
||||||
|
error = new Error(error.message || error);
|
||||||
|
error.showStack = false;
|
||||||
|
}
|
||||||
|
done(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var tslintTask = function(strict) {
|
||||||
|
return function(done) {
|
||||||
|
if (hasError) {
|
||||||
|
done();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return gulp.src([TF_COMPONENTS_TYPESCRIPT_GLOB, TF_LIB_TYPESCRIPT_GLOB])
|
||||||
|
.pipe(tslint())
|
||||||
|
.pipe(tslint.report('verbose', {
|
||||||
|
emitError: strict,
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Since constructs like console.log are disabled by tslint
|
||||||
|
// but very useful while developing, create a "permissive"
|
||||||
|
// version of tslint that warns without erroring, for the
|
||||||
|
// watch task.
|
||||||
|
gulp.task('tslint-permissive', [], tslintTask(false));
|
||||||
|
gulp.task('tslint-strict', [], tslintTask(true));
|
||||||
|
|
||||||
|
gulp.task('watch', ['compile.all', 'tslint-permissive'], function() {
|
||||||
|
failOnError = false;
|
||||||
|
// Avoid watching generated .d.ts in the build (aka output) directory.
|
||||||
|
return gulp.watch([TF_COMPONENTS_TYPESCRIPT_GLOB, TF_LIB_TYPESCRIPT_GLOB],
|
||||||
|
{ignoreInitial: true},
|
||||||
|
['compile.all', 'tslint-permissive']);
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('server', function() {
|
||||||
gulp.src('.').pipe(server({
|
gulp.src('.').pipe(server({
|
||||||
host: options.h,
|
host: options.h,
|
||||||
port: options.p,
|
port: options.p,
|
||||||
@ -64,8 +152,50 @@ gulp.task('server', ['first-compile'], function() {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO(danmane): When testing is nicer, integrate into vulcanize task
|
/**
|
||||||
gulp.task('vulcanize', ['first-compile', 'tslint'], getTask('vulcanize'));
|
* Returns a list of non-tensorboard components inside the components
|
||||||
|
* directory, i.e. components that don't begin with 'tf-'.
|
||||||
|
*/
|
||||||
|
function getNonTensorBoardComponents() {
|
||||||
|
return fs.readdirSync('components')
|
||||||
|
.filter(function(file) {
|
||||||
|
var filePrefix = file.slice(0, TF_COMPONENTS_PREFIX.length);
|
||||||
|
return fs.statSync(path.join('components', file)).isDirectory() &&
|
||||||
|
filePrefix !== TF_COMPONENTS_PREFIX;
|
||||||
|
})
|
||||||
|
.map(function(dir) { return '/' + dir + '/'; });
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(danmane): consider making bower install part of default task
|
|
||||||
gulp.task('default', ['watch', 'server']);
|
var linkRegex = /<link rel="[^"]*" (type="[^"]*" )?href="[^"]*">\n/g;
|
||||||
|
var scriptRegex = /<script src="[^"]*"><\/script>\n/g;
|
||||||
|
gulp.task('vulcanize', ['compile.all', 'tslint-strict'], function() {
|
||||||
|
// Vulcanize TensorBoard without external libraries.
|
||||||
|
gulp.src('components/tf-tensorboard/tf-tensorboard.html')
|
||||||
|
.pipe(vulcanize({
|
||||||
|
inlineScripts: true,
|
||||||
|
inlineCss: true,
|
||||||
|
stripComments: true,
|
||||||
|
excludes: getNonTensorBoardComponents(),
|
||||||
|
}))
|
||||||
|
// TODO(danmane): Remove this worrisome brittleness when vulcanize
|
||||||
|
// fixes https://github.com/Polymer/vulcanize/issues/273
|
||||||
|
.pipe(replace(linkRegex, ''))
|
||||||
|
.pipe(replace(scriptRegex, ''))
|
||||||
|
.pipe(header('// AUTOGENERATED FILE - DO NOT MODIFY \n'))
|
||||||
|
.pipe(rename('tf-tensorboard.html.OPENSOURCE'))
|
||||||
|
.pipe(gulp.dest('./dist'));
|
||||||
|
|
||||||
|
|
||||||
|
gulp.src('components/tf-tensorboard/tf-tensorboard-demo.html')
|
||||||
|
.pipe(vulcanize({
|
||||||
|
inlineScripts: true,
|
||||||
|
inlineCss: true,
|
||||||
|
stripComments: true,
|
||||||
|
}))
|
||||||
|
.pipe(header('// AUTOGENERATED FILE - DO NOT MODIFY \n'))
|
||||||
|
.pipe(gulp.dest('dist'));
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('serve', ['server']); // alias
|
||||||
|
gulp.task('default', ['compile.all', 'watch', 'serve']);
|
||||||
|
Loading…
Reference in New Issue
Block a user