Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 Copyright 2016 The LUCI Authors. All rights reserved. | 2 Copyright 2016 The LUCI Authors. All rights reserved. |
| 3 Use of this source code is governed under the Apache License, Version 2.0 | 3 Use of this source code is governed under the Apache License, Version 2.0 |
| 4 that can be found in the LICENSE file. | 4 that can be found in the LICENSE file. |
| 5 | 5 |
| 6 This document has been largely derived from the Polymer Starter Kit: | 6 This document has been largely derived from the Polymer Starter Kit: |
| 7 https://github.com/PolymerElements/polymer-starter-kit | 7 https://github.com/PolymerElements/polymer-starter-kit |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 'use strict'; | 10 'use strict'; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 }); | 102 }); |
| 103 | 103 |
| 104 // Build production files, the default task | 104 // Build production files, the default task |
| 105 gulp.task('lint', ['tslint']); | 105 gulp.task('lint', ['tslint']); |
| 106 | 106 |
| 107 // Build production files, the default task | 107 // Build production files, the default task |
| 108 gulp.task('presubmit', ['lint', 'check-format', 'check-ts']); | 108 gulp.task('presubmit', ['lint', 'check-format', 'check-ts']); |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 // Project-specific tasks. | 111 // Project-specific tasks. |
| 112 exports.setup = function(gulp, config) { | 112 exports.setup = function(gulp, appDir, config) { |
| 113 var APP = path.basename(config.dir); | 113 var APP = path.basename(appDir); |
| 114 var DIST = path.join(exports.out, 'dist', APP); | 114 var DIST = path.join(exports.out, 'dist', APP); |
| 115 | 115 |
| 116 console.log("APP:", APP) | |
| 116 var layout = { | 117 var layout = { |
| 117 app: APP, | 118 app: APP, |
| 119 dir: process.cwd(), | |
| 120 web: '../..', | |
| 121 inc: './inc', | |
| 118 distPath: DIST, | 122 distPath: DIST, |
| 119 | 123 |
| 120 // NOTE: Takes vararg via "arguments". | 124 // NOTE: Takes vararg via "arguments". |
| 121 dist: function() { | 125 dist: function() { |
| 122 return extendPath(DIST).apply(null, arguments); | 126 return extendPath(DIST).apply(null, arguments); |
| 123 }, | 127 }, |
| 124 }; | 128 }; |
| 125 | 129 |
| 126 var extendPath = function() { | 130 var extendPath = function() { |
| 127 var base = [].slice.call(arguments); | 131 var base = [].slice.call(arguments); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 153 .pipe($.imagemin({ | 157 .pipe($.imagemin({ |
| 154 progressive: true, | 158 progressive: true, |
| 155 interlaced: true | 159 interlaced: true |
| 156 })) | 160 })) |
| 157 .pipe(gulp.dest(dest)) | 161 .pipe(gulp.dest(dest)) |
| 158 .pipe($.size({title: 'images'})); | 162 .pipe($.size({title: 'images'})); |
| 159 }; | 163 }; |
| 160 | 164 |
| 161 var optimizeHtmlTask = function(src, dest) { | 165 var optimizeHtmlTask = function(src, dest) { |
| 162 var assets = $.useref.assets({ | 166 var assets = $.useref.assets({ |
| 163 searchPath: ['.tmp', config.dir] | 167 searchPath: ['.tmp', '.'] |
| 164 }); | 168 }); |
| 165 | 169 |
| 166 return gulp.src(src) | 170 return gulp.src(src) |
| 167 .pipe(assets) | 171 .pipe(assets) |
| 168 // Concatenate and minify JavaScript | 172 // Concatenate and minify JavaScript |
| 169 .pipe($.if('*.js', $.uglify({ | 173 .pipe($.if('*.js', $.uglify({ |
| 170 preserveComments: 'some' | 174 preserveComments: 'some' |
| 171 }))) | 175 }))) |
| 172 // Concatenate and minify styles | 176 // Concatenate and minify styles |
| 173 // In case you are still using useref build blocks | 177 // In case you are still using useref build blocks |
| 174 .pipe($.if('*.css', cleanCSS())) | 178 .pipe($.if('*.css', cleanCSS())) |
| 175 .pipe(assets.restore()) | 179 .pipe(assets.restore()) |
| 176 .pipe($.useref()) | 180 .pipe($.useref()) |
| 177 // Minify any HTML | 181 // Minify any HTML |
| 178 .pipe($.if('*.html', htmlmin({ | 182 .pipe($.if('*.html', htmlmin({ |
| 179 remoteAttributeQuotes: false, | 183 remoteAttributeQuotes: false, |
| 180 remoteEmptyAttributes: false, | 184 remoteEmptyAttributes: false, |
| 181 remoteRedundantAttributes: false, | 185 remoteRedundantAttributes: false, |
| 182 }))) | 186 }))) |
| 183 // Output files | 187 // Output files |
| 184 .pipe(gulp.dest(dest)) | 188 .pipe(gulp.dest(dest)) |
| 185 .pipe($.size({ | 189 .pipe($.size({ |
| 186 title: 'html' | 190 title: 'html' |
| 187 })); | 191 })); |
| 188 }; | 192 }; |
| 189 | 193 |
| 190 // Transpiles "inc/*/*.ts" and deposits the result alongside their source | 194 // Transpiles "inc/*/*.ts" and deposits the result alongside their source |
| 191 // "ts" files. | 195 // "ts" files. |
| 192 gulp.task('ts', function() { | 196 gulp.task('ts', function() { |
| 193 // Transpile each TypeScript module independently into JavaScript. | |
| 194 var tsconfigPath = path.join(exports.incDir, 'tsconfig.json'); | |
| 195 | |
| 196 // Compile the files in "scripts-ts/*.ts" into a single out file. | 197 // Compile the files in "scripts-ts/*.ts" into a single out file. |
| 197 var scriptsTs = path.join(config.dir, 'scripts-ts'); | 198 var appTsDir = path.join(layout.inc, 'apps', layout.app); |
| 198 var tsProj = ts.createProject(tsconfigPath, { | 199 var tsProj = ts.createProject(path.join(layout.inc, 'tsconfig.json'), { |
| 199 typeRoots: [path.join(exports.base, 'node_modules', '@types')], | 200 typeRoots: [path.join(exports.base, 'node_modules', '@types')], |
| 200 outFile: 'main.js', | 201 outFile: path.join(appTsDir, 'main.js'), |
| 201 }); | 202 }); |
| 202 | 203 |
| 203 return gulp.src('*.ts', {cwd: scriptsTs, exclude: ['*_test.ts']}) | 204 return gulp.src(path.join(layout.inc, 'apps', layout.app, '*.ts'), { |
| 205 exclude: ['*_test.ts'], | |
| 206 }) | |
| 204 .pipe(sourcemaps.init()) | 207 .pipe(sourcemaps.init()) |
| 205 .pipe(tsProj()) | 208 .pipe(tsProj()) |
| 206 .pipe(sourcemaps.write('.')) | 209 .pipe(sourcemaps.write('.')) |
| 207 .pipe(gulp.dest(scriptsTs)); | 210 .pipe(gulp.dest(layout.inc)) |
| 208 }); | 211 }); |
| 209 | 212 |
| 210 // Compile and automatically prefix stylesheets | 213 // Compile and automatically prefix stylesheets |
| 211 gulp.task('styles', function() { | 214 gulp.task('styles', function() { |
| 212 return styleTask('styles', ['**/*.css']); | 215 return styleTask('styles', ['**/*.css']); |
| 213 }); | 216 }); |
| 214 | 217 |
| 215 gulp.task('elements', function() { | 218 gulp.task('elements', function() { |
| 216 return styleTask('elements', ['**/*.css']); | 219 return styleTask('elements', ['**/*.css']); |
| 217 }); | 220 }); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 // Clean output directory | 290 // Clean output directory |
| 288 gulp.task('clean', function() { | 291 gulp.task('clean', function() { |
| 289 var dist = layout.dist(); | 292 var dist = layout.dist(); |
| 290 var remove = ['.tmp', path.join(dist, '*')]; | 293 var remove = ['.tmp', path.join(dist, '*')]; |
| 291 var keep = '!'+path.join(dist, '.keep'); | 294 var keep = '!'+path.join(dist, '.keep'); |
| 292 return del(remove.concat(keep), {force: true, dot:true}); | 295 return del(remove.concat(keep), {force: true, dot:true}); |
| 293 }); | 296 }); |
| 294 | 297 |
| 295 // Watch files for changes & reload | 298 // Watch files for changes & reload |
| 296 gulp.task('serve', ['default'], function() { | 299 gulp.task('serve', ['default'], function() { |
| 300 console.log("CURRENT WORKING DIRECTORY MAYBE CHANGE TO APP DIR:", process.cw d()); | |
|
Ryan Tseng
2017/07/28 13:48:40
???
dnj
2017/07/28 13:50:36
oops.
| |
| 301 //process.chdir(layout.dir); | |
|
Ryan Tseng
2017/07/28 13:48:40
This supposed to be here?
dnj
2017/07/28 13:50:36
nope, thanks for catching.
| |
| 302 | |
| 297 browserSync({ | 303 browserSync({ |
| 298 port: 5000, | 304 port: 5000, |
| 299 ui: { | 305 ui: { |
| 300 port: 5080, | 306 port: 5080, |
| 301 }, | 307 }, |
| 302 notify: false, | 308 notify: false, |
| 303 logPrefix: 'PSK', | 309 logPrefix: 'PSK', |
| 304 snippetOptions: { | 310 snippetOptions: { |
| 305 rule: { | 311 rule: { |
| 306 match: '<span id="browser-sync-binding"></span>', | 312 match: '<span id="browser-sync-binding"></span>', |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 }); | 367 }); |
| 362 | 368 |
| 363 // Install common targets. | 369 // Install common targets. |
| 364 exports.setup_common(gulp); | 370 exports.setup_common(gulp); |
| 365 }; | 371 }; |
| 366 | 372 |
| 367 // Load custom tasks from the `tasks` directory | 373 // Load custom tasks from the `tasks` directory |
| 368 try { | 374 try { |
| 369 require('require-dir')('tasks'); | 375 require('require-dir')('tasks'); |
| 370 } catch (err) {} | 376 } catch (err) {} |
| OLD | NEW |