-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathi18n-inlining.ts
57 lines (52 loc) · 1.6 KB
/
i18n-inlining.ts
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
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { EmittedFiles } from '@angular-devkit/build-webpack';
import * as fs from 'fs';
import * as path from 'path';
import { InlineOptions } from './process-bundle';
export function emittedFilesToInlineOptions(
emittedFiles: EmittedFiles[],
scriptsEntryPointName: string[],
emittedPath: string,
outputPath: string,
es5: boolean,
missingTranslation: 'error' | 'warning' | 'ignore' | undefined,
): { options: InlineOptions[]; originalFiles: string[] } {
const options: InlineOptions[] = [];
const originalFiles: string[] = [];
for (const emittedFile of emittedFiles) {
if (
emittedFile.asset ||
emittedFile.extension !== '.js' ||
(emittedFile.name && scriptsEntryPointName.includes(emittedFile.name))
) {
continue;
}
const originalPath = path.join(emittedPath, emittedFile.file);
const action: InlineOptions = {
filename: emittedFile.file,
code: fs.readFileSync(originalPath, 'utf8'),
es5,
outputPath,
missingTranslation,
setLocale: emittedFile.name === 'main',
};
originalFiles.push(originalPath);
try {
const originalMapPath = originalPath + '.map';
action.map = fs.readFileSync(originalMapPath, 'utf8');
originalFiles.push(originalMapPath);
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
options.push(action);
}
return { options, originalFiles };
}