diff options
author | Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com> | 2021-08-15 08:35:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-15 14:05:57 +0530 |
commit | ab213dd0a1e51699aae492f8b546e4a311fcb97d (patch) | |
tree | 2dbd59ee85db4899f78f660432190a2df356e8e8 /gulpfile.babel.js | |
parent | fix: Fixed the 'Changelog' menu item to point to the correct branch (diff) | |
download | ferdium-app-ab213dd0a1e51699aae492f8b546e4a311fcb97d.tar.gz ferdium-app-ab213dd0a1e51699aae492f8b546e4a311fcb97d.tar.zst ferdium-app-ab213dd0a1e51699aae492f8b546e4a311fcb97d.zip |
Initial plumbing and conversion of a simple javascript to typescript (#1790)
* initial conversion of a simple script
* Moved some of the 'gulp' and related npm modules from being runtime dependencies to development dependencies.
Diffstat (limited to 'gulpfile.babel.js')
-rw-r--r-- | gulpfile.babel.js | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 08cc34b63..1f3c42a3d 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js | |||
@@ -14,6 +14,7 @@ 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'; |
@@ -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 { |
@@ -67,7 +70,7 @@ const paths = { | |||
67 | src: 'src/styles/vertical.scss', | 70 | src: 'src/styles/vertical.scss', |
68 | dest: 'build/styles', | 71 | dest: 'build/styles', |
69 | }, | 72 | }, |
70 | scripts: { | 73 | javascripts: { |
71 | src: 'src/**/*.js', | 74 | src: 'src/**/*.js', |
72 | dest: 'build/', | 75 | dest: 'build/', |
73 | watch: [ | 76 | watch: [ |
@@ -75,6 +78,14 @@ const paths = { | |||
75 | 'src/**/*.js', | 78 | 'src/**/*.js', |
76 | ], | 79 | ], |
77 | }, | 80 | }, |
81 | typescripts: { | ||
82 | src: 'src/**/*.ts', | ||
83 | dest: 'build/', | ||
84 | watch: [ | ||
85 | // 'packages/**/*.ts', | ||
86 | 'src/**/*.ts', | ||
87 | ], | ||
88 | }, | ||
78 | packages: { | 89 | packages: { |
79 | watch: 'packages/**/*', | 90 | watch: 'packages/**/*', |
80 | // dest: 'build/', | 91 | // dest: 'build/', |
@@ -121,9 +132,11 @@ 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[1]}`, |
136 | `!${paths.typescripts.watch[1]}`, | ||
125 | `!${paths.src}/styles/**`, | 137 | `!${paths.src}/styles/**`, |
126 | `!${paths.src}/**/*.js`, | 138 | `!${paths.src}/**/*.js`, |
139 | `!${paths.src}/**/*.ts`, | ||
127 | ], | 140 | ], |
128 | { since: gulp.lastRun(mvSrc) }, | 141 | { since: gulp.lastRun(mvSrc) }, |
129 | ) | 142 | ) |
@@ -226,16 +239,39 @@ export function verticalStyle() { | |||
226 | .pipe(connect.reload()); | 239 | .pipe(connect.reload()); |
227 | } | 240 | } |
228 | 241 | ||
229 | export function scripts() { | 242 | export function processJavascripts() { |
230 | return gulp | 243 | return gulp |
231 | .src(paths.scripts.src, { since: gulp.lastRun(scripts) }) | 244 | .src( |
245 | [ | ||
246 | paths.javascripts.src, | ||
247 | ], | ||
248 | { since: gulp.lastRun(processJavascripts) }) | ||
249 | .pipe( | ||
250 | babel({ | ||
251 | comments: false, | ||
252 | }), | ||
253 | ) | ||
254 | .pipe(gulpIf(!isDevBuild, uglify())) // Only uglify in production to speed up dev builds | ||
255 | .pipe(gulp.dest(paths.javascripts.dest)) | ||
256 | .pipe(connect.reload()); | ||
257 | } | ||
258 | |||
259 | export function processTypescripts() { | ||
260 | return gulp | ||
261 | .src( | ||
262 | [ | ||
263 | paths.typescripts.src, | ||
264 | ], | ||
265 | { since: gulp.lastRun(processTypescripts) }) | ||
266 | .pipe(tsProject()) | ||
267 | .js | ||
232 | .pipe( | 268 | .pipe( |
233 | babel({ | 269 | babel({ |
234 | comments: false, | 270 | comments: false, |
235 | }), | 271 | }), |
236 | ) | 272 | ) |
237 | .pipe(gulpIf(!isDevBuild, uglify())) // Only uglify in production to speed up dev builds | 273 | .pipe(gulpIf(!isDevBuild, uglify())) // Only uglify in production to speed up dev builds |
238 | .pipe(gulp.dest(paths.scripts.dest)) | 274 | .pipe(gulp.dest(paths.typescripts.dest)) |
239 | .pipe(connect.reload()); | 275 | .pipe(connect.reload()); |
240 | } | 276 | } |
241 | 277 | ||
@@ -244,9 +280,10 @@ export function watch() { | |||
244 | gulp.watch(paths.styles.watch, styles); | 280 | gulp.watch(paths.styles.watch, styles); |
245 | gulp.watch(paths.verticalStyle.src, verticalStyle); | 281 | gulp.watch(paths.verticalStyle.src, verticalStyle); |
246 | 282 | ||
247 | gulp.watch([paths.src, `${paths.scripts.src}`, `${paths.styles.src}`], mvSrc); | 283 | gulp.watch([paths.src, `${paths.javascripts.src}`, `${paths.styles.src}`], mvSrc); |
248 | 284 | ||
249 | gulp.watch(paths.scripts.watch, scripts); | 285 | gulp.watch(paths.javascripts.watch, processJavascripts); |
286 | gulp.watch(paths.typescripts.watch, processTypescripts); | ||
250 | } | 287 | } |
251 | 288 | ||
252 | export function webserver() { | 289 | export function webserver() { |
@@ -270,7 +307,7 @@ export function recipeInfo() { | |||
270 | const build = gulp.series( | 307 | const build = gulp.series( |
271 | clean, | 308 | clean, |
272 | gulp.parallel(mvSrc, mvPackageJson, mvLernaPackages, exportBuildInfo), | 309 | gulp.parallel(mvSrc, mvPackageJson, mvLernaPackages, exportBuildInfo), |
273 | gulp.parallel(html, scripts, styles, verticalStyle, recipes, recipeInfo), | 310 | gulp.parallel(html, processJavascripts, processTypescripts, styles, verticalStyle, recipes, recipeInfo), |
274 | ); | 311 | ); |
275 | export { build }; | 312 | export { build }; |
276 | 313 | ||