chanjs 2.0.19 → 2.0.20
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/core/service.js +2 -1
- package/global/global.js +12 -1
- package/index.js +3 -1
- package/package.json +1 -1
package/core/service.js
CHANGED
package/global/global.js
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
|
-
import { pathToFileURL, fileURLToPath } from "url";
|
|
2
1
|
import path from "path";
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import { pathToFileURL, fileURLToPath } from "url";
|
|
4
|
+
|
|
3
5
|
const ROOT_PATH = process.cwd();
|
|
4
6
|
const APP_PATH = path.join(ROOT_PATH, "app");
|
|
5
7
|
const __filename = fileURLToPath(import.meta.url);
|
|
6
8
|
const __dirname = path.dirname(__filename);
|
|
7
9
|
|
|
10
|
+
const getVersion = () => {
|
|
11
|
+
const packageJsonPath = path.join(ROOT_PATH, "package.json");
|
|
12
|
+
const packageJson = JSON.parse(
|
|
13
|
+
readFileSync(packageJsonPath, "utf8")
|
|
14
|
+
);
|
|
15
|
+
return packageJson?.version || "1.0.0";
|
|
16
|
+
};
|
|
17
|
+
|
|
8
18
|
const globals = {
|
|
9
19
|
__dirname,
|
|
10
20
|
__filename,
|
|
11
21
|
ROOT_PATH,
|
|
12
22
|
APP_PATH,
|
|
23
|
+
APP_VERSION: getVersion(),
|
|
13
24
|
CONFIG_PATH: path.join(ROOT_PATH, "config"),
|
|
14
25
|
EXTEND_PATH: path.join(APP_PATH, "extend"),
|
|
15
26
|
PUBLIC_PATH: path.join(ROOT_PATH, "public"),
|
package/index.js
CHANGED
|
@@ -21,7 +21,7 @@ import { dirname } from "./helper/file.js";
|
|
|
21
21
|
|
|
22
22
|
class Chan {
|
|
23
23
|
//版本号
|
|
24
|
-
#version = "
|
|
24
|
+
#version = "1.0.0";
|
|
25
25
|
static helper = {};
|
|
26
26
|
static common = {}; //公共方法
|
|
27
27
|
static config = {}; //配置
|
|
@@ -50,6 +50,8 @@ class Chan {
|
|
|
50
50
|
//加载配置文件
|
|
51
51
|
async config() {
|
|
52
52
|
let config = await loadConfig();
|
|
53
|
+
//版本号,先从package.json中获取,如果没有,则使用默认版本号
|
|
54
|
+
config.APP_VERSION = APP_VERSION || config.APP_VERSION;
|
|
53
55
|
Chan.config = config;
|
|
54
56
|
}
|
|
55
57
|
|