1 | const getPublic = require('./get-public-dir');
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | module.exports = localeId => {
|
9 | if (typeof process.env.KOOT_PWA_PATHNAME !== 'string') return '';
|
10 |
|
11 |
|
12 | if (typeof localeId === 'object') {
|
13 | const { 'service-worker': sw = [] } = localeId;
|
14 | if (sw.length) {
|
15 | const file = sw[0];
|
16 | const { '.public': p } = localeId;
|
17 | const regex = new RegExp(`^${p}`);
|
18 | const P = getPublic();
|
19 | if (regex.test(file)) return P + file.replace(regex, '');
|
20 | return P + file.replace(/^public\//, '');
|
21 | }
|
22 | return '';
|
23 | }
|
24 |
|
25 | const i18nType = JSON.parse(process.env.KOOT_I18N)
|
26 | ? JSON.parse(process.env.KOOT_I18N_TYPE)
|
27 | : undefined;
|
28 |
|
29 | const pwaPathname = JSON.parse(process.env.KOOT_PWA_PATHNAME);
|
30 |
|
31 | if (i18nType !== 'default') return pwaPathname;
|
32 |
|
33 | if (!localeId) return pwaPathname;
|
34 |
|
35 | const chunks = pwaPathname.split('.');
|
36 | chunks.splice(chunks.length - 1, 0, localeId);
|
37 | return chunks.join('.');
|
38 | };
|