1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var fs_1 = require("fs");
|
4 | var path_1 = require("path");
|
5 | var util_1 = require("../deep-linking/util");
|
6 | var config_1 = require("../util/config");
|
7 | var Constants = require("../util/constants");
|
8 | var glob_util_1 = require("../util/glob-util");
|
9 | var helpers_1 = require("../util/helpers");
|
10 | var typescript_utils_1 = require("../util/typescript-utils");
|
11 | function getTsFilePaths(context) {
|
12 | var tsFileGlobString = path_1.join(context.srcDir, '**', '*.ts');
|
13 | return glob_util_1.globAll([tsFileGlobString]).then(function (results) {
|
14 | return results.map(function (result) { return result.absolutePath; });
|
15 | });
|
16 | }
|
17 | exports.getTsFilePaths = getTsFilePaths;
|
18 | function readTsFiles(context, tsFilePaths) {
|
19 | var promises = tsFilePaths.map(function (tsFilePath) {
|
20 | var promise = helpers_1.readFileAsync(tsFilePath);
|
21 | promise.then(function (fileContent) {
|
22 | context.fileCache.set(tsFilePath, { path: tsFilePath, content: fileContent });
|
23 | });
|
24 | return promise;
|
25 | });
|
26 | return Promise.all(promises);
|
27 | }
|
28 | exports.readTsFiles = readTsFiles;
|
29 | function generateAndWriteNgModules(fileCache) {
|
30 | fileCache.getAll().forEach(function (file) {
|
31 | var sourceFile = typescript_utils_1.getTypescriptSourceFile(file.path, file.content);
|
32 | var deepLinkDecoratorData = util_1.getDeepLinkDecoratorContentForSourceFile(sourceFile);
|
33 | if (deepLinkDecoratorData) {
|
34 |
|
35 | var correspondingNgModulePath = util_1.getNgModulePathFromCorrespondingPage(file.path);
|
36 | var ngModuleFile = fileCache.get(correspondingNgModulePath);
|
37 | if (!ngModuleFile) {
|
38 |
|
39 | var defaultNgModuleContent = util_1.generateDefaultDeepLinkNgModuleContent(file.path, deepLinkDecoratorData.className);
|
40 | var ngModuleFilePath = helpers_1.changeExtension(file.path, helpers_1.getStringPropertyValue(Constants.ENV_NG_MODULE_FILE_NAME_SUFFIX));
|
41 | fs_1.writeFileSync(ngModuleFilePath, defaultNgModuleContent);
|
42 | }
|
43 | }
|
44 | });
|
45 | }
|
46 | exports.generateAndWriteNgModules = generateAndWriteNgModules;
|
47 | function run() {
|
48 | var context = config_1.generateContext();
|
49 |
|
50 | return getTsFilePaths(context).then(function (filePaths) {
|
51 |
|
52 | return readTsFiles(context, filePaths);
|
53 | }).then(function () {
|
54 | generateAndWriteNgModules(context.fileCache);
|
55 | });
|
56 | }
|
57 | run();
|