diff options
Diffstat (limited to 'gulpfile.babel.js')
-rw-r--r-- | gulpfile.babel.js | 90 |
1 files changed, 48 insertions, 42 deletions
diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 08cc34b63..f87958a77 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js | |||
@@ -14,11 +14,12 @@ import sassVariables from 'gulp-sass-variables'; | |||
14 | import { removeSync, outputJson } from 'fs-extra'; | 14 | import { removeSync, outputJson } from 'fs-extra'; |
15 | import kebabCase from 'kebab-case'; | 15 | import kebabCase from 'kebab-case'; |
16 | import hexRgb from 'hex-rgb'; | 16 | import hexRgb from 'hex-rgb'; |
17 | import ts from 'gulp-typescript'; | ||
17 | 18 | ||
18 | import * as buildInfo from 'preval-build-info'; | 19 | import * as buildInfo from 'preval-build-info'; |
19 | import config from './package.json'; | 20 | import config from './package.json'; |
20 | 21 | ||
21 | import * as rawStyleConfig from './src/theme/default/legacy'; | 22 | import * as rawStyleConfig from './scripts/theme/default/legacy'; |
22 | 23 | ||
23 | dotenv.config(); | 24 | dotenv.config(); |
24 | 25 | ||
@@ -29,6 +30,8 @@ const isDevBuild = process.env.NODE_ENV === 'development'; | |||
29 | 30 | ||
30 | const getTargetEnv = isDevBuild ? 'development' : 'production'; | 31 | const getTargetEnv = isDevBuild ? 'development' : 'production'; |
31 | 32 | ||
33 | const tsProject = ts.createProject('tsconfig.json'); | ||
34 | |||
32 | const styleConfig = Object.keys(rawStyleConfig).map(key => { | 35 | const styleConfig = Object.keys(rawStyleConfig).map(key => { |
33 | const isHex = /^#[0-9A-F]{6}$/i.test(rawStyleConfig[key]); | 36 | const isHex = /^#[0-9A-F]{6}$/i.test(rawStyleConfig[key]); |
34 | return { | 37 | return { |
@@ -59,28 +62,36 @@ const paths = { | |||
59 | watch: 'src/**/*.html', | 62 | watch: 'src/**/*.html', |
60 | }, | 63 | }, |
61 | styles: { | 64 | styles: { |
62 | src: 'src/styles/main.scss', | 65 | src: [ |
66 | 'src/styles/main.scss', | ||
67 | 'src/styles/vertical.scss', | ||
68 | 'src/styles/animations.scss', | ||
69 | ], | ||
63 | dest: 'build/styles', | 70 | dest: 'build/styles', |
64 | watch: 'src/styles/**/*.scss', | 71 | watch: 'src/styles/**/*.scss', |
65 | }, | 72 | }, |
66 | verticalStyle: { | 73 | javascripts: { |
67 | src: 'src/styles/vertical.scss', | ||
68 | dest: 'build/styles', | ||
69 | }, | ||
70 | scripts: { | ||
71 | src: 'src/**/*.js', | 74 | src: 'src/**/*.js', |
72 | dest: 'build/', | 75 | dest: 'build/', |
73 | watch: [ | 76 | watch: [ |
74 | // 'packages/**/*.js', | ||
75 | 'src/**/*.js', | 77 | 'src/**/*.js', |
78 | // 'packages/**/*.js', | ||
79 | ], | ||
80 | }, | ||
81 | typescripts: { | ||
82 | src: 'src/**/*.ts', | ||
83 | dest: 'build/', | ||
84 | watch: [ | ||
85 | 'src/**/*.ts', | ||
86 | // 'packages/**/*.ts', | ||
76 | ], | 87 | ], |
77 | }, | 88 | }, |
78 | packages: { | 89 | packages: { |
79 | watch: 'packages/**/*', | 90 | watch: 'packages/**/*', |
80 | // dest: 'build/', | 91 | // dest: 'build/', |
81 | // watch: [ | 92 | // watch: [ |
82 | // // 'packages/**/*.js', | ||
83 | // 'src/**/*.js', | 93 | // 'src/**/*.js', |
94 | // // 'packages/**/*.js', | ||
84 | // ], | 95 | // ], |
85 | }, | 96 | }, |
86 | }; | 97 | }; |
@@ -121,9 +132,9 @@ export function mvSrc() { | |||
121 | [ | 132 | [ |
122 | `${paths.src}/*`, | 133 | `${paths.src}/*`, |
123 | `${paths.src}/*/**`, | 134 | `${paths.src}/*/**`, |
124 | `!${paths.scripts.watch[1]}`, | 135 | `!${paths.javascripts.watch[0]}`, |
136 | `!${paths.typescripts.watch[0]}`, | ||
125 | `!${paths.src}/styles/**`, | 137 | `!${paths.src}/styles/**`, |
126 | `!${paths.src}/**/*.js`, | ||
127 | ], | 138 | ], |
128 | { since: gulp.lastRun(mvSrc) }, | 139 | { since: gulp.lastRun(mvSrc) }, |
129 | ) | 140 | ) |
@@ -195,58 +206,52 @@ export function styles() { | |||
195 | .pipe(connect.reload()); | 206 | .pipe(connect.reload()); |
196 | } | 207 | } |
197 | 208 | ||
198 | export function verticalStyle() { | 209 | export function processJavascripts() { |
199 | return gulp | 210 | return gulp |
200 | .src(paths.verticalStyle.src) | 211 | .src( |
201 | .pipe( | 212 | [ |
202 | sassVariables( | 213 | paths.javascripts.src, |
203 | Object.assign( | 214 | ], |
204 | { | 215 | { since: gulp.lastRun(processJavascripts) }, |
205 | $env: getTargetEnv, | ||
206 | }, | ||
207 | ...styleConfig, | ||
208 | ), | ||
209 | ), | ||
210 | ) | ||
211 | .pipe( | ||
212 | sass({ | ||
213 | includePaths: ['./node_modules', '../node_modules'], | ||
214 | }).on('error', sass.logError), | ||
215 | ) | 216 | ) |
216 | .pipe( | 217 | .pipe( |
217 | gulpIf( | 218 | babel({ |
218 | !isDevBuild, | 219 | comments: false, |
219 | csso({ | 220 | }), |
220 | // Only minify in production to speed up dev builds | ||
221 | restructure: false, // Don't restructure CSS, otherwise it will break the styles | ||
222 | }), | ||
223 | ), | ||
224 | ) | 221 | ) |
225 | .pipe(gulp.dest(paths.verticalStyle.dest)) | 222 | .pipe(gulpIf(!isDevBuild, uglify())) // Only uglify in production to speed up dev builds |
223 | .pipe(gulp.dest(paths.javascripts.dest)) | ||
226 | .pipe(connect.reload()); | 224 | .pipe(connect.reload()); |
227 | } | 225 | } |
228 | 226 | ||
229 | export function scripts() { | 227 | export function processTypescripts() { |
230 | return gulp | 228 | return gulp |
231 | .src(paths.scripts.src, { since: gulp.lastRun(scripts) }) | 229 | .src( |
230 | [ | ||
231 | paths.typescripts.src, | ||
232 | ], | ||
233 | { since: gulp.lastRun(processTypescripts) }, | ||
234 | ) | ||
235 | .pipe(tsProject()) | ||
236 | .js | ||
232 | .pipe( | 237 | .pipe( |
233 | babel({ | 238 | babel({ |
234 | comments: false, | 239 | comments: false, |
235 | }), | 240 | }), |
236 | ) | 241 | ) |
237 | .pipe(gulpIf(!isDevBuild, uglify())) // Only uglify in production to speed up dev builds | 242 | .pipe(gulpIf(!isDevBuild, uglify())) // Only uglify in production to speed up dev builds |
238 | .pipe(gulp.dest(paths.scripts.dest)) | 243 | .pipe(gulp.dest(paths.typescripts.dest)) |
239 | .pipe(connect.reload()); | 244 | .pipe(connect.reload()); |
240 | } | 245 | } |
241 | 246 | ||
242 | export function watch() { | 247 | export function watch() { |
243 | gulp.watch(paths.packages.watch, mvLernaPackages); | 248 | gulp.watch(paths.packages.watch, mvLernaPackages); |
244 | gulp.watch(paths.styles.watch, styles); | 249 | gulp.watch(paths.styles.watch, styles); |
245 | gulp.watch(paths.verticalStyle.src, verticalStyle); | ||
246 | 250 | ||
247 | gulp.watch([paths.src, `${paths.scripts.src}`, `${paths.styles.src}`], mvSrc); | 251 | gulp.watch([paths.src], mvSrc); |
248 | 252 | ||
249 | gulp.watch(paths.scripts.watch, scripts); | 253 | gulp.watch(paths.javascripts.watch, processJavascripts); |
254 | gulp.watch(paths.typescripts.watch, processTypescripts); | ||
250 | } | 255 | } |
251 | 256 | ||
252 | export function webserver() { | 257 | export function webserver() { |
@@ -261,6 +266,7 @@ export function recipes() { | |||
261 | .src(paths.recipes.src, { since: gulp.lastRun(recipes) }) | 266 | .src(paths.recipes.src, { since: gulp.lastRun(recipes) }) |
262 | .pipe(gulp.dest(paths.recipes.dest)); | 267 | .pipe(gulp.dest(paths.recipes.dest)); |
263 | } | 268 | } |
269 | |||
264 | export function recipeInfo() { | 270 | export function recipeInfo() { |
265 | return gulp | 271 | return gulp |
266 | .src(paths.recipeInfo.src, { since: gulp.lastRun(recipeInfo) }) | 272 | .src(paths.recipeInfo.src, { since: gulp.lastRun(recipeInfo) }) |
@@ -270,7 +276,7 @@ export function recipeInfo() { | |||
270 | const build = gulp.series( | 276 | const build = gulp.series( |
271 | clean, | 277 | clean, |
272 | gulp.parallel(mvSrc, mvPackageJson, mvLernaPackages, exportBuildInfo), | 278 | gulp.parallel(mvSrc, mvPackageJson, mvLernaPackages, exportBuildInfo), |
273 | gulp.parallel(html, scripts, styles, verticalStyle, recipes, recipeInfo), | 279 | gulp.parallel(html, processJavascripts, processTypescripts, styles, recipes, recipeInfo), |
274 | ); | 280 | ); |
275 | export { build }; | 281 | export { build }; |
276 | 282 | ||