diff options
-rw-r--r-- | tensorflow/tensorboard/DEVELOPMENT.md | 9 | ||||
-rw-r--r-- | tensorflow/tensorboard/gulp_tasks/bower.js | 23 | ||||
-rw-r--r-- | tensorflow/tensorboard/gulp_tasks/compile.js | 38 | ||||
-rw-r--r-- | tensorflow/tensorboard/gulp_tasks/test.js | 28 | ||||
-rw-r--r-- | tensorflow/tensorboard/gulp_tasks/tslint.js | 27 | ||||
-rw-r--r-- | tensorflow/tensorboard/gulp_tasks/typings.js | 21 | ||||
-rw-r--r-- | tensorflow/tensorboard/gulp_tasks/vulcanize.js | 89 | ||||
-rw-r--r-- | tensorflow/tensorboard/gulpfile.js | 182 | ||||
-rw-r--r-- | tensorflow/tensorboard/tsconfig.json | 3 |
9 files changed, 260 insertions, 160 deletions
diff --git a/tensorflow/tensorboard/DEVELOPMENT.md b/tensorflow/tensorboard/DEVELOPMENT.md index 2f47f8c48f..77c3412b2c 100644 --- a/tensorflow/tensorboard/DEVELOPMENT.md +++ b/tensorflow/tensorboard/DEVELOPMENT.md @@ -40,12 +40,11 @@ to create a realistic demo directory from your own data files. ## Launching TensorBoard with modified source If you are developing in open source, and have made some changes to TensorBoard -that you'd like to try out on real data, then you need to overwrite -`dist/tf-tensorboard.html`. Run `gulp vulcanize`, and you'll get a new file -called `dist/tf-tensorboard.html.OPENSOURCE`. Overwite -`dist/tf-tensorboard.html` with that file: +that you'd like to try out on real data, then you need to regenerate +`dist/tf-tensorboard.html`. -`mv dist/tf-tensorboard.html.OPENSOURCE dist/tf-tensorboard.html`. +Run `gulp regenerate`. That will recompile all of the TensorBoard assets, and +produce a new tf-tensorboard.html with your changes. Now, you can use `bazel` to launch TensorBoard: diff --git a/tensorflow/tensorboard/gulp_tasks/bower.js b/tensorflow/tensorboard/gulp_tasks/bower.js new file mode 100644 index 0000000000..16f4b64228 --- /dev/null +++ b/tensorflow/tensorboard/gulp_tasks/bower.js @@ -0,0 +1,23 @@ +/* Copyright 2015 Google Inc. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +var gulp = require('gulp'); +var bower = require('gulp-bower'); + +module.exports = function() { + return function() { + return bower(); + } +} diff --git a/tensorflow/tensorboard/gulp_tasks/compile.js b/tensorflow/tensorboard/gulp_tasks/compile.js new file mode 100644 index 0000000000..d25af4a23d --- /dev/null +++ b/tensorflow/tensorboard/gulp_tasks/compile.js @@ -0,0 +1,38 @@ +/* Copyright 2015 Google Inc. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +var gulp = require('gulp'); +var ts = require('gulp-typescript'); +var typescript = require('typescript'); +var gutil = require('gulp-util'); +var filter = require('gulp-filter'); +var merge = require('merge2'); + +var tsProject = ts.createProject('./tsconfig.json', { + typescript: typescript, + noExternalResolve: true, // opt-in for faster compilation! +}); + + +module.exports = function() { + var isComponent = filter(['components/**/*.js']); + + return tsProject.src() + .pipe(ts(tsProject)) + .js + .pipe(isComponent) + .pipe(gulp.dest('.')) + +} diff --git a/tensorflow/tensorboard/gulp_tasks/test.js b/tensorflow/tensorboard/gulp_tasks/test.js new file mode 100644 index 0000000000..1d82f2f38f --- /dev/null +++ b/tensorflow/tensorboard/gulp_tasks/test.js @@ -0,0 +1,28 @@ +/* Copyright 2015 Google Inc. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +var gulp = require('gulp'); +var tester = require('web-component-tester').test; + +module.exports = function(done) { + tester({}, function(error) { + if (error) { + // Pretty error for gulp. + error = new Error(error.message || error); + error.showStack = false; + } + done(error); + }); +} diff --git a/tensorflow/tensorboard/gulp_tasks/tslint.js b/tensorflow/tensorboard/gulp_tasks/tslint.js new file mode 100644 index 0000000000..b774a91165 --- /dev/null +++ b/tensorflow/tensorboard/gulp_tasks/tslint.js @@ -0,0 +1,27 @@ +/* Copyright 2015 Google Inc. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +var gulp = require('gulp'); +var tslint = require('gulp-tslint'); + +module.exports = function(strict) { + return function() { + return gulp.src('components/tf-*/**/*.ts') + .pipe(tslint()) + .pipe(tslint.report('verbose', { + emitError: strict, + })); + }; +} diff --git a/tensorflow/tensorboard/gulp_tasks/typings.js b/tensorflow/tensorboard/gulp_tasks/typings.js new file mode 100644 index 0000000000..e433568123 --- /dev/null +++ b/tensorflow/tensorboard/gulp_tasks/typings.js @@ -0,0 +1,21 @@ +/* Copyright 2015 Google Inc. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +var gulp = require('gulp'); +var typings = require('gulp-typings'); + +module.exports = function() { + return gulp.src('./typings.json') + .pipe(typings()); +} diff --git a/tensorflow/tensorboard/gulp_tasks/vulcanize.js b/tensorflow/tensorboard/gulp_tasks/vulcanize.js new file mode 100644 index 0000000000..afbeb9d7c6 --- /dev/null +++ b/tensorflow/tensorboard/gulp_tasks/vulcanize.js @@ -0,0 +1,89 @@ +/* Copyright 2015 Google Inc. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +var gulp = require('gulp'); +var fs = require('fs'); +var path = require('path'); +var vulcanize = require('gulp-vulcanize'); +var replace = require('gulp-replace'); +var rename = require('gulp-rename'); +var header = require('gulp-header'); + +var HEADER_STR = '<!-- Copyright 2015 Google Inc. All Rights Reserved.\n\ +\n\ +Licensed under the Apache License, Version 2.0 (the "License");\n\ +you may not use this file except in compliance with the License.\n\ +You may obtain a copy of the License at\n\ +\n\ + http://www.apache.org/licenses/LICENSE-2.0\n\ +\n\ +Unless required by applicable law or agreed to in writing, software\n\ +distributed under the License is distributed on an "AS IS" BASIS,\n\ +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\ +See the License for the specific language governing permissions and\n\ +limitations under the License.\n\ +============================================================================\n\ +\n\ +This file is generated by `gulp` & `vulcanize`. Do not directly change it.\n\ +Instead, use `gulp regenerate` to create a new version with your changes.\n\ +-->\n\n' + +/** + * 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 prefix = file.slice(0,3); + return fs.statSync(path.join('components', file)).isDirectory() && + prefix !== 'tf-'; + }) + .map(function(dir) { return '/' + dir + '/'; }); +} + +var linkRegex = /<link rel="[^"]*" (type="[^"]*" )?href="[^"]*">\n/g; +var scriptRegex = /<script src="[^"]*"><\/script>\n/g; + +module.exports = function(overwrite) { + return function() { + var suffix = overwrite ? '' : '.OPENSOURCE'; + // 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(HEADER_STR)) + .pipe(rename('tf-tensorboard.html' + suffix)) + .pipe(gulp.dest('./dist')); + + + gulp.src('components/tf-tensorboard/tf-tensorboard-demo.html') + .pipe(vulcanize({ + inlineScripts: true, + inlineCss: true, + stripComments: true, + })) + .pipe(header(HEADER_STR)) + .pipe(gulp.dest('./dist')); + } +} diff --git a/tensorflow/tensorboard/gulpfile.js b/tensorflow/tensorboard/gulpfile.js index 6eeb24ddbe..1229ff49ba 100644 --- a/tensorflow/tensorboard/gulpfile.js +++ b/tensorflow/tensorboard/gulpfile.js @@ -13,26 +13,10 @@ See the License for the specific language governing permissions and 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 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 merge = require('merge2'); -var gulpFilter = require('gulp-filter'); -var vulcanize = require('gulp-vulcanize'); var minimist = require('minimist'); -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), { default: { p: 8000, // port for gulp server @@ -40,104 +24,33 @@ var options = minimist(process.argv.slice(2), { } }); -var tsProject = ts.createProject('tsconfig.json', { - typescript: typescript, - noExternalResolve: true, // opt-in for faster compilation! -}); - -var hasError; -var failOnError = true; // Is set to false when watching. - -var onError = function(err) { - hasError = true; - gutil.log(err.message); - if (failOnError) { - 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({}, function(error) { - if (error) { - // Pretty error for gulp. - error = new Error(error.message || error); - error.showStack = false; - } - done(error); - }); -}); +function getTask(task) { + return require('./gulp_tasks/' + task); +} -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('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', ['compile.all', 'tslint-permissive'], function() { - failOnError = false; +gulp.task('watch', [], function() { // Avoid watching generated .d.ts in the build (aka output) directory. - return gulp.watch([TF_COMPONENTS_TYPESCRIPT_GLOB, TF_LIB_TYPESCRIPT_GLOB], + return gulp.watch('components/tf-*/**/*.ts', {ignoreInitial: true}, - ['compile.all', 'tslint-permissive']); + ['compile', 'tslint.permissive']); }); -gulp.task('server', function() { + +// Do first-compile before turning on server, to avoid spamming +// livereload info +// TODO(danmane): Disconnect this once we can get livereload to +// no longer spam. +gulp.task('server', ['first-compile'], function() { gulp.src('.').pipe(server({ host: options.h, port: options.p, @@ -151,50 +64,11 @@ gulp.task('server', function() { })); }); -/** - * 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 + '/'; }); -} - - -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')); -}); +// TODO(danmane): When testing is nicer, integrate into vulcanize task +// gulp vulcanize: Regenerate the tf-tensorboard.html.OPENSOURCE file for pre-release +gulp.task('vulcanize', ['first-compile', 'tslint.permissive'], getTask('vulcanize')(false)); +// gulp regenerate: Regenerate the tf-tensorboard.html for interactive bazel development +gulp.task('regenerate', ['first-compile', 'tslint.permissive'], getTask('vulcanize')(true)); -gulp.task('serve', ['server']); // alias -gulp.task('default', ['compile.all', 'watch', 'serve']); +// TODO(danmane): consider making bower install part of default task +gulp.task('default', ['watch', 'server']); diff --git a/tensorflow/tensorboard/tsconfig.json b/tensorflow/tensorboard/tsconfig.json index 81f42ce7cf..1ecec4f922 100644 --- a/tensorflow/tensorboard/tsconfig.json +++ b/tensorflow/tensorboard/tsconfig.json @@ -8,6 +8,7 @@ "exclude": [ "node_modules", "typings/main.d.ts", - "typings/main" + "typings/main", + "lib" ] } |