aboutsummaryrefslogtreecommitdiffstats
path: root/gulpfile.babel.js
diff options
context:
space:
mode:
Diffstat (limited to 'gulpfile.babel.js')
-rw-r--r--gulpfile.babel.js181
1 files changed, 100 insertions, 81 deletions
diff --git a/gulpfile.babel.js b/gulpfile.babel.js
index 06e995d07..dda198c18 100644
--- a/gulpfile.babel.js
+++ b/gulpfile.babel.js
@@ -1,7 +1,12 @@
1/* eslint max-len: 0 */ 1/* eslint max-len: 0 */
2import gulp from 'gulp'; 2import gulp from 'gulp';
3import gulpIf from 'gulp-if';
3import babel from 'gulp-babel'; 4import babel from 'gulp-babel';
4import sass from 'gulp-sass'; 5import sass from 'gulp-sass';
6import csso from 'gulp-csso';
7import terser from 'terser';
8import composer from 'gulp-uglify/composer';
9import htmlMin from 'gulp-htmlmin';
5import server from 'gulp-server-livereload'; 10import server from 'gulp-server-livereload';
6import { exec } from 'child_process'; 11import { exec } from 'child_process';
7import dotenv from 'dotenv'; 12import dotenv from 'dotenv';
@@ -17,17 +22,32 @@ import * as rawStyleConfig from './src/theme/default/legacy.js';
17 22
18dotenv.config(); 23dotenv.config();
19 24
25const uglify = composer(terser, console);
26
20const styleConfig = Object.keys(rawStyleConfig).map((key) => { 27const styleConfig = Object.keys(rawStyleConfig).map((key) => {
21 const isHex = /^#[0-9A-F]{6}$/i.test(rawStyleConfig[key]); 28 const isHex = /^#[0-9A-F]{6}$/i.test(rawStyleConfig[key]);
22 return ({ [`$raw_${kebabCase(key)}`]: isHex ? hexRgb(rawStyleConfig[key], { format: 'array' }).splice(0, 3).join(',') : rawStyleConfig[key] }); 29 return {
30 [`$raw_${kebabCase(key)}`]: isHex
31 ? hexRgb(rawStyleConfig[key], { format: 'array' })
32 .splice(0, 3)
33 .join(',')
34 : rawStyleConfig[key],
35 };
23}); 36});
24 37
25const paths = { 38const paths = {
26 src: 'src', 39 src: 'src',
27 dest: 'build', 40 dest: 'build',
28 tmp: '.tmp', 41 tmp: '.tmp',
29 dictionaries: 'dictionaries',
30 package: `out/${config.version}`, 42 package: `out/${config.version}`,
43 recipes: {
44 src: 'recipes/*.tar.gz',
45 dest: 'build/recipes/',
46 },
47 recipeInfo: {
48 src: 'recipes/*.json',
49 dest: 'build/recipes/',
50 },
31 html: { 51 html: {
32 src: 'src/**/*.html', 52 src: 'src/**/*.html',
33 dest: 'build/', 53 dest: 'build/',
@@ -58,18 +78,22 @@ const paths = {
58 78
59function _shell(cmd, cb) { 79function _shell(cmd, cb) {
60 console.log('executing', cmd); 80 console.log('executing', cmd);
61 exec(cmd, { 81 exec(
62 cwd: paths.dest, 82 cmd,
63 }, (error, stdout, stderr) => { 83 {
64 if (error) { 84 cwd: paths.dest,
65 console.error(`exec error: ${error}`); 85 },
66 return; 86 (error, stdout, stderr) => {
67 } 87 if (error) {
68 console.log(`stdout: ${stdout}`); 88 console.error(`exec error: ${error}`);
69 console.log(`stderr: ${stderr}`); 89 return;
70 90 }
71 cb(); 91 console.log(`stdout: ${stdout}`);
72 }); 92 console.log(`stderr: ${stderr}`);
93
94 cb();
95 },
96 );
73} 97}
74 98
75const clean = (done) => { 99const clean = (done) => {
@@ -81,60 +105,74 @@ const clean = (done) => {
81export { clean }; 105export { clean };
82 106
83export function mvSrc() { 107export function mvSrc() {
84 return gulp.src( 108 return gulp
85 [ 109 .src(
86 `${paths.src}/*`, 110 [
87 `${paths.src}/*/**`, 111 `${paths.src}/*`,
88 `!${paths.scripts.watch[1]}`, 112 `${paths.src}/*/**`,
89 `!${paths.src}/styles/**`, 113 `!${paths.scripts.watch[1]}`,
90 `!${paths.src}/**/*.js`, 114 `!${paths.src}/styles/**`,
91 ], { since: gulp.lastRun(mvSrc) }, 115 `!${paths.src}/**/*.js`,
92 ) 116 ],
117 { since: gulp.lastRun(mvSrc) },
118 )
93 .pipe(gulp.dest(paths.dest)); 119 .pipe(gulp.dest(paths.dest));
94} 120}
95 121
96export function mvPackageJson() { 122export function mvPackageJson() {
97 return gulp.src( 123 return gulp.src(['./package.json']).pipe(gulp.dest(paths.dest));
98 [
99 './package.json',
100 ],
101 )
102 .pipe(gulp.dest(paths.dest));
103} 124}
104 125
105export function mvLernaPackages() { 126export function mvLernaPackages() {
106 return gulp.src( 127 return gulp.src(['packages/**']).pipe(gulp.dest(`${paths.dest}/packages`));
107 [
108 'packages/**',
109 ],
110 )
111 .pipe(gulp.dest(`${paths.dest}/packages`));
112} 128}
113 129
114export function html() { 130export function html() {
115 return gulp.src(paths.html.src, { since: gulp.lastRun(html) }) 131 return gulp
132 .src(paths.html.src, { since: gulp.lastRun(html) })
133 .pipe(gulpIf(process.env.NODE_ENV !== 'development', htmlMin({ // Only minify in production to speed up dev builds
134 collapseWhitespace: true,
135 removeComments: true
136 })))
116 .pipe(gulp.dest(paths.html.dest)); 137 .pipe(gulp.dest(paths.html.dest));
117} 138}
118 139
119export function styles() { 140export function styles() {
120 return gulp.src(paths.styles.src) 141 return gulp
121 .pipe(sassVariables(Object.assign({ 142 .src(paths.styles.src)
122 $env: process.env.NODE_ENV === 'development' ? 'development' : 'production', 143 .pipe(
123 }, ...styleConfig))) 144 sassVariables(
124 .pipe(sass({ 145 Object.assign(
125 includePaths: [ 146 {
126 './node_modules', 147 $env:
127 '../node_modules', 148 process.env.NODE_ENV === 'development'
128 ], 149 ? 'development'
129 }).on('error', sass.logError)) 150 : 'production',
151 },
152 ...styleConfig,
153 ),
154 ),
155 )
156 .pipe(
157 sass({
158 includePaths: ['./node_modules', '../node_modules'],
159 }).on('error', sass.logError),
160 )
161 .pipe((gulpIf(process.env.NODE_ENV !== 'development', csso({ // Only minify in production to speed up dev builds
162 restructure: false, // Don't restructure CSS, otherwise it will break the styles
163 }))))
130 .pipe(gulp.dest(paths.styles.dest)); 164 .pipe(gulp.dest(paths.styles.dest));
131} 165}
132 166
133export function scripts() { 167export function scripts() {
134 return gulp.src(paths.scripts.src, { since: gulp.lastRun(scripts) }) 168 return gulp
135 .pipe(babel({ 169 .src(paths.scripts.src, { since: gulp.lastRun(scripts) })
136 comments: false, 170 .pipe(
137 })) 171 babel({
172 comments: false,
173 }),
174 )
175 .pipe(gulpIf(process.env.NODE_ENV !== 'development', uglify())) // Only uglify in production to speed up dev builds
138 .pipe(gulp.dest(paths.scripts.dest)); 176 .pipe(gulp.dest(paths.scripts.dest));
139} 177}
140 178
@@ -142,51 +180,32 @@ export function watch() {
142 gulp.watch(paths.packages.watch, mvLernaPackages); 180 gulp.watch(paths.packages.watch, mvLernaPackages);
143 gulp.watch(paths.styles.watch, styles); 181 gulp.watch(paths.styles.watch, styles);
144 182
145 gulp.watch([ 183 gulp.watch([paths.src, `${paths.scripts.src}`, `${paths.styles.src}`], mvSrc);
146 paths.src,
147 `${paths.scripts.src}`,
148 `${paths.styles.src}`,
149 ], mvSrc);
150 184
151 gulp.watch(paths.scripts.watch, scripts); 185 gulp.watch(paths.scripts.watch, scripts);
152} 186}
153 187
154export function webserver() { 188export function webserver() {
155 gulp.src([ 189 gulp.src([paths.dest]).pipe(
156 paths.dest, 190 server({
157 ])
158 .pipe(server({
159 livereload: true, 191 livereload: true,
160 })); 192 }),
193 );
161} 194}
162 195
163export function dictionaries(done) { 196export function recipes() {
164 const { SPELLCHECKER_LOCALES } = require('./build/i18n/languages'); 197 return gulp.src(paths.recipes.src, { since: gulp.lastRun(recipes) })
165 198 .pipe(gulp.dest(paths.recipes.dest));
166 let packages = '';
167 Object.keys(SPELLCHECKER_LOCALES).forEach((key) => { packages = `${packages} hunspell-dict-${key}`; });
168
169 _shell(`npm install --prefix ${path.join(__dirname, 'temp')} ${packages}`, () => {
170 moveSync(
171 path.join(__dirname, 'temp', 'node_modules'),
172 path.join(__dirname, 'build', paths.dictionaries),
173 );
174
175 removeSync(path.join(__dirname, 'temp'));
176
177 done();
178 });
179} 199}
180 200export function recipeInfo() {
181export function sign(done) { 201 return gulp.src(paths.recipeInfo.src, { since: gulp.lastRun(recipeInfo) })
182 _shell(`codesign --verbose=4 --deep --strict --force --sign "${process.env.SIGNING_IDENTITY}" "${__dirname}/node_modules/electron/dist/Electron.app"`, done); 202 .pipe(gulp.dest(paths.recipeInfo.dest));
183} 203}
184 204
185const build = gulp.series( 205const build = gulp.series(
186 clean, 206 clean,
187 gulp.parallel(mvSrc, mvPackageJson, mvLernaPackages), 207 gulp.parallel(mvSrc, mvPackageJson, mvLernaPackages),
188 gulp.parallel(html, scripts, styles), 208 gulp.parallel(html, scripts, styles, recipes, recipeInfo),
189 dictionaries,
190); 209);
191export { build }; 210export { build };
192 211