alemonjs 1.0.7 → 1.0.8
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/lib/define/main.js +13 -5
- package/lib/define/plugin.js +11 -49
- package/package.json +1 -1
- package/types/define/plugin.d.ts +1 -1
- package/types/define/types.d.ts +10 -1
package/lib/define/main.js
CHANGED
|
@@ -153,17 +153,25 @@ export async function defineAlemonConfig(Options) {
|
|
|
153
153
|
* ***************
|
|
154
154
|
*/
|
|
155
155
|
if (Options?.plugin?.mountFile) {
|
|
156
|
-
copyAppsFile(join(process.cwd(), `/${address}`))
|
|
156
|
+
copyAppsFile(join(process.cwd(), `/${address}`).replace(/\\/g, '/'), Options?.plugin?.monutControl ?? [
|
|
157
|
+
'assets',
|
|
158
|
+
'pages',
|
|
159
|
+
'public',
|
|
160
|
+
'plugins',
|
|
161
|
+
'server'
|
|
162
|
+
]);
|
|
157
163
|
}
|
|
158
164
|
/**
|
|
159
165
|
* ************
|
|
160
166
|
* 扫描插件
|
|
161
167
|
* ************
|
|
162
168
|
*/
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
169
|
+
if (Options?.plugin?.init) {
|
|
170
|
+
await loadInit({
|
|
171
|
+
mount: mount,
|
|
172
|
+
address: address == undefined ? '/application' : `/${address}`
|
|
173
|
+
});
|
|
174
|
+
}
|
|
167
175
|
/**
|
|
168
176
|
* ************
|
|
169
177
|
* 编译独立插件
|
package/lib/define/plugin.js
CHANGED
|
@@ -1,65 +1,27 @@
|
|
|
1
|
-
import { existsSync, readdirSync,
|
|
1
|
+
import { existsSync, readdirSync, cpSync } from 'fs';
|
|
2
2
|
import { getAppRegex } from '../alemon/index.js';
|
|
3
3
|
import { join } from 'path';
|
|
4
|
-
/**
|
|
5
|
-
* 遍历复制方法
|
|
6
|
-
*/
|
|
7
|
-
const copyFiles = (source, destination) => {
|
|
8
|
-
if (!existsSync(destination)) {
|
|
9
|
-
mkdirSync(destination, { recursive: true });
|
|
10
|
-
}
|
|
11
|
-
const files = readdirSync(source);
|
|
12
|
-
for (const file of files) {
|
|
13
|
-
const sourcePath = join(source, file);
|
|
14
|
-
const destinationPath = join(destination, file);
|
|
15
|
-
copyFileSync(sourcePath, destinationPath);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
4
|
/**
|
|
19
5
|
* 同步挂载文件
|
|
20
6
|
* @param dir 插件目录
|
|
21
7
|
*/
|
|
22
|
-
export function copyAppsFile(dir) {
|
|
8
|
+
export function copyAppsFile(dir, control = []) {
|
|
23
9
|
if (!existsSync(dir))
|
|
24
10
|
return;
|
|
25
11
|
const flies = readdirSync(dir);
|
|
26
12
|
if (flies.length === 0)
|
|
27
13
|
return;
|
|
28
14
|
const { RegexOpen, RegexClose } = getAppRegex();
|
|
29
|
-
|
|
30
|
-
const apps = flies
|
|
31
|
-
.filter(item => RegexOpen.test(item))
|
|
32
|
-
.filter(item => {
|
|
33
|
-
// 关闭符合条件的
|
|
34
|
-
if (!RegexClose) {
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
if (RegexClose.test(item)) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
return true;
|
|
41
|
-
});
|
|
42
|
-
for (const appname of apps) {
|
|
15
|
+
for (const appname of flies) {
|
|
43
16
|
const appPath = join(dir, appname);
|
|
44
|
-
if (
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
copyFiles(originalAddress, destinationAddress);
|
|
53
|
-
}
|
|
54
|
-
if (existsSync(`${appPath}/plugins`)) {
|
|
55
|
-
const originalAddress = `${appPath}/plugins`;
|
|
56
|
-
const destinationAddress = join(process.cwd(), `/plugins/.${appname}/plugins`);
|
|
57
|
-
copyFiles(originalAddress, destinationAddress);
|
|
58
|
-
}
|
|
59
|
-
if (existsSync(`${appPath}/server`)) {
|
|
60
|
-
const originalAddress = `${appPath}/server`;
|
|
61
|
-
const destinationAddress = join(process.cwd(), `/server/.${appname}/server`);
|
|
62
|
-
copyFiles(originalAddress, destinationAddress);
|
|
17
|
+
if (RegexOpen.test(appname) && (!RegexClose || !RegexClose.test(appname))) {
|
|
18
|
+
for (const name of control) {
|
|
19
|
+
if (existsSync(`${appPath}/${name}`)) {
|
|
20
|
+
const originalAddress = `${appPath}/${name}`;
|
|
21
|
+
const destinationAddress = join(process.cwd(), `./${name}/.${appname}`);
|
|
22
|
+
cpSync(originalAddress, destinationAddress, { recursive: true });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
63
25
|
}
|
|
64
26
|
}
|
|
65
27
|
}
|
package/package.json
CHANGED
package/types/define/plugin.d.ts
CHANGED
package/types/define/types.d.ts
CHANGED
|
@@ -58,6 +58,10 @@ export interface AlemonOptions {
|
|
|
58
58
|
* 插件配置
|
|
59
59
|
*/
|
|
60
60
|
plugin?: {
|
|
61
|
+
/**
|
|
62
|
+
* 是否加载插件
|
|
63
|
+
*/
|
|
64
|
+
init?: boolean;
|
|
61
65
|
/**
|
|
62
66
|
* 插件目录
|
|
63
67
|
*/
|
|
@@ -66,7 +70,12 @@ export interface AlemonOptions {
|
|
|
66
70
|
* 挂载文件
|
|
67
71
|
* default true
|
|
68
72
|
*/
|
|
69
|
-
mountFile?:
|
|
73
|
+
mountFile?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* 选择性挂载
|
|
76
|
+
* 默认 ['assets', 'pages', 'public', 'plugins', 'server']
|
|
77
|
+
*/
|
|
78
|
+
monutControl?: string[];
|
|
70
79
|
/**
|
|
71
80
|
* 插件名匹配规则
|
|
72
81
|
*/
|