-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1030 from Aam-Digital/master
Release 2.58.1
- Loading branch information
Showing
162 changed files
with
2,018 additions
and
829 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const fs = require("fs"); | ||
|
||
const distFolder = "dist"; | ||
|
||
function getNgswConfig(locale) { | ||
const swConfig = fs.readFileSync(`${distFolder}/${locale}/ngsw.json`); | ||
return JSON.parse(swConfig); | ||
} | ||
|
||
const locales = fs | ||
.readdirSync(distFolder) | ||
.filter((locale) => fs.lstatSync(`${distFolder}/${locale}`).isDirectory()); | ||
|
||
// Merge the ngsw.json files | ||
const firstLocale = locales.pop(); | ||
const combined = getNgswConfig(firstLocale); | ||
locales.forEach((locale) => { | ||
const additional = getNgswConfig(locale); | ||
|
||
// Merge data and asset groups | ||
const toBeMergedGroups = [ | ||
{ groupType: "dataGroups", property: "patterns" }, | ||
{ groupType: "assetGroups", property: "urls" }, | ||
]; | ||
toBeMergedGroups.forEach(({ groupType, property }) => { | ||
additional[groupType].forEach((group) => { | ||
combined[groupType] | ||
.find((g) => g.name === group.name) | ||
[property].push(...group[property]); | ||
}); | ||
}); | ||
|
||
// combine hash tables | ||
Object.assign(combined.hashTable, additional.hashTable); | ||
fs.unlinkSync(`${distFolder}/${locale}/ngsw.json`); | ||
fs.unlinkSync(`${distFolder}/${locale}/ngsw-worker.js`); | ||
}); | ||
|
||
combined.index = "/index.html"; | ||
|
||
fs.writeFileSync(`${distFolder}/ngsw.json`, JSON.stringify(combined)); | ||
fs.unlinkSync(`${distFolder}/${firstLocale}/ngsw.json`); | ||
|
||
// Adjust service worker to allow changing language offline | ||
const swFile = fs | ||
.readFileSync(`${distFolder}/${firstLocale}/ngsw-worker.js`) | ||
.toString(); | ||
const patchedSw = swFile.replace( | ||
"return this.handleFetch(this.adapter.newRequest(this.indexUrl), context);", | ||
"return this.handleFetch(this.adapter.newRequest('/' + this.adapter.normalizeUrl(req.url).split('/')[1] + '/index.html'), context);" | ||
); | ||
fs.writeFileSync(`${distFolder}/ngsw-worker.js`, patchedSw); | ||
fs.unlinkSync(`${distFolder}/${firstLocale}/ngsw-worker.js`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.