chanjs 2.0.0 → 2.0.2
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/README.md +5 -2
- package/common/global.js +7 -0
- package/middleware/favicon.js +1 -1
- package/package.json +3 -2
- package/utils/db.js +2 -0
- package/utils/index.js +1 -0
- package/utils/loader.js +4 -1
- package/utils/response.js +3 -3
package/README.md
CHANGED
@@ -20,7 +20,6 @@ Chanjs 是一个基于 Express5+ 构建的轻量级 MVC 框架,完全使用 Ja
|
|
20
20
|
|
21
21
|
```code
|
22
22
|
|- app
|
23
|
-
|- config
|
24
23
|
|- module
|
25
24
|
|- module1
|
26
25
|
|- controller
|
@@ -45,8 +44,12 @@ Chanjs 是一个基于 Express5+ 构建的轻量级 MVC 框架,完全使用 Ja
|
|
45
44
|
|- service
|
46
45
|
|- view
|
47
46
|
|- router.js
|
48
|
-
|
47
|
+
|- config
|
48
|
+
|- public
|
49
49
|
|- index.js
|
50
|
+
|-.env.dev
|
51
|
+
|-.env.prd
|
52
|
+
|
50
53
|
```
|
51
54
|
|
52
55
|
### 初始化过程
|
package/common/global.js
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
|
1
2
|
import path from "path";
|
2
3
|
import fs from "fs";
|
3
4
|
import { pathToFileURL } from 'url'; // 新增顶部导入
|
5
|
+
import dotenv from "dotenv";
|
6
|
+
|
4
7
|
const ROOT_PATH = process.cwd();
|
5
8
|
const APP_PATH = path.join(ROOT_PATH, "app");
|
6
9
|
const CONFIG_PATH = path.join(APP_PATH, "config");
|
@@ -18,6 +21,10 @@ global.__dirname = path.dirname(new URL(import.meta.url).pathname);
|
|
18
21
|
//实现__filename
|
19
22
|
global.__filename = new URL(import.meta.url).pathname;
|
20
23
|
|
24
|
+
//加载环境变量
|
25
|
+
const envFile = process.env.ENV_FILE || '.env.prd'
|
26
|
+
dotenv.config({ path: path.join(ROOT_PATH, envFile) })
|
27
|
+
|
21
28
|
// app
|
22
29
|
global.APP_PATH = APP_PATH;
|
23
30
|
// config
|
package/middleware/favicon.js
CHANGED
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"type": "module",
|
3
3
|
"name": "chanjs",
|
4
|
-
"version": "2.0.
|
4
|
+
"version": "2.0.2",
|
5
5
|
"description": "chanjs基于express5 纯js研发的轻量级mvc框架。",
|
6
6
|
"main": "index.js",
|
7
7
|
"module": "index.js",
|
@@ -14,7 +14,7 @@
|
|
14
14
|
"nodejs mvc"
|
15
15
|
],
|
16
16
|
"engines": {
|
17
|
-
"node": ">=
|
17
|
+
"node": ">=22.18.0"
|
18
18
|
},
|
19
19
|
"author": "明空",
|
20
20
|
"license": "ISC",
|
@@ -23,6 +23,7 @@
|
|
23
23
|
"body-parser": "^2.2.0",
|
24
24
|
"cookie-parser": "^1.4.7",
|
25
25
|
"cors": "^2.8.5",
|
26
|
+
"dotenv": "^17.2.1",
|
26
27
|
"dayjs": "^1.11.13",
|
27
28
|
"express": "^5.1.0",
|
28
29
|
"express-art-template": "^1.0.1",
|
package/utils/db.js
CHANGED
package/utils/index.js
CHANGED
package/utils/loader.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import fs from 'fs';
|
2
2
|
import path from 'path';
|
3
|
+
import { bindClass } from './bind.js';
|
3
4
|
|
4
5
|
/**
|
5
6
|
*
|
@@ -22,7 +23,7 @@ export const getPackage = async function(){
|
|
22
23
|
}
|
23
24
|
|
24
25
|
export const loadConfig = async function(){
|
25
|
-
let config = await importFile('
|
26
|
+
let config = await importFile('config/index.js')
|
26
27
|
return config;
|
27
28
|
}
|
28
29
|
|
@@ -43,9 +44,11 @@ export const loadController = async function (moduleName) {
|
|
43
44
|
}
|
44
45
|
|
45
46
|
const files = fs.readdirSync(dir).filter(file => file.endsWith('.js'));
|
47
|
+
|
46
48
|
for (const file of files) {
|
47
49
|
const filePath = path.join(dir, file);
|
48
50
|
const name = file.replace(/\.js$/i, ''); // 安全处理 .js 后缀
|
51
|
+
|
49
52
|
try {
|
50
53
|
const module = await importFile(filePath);
|
51
54
|
controller[name] = { ...module};
|
package/utils/response.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
export let success = (data) => {
|
2
2
|
return {
|
3
3
|
success: true,
|
4
|
-
msg: "
|
4
|
+
msg: "�����ɹ�",
|
5
5
|
code: 200,
|
6
6
|
data,
|
7
7
|
};
|
@@ -10,7 +10,7 @@ export let success = (data) => {
|
|
10
10
|
export let fail = (data, code = 201) => {
|
11
11
|
return {
|
12
12
|
success: false,
|
13
|
-
msg: "
|
13
|
+
msg: "����ʧ��",
|
14
14
|
code,
|
15
15
|
data,
|
16
16
|
};
|
@@ -19,7 +19,7 @@ export let fail = (data, code = 201) => {
|
|
19
19
|
export let err = (data = {}, code = 500) => {
|
20
20
|
return {
|
21
21
|
success: false,
|
22
|
-
msg: "
|
22
|
+
msg: "ϵͳ�쳣",
|
23
23
|
code,
|
24
24
|
data,
|
25
25
|
};
|