1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var path_1 = require("path");
|
4 | var fs_extra_1 = require("fs-extra");
|
5 | var logger_1 = require("./logger/logger");
|
6 | var Constants = require("./util/constants");
|
7 | var helpers_1 = require("./util/helpers");
|
8 | var inject_scripts_1 = require("./core/inject-scripts");
|
9 | var source_maps_1 = require("./util/source-maps");
|
10 | var remove_unused_fonts_1 = require("./optimization/remove-unused-fonts");
|
11 | function postprocess(context) {
|
12 | var logger = new logger_1.Logger("postprocess");
|
13 | return postprocessWorker(context).then(function () {
|
14 | logger.finish();
|
15 | })
|
16 | .catch(function (err) {
|
17 | throw logger.fail(err);
|
18 | });
|
19 | }
|
20 | exports.postprocess = postprocess;
|
21 | function postprocessWorker(context) {
|
22 | var promises = [];
|
23 | promises.push(source_maps_1.purgeSourceMapsIfNeeded(context));
|
24 | promises.push(inject_scripts_1.updateIndexHtml(context));
|
25 | if (helpers_1.getBooleanPropertyValue(Constants.ENV_AOT_WRITE_TO_DISK)) {
|
26 | promises.push(writeFilesToDisk(context));
|
27 | }
|
28 | if (context.optimizeJs && helpers_1.getBooleanPropertyValue(Constants.ENV_PURGE_UNUSED_FONTS)) {
|
29 | promises.push(remove_unused_fonts_1.removeUnusedFonts(context));
|
30 | }
|
31 | return Promise.all(promises);
|
32 | }
|
33 | function writeFilesToDisk(context) {
|
34 | fs_extra_1.emptyDirSync(context.tmpDir);
|
35 | var files = context.fileCache.getAll();
|
36 | files.forEach(function (file) {
|
37 | var dirName = path_1.dirname(file.path);
|
38 | var relativePath = path_1.relative(process.cwd(), dirName);
|
39 | var tmpPath = path_1.join(context.tmpDir, relativePath);
|
40 | var fileName = path_1.basename(file.path);
|
41 | var fileToWrite = path_1.join(tmpPath, fileName);
|
42 | fs_extra_1.mkdirpSync(tmpPath);
|
43 | fs_extra_1.writeFileSync(fileToWrite, file.content);
|
44 | });
|
45 | return Promise.resolve();
|
46 | }
|
47 | exports.writeFilesToDisk = writeFilesToDisk;
|