not-node 6.3.71 → 6.3.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/const.js +13 -0
- package/src/init/lib/env.js +77 -15
package/package.json
CHANGED
package/src/const.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const DEFAULT_PATH_TMP = "../../tmp";
|
|
2
|
+
const DEFAULT_PATH_STATIC = "../static";
|
|
3
|
+
const DEFAULT_PATH_MODULES = "./modules";
|
|
4
|
+
const DEFAULT_PATH_WS = "./ws";
|
|
5
|
+
const DEFAULT_PATH_DB_DUMPS = "../../db.dumps";
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
DEFAULT_PATH_WS,
|
|
9
|
+
DEFAULT_PATH_MODULES,
|
|
10
|
+
DEFAULT_PATH_STATIC,
|
|
11
|
+
DEFAULT_PATH_TMP,
|
|
12
|
+
DEFAULT_PATH_DB_DUMPS,
|
|
13
|
+
};
|
package/src/init/lib/env.js
CHANGED
|
@@ -1,7 +1,43 @@
|
|
|
1
1
|
const log = require("not-log")(module, "not-node//init//env");
|
|
2
2
|
const { tryDirAsync } = require("../../common");
|
|
3
|
+
const notEnv = require("../../env");
|
|
4
|
+
const {
|
|
5
|
+
DEFAULT_PATH_WS,
|
|
6
|
+
DEFAULT_PATH_MODULES,
|
|
7
|
+
DEFAULT_PATH_STATIC,
|
|
8
|
+
DEFAULT_PATH_TMP,
|
|
9
|
+
DEFAULT_PATH_DB_DUMPS,
|
|
10
|
+
} = require("../../const");
|
|
3
11
|
|
|
4
12
|
module.exports = class InitENV {
|
|
13
|
+
static CONFIG_SET = [
|
|
14
|
+
{
|
|
15
|
+
from: "path:static",
|
|
16
|
+
to: "staticPath",
|
|
17
|
+
def: DEFAULT_PATH_STATIC,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
from: "path:modules",
|
|
21
|
+
to: "modulesPath",
|
|
22
|
+
def: DEFAULT_PATH_MODULES,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
from: "path:tmp",
|
|
26
|
+
to: "tmpPath",
|
|
27
|
+
def: DEFAULT_PATH_TMP,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
from: "path:dbDumps",
|
|
31
|
+
to: "dbDumpsPath",
|
|
32
|
+
def: DEFAULT_PATH_DB_DUMPS,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
from: "path:ws",
|
|
36
|
+
to: "wsPath",
|
|
37
|
+
def: DEFAULT_PATH_WS,
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
|
|
5
41
|
static getProxyPort(config) {
|
|
6
42
|
return parseInt(config.get("proxy:port") || config.get("port"));
|
|
7
43
|
}
|
|
@@ -34,30 +70,56 @@ module.exports = class InitENV {
|
|
|
34
70
|
}
|
|
35
71
|
}
|
|
36
72
|
|
|
73
|
+
static addToEnv(key, val) {
|
|
74
|
+
notEnv.setEnv(key, val);
|
|
75
|
+
return val;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static setObsoleteAndNew({ config, master, from, to, def }) {
|
|
79
|
+
config.set(
|
|
80
|
+
to,
|
|
81
|
+
InitENV.addToEnv(to, master.getAbsolutePath(config.get(from, def))),
|
|
82
|
+
`obsolete: use notEnv.getEnv('${to}') instead`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static initFromTemplate({ config, master }) {
|
|
87
|
+
InitENV.CONFIG_SET.forEach((item) => {
|
|
88
|
+
InitENV.setObsoleteAndNew({
|
|
89
|
+
config,
|
|
90
|
+
master,
|
|
91
|
+
...item,
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
37
96
|
async run({ config, options, master, emit }) {
|
|
38
97
|
log?.info("Setting up server environment variables...");
|
|
39
98
|
await emit("env.pre", { config, options, master });
|
|
99
|
+
|
|
100
|
+
InitENV.initFromTemplate({ config, master });
|
|
101
|
+
|
|
40
102
|
config.set(
|
|
41
|
-
"
|
|
42
|
-
|
|
103
|
+
"appPath",
|
|
104
|
+
InitENV.addToEnv("appPath", options.pathToApp),
|
|
105
|
+
"obsolete: use notEnv.getEnv('appPath')"
|
|
43
106
|
);
|
|
107
|
+
|
|
44
108
|
config.set(
|
|
45
|
-
"
|
|
46
|
-
|
|
109
|
+
"npmPath",
|
|
110
|
+
InitENV.addToEnv("npmPath", options.pathToNPM),
|
|
111
|
+
"obsolete: use notEnv.getEnv('npmPath')"
|
|
47
112
|
);
|
|
113
|
+
|
|
48
114
|
config.set(
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
115
|
+
"fullServerName",
|
|
116
|
+
InitENV.addToEnv(
|
|
117
|
+
"fullServerName",
|
|
118
|
+
InitENV.getFullServerName(config)
|
|
119
|
+
),
|
|
120
|
+
"obsolete: use notEnv.getEnv('fullServerName')"
|
|
53
121
|
);
|
|
54
|
-
|
|
55
|
-
config.set("npmPath", options.pathToNPM);
|
|
56
|
-
config.set("fullServerName", InitENV.getFullServerName(config));
|
|
57
|
-
if (config.get("path:ws")) {
|
|
58
|
-
log?.log("wsPath", master.getAbsolutePath(config.get("path:ws")));
|
|
59
|
-
config.set("wsPath", master.getAbsolutePath(config.get("path:ws")));
|
|
60
|
-
}
|
|
122
|
+
|
|
61
123
|
await InitENV.checkPaths(master, config);
|
|
62
124
|
await emit("env.post", { config, options, master });
|
|
63
125
|
}
|