1 | const path = require("path");
|
2 | const { existsSync } = require("fs");
|
3 | const { ANDROID_APP_PATH } = require("./androidProjectHelpers");
|
4 | const {
|
5 | getPackageJson,
|
6 | isAndroid,
|
7 | isIos,
|
8 | } = require("./projectHelpers");
|
9 |
|
10 | Object.assign(exports, require("./plugins"));
|
11 | Object.assign(exports, require("./host/resolver"));
|
12 |
|
13 | exports.getAotEntryModule = function (appDirectory) {
|
14 | verifyEntryModuleDirectory(appDirectory);
|
15 |
|
16 | const entry = getPackageJsonEntry(appDirectory);
|
17 | const aotEntry = `${entry}.aot.ts`;
|
18 |
|
19 | const aotEntryPath = path.resolve(appDirectory, aotEntry);
|
20 | if (!existsSync(aotEntryPath)) {
|
21 | throw new Error(`For ahead-of-time compilation you need to have an entry module ` +
|
22 | `at ${aotEntryPath} that bootstraps the app with a static platform instead of dynamic one!`)
|
23 | }
|
24 |
|
25 | return aotEntry;
|
26 | }
|
27 |
|
28 | exports.getEntryModule = function (appDirectory) {
|
29 | verifyEntryModuleDirectory(appDirectory);
|
30 |
|
31 | const entry = getPackageJsonEntry(appDirectory);
|
32 |
|
33 | const tsEntryPath = path.resolve(appDirectory, `${entry}.ts`);
|
34 | const jsEntryPath = path.resolve(appDirectory, `${entry}.js`);
|
35 | if (!existsSync(tsEntryPath) && !existsSync(jsEntryPath)) {
|
36 | throw new Error(`The entry module ${entry} specified in ` +
|
37 | `${appDirectory}/package.json doesn't exist!`)
|
38 | }
|
39 |
|
40 | return entry;
|
41 | };
|
42 |
|
43 | exports.getAppPath = (platform, projectDir) => {
|
44 | if (isIos(platform)) {
|
45 | const appName = path.basename(projectDir);
|
46 | const sanitizedName = sanitize(appName);
|
47 |
|
48 | return `platforms/ios/${sanitizedName}/app`;
|
49 | } else if (isAndroid(platform)) {
|
50 | return ANDROID_APP_PATH;
|
51 | } else {
|
52 | throw new Error(`Invalid platform: ${platform}`);
|
53 | }
|
54 | };
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | exports.getConvertedExternals = (externals) => {
|
68 | const modifiedExternals = (externals || []).map((e) => {
|
69 | return new RegExp(`^${e}((/.*)|$)`);
|
70 | });
|
71 |
|
72 | return modifiedExternals;
|
73 | };
|
74 |
|
75 | const sanitize = name => name
|
76 | .split("")
|
77 | .filter(char => /[a-zA-Z0-9]/.test(char))
|
78 | .join("");
|
79 |
|
80 | function getPackageJsonEntry(appDirectory) {
|
81 | const packageJsonSource = getPackageJson(appDirectory);
|
82 | const entry = packageJsonSource.main;
|
83 |
|
84 | if (!entry) {
|
85 | throw new Error(`${appDirectory}/package.json must contain a 'main' attribute!`);
|
86 | }
|
87 |
|
88 | return entry.replace(/\.js$/i, "");
|
89 | }
|
90 |
|
91 | function verifyEntryModuleDirectory(appDirectory) {
|
92 | if (!appDirectory) {
|
93 | throw new Error("Path to app directory is not specified. Unable to find entry module.");
|
94 | }
|
95 |
|
96 | if (!existsSync(appDirectory)) {
|
97 | throw new Error(`The specified path to app directory ${appDirectory} does not exist. Unable to find entry module.`);
|
98 | }
|
99 | }
|