source: trip-planner-front/node_modules/@angular-devkit/build-angular/src/utils/i18n-inlining.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.3 KB
Line 
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10 if (k2 === undefined) k2 = k;
11 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12}) : (function(o, m, k, k2) {
13 if (k2 === undefined) k2 = k;
14 o[k2] = m[k];
15}));
16var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17 Object.defineProperty(o, "default", { enumerable: true, value: v });
18}) : function(o, v) {
19 o["default"] = v;
20});
21var __importStar = (this && this.__importStar) || function (mod) {
22 if (mod && mod.__esModule) return mod;
23 var result = {};
24 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25 __setModuleDefault(result, mod);
26 return result;
27};
28Object.defineProperty(exports, "__esModule", { value: true });
29exports.i18nInlineEmittedFiles = void 0;
30const fs = __importStar(require("fs"));
31const path = __importStar(require("path"));
32const action_executor_1 = require("./action-executor");
33const copy_assets_1 = require("./copy-assets");
34const spinner_1 = require("./spinner");
35function emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emittedPath, outputPath, es5, missingTranslation) {
36 const options = [];
37 const originalFiles = [];
38 for (const emittedFile of emittedFiles) {
39 if (emittedFile.asset ||
40 emittedFile.extension !== '.js' ||
41 (emittedFile.name && scriptsEntryPointName.includes(emittedFile.name))) {
42 continue;
43 }
44 const originalPath = path.join(emittedPath, emittedFile.file);
45 const action = {
46 filename: emittedFile.file,
47 code: fs.readFileSync(originalPath, 'utf8'),
48 es5,
49 outputPath,
50 missingTranslation,
51 setLocale: emittedFile.name === 'main' || emittedFile.name === 'vendor',
52 };
53 originalFiles.push(originalPath);
54 try {
55 const originalMapPath = originalPath + '.map';
56 action.map = fs.readFileSync(originalMapPath, 'utf8');
57 originalFiles.push(originalMapPath);
58 }
59 catch (err) {
60 if (err.code !== 'ENOENT') {
61 throw err;
62 }
63 }
64 options.push(action);
65 }
66 return { options, originalFiles };
67}
68async function i18nInlineEmittedFiles(context, emittedFiles, i18n, baseOutputPath, outputPaths, scriptsEntryPointName, emittedPath, es5, missingTranslation) {
69 const executor = new action_executor_1.BundleActionExecutor({ i18n });
70 let hasErrors = false;
71 const spinner = new spinner_1.Spinner();
72 spinner.start('Generating localized bundles...');
73 try {
74 const { options, originalFiles: processedFiles } = emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emittedPath, baseOutputPath, es5, missingTranslation);
75 for await (const result of executor.inlineAll(options)) {
76 for (const diagnostic of result.diagnostics) {
77 spinner.stop();
78 if (diagnostic.type === 'error') {
79 hasErrors = true;
80 context.logger.error(diagnostic.message);
81 }
82 else {
83 context.logger.warn(diagnostic.message);
84 }
85 spinner.start();
86 }
87 }
88 // Copy any non-processed files into the output locations
89 await copy_assets_1.copyAssets([
90 {
91 glob: '**/*',
92 input: emittedPath,
93 output: '',
94 ignore: [...processedFiles].map((f) => path.relative(emittedPath, f)),
95 },
96 ], outputPaths, '');
97 }
98 catch (err) {
99 spinner.fail('Localized bundle generation failed: ' + err.message);
100 return false;
101 }
102 finally {
103 executor.stop();
104 }
105 if (hasErrors) {
106 spinner.fail('Localized bundle generation failed.');
107 }
108 else {
109 spinner.succeed('Localized bundle generation complete.');
110 }
111 return !hasErrors;
112}
113exports.i18nInlineEmittedFiles = i18nInlineEmittedFiles;
Note: See TracBrowser for help on using the repository browser.