aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/tensorboard/gulpfile.js
blob: ea12304f8472f98d9e0210a6e5b8c69196425e5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* 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.
==============================================================================*/

// 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 concat = require('gulp-concat');
var merge = require('merge2');
var gulpFilter = require('gulp-filter');
var vulcanize = require('gulp-vulcanize');
var rename = require('gulp-rename');
var minimist = require('minimist');
var replace = require('gulp-replace');

var options = minimist(process.argv.slice(2), {
  default: {
    p: 8000  // port for gulp server
  }
});

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);
  }
};

gulp.task('compile.all', function() {
  hasError = false;
  var isComponent = gulpFilter(['components/**/*.js']);
  var isApp = gulpFilter(['app/**/*.js']);

  var srcs = ['components/**/*.ts', 'test/**/*.ts', 'app/**/*.ts',
              'typings/**/*.d.ts', 'bower_components/**/*.d.ts'];

  var tsResult = gulp.src(srcs, {base: '.'})
                     .pipe(ts(tsProject))
                     .on('error', onError);
  return merge([
    // Send concatenated component code to build/component
    tsResult.js
            .pipe(isComponent)
            .pipe(concat('components.js'))
            .pipe(gulp.dest('build')),

    // 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(isApp)
            .pipe(gulp.dest('.')),

    // Create a unified defintions file at build/all.d.ts
    tsResult.dts
            .pipe(concat('all.d.ts'))
            .pipe(gulp.dest('build')),
  ]);
});

gulp.task('test', ['tslint-strict', 'compile.all'], function(done) {
  tester({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(['components/**/*.ts', 'test/**/*.ts'])
               .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(['test/**/*.ts', 'components/**/*.ts'],
          {ignoreInitial: true},
          ['compile.all', 'tslint-permissive']);
});

gulp.task('server', function() {
  gulp.src('.')
      .pipe(server({
        host: '0.0.0.0',
        port: options.p,
        livereload: {
          enable: true,
          port: 27729 + options.p
        },
        directoryListing: true,
      }));
});


var linkRegex = /<link rel="[^"]*" (type="[^"]*" )?href=".*bower_components[^"]*">\n/g;
var scriptRegex = /<script src=".*bower_components[^"]*"><\/script>\n/g;
gulp.task('vulcanize', ['compile.all', 'tslint-strict'], function() {
      gulp.src('app/tf-tensorboard.html')
          .pipe(vulcanize({
            inlineScripts: true,
            inlineCss: true,
            stripComments: true,
            excludes: ['/bower_components/'],
          }))
          // TODO(danmane): Remove this worrysome brittleness when vulcanize
          // fixes https://github.com/Polymer/vulcanize/issues/273
          .pipe(replace(linkRegex, ''))
          .pipe(replace(scriptRegex, ''))
          .pipe(gulp.dest('dist'));

      gulp.src('app/index.html')
          .pipe(vulcanize({
            inlineScripts: true,
            inlineCss: true,
            stripComments: true,
          }))
          .pipe(gulp.dest('dist'));

      gulp.src('app/tf-tensorboard-demo.html')
          .pipe(vulcanize({
            inlineScripts: true,
            inlineCss: true,
            stripComments: true,
          }))
          .pipe(gulp.dest('dist'));
});

gulp.task('serve', ['server']); // alias
gulp.task('default', ['watch']);