Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: web/apps/gulp-common.js

Issue 2985273002: [web] Restructure and fix builds. (Closed)
Patch Set: [web] Restructure and fix builds. Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « web/.gitignore ('k') | web/apps/logdog-app/elements/logdog-app/logdog-app.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 'bb >= 10' 52 'bb >= 10'
53 ]; 53 ];
54 54
55 // Include directory (/web/inc/) 55 // Include directory (/web/inc/)
56 exports.incDir = path.join(exports.base, 'inc'); 56 exports.incDir = path.join(exports.base, 'inc');
57 57
58 // Common (global) tasks. 58 // Common (global) tasks.
59 exports.setup_common = function(gulp) { 59 exports.setup_common = function(gulp) {
60 // Verify TypeScript file integrity and formatting. 60 // Verify TypeScript file integrity and formatting.
61 gulp.task('tslint', function() { 61 gulp.task('tslint', function() {
62 process.chdir(exports.base); 62 process.chdir(exports.incDir);
63 63
64 return gulp.src('inc/*/*.ts') 64 return gulp.src(['**/*.ts', '!bower_components/**'])
65 .pipe(tslint({ 65 .pipe(tslint({
66 configuration: path.join(exports.base, 'inc', 'tslint.json'), 66 configuration: './tslint.json',
67 formatter: 'verbose', 67 formatter: 'verbose',
68 })) 68 }))
69 .pipe(tslint.report()); 69 .pipe(tslint.report());
70 }); 70 });
71 71
72 gulp.task('check-ts', function() { 72 gulp.task('check-ts', function() {
73 process.chdir(exports.incDir);
74
73 // Transpile each TypeScript module independently into JavaScript. 75 // Transpile each TypeScript module independently into JavaScript.
74 var tsconfigPath = path.join(exports.incDir, 'tsconfig.json'); 76 var tsconfigPath = path.join(exports.incDir, 'tsconfig.json');
75 77
76 // Compile the files in "scripts-ts/*.ts" into a single out file. 78 // Compile the files in "scripts-ts/*.ts" into a single out file.
77 var tsProj = ts.createProject(tsconfigPath, { 79 var tsProj = ts.createProject(tsconfigPath, {
78 typeRoots: [path.join(exports.base, 'node_modules', '@types')], 80 typeRoots: [path.join(exports.base, 'node_modules', '@types')],
79 }); 81 });
80 82
81 return gulp.src(['**/*.ts', '!bower_components/**'], {cwd: exports.incDir}) 83 return gulp.src(['**/*.ts', '!bower_components/**'])
82 .pipe(tsProj()); 84 .pipe(tsProj());
83 }); 85 });
84 86
85 gulp.task('check-format', function() { 87 gulp.task('check-format', function() {
86 process.chdir(exports.base); 88 process.chdir(exports.incDir);
87 return gulp.src('inc/*/*.ts') 89 return gulp.src(['**/*.ts', '!bower_components/**'])
88 .pipe(format.checkFormat()) 90 .pipe(format.checkFormat())
89 .on('warning', function(e) { 91 .on('warning', function(e) {
90 process.stdout.write(e.message); 92 process.stdout.write(e.message);
91 process.exit(1) 93 process.exit(1)
92 }); 94 });
93 }); 95 });
94 96
95 gulp.task('format', function() { 97 gulp.task('format', function() {
96 process.chdir(exports.base); 98 process.chdir(exports.incDir);
97 99
98 // The base option ensures the glob doesn't strip prefixes. 100 // The base option ensures the glob doesn't strip prefixes.
99 return gulp.src('inc/*/*.ts', {base: '.'}) 101 return gulp.src(['**/*.ts', '!bower_components/**'])
100 .pipe(format.format()) 102 .pipe(format.format())
101 .pipe(gulp.dest('.')); 103 .pipe(gulp.dest('.'));
102 }); 104 });
103 105
104 // Build production files, the default task 106 // Build production files, the default task
105 gulp.task('lint', ['tslint']); 107 gulp.task('lint', ['tslint']);
106 108
107 // Build production files, the default task 109 // Build production files, the default task
108 gulp.task('presubmit', ['lint', 'check-format', 'check-ts']); 110 gulp.task('presubmit', ['lint', 'check-format', 'check-ts']);
109 }; 111 };
110 112
111 // Project-specific tasks. 113 // Project-specific tasks.
112 exports.setup = function(gulp, config) { 114 exports.setup = function(gulp, appDir, config) {
113 var APP = path.basename(config.dir); 115 var APP = path.basename(appDir);
114 var DIST = path.join(exports.out, 'dist', APP); 116 var DIST = path.join(exports.out, 'dist', APP);
115 117
116 var layout = { 118 var layout = {
117 app: APP, 119 app: APP,
120 dir: process.cwd(),
121 web: '../..',
122 inc: './inc',
118 distPath: DIST, 123 distPath: DIST,
119 124
120 // NOTE: Takes vararg via "arguments". 125 // NOTE: Takes vararg via "arguments".
121 dist: function() { 126 dist: function() {
122 return extendPath(DIST).apply(null, arguments); 127 return extendPath(DIST).apply(null, arguments);
123 }, 128 },
124 }; 129 };
125 130
126 var extendPath = function() { 131 var extendPath = function() {
127 var base = [].slice.call(arguments); 132 var base = [].slice.call(arguments);
(...skipping 25 matching lines...) Expand all
153 .pipe($.imagemin({ 158 .pipe($.imagemin({
154 progressive: true, 159 progressive: true,
155 interlaced: true 160 interlaced: true
156 })) 161 }))
157 .pipe(gulp.dest(dest)) 162 .pipe(gulp.dest(dest))
158 .pipe($.size({title: 'images'})); 163 .pipe($.size({title: 'images'}));
159 }; 164 };
160 165
161 var optimizeHtmlTask = function(src, dest) { 166 var optimizeHtmlTask = function(src, dest) {
162 var assets = $.useref.assets({ 167 var assets = $.useref.assets({
163 searchPath: ['.tmp', config.dir] 168 searchPath: ['.tmp', '.']
164 }); 169 });
165 170
166 return gulp.src(src) 171 return gulp.src(src)
167 .pipe(assets) 172 .pipe(assets)
168 // Concatenate and minify JavaScript 173 // Concatenate and minify JavaScript
169 .pipe($.if('*.js', $.uglify({ 174 .pipe($.if('*.js', $.uglify({
170 preserveComments: 'some' 175 preserveComments: 'some'
171 }))) 176 })))
172 // Concatenate and minify styles 177 // Concatenate and minify styles
173 // In case you are still using useref build blocks 178 // In case you are still using useref build blocks
174 .pipe($.if('*.css', cleanCSS())) 179 .pipe($.if('*.css', cleanCSS()))
175 .pipe(assets.restore()) 180 .pipe(assets.restore())
176 .pipe($.useref()) 181 .pipe($.useref())
177 // Minify any HTML 182 // Minify any HTML
178 .pipe($.if('*.html', htmlmin({ 183 .pipe($.if('*.html', htmlmin({
179 remoteAttributeQuotes: false, 184 remoteAttributeQuotes: false,
180 remoteEmptyAttributes: false, 185 remoteEmptyAttributes: false,
181 remoteRedundantAttributes: false, 186 remoteRedundantAttributes: false,
182 }))) 187 })))
183 // Output files 188 // Output files
184 .pipe(gulp.dest(dest)) 189 .pipe(gulp.dest(dest))
185 .pipe($.size({ 190 .pipe($.size({
186 title: 'html' 191 title: 'html'
187 })); 192 }));
188 }; 193 };
189 194
190 // Transpiles "inc/*/*.ts" and deposits the result alongside their source 195 // Transpiles "inc/*/*.ts" and deposits the result alongside their source
191 // "ts" files. 196 // "ts" files.
192 gulp.task('ts', function() { 197 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. 198 // Compile the files in "scripts-ts/*.ts" into a single out file.
197 var scriptsTs = path.join(config.dir, 'scripts-ts'); 199 var appTsDir = path.join(layout.inc, 'apps', layout.app);
198 var tsProj = ts.createProject(tsconfigPath, { 200 var tsProj = ts.createProject(path.join(layout.inc, 'tsconfig.json'), {
199 typeRoots: [path.join(exports.base, 'node_modules', '@types')], 201 typeRoots: [path.join(exports.base, 'node_modules', '@types')],
200 outFile: 'main.js', 202 outFile: path.join(appTsDir, 'main.js'),
201 }); 203 });
202 204
203 return gulp.src('*.ts', {cwd: scriptsTs, exclude: ['*_test.ts']}) 205 return gulp.src(path.join(layout.inc, 'apps', layout.app, '*.ts'), {
206 exclude: ['*_test.ts'],
207 })
204 .pipe(sourcemaps.init()) 208 .pipe(sourcemaps.init())
205 .pipe(tsProj()) 209 .pipe(tsProj())
206 .pipe(sourcemaps.write('.')) 210 .pipe(sourcemaps.write('.'))
207 .pipe(gulp.dest(scriptsTs)); 211 .pipe(gulp.dest(layout.inc))
208 }); 212 });
209 213
210 // Compile and automatically prefix stylesheets 214 // Compile and automatically prefix stylesheets
211 gulp.task('styles', function() { 215 gulp.task('styles', function() {
212 return styleTask('styles', ['**/*.css']); 216 return styleTask('styles', ['**/*.css']);
213 }); 217 });
214 218
215 gulp.task('elements', function() { 219 gulp.task('elements', function() {
216 return styleTask('elements', ['**/*.css']); 220 return styleTask('elements', ['**/*.css']);
217 }); 221 });
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 }); 365 });
362 366
363 // Install common targets. 367 // Install common targets.
364 exports.setup_common(gulp); 368 exports.setup_common(gulp);
365 }; 369 };
366 370
367 // Load custom tasks from the `tasks` directory 371 // Load custom tasks from the `tasks` directory
368 try { 372 try {
369 require('require-dir')('tasks'); 373 require('require-dir')('tasks');
370 } catch (err) {} 374 } catch (err) {}
OLDNEW
« no previous file with comments | « web/.gitignore ('k') | web/apps/logdog-app/elements/logdog-app/logdog-app.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698