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