forked from NativeScript/nativescript-dev-webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (43 loc) · 1.67 KB
/
index.js
File metadata and controls
57 lines (43 loc) · 1.67 KB
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
const path = require("path");
const { existsSync } = require("fs");
const { getPackageJson, getProjectDir, isAngular } = require("./projectHelpers");
const PROJECT_DIR = getProjectDir({ nestingLvl: 2 });
const APP_DIR = path.join(PROJECT_DIR, "app");
Object.assign(exports, require('./plugins'));
if (isAngular({projectDir: PROJECT_DIR})) {
Object.assign(exports, require('./plugins/angular'));
}
exports.uglifyMangleExcludes = require("./mangle-excludes");
exports.getEntryModule = function () {
const maybePackageJsonEntry = getPackageJsonEntry();
if (!maybePackageJsonEntry) {
throw new Error("app/package.json must contain a `main` attribute.");
}
const maybeAotEntry = getAotEntry(maybePackageJsonEntry);
return maybeAotEntry || maybePackageJsonEntry;
};
exports.getAppPath = platform => {
if (/ios/i.test(platform)) {
const appName = path.basename(PROJECT_DIR);
const sanitizedName = sanitize(appName);
return `platforms/ios/${sanitizedName}/app`;
} else if (/android/i.test(platform)) {
return path.join(PROJECT_DIR, "platforms/android/src/main/assets/app");
} else {
throw new Error(`Invalid platform: ${platform}`);
}
};
const sanitize = name => name
.split("")
.filter(char => /[a-zA-Z0-9]/.test(char))
.join("");
function getPackageJsonEntry() {
const packageJsonSource = getPackageJson(APP_DIR);
const entry = packageJsonSource.main;
return entry ? entry.replace(/\.js$/i, "") : null;
}
function getAotEntry(entry) {
const aotEntry = `${entry}.aot.ts`;
const aotEntryPath = path.join(APP_DIR, aotEntry);
return existsSync(aotEntryPath) ? aotEntry : null;
}