@charming_dans/elpis 0.0.0-stage → 1.0.0
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/.eslintignore +3 -0
- package/.eslintrc +55 -0
- package/README.md +294 -2
- package/app/controller/base.js +39 -0
- package/app/controller/project.js +77 -0
- package/app/controller/view.js +19 -0
- package/app/extend/database.js +5 -0
- package/app/extend/logger.js +38 -0
- package/app/middleware/api-params-verify.js +75 -0
- package/app/middleware/api-sign-verify.js +38 -0
- package/app/middleware/error-handler.js +34 -0
- package/app/middleware/project-handler.js +28 -0
- package/app/middleware.js +38 -0
- package/app/pages/asserts/custom.css +12 -0
- package/app/pages/boot.js +49 -0
- package/app/pages/common/curl.js +85 -0
- package/app/pages/common/utils.js +3 -0
- package/app/pages/dashboard/complex-view/header-view/complex-view/sub-menu/sub-menu.vue +20 -0
- package/app/pages/dashboard/complex-view/header-view/header-view.vue +118 -0
- package/app/pages/dashboard/complex-view/iframe-view/iframe-view.vue +44 -0
- package/app/pages/dashboard/complex-view/schema-view/complex-view/search-panel/search-panel.vue +39 -0
- package/app/pages/dashboard/complex-view/schema-view/complex-view/table-panel/table-panel.vue +130 -0
- package/app/pages/dashboard/complex-view/schema-view/components/component-config.js +23 -0
- package/app/pages/dashboard/complex-view/schema-view/components/create-form/create-form.vue +99 -0
- package/app/pages/dashboard/complex-view/schema-view/components/detail-panel/detail-panel.vue +113 -0
- package/app/pages/dashboard/complex-view/schema-view/components/edit-form/edit-form.vue +129 -0
- package/app/pages/dashboard/complex-view/schema-view/hook/schema.js +128 -0
- package/app/pages/dashboard/complex-view/schema-view/schema-view.vue +98 -0
- package/app/pages/dashboard/complex-view/sider-view/complex-view/sub-menu/sub-menu.vue +25 -0
- package/app/pages/dashboard/complex-view/sider-view/sider-view.vue +120 -0
- package/app/pages/dashboard/dashboard.vue +98 -0
- package/app/pages/dashboard/entry.dashboard.js +42 -0
- package/app/pages/store/index.js +3 -0
- package/app/pages/store/menu.js +61 -0
- package/app/pages/store/project.js +17 -0
- package/app/pages/widgets/header-container/asserts/logo.png +0 -0
- package/app/pages/widgets/header-container/header-container.vue +81 -0
- package/app/pages/widgets/schema-form/complex-view/input/input.vue +139 -0
- package/app/pages/widgets/schema-form/complex-view/input-number/input-number.vue +138 -0
- package/app/pages/widgets/schema-form/complex-view/select/select.vue +116 -0
- package/app/pages/widgets/schema-form/form-item-config.js +23 -0
- package/app/pages/widgets/schema-form/schema-form.vue +131 -0
- package/app/pages/widgets/schema-search-bar/complex-view/date-range/date-range.vue +47 -0
- package/app/pages/widgets/schema-search-bar/complex-view/dynamic-select/dynamic-select.vue +63 -0
- package/app/pages/widgets/schema-search-bar/complex-view/input/input.vue +41 -0
- package/app/pages/widgets/schema-search-bar/complex-view/select/select.vue +48 -0
- package/app/pages/widgets/schema-search-bar/schema-search-bar.vue +130 -0
- package/app/pages/widgets/schema-search-bar/search-item-config.js +27 -0
- package/app/pages/widgets/schema-table/schema-table.vue +237 -0
- package/app/pages/widgets/sider-container/sider-container.vue +30 -0
- package/app/public/static/logo.png +0 -0
- package/app/public/static/normalize.css +239 -0
- package/app/router/project.js +6 -0
- package/app/router/view.js +8 -0
- package/app/router-schema/project.js +30 -0
- package/app/service/base.js +12 -0
- package/app/service/project.js +47 -0
- package/app/view/entry.tpl +25 -0
- package/app/webpack/config/webpack.base.js +210 -0
- package/app/webpack/config/webpack.dev.js +58 -0
- package/app/webpack/config/webpack.prod.js +113 -0
- package/app/webpack/dev.js +56 -0
- package/app/webpack/libs/blank.js +1 -0
- package/app/webpack/prod.js +21 -0
- package/config/config.default.js +3 -0
- package/elpis-core/env.js +23 -0
- package/elpis-core/index.js +95 -0
- package/elpis-core/loader/config.js +50 -0
- package/elpis-core/loader/controller.js +66 -0
- package/elpis-core/loader/extend.js +56 -0
- package/elpis-core/loader/middleware.js +65 -0
- package/elpis-core/loader/router-schema.js +48 -0
- package/elpis-core/loader/router.js +41 -0
- package/elpis-core/loader/service.js +66 -0
- package/index.js +38 -0
- package/model/index.js +99 -0
- package/package.json +90 -4
- package/test/controller/project.test.js +205 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const glob = require('glob');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { sep } = path;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* controller loader
|
|
7
|
+
* @param {object} app Koa 实例
|
|
8
|
+
*
|
|
9
|
+
* 加载所有 controller,可通过 'app.controller.${目录}.${文件}' 访问
|
|
10
|
+
*
|
|
11
|
+
例子:
|
|
12
|
+
app/controller
|
|
13
|
+
|
|
|
14
|
+
| -- custom-module
|
|
15
|
+
|
|
|
16
|
+
| -- custom-controller.js
|
|
17
|
+
|
|
18
|
+
=> app.controller.customModule.customController
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
module.exports = (app) => {
|
|
22
|
+
const controller = {};
|
|
23
|
+
|
|
24
|
+
// 读取 elpis/app/controller/**/**.js 下所有的文件
|
|
25
|
+
const eplisControllerPath = path.resolve(__dirname, `..${sep}..${sep}app${sep}controller`);
|
|
26
|
+
const elpisFileList = glob.sync(path.resolve(eplisControllerPath, `.${sep}**${sep}**.js`));
|
|
27
|
+
elpisFileList.forEach(file => {
|
|
28
|
+
handleFile(file);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// 读取 业务/app/controller/**/**.js 下所有的文件
|
|
32
|
+
const businessControllerPath = path.resolve(app.businessPath, `.${sep}controller`);
|
|
33
|
+
const businessFileList = glob.sync(path.resolve(businessControllerPath, `.${sep}**${sep}**.js`));
|
|
34
|
+
businessFileList.forEach(file => {
|
|
35
|
+
handleFile(file);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// 把内容加载到 app.controller 下
|
|
39
|
+
function handleFile(file) {
|
|
40
|
+
// 提取文件名称
|
|
41
|
+
let name = path.resolve(file);
|
|
42
|
+
|
|
43
|
+
// 截取路径 app/controller/custom-module/custom-controller.js => custom-module/custom-controller
|
|
44
|
+
name = name.substring(name.lastIndexOf(`controller${sep}`) + `controller${sep}`.length, name.lastIndexOf('.'));
|
|
45
|
+
|
|
46
|
+
// 把 '-' 统一改为驼峰式,custom-module/custom-controller.js => customModule.customController
|
|
47
|
+
name = name.replace(/[_-][a-z]/ig, (s) => s.substring(1).toUpperCase());
|
|
48
|
+
|
|
49
|
+
// 挂载 controller 到内存 app 对象中
|
|
50
|
+
let tempController = controller;
|
|
51
|
+
const names = name.split(sep); // [ customModule(目录), customController(文件) ]
|
|
52
|
+
for (let i = 0, len = names.length; i < len; ++i) {
|
|
53
|
+
if (i === len - 1) { // 文件
|
|
54
|
+
const ControllerMoule = require(path.resolve(file))(app);
|
|
55
|
+
tempController[names[i]] = new ControllerMoule();
|
|
56
|
+
} else { // 文件夹
|
|
57
|
+
if (!tempController[names[i]]) {
|
|
58
|
+
tempController[names[i]] = {};
|
|
59
|
+
}
|
|
60
|
+
tempController = tempController[names[i]];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
app.controller = controller;
|
|
66
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const glob = require('glob');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { sep } = path;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* extend loader
|
|
7
|
+
* @param {object} app Koa 实例
|
|
8
|
+
*
|
|
9
|
+
* 加载所有 extend,可通过 'app.extend.${文件}' 访问
|
|
10
|
+
*
|
|
11
|
+
例子:
|
|
12
|
+
app/extend
|
|
13
|
+
|
|
|
14
|
+
| -- custom-extend.js
|
|
15
|
+
|
|
16
|
+
=> app.extend.customExtend 访问
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
module.exports = (app) => {
|
|
20
|
+
// 读取 elpis/app/extend/**.js 下所有的文件
|
|
21
|
+
const elpisExtendPath = path.resolve(__dirname, `..${sep}..${sep}app${sep}extend`);
|
|
22
|
+
const elpisFileList = glob.sync(path.resolve(elpisExtendPath, `.${sep}**${sep}**.js`));
|
|
23
|
+
elpisFileList.forEach(file => {
|
|
24
|
+
handleFile(file);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// 读取 业务/app/extend/**.js 下所有的文件
|
|
28
|
+
const businessExtendPath = path.resolve(app.businessPath, `.${sep}extend`);
|
|
29
|
+
const businessFileList = glob.sync(path.resolve(businessExtendPath, `.${sep}**${sep}**.js`));
|
|
30
|
+
businessFileList.forEach(file => {
|
|
31
|
+
handleFile(file);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// 把内容加载到 app.extend 下
|
|
35
|
+
function handleFile(file) {
|
|
36
|
+
// 提取文件名称
|
|
37
|
+
let name = path.resolve(file);
|
|
38
|
+
|
|
39
|
+
// 截取路径 app/extend/custom-extend.js => custom-extend
|
|
40
|
+
name = name.substring(name.lastIndexOf(`extend${sep}`) + `extend${sep}`.length, name.lastIndexOf('.'));
|
|
41
|
+
|
|
42
|
+
// 把 '-' 统一改为驼峰式,custom-module/custom-extend.js => customModule.customExtend
|
|
43
|
+
name = name.replace(/[_-][a-z]/ig, (s) => s.substring(1).toUpperCase());
|
|
44
|
+
|
|
45
|
+
// 过滤 app 已经存在的 key
|
|
46
|
+
for (const key in app) {
|
|
47
|
+
if (key === name) {
|
|
48
|
+
console.log(`[extend load error] name:${name} is already in app`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 挂载 extend 到 app 上
|
|
54
|
+
app[name] = require(path.resolve(file))(app);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const glob = require('glob');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { sep } = path;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* middleware loader
|
|
7
|
+
* @param {object} app Koa 实例
|
|
8
|
+
*
|
|
9
|
+
* 加载所有 middleware,可通过 'app.middlewares.${目录}.${文件}' 访问
|
|
10
|
+
*
|
|
11
|
+
例子:
|
|
12
|
+
app/middleware
|
|
13
|
+
|
|
|
14
|
+
| -- custom-module
|
|
15
|
+
|
|
|
16
|
+
| -- custom-middleware.js
|
|
17
|
+
|
|
18
|
+
=> app.middlewares.customModule.customMiddleware
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
module.exports = (app) => {
|
|
22
|
+
const middlewares = {};
|
|
23
|
+
|
|
24
|
+
// 读取 elpis/app/middleware/**/**.js 下所有的文件
|
|
25
|
+
const elpisMiddlewarePath = path.resolve(__dirname, `..${sep}..${sep}app${sep}middleware`);
|
|
26
|
+
const elpisFileList = glob.sync(path.resolve(elpisMiddlewarePath, `.${sep}**${sep}**.js`));
|
|
27
|
+
elpisFileList.forEach(file => {
|
|
28
|
+
handleFile(file);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// 读取 业务根目录/app/middleware/**/**.js 下所有的文件
|
|
32
|
+
const businessMiddlewarePath = path.resolve(app.businessPath, `.${sep}middleware`);
|
|
33
|
+
const businessFileList = glob.sync(path.resolve(businessMiddlewarePath, `.${sep}**${sep}**.js`));
|
|
34
|
+
businessFileList.forEach(file => {
|
|
35
|
+
handleFile(file);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// 把内容加载到 app.middlewares 下
|
|
39
|
+
function handleFile(file) {
|
|
40
|
+
// 提取文件名称
|
|
41
|
+
let name = path.resolve(file);
|
|
42
|
+
|
|
43
|
+
// 截取路径 app/middlewares/custom-module/custom-middleware.js => custom-module/custom-middleware
|
|
44
|
+
name = name.substring(name.lastIndexOf(`middleware${sep}`) + `middleware${sep}`.length, name.lastIndexOf('.'));
|
|
45
|
+
|
|
46
|
+
// 把 '-' 统一改为驼峰式,custom-module/custom-middleware.js => customModule.customMiddleware
|
|
47
|
+
name = name.replace(/[_-][a-z]/ig, (s) => s.substring(1).toUpperCase());
|
|
48
|
+
|
|
49
|
+
// 挂载 middlerware 到内存 app 对象中
|
|
50
|
+
let tempMiddleware = middlewares;
|
|
51
|
+
const names = name.split(sep);
|
|
52
|
+
for (let i = 0, len = names.length; i < len; ++i) {
|
|
53
|
+
if (i === len - 1) {
|
|
54
|
+
tempMiddleware[names[i]] = require(path.resolve(file))(app);
|
|
55
|
+
} else {
|
|
56
|
+
if (!tempMiddleware[names[i]]) {
|
|
57
|
+
tempMiddleware[names[i]] = {};
|
|
58
|
+
}
|
|
59
|
+
tempMiddleware = tempMiddleware[names[i]];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
app.middlewares = middlewares;
|
|
65
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const glob = require('glob');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { sep } = path;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* router-schema loader
|
|
7
|
+
* @param {object} app koa 实例
|
|
8
|
+
*
|
|
9
|
+
* 通过 'json-schema & ajv' 对 API 规则进行约束,配合 api-params-verify 中间件使用
|
|
10
|
+
*
|
|
11
|
+
* app/router-schema/**.js
|
|
12
|
+
|
|
13
|
+
输出:
|
|
14
|
+
app.rouSchema = {
|
|
15
|
+
'${api1}': ${jsonSchema},
|
|
16
|
+
'${api2}': ${jsonSchema},
|
|
17
|
+
'${api3}': ${jsonSchema},
|
|
18
|
+
'${api4}': ${jsonSchema}
|
|
19
|
+
}
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
module.exports = (app) => {
|
|
23
|
+
let routerSchema = {};
|
|
24
|
+
|
|
25
|
+
// 读取 elpis/app/router-schema/**/**.js 下所有的文件
|
|
26
|
+
const elpisRouterSchemaPath = path.resolve(__dirname, `..${sep}..${sep}app${sep}router-schema`);
|
|
27
|
+
const elpisFileList = glob.sync(path.resolve(elpisRouterSchemaPath, `.${sep}**${sep}**.js`));
|
|
28
|
+
elpisFileList.forEach(file => {
|
|
29
|
+
handleFile(file);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// 读取 业务/app/router-schema/**/**.js 下所有的文件
|
|
33
|
+
const businessRouterSchemaPath = path.resolve(app.businessPath, `.${sep}router-schema`);
|
|
34
|
+
const businessFileList = glob.sync(path.resolve(businessRouterSchemaPath, `.${sep}**${sep}**.js`));
|
|
35
|
+
businessFileList.forEach(file => {
|
|
36
|
+
handleFile(file);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// 注册所有 routerSchema ,使得可以 'app.routerSchema' 这样访问
|
|
40
|
+
function handleFile(file) {
|
|
41
|
+
routerSchema = {
|
|
42
|
+
...routerSchema,
|
|
43
|
+
...require(path.resolve(file))
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
app.routerSchema = routerSchema;
|
|
48
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const KoaRouter = require('koa-router');
|
|
2
|
+
const glob = require('glob');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { sep } = path;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* router loader
|
|
8
|
+
* @param {object} app koa 实例
|
|
9
|
+
*
|
|
10
|
+
* 解析所有 app/router/ 下所有 js 文件,加载到 KoaRouter 下
|
|
11
|
+
*/
|
|
12
|
+
module.exports = (app) => {
|
|
13
|
+
// 实例化 KoaRouter
|
|
14
|
+
const router = new KoaRouter();
|
|
15
|
+
|
|
16
|
+
// 找到 elpis 路由文件路径
|
|
17
|
+
const elpisRouterPath = path.resolve(__dirname, `..${sep}..${sep}app${sep}router`);
|
|
18
|
+
// 注册所有 elpis 路由
|
|
19
|
+
const elpisFileList = glob.sync(path.resolve(elpisRouterPath, `.${sep}**${sep}**.js`));
|
|
20
|
+
elpisFileList.forEach(file => {
|
|
21
|
+
require(path.resolve(file))(app, router);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// 找到业务路由文件路径
|
|
25
|
+
const businessRouterPath = path.resolve(app.businessPath, `.${sep}router`);
|
|
26
|
+
// 注册所有业务路由
|
|
27
|
+
const businessFileList = glob.sync(path.resolve(businessRouterPath, `.${sep}**${sep}**.js`));
|
|
28
|
+
businessFileList.forEach(file => {
|
|
29
|
+
require(path.resolve(file))(app, router);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// 路由兜底(健壮性)
|
|
33
|
+
router.get('*', async (ctx, next) => {
|
|
34
|
+
ctx.status = 302; // 临时重定向
|
|
35
|
+
ctx.redirect(`${app?.options?.homePage ?? '/'}`);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// 路由注册到 app 上
|
|
39
|
+
app.use(router.routes());
|
|
40
|
+
app.use(router.allowedMethods());
|
|
41
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const glob = require('glob');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { sep } = path;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* service loader
|
|
7
|
+
* @param {object} app Koa 实例
|
|
8
|
+
*
|
|
9
|
+
* 加载所有 service,可通过 'app.service.${目录}.${文件}' 访问
|
|
10
|
+
*
|
|
11
|
+
例子:
|
|
12
|
+
app/service
|
|
13
|
+
|
|
|
14
|
+
| -- custom-module
|
|
15
|
+
|
|
|
16
|
+
| -- custom-service.js
|
|
17
|
+
|
|
18
|
+
=> app.service.customModule.customService
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
module.exports = (app) => {
|
|
22
|
+
const service = {};
|
|
23
|
+
|
|
24
|
+
// 读取 elpis/app/service/**/**.js 下所有的文件
|
|
25
|
+
const elpisServicePath = path.resolve(__dirname, `..${sep}..${sep}app${sep}service`);
|
|
26
|
+
const elpisFileList = glob.sync(path.resolve(elpisServicePath, `.${sep}**${sep}**.js`));
|
|
27
|
+
elpisFileList.forEach(file => {
|
|
28
|
+
handleFile(file);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// 读取 业务/app/service/**/**.js 下所有的文件
|
|
32
|
+
const businessServicePath = path.resolve(app.businessPath, `.${sep}service`);
|
|
33
|
+
const businessFileList = glob.sync(path.resolve(businessServicePath, `.${sep}**${sep}**.js`));
|
|
34
|
+
businessFileList.forEach(file => {
|
|
35
|
+
handleFile(file);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// 把内容加载到 app.service 下
|
|
39
|
+
function handleFile(file) {
|
|
40
|
+
// 提取文件名称
|
|
41
|
+
let name = path.resolve(file);
|
|
42
|
+
|
|
43
|
+
// 截取路径 app/service/custom-module/custom-service.js => custom-module/custom-service
|
|
44
|
+
name = name.substring(name.lastIndexOf(`service${sep}`) + `service${sep}`.length, name.lastIndexOf('.'));
|
|
45
|
+
|
|
46
|
+
// 把 '-' 统一改为驼峰式,custom-module/custom-service.js => customModule.customService
|
|
47
|
+
name = name.replace(/[_-][a-z]/ig, (s) => s.substring(1).toUpperCase());
|
|
48
|
+
|
|
49
|
+
// 挂载 service 到内存 app 对象中
|
|
50
|
+
let tempService = service;
|
|
51
|
+
const names = name.split(sep); // [ customModule(目录), customService(文件) ]
|
|
52
|
+
for (let i = 0, len = names.length; i < len; ++i) {
|
|
53
|
+
if (i === len - 1) { // 文件
|
|
54
|
+
const ServiceMoule = require(path.resolve(file))(app);
|
|
55
|
+
tempService[names[i]] = new ServiceMoule();
|
|
56
|
+
} else { // 文件夹
|
|
57
|
+
if (!tempService[names[i]]) {
|
|
58
|
+
tempService[names[i]] = {};
|
|
59
|
+
}
|
|
60
|
+
tempService = tempService[names[i]];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
app.service = service;
|
|
66
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// 引入 eplis-core
|
|
2
|
+
const ElpisCore = require('./elpis-core');
|
|
3
|
+
// 引入 前端工程化构建方法
|
|
4
|
+
const FEBuildDev = require('./app/webpack/dev.js');
|
|
5
|
+
const FEBuildProd = require('./app/webpack/prod.js');
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
/**
|
|
9
|
+
* 服务端基础
|
|
10
|
+
*/
|
|
11
|
+
Controller: {
|
|
12
|
+
Base: require('./app/controller/base.js')
|
|
13
|
+
},
|
|
14
|
+
Service: {
|
|
15
|
+
Base: require('./app/service/base.js')
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 编译构建前端工程
|
|
20
|
+
* @params env 环境变量 local/production
|
|
21
|
+
*/
|
|
22
|
+
frontendBuild(env) {
|
|
23
|
+
if (env === 'local') {
|
|
24
|
+
FEBuildDev();
|
|
25
|
+
} else if (env === 'production') {
|
|
26
|
+
FEBuildProd();
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 启动 elpis
|
|
32
|
+
* @params options 项目配置,透传到 elpis-core
|
|
33
|
+
*/
|
|
34
|
+
serverStart(options = {}) {
|
|
35
|
+
const app = ElpisCore.start(options);
|
|
36
|
+
return app;
|
|
37
|
+
}
|
|
38
|
+
}
|
package/model/index.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const _ = require('lodash');
|
|
2
|
+
const glob = require('glob');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { sep } = path;
|
|
5
|
+
|
|
6
|
+
// project 继承 model 方法
|
|
7
|
+
const projectExtendModel = (model, project) => {
|
|
8
|
+
return _.mergeWith({}, model, project, (modelValue, projValue) => {
|
|
9
|
+
// 处理数组合并的特殊情况
|
|
10
|
+
if (Array.isArray(modelValue) && Array.isArray(projValue)) {
|
|
11
|
+
let result = [];
|
|
12
|
+
|
|
13
|
+
// 因为 project 继承 model,所以需要处理修改和新增内容的情况
|
|
14
|
+
// project有的键值,model也有 => 修改(重载)
|
|
15
|
+
// project有的键值,model没有 => 新增
|
|
16
|
+
// model有的键值,project没有 => 保留(继承)
|
|
17
|
+
|
|
18
|
+
// 处理修改和保留
|
|
19
|
+
for (let i = 0; i < modelValue.length; ++i) {
|
|
20
|
+
let modelItem = modelValue[i];
|
|
21
|
+
const projItem = projValue.find(projItem => projItem.key === modelItem.key);
|
|
22
|
+
// project有的键值,model也有,则递归调用 projectExtendModel 方法覆盖修改
|
|
23
|
+
result.push(projItem ? projectExtendModel(modelItem, projItem) : modelItem);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 处理新增
|
|
27
|
+
for (let i = 0; i < projValue.length; ++i) {
|
|
28
|
+
const projItem = projValue[i];
|
|
29
|
+
const modelItem = modelValue.find(modelItem => modelItem.key === projItem.key);
|
|
30
|
+
if (!modelItem) {
|
|
31
|
+
result.push(projItem);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 解析 model 配置,并返回组织且继承后的数据结构
|
|
42
|
+
[{
|
|
43
|
+
model: ${model}
|
|
44
|
+
project: {
|
|
45
|
+
proj1Key: ${proj1},
|
|
46
|
+
proj2Key: ${proj2}
|
|
47
|
+
}
|
|
48
|
+
}, ...]
|
|
49
|
+
*/
|
|
50
|
+
module.exports = (app) => {
|
|
51
|
+
const modelList = [];
|
|
52
|
+
|
|
53
|
+
// 遍历当前文件夹,构造模型数据结构,挂载到 modelList 上
|
|
54
|
+
const modelPath = path.resolve(process.cwd(), `.${sep}model`);
|
|
55
|
+
const fileList = glob.sync(path.resolve(modelPath, `.${sep}**${sep}**.js`));
|
|
56
|
+
fileList.forEach(file => {
|
|
57
|
+
if (file.indexOf('index.js') > -1) { return; }
|
|
58
|
+
|
|
59
|
+
// 区分配置类型 (model / project)
|
|
60
|
+
const type = file.indexOf(`${sep}project${sep}`) > -1 ? 'project' : 'model';
|
|
61
|
+
|
|
62
|
+
if (type === 'project') {
|
|
63
|
+
const modelKey = file.match(/\/model\/(.*?)\/project/)?.[1];
|
|
64
|
+
const projKey = file.match(/\/project\/(.*?)\.js/)?.[1];
|
|
65
|
+
let modelItem = modelList.find(item => item.model?.key === modelKey);
|
|
66
|
+
if (!modelItem) { // 初始化 model 数据结构
|
|
67
|
+
modelItem = {};
|
|
68
|
+
modelList.push(modelItem);
|
|
69
|
+
}
|
|
70
|
+
if (!modelItem.project) { // 初始化 project 数据结构
|
|
71
|
+
modelItem.project = {};
|
|
72
|
+
}
|
|
73
|
+
modelItem.project[projKey] = require(path.resolve(file));
|
|
74
|
+
modelItem.project[projKey].key = projKey; // 注入 projectKey
|
|
75
|
+
modelItem.project[projKey].modelKey = modelKey; // 注入 modelKey
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (type === 'model') {
|
|
79
|
+
const modelKey = file.match(/\/model\/(.*?)\/model\.js/)?.[1];
|
|
80
|
+
let modelItem = modelList.find(item => item.model?.key === modelKey);
|
|
81
|
+
if (!modelItem) { // 初始化 model 数据结构
|
|
82
|
+
modelItem = {};
|
|
83
|
+
modelList.push(modelItem);
|
|
84
|
+
}
|
|
85
|
+
modelItem.model = require(path.resolve(file));
|
|
86
|
+
modelItem.model.key = modelKey; // 注入 modelKey
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// 数据进一步整理: project => 继承 model
|
|
91
|
+
modelList.forEach(item => {
|
|
92
|
+
const { model, project } = item;
|
|
93
|
+
for (const key in project) {
|
|
94
|
+
project[key] = projectExtendModel(model, project[key]);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
return modelList;
|
|
99
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,92 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@charming_dans/elpis",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"lint": "eslint --quiet --ext js,vue .",
|
|
8
|
+
"test": "_ENV='local' mocha 'test/**/*.js'"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://e.coding.net/zhexuanqianduan/elpis/elpis.git"
|
|
13
|
+
},
|
|
14
|
+
"author": "哲玄",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@babel/core": "^7.24.0",
|
|
18
|
+
"@babel/plugin-transform-runtime": "^7.1.0",
|
|
19
|
+
"@babel/preset-env": "^7.4.5",
|
|
20
|
+
"@babel/runtime": "^7.28.3",
|
|
21
|
+
"@element-plus/icons-vue": "^2.3.1",
|
|
22
|
+
"ajv": "^6.10.2",
|
|
23
|
+
"axios": "^0.19.2",
|
|
24
|
+
"babel-loader": "^8.0.4",
|
|
25
|
+
"clean-webpack-plugin": "^0.1.19",
|
|
26
|
+
"consoler": "^0.2.0",
|
|
27
|
+
"css-loader": "^0.23.1",
|
|
28
|
+
"css-minimizer-webpack-plugin": "^5.0.1",
|
|
29
|
+
"directory-named-webpack-plugin": "^4.0.1",
|
|
30
|
+
"echarts": "^5.5.0",
|
|
31
|
+
"element-plus": "^2.3.7",
|
|
32
|
+
"express": "^4.18.2",
|
|
33
|
+
"file-loader": "^6.2.0",
|
|
34
|
+
"generate-password": "^1.7.1",
|
|
35
|
+
"glob": "^7.1.4",
|
|
36
|
+
"happypack": "^5.0.1",
|
|
37
|
+
"html-webpack-inject-attributes-plugin": "^1.0.1",
|
|
38
|
+
"html-webpack-plugin": "^5.5.3",
|
|
39
|
+
"jsonwebtoken": "^9.0.2",
|
|
40
|
+
"knex": "^0.19.0",
|
|
41
|
+
"koa": "2.7.0",
|
|
42
|
+
"koa-bodyparser": "^4.2.1",
|
|
43
|
+
"koa-nunjucks-2": "^3.0.2",
|
|
44
|
+
"koa-router": "^7.4.0",
|
|
45
|
+
"koa-static": "^5.0.0",
|
|
46
|
+
"koa-useragent": "2.0.0",
|
|
47
|
+
"koa2-cors": "^2.0.6",
|
|
48
|
+
"less": "^3.8.1",
|
|
49
|
+
"less-loader": "^11.1.3",
|
|
50
|
+
"lodash": "^4.17.21",
|
|
51
|
+
"log4js": "^6.9.1",
|
|
52
|
+
"md5": "^2.2.1",
|
|
53
|
+
"mini-css-extract-plugin": "^2.7.6",
|
|
54
|
+
"moment": "^2.29.4",
|
|
55
|
+
"mysql2": "^3.23.1",
|
|
56
|
+
"node-schedule": "^2.1.1",
|
|
57
|
+
"nodemon": "^1.19.2",
|
|
58
|
+
"path": "^0.12.7",
|
|
59
|
+
"pinia": "^2.1.6",
|
|
60
|
+
"style-loader": "^0.14.1",
|
|
61
|
+
"superagent": "^8.1.2",
|
|
62
|
+
"terser-webpack-plugin": "^2.3.5",
|
|
63
|
+
"url-loader": "^4.1.1",
|
|
64
|
+
"vue": "^3.3.4",
|
|
65
|
+
"vue-json-viewer": "^3.0.4",
|
|
66
|
+
"vue-loader": "^17.2.2",
|
|
67
|
+
"vue-router": "^4.2.4",
|
|
68
|
+
"vue-style-loader": "^4.1.2",
|
|
69
|
+
"vuex": "^4.1.0",
|
|
70
|
+
"webpack": "^5.88.1",
|
|
71
|
+
"webpack-dev-middleware": "^6.1.1",
|
|
72
|
+
"webpack-hot-middleware": "^2.25.4",
|
|
73
|
+
"webpack-merge": "^4.2.1"
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"assert": "^2.0.0",
|
|
77
|
+
"babel-eslint": "^10.0.2",
|
|
78
|
+
"eslint": "^7.32.0",
|
|
79
|
+
"eslint-plugin-import": "^2.28.1",
|
|
80
|
+
"eslint-plugin-vue": "^9.17.0",
|
|
81
|
+
"ghooks": "~1.0.3",
|
|
82
|
+
"mocha": "^6.1.4",
|
|
83
|
+
"supertest": "^4.0.2",
|
|
84
|
+
"validate-commit-msg": "~2.14.0"
|
|
85
|
+
},
|
|
86
|
+
"config": {
|
|
87
|
+
"ghooks": {
|
|
88
|
+
"commit-msg": "validate-commit-msg",
|
|
89
|
+
"pre-commit": "npm run lint"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|