diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-03-30 13:34:40 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-05-16 00:54:57 +0200 |
commit | 0f8c96d26a74865a35440338739de037bf984315 (patch) | |
tree | 77767c4107b72ee763115ddb4ecad64d898bdafd /scripts | |
parent | feat(main): Add localization support (diff) | |
download | sophie-0f8c96d26a74865a35440338739de037bf984315.tar.gz sophie-0f8c96d26a74865a35440338739de037bf984315.tar.zst sophie-0f8c96d26a74865a35440338739de037bf984315.zip |
feat(main): Translation hot reloading during development
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/watch.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/scripts/watch.js b/scripts/watch.js index 8ea5f29..be05f2b 100644 --- a/scripts/watch.js +++ b/scripts/watch.js | |||
@@ -191,6 +191,25 @@ function setupMainPackageWatcher(viteDevServer) { | |||
191 | } | 191 | } |
192 | 192 | ||
193 | /** | 193 | /** |
194 | * @param {(event: import('vite').HMRPayload) => void} sendEvent | ||
195 | */ | ||
196 | function setupTranslationsWatcher(sendEvent) { | ||
197 | const localesDir = path.join(thisDir, '../locales'); | ||
198 | const watcher = watch(localesDir, { | ||
199 | ignored: /\.missing\.json$/, | ||
200 | ignoreInitial: true, | ||
201 | persistent: true, | ||
202 | }); | ||
203 | watcher.on('change', () => { | ||
204 | console.log(`\u26A1 Reloading translations`); | ||
205 | sendEvent({ | ||
206 | type: 'custom', | ||
207 | event: 'sophie:reload-translations', | ||
208 | }); | ||
209 | }); | ||
210 | } | ||
211 | |||
212 | /** | ||
194 | * @returns {Promise<void>} | 213 | * @returns {Promise<void>} |
195 | */ | 214 | */ |
196 | async function setupDevEnvironment() { | 215 | async function setupDevEnvironment() { |
@@ -246,6 +265,8 @@ async function setupDevEnvironment() { | |||
246 | return; | 265 | return; |
247 | } | 266 | } |
248 | 267 | ||
268 | setupTranslationsWatcher(sendEvent); | ||
269 | |||
249 | console.log('\uD83C\uDF80 Sophie is starting up'); | 270 | console.log('\uD83C\uDF80 Sophie is starting up'); |
250 | await setupMainPackageWatcher(viteDevServer); | 271 | await setupMainPackageWatcher(viteDevServer); |
251 | } | 272 | } |