-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathpostbuild.ts
More file actions
66 lines (58 loc) · 2.63 KB
/
Copy pathpostbuild.ts
File metadata and controls
66 lines (58 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// This file contains some updates made right after Angular Cli
import { buildInfo } from './build-info.postbuild'
import {
addLanguageCodeToHashesOnToHTMLFiles,
addLanguageCodeToHashesOnJSFiles,
} from './uniqueLanguageFilesNames'
import { getOptionsObjet, save } from './utils'
import { renameSync, readFileSync } from 'fs'
import { createShareAssetsFolder } from './moveToShareFolder.postbuild'
import { addOneTrustNotAutoBlockForAppScripts } from './onetrust.postbuild'
import { newRelic } from './new-relic.postbuild'
import { localizeAndWritePrintViewScript } from './print-view-localize.postbuild'
const glob = require('glob')
// Run updates on index.html files across languages
glob.sync('./dist/*/index.html').forEach((file) => {
const options = getOptionsObjet(file)
let data = readFileSync(file, 'utf8')
data = buildInfo(data, options)
// Replace all the `*.js` references to match updated JS file names with the language code.
data = addLanguageCodeToHashesOnToHTMLFiles(data, options)
data = newRelic(data, options)
data = addOneTrustNotAutoBlockForAppScripts(data)
// data = robotsMetadata(data, options) DISABLE robots headers, as those will be handle via nginx
save(data, options)
})
// The following code is added to generate unique hash names for each language.
// For instance `runtime.<hash>.js` and `polyfills.<hash>.js will will become `runtime.<hash>-it.js` and `polyfills.<hash>-it.js for italian
const hashRegExp = RegExp(/[a-z0-9]{16}/gm)
const replacedHash = {}
glob.sync('./dist/*/*.js').forEach((file) => {
const options = getOptionsObjet(file)
const hash = file.match(hashRegExp)
renameSync(file, file.replace('.js', '-' + options.languageCode + '.js'))
// Save all the modified hash to update
replacedHash[hash] = true
})
// Translate and write the print-view script for every locale using
// @angular/localize/tools so $localize calls are replaced with the
// correct locale's strings at build time.
localizeAndWritePrintViewScript()
// Replace all the `runtime*.js` references to match updated JS values with language code
glob.sync('./dist/*/runtime*.js').forEach((file) => {
const options = getOptionsObjet(file)
let data = readFileSync(file, 'utf8')
data = addLanguageCodeToHashesOnJSFiles(
data,
Object.keys(replacedHash),
options
)
save(data, options)
})
// Rename chinese folders to use underscore to allow Orcid Source and Nginx to correctly point these folders
glob.sync('./dist/*/index.html').forEach((file) => {
const options = getOptionsObjet(file)
renameSync(options.folder, options.folder.replace('-', '_'))
})
// Move all assets into a single shared folder
createShareAssetsFolder()