forked from NativeScript/nativescript-dev-webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnsCliHelpers.js
More file actions
50 lines (39 loc) · 980 Bytes
/
nsCliHelpers.js
File metadata and controls
50 lines (39 loc) · 980 Bytes
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
const { getPath } = require("global-modules-path");
const PROJECT_DATA_GETTERS = {
appPath: "getAppDirectoryRelativePath",
appResourcesPath: "getAppResourcesRelativeDirectoryPath",
};
function getProjectData(projectDir) {
const cli = getNsCli();
if (!cli) {
return {};
}
const projectDataService = cli.projectDataService;
const projectData = safeGet(projectDataService, "getProjectData", projectDir);
return projectData;
}
function getNsCli() {
const cliPath = getPath("nativescript", "tns");
if (!cliPath) {
return;
}
const cli = require(cliPath);
return cli;
}
function safeGet(object, property, ...args) {
if (!object) {
return;
}
const value = object[property];
if (!value) {
return;
}
return typeof value === "function" ?
value.bind(object)(...args) :
value;
}
module.exports = {
PROJECT_DATA_GETTERS,
getProjectData,
safeGet,
};