diff options
author | Balaji Vijayakumar <kuttibalaji.v6@gmail.com> | 2022-12-08 22:28:46 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-08 16:58:46 +0000 |
commit | 93d61ced55e7e1c486cdbe6c02c16435ca698860 (patch) | |
tree | e4d9e53260e508711cfcf45232d086e906a09d8e /gulpfile.babel.ts | |
parent | Backported deprecation fixes from electron v22 upgrade (diff) | |
download | ferdium-app-93d61ced55e7e1c486cdbe6c02c16435ca698860.tar.gz ferdium-app-93d61ced55e7e1c486cdbe6c02c16435ca698860.tar.zst ferdium-app-93d61ced55e7e1c486cdbe6c02c16435ca698860.zip |
migrate from gulp to esbuild for faster builds (#815)
Diffstat (limited to 'gulpfile.babel.ts')
-rw-r--r-- | gulpfile.babel.ts | 241 |
1 files changed, 0 insertions, 241 deletions
diff --git a/gulpfile.babel.ts b/gulpfile.babel.ts deleted file mode 100644 index ea5960315..000000000 --- a/gulpfile.babel.ts +++ /dev/null | |||
@@ -1,241 +0,0 @@ | |||
1 | import gulp from 'gulp'; | ||
2 | import gulpIf from 'gulp-if'; | ||
3 | import babel from 'gulp-babel'; | ||
4 | import dartSass from 'sass'; | ||
5 | import gulpSass from 'gulp-sass'; | ||
6 | import csso from 'gulp-csso'; | ||
7 | import rename from 'gulp-rename'; | ||
8 | import terser from 'gulp-terser'; | ||
9 | import htmlMin from 'gulp-htmlmin'; | ||
10 | import connect from 'gulp-connect'; | ||
11 | import sassVariables from 'gulp-sass-variables'; | ||
12 | import { removeSync, outputJson } from 'fs-extra'; | ||
13 | import kebabCase from 'kebab-case'; | ||
14 | import hexRgb from 'hex-rgb'; | ||
15 | import ts from 'gulp-typescript'; | ||
16 | |||
17 | import * as buildInfo from 'preval-build-info'; | ||
18 | import config from './package.json'; | ||
19 | |||
20 | import rawStyleConfig from './scripts/theme/default/legacy'; | ||
21 | |||
22 | import 'dotenv/config'; | ||
23 | |||
24 | const sass = gulpSass(dartSass); | ||
25 | |||
26 | const isDevBuild = process.env.NODE_ENV === 'development'; | ||
27 | |||
28 | const getTargetEnv = isDevBuild ? 'development' : 'production'; | ||
29 | |||
30 | const tsProject = ts.createProject('tsconfig.json'); | ||
31 | |||
32 | const styleConfig = Object.keys(rawStyleConfig).map(key => { | ||
33 | const isHex = /^#[\da-f]{6}$/i.test(rawStyleConfig[key]); | ||
34 | return { | ||
35 | [`$raw_${kebabCase(key)}`]: isHex | ||
36 | ? hexRgb(rawStyleConfig[key], { format: 'array' }).splice(0, 3).join(',') | ||
37 | : rawStyleConfig[key], | ||
38 | }; | ||
39 | }); | ||
40 | |||
41 | const paths = { | ||
42 | src: 'src', | ||
43 | dest: 'build', | ||
44 | tmp: '.tmp', | ||
45 | dist: 'out', | ||
46 | package: `out/${config.version}`, | ||
47 | buildInfoDestFile: 'build/buildInfo.json', | ||
48 | recipes: { | ||
49 | src: 'recipes/archives/*.tar.gz', | ||
50 | dest: 'build/recipes/', | ||
51 | }, | ||
52 | recipeInfo: { | ||
53 | src: 'recipes/*.json', | ||
54 | dest: 'build/recipes/', | ||
55 | }, | ||
56 | html: { | ||
57 | src: 'src/**/*.html', | ||
58 | dest: 'build/', | ||
59 | watch: 'src/**/*.html', | ||
60 | }, | ||
61 | styles: { | ||
62 | src: [ | ||
63 | 'src/styles/main.scss', | ||
64 | 'src/styles/vertical.scss', | ||
65 | 'src/styles/animations.scss', | ||
66 | ], | ||
67 | dest: 'build/styles', | ||
68 | watch: 'src/styles/**/*.scss', | ||
69 | }, | ||
70 | javascript: { | ||
71 | src: ['src/**/*.js', 'src/**/*.jsx'], | ||
72 | dest: 'build/', | ||
73 | watch: ['src/**/*.js', 'src/**/*.jsx'], | ||
74 | }, | ||
75 | typescript: { | ||
76 | src: ['src/**/*.ts', 'src/**/*.tsx'], | ||
77 | dest: 'build/', | ||
78 | watch: ['src/**/*.ts', 'src/**/*.tsx'], | ||
79 | }, | ||
80 | }; | ||
81 | |||
82 | const clean: (done: any) => void = done => { | ||
83 | removeSync(paths.tmp); | ||
84 | removeSync(paths.dest); | ||
85 | removeSync(paths.dist); | ||
86 | |||
87 | done(); | ||
88 | }; | ||
89 | |||
90 | function mvSrc() { | ||
91 | return gulp | ||
92 | .src( | ||
93 | [ | ||
94 | `${paths.src}/*`, | ||
95 | `${paths.src}/*/**`, | ||
96 | `!${paths.javascript.watch[0]}`, | ||
97 | `!${paths.typescript.watch[0]}`, | ||
98 | `!${paths.src}/styles/**`, | ||
99 | ], | ||
100 | { since: gulp.lastRun(mvSrc) }, | ||
101 | ) | ||
102 | .pipe(gulp.dest(paths.dest)); | ||
103 | } | ||
104 | |||
105 | function mvElectronNpmrc() { | ||
106 | return gulp | ||
107 | .src(['electron-builder.npmrc']) | ||
108 | .pipe(rename('.npmrc')) | ||
109 | .pipe(gulp.dest(paths.dest)); | ||
110 | } | ||
111 | |||
112 | function mvPackageJson() { | ||
113 | return gulp.src(['./package.json']).pipe(gulp.dest(paths.dest)); | ||
114 | } | ||
115 | |||
116 | function BuildInfo() { | ||
117 | const buildInfoData = { | ||
118 | timestamp: buildInfo.timestamp, | ||
119 | gitHashShort: buildInfo.gitHashShort, | ||
120 | gitBranch: buildInfo.gitBranch, | ||
121 | }; | ||
122 | return outputJson(paths.buildInfoDestFile, buildInfoData); | ||
123 | } | ||
124 | |||
125 | function html() { | ||
126 | return gulp | ||
127 | .src(paths.html.src, { since: gulp.lastRun(html) }) | ||
128 | .pipe( | ||
129 | gulpIf( | ||
130 | !isDevBuild, | ||
131 | htmlMin({ | ||
132 | // Only minify in production to speed up dev builds | ||
133 | collapseWhitespace: true, | ||
134 | removeComments: true, | ||
135 | }), | ||
136 | ), | ||
137 | ) | ||
138 | .pipe(gulp.dest(paths.html.dest)) | ||
139 | .pipe(connect.reload()); | ||
140 | } | ||
141 | |||
142 | function styles(): NodeJS.ReadWriteStream { | ||
143 | return gulp | ||
144 | .src(paths.styles.src) | ||
145 | .pipe( | ||
146 | sassVariables( | ||
147 | Object.assign( | ||
148 | { | ||
149 | $env: getTargetEnv, | ||
150 | }, | ||
151 | ...styleConfig, | ||
152 | ), | ||
153 | ), | ||
154 | ) | ||
155 | .pipe( | ||
156 | sass({ | ||
157 | includePaths: ['./node_modules', '../node_modules'], | ||
158 | }).on('error', sass.logError), | ||
159 | ) | ||
160 | .pipe( | ||
161 | gulpIf( | ||
162 | !isDevBuild, | ||
163 | csso({ | ||
164 | // Only minify in production to speed up dev builds | ||
165 | restructure: false, // Don't restructure CSS, otherwise it will break the styles | ||
166 | }), | ||
167 | ), | ||
168 | ) | ||
169 | .pipe(gulp.dest(paths.styles.dest)) | ||
170 | .pipe(connect.reload()); | ||
171 | } | ||
172 | |||
173 | function processJavascript() { | ||
174 | return gulp | ||
175 | .src(paths.javascript.src, { since: gulp.lastRun(processJavascript) }) | ||
176 | .pipe( | ||
177 | babel({ | ||
178 | comments: false, | ||
179 | }), | ||
180 | ) | ||
181 | .pipe(gulpIf(!isDevBuild, terser())) // Only uglify in production to speed up dev builds | ||
182 | .pipe(gulp.dest(paths.javascript.dest)) | ||
183 | .pipe(connect.reload()); | ||
184 | } | ||
185 | |||
186 | function processTypescript() { | ||
187 | return gulp | ||
188 | .src(paths.typescript.src, { since: gulp.lastRun(processTypescript) }) | ||
189 | .pipe(tsProject()) | ||
190 | .js.pipe( | ||
191 | babel({ | ||
192 | comments: false, | ||
193 | }), | ||
194 | ) | ||
195 | .pipe(gulpIf(!isDevBuild, terser())) // Only uglify in production to speed up dev builds | ||
196 | .pipe(gulp.dest(paths.typescript.dest)) | ||
197 | .pipe(connect.reload()); | ||
198 | } | ||
199 | |||
200 | function watch() { | ||
201 | gulp.watch(paths.styles.watch, styles); | ||
202 | |||
203 | gulp.watch([paths.src], mvSrc); | ||
204 | |||
205 | gulp.watch(paths.javascript.watch, processJavascript); | ||
206 | gulp.watch(paths.typescript.watch, processTypescript); | ||
207 | } | ||
208 | |||
209 | function webserver() { | ||
210 | connect.server({ | ||
211 | root: paths.dest, | ||
212 | livereload: true, | ||
213 | }); | ||
214 | } | ||
215 | |||
216 | function recipes() { | ||
217 | return gulp | ||
218 | .src(paths.recipes.src, { since: gulp.lastRun(recipes) }) | ||
219 | .pipe(gulp.dest(paths.recipes.dest)); | ||
220 | } | ||
221 | |||
222 | function recipeInfo() { | ||
223 | return gulp | ||
224 | .src(paths.recipeInfo.src, { since: gulp.lastRun(recipeInfo) }) | ||
225 | .pipe(gulp.dest(paths.recipeInfo.dest)); | ||
226 | } | ||
227 | |||
228 | export const build = gulp.series( | ||
229 | clean, | ||
230 | gulp.parallel(mvElectronNpmrc, mvSrc, mvPackageJson, BuildInfo), | ||
231 | gulp.parallel( | ||
232 | html, | ||
233 | processJavascript, | ||
234 | processTypescript, | ||
235 | styles, | ||
236 | recipes, | ||
237 | recipeInfo, | ||
238 | ), | ||
239 | ); | ||
240 | |||
241 | export const dev = gulp.series(build, gulp.parallel(webserver, watch)); | ||