@wagq/wa-cli 0.6.4 → 0.6.6
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/daml/asyncByApp.js +233 -198
- package/lib/server/index.js +20 -2
- package/package.json +1 -2
package/lib/daml/asyncByApp.js
CHANGED
|
@@ -3,216 +3,251 @@ const Prompt = require("inquirer");
|
|
|
3
3
|
const log = require("../../utils/log");
|
|
4
4
|
const string2Data = require("../../utils/string2Data");
|
|
5
5
|
|
|
6
|
-
const catalogue =
|
|
6
|
+
const catalogue = "pages";
|
|
7
7
|
|
|
8
8
|
const initQuestions = () => [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
]
|
|
9
|
+
{
|
|
10
|
+
type: "list",
|
|
11
|
+
name: "ignore",
|
|
12
|
+
message: "git是否忽略当前目录",
|
|
13
|
+
choices: [true, false],
|
|
14
|
+
default: true,
|
|
15
|
+
},
|
|
16
|
+
];
|
|
17
17
|
|
|
18
18
|
const handleIgnore = async (ignore, catalogue) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
19
|
+
try {
|
|
20
|
+
if (ignore) {
|
|
21
|
+
const ignoreExist = await fs.existsSync(`${process.cwd()}/.gitignore`);
|
|
22
|
+
if (!ignoreExist) {
|
|
23
|
+
await fs.writeFileSync(`.gitignore`, `${catalogue}`, {
|
|
24
|
+
cwd: process.cwd(),
|
|
25
|
+
});
|
|
26
|
+
} else {
|
|
27
|
+
const hasCatalogue = await fs
|
|
28
|
+
.readFileSync(`${process.cwd()}/.gitignore`)
|
|
29
|
+
.toString()
|
|
30
|
+
.includes(catalogue);
|
|
31
|
+
if (!hasCatalogue) {
|
|
32
|
+
await fs.appendFileSync(
|
|
33
|
+
`${process.cwd()}/.gitignore`,
|
|
34
|
+
`\n${catalogue}`
|
|
35
|
+
);
|
|
33
36
|
}
|
|
34
|
-
|
|
35
|
-
return Promise.resolve();
|
|
37
|
+
}
|
|
36
38
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
39
|
+
|
|
40
|
+
return Promise.resolve();
|
|
41
|
+
} finally {
|
|
42
|
+
return Promise.resolve();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const getList = async (origin, appId, branchid, token) => {
|
|
47
|
+
try {
|
|
48
|
+
const request = () =>
|
|
49
|
+
fetch(`${origin}/api/assembler/page/list`, {
|
|
50
|
+
headers: {
|
|
51
|
+
accept: "application/json, text/plain, */*",
|
|
52
|
+
"accept-language":
|
|
53
|
+
"zh,ja;q=0.9,zh-CN;q=0.8,en;q=0.7,ko;q=0.6,vi;q=0.5,zh-TW;q=0.4",
|
|
54
|
+
"access-token": token,
|
|
55
|
+
appid: appId,
|
|
56
|
+
branchid: branchid,
|
|
57
|
+
"cache-control": "no-cache",
|
|
58
|
+
"content-type": "application/json",
|
|
59
|
+
pragma: "no-cache",
|
|
60
|
+
"sec-ch-ua":
|
|
61
|
+
'"Chromium";v="134", "Not:A-Brand";v="24", "Google Chrome";v="134"',
|
|
62
|
+
"sec-ch-ua-mobile": "?0",
|
|
63
|
+
"sec-ch-ua-platform": '"Windows"',
|
|
64
|
+
"sec-fetch-dest": "empty",
|
|
65
|
+
"sec-fetch-mode": "cors",
|
|
66
|
+
"sec-fetch-site": "same-origin",
|
|
67
|
+
},
|
|
68
|
+
body: `{"current":1,"size":1000,"name":"","path":"","type":"","appId":${appId}}`,
|
|
69
|
+
method: "POST",
|
|
70
|
+
});
|
|
71
|
+
const res = await request().then((res) => res.json());
|
|
72
|
+
|
|
73
|
+
const lists = res.data.records.map((i) => {
|
|
74
|
+
return {
|
|
75
|
+
id: i.id,
|
|
76
|
+
name: `${i.name}(${i.path.replace(/\//g, "_")})`,
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return lists || [];
|
|
81
|
+
} catch (err) {
|
|
82
|
+
log.error(
|
|
83
|
+
`请求页面列表失败,请检查参数是否正确, origin:${origin}, appId: ${appId}, branchid: ${branchid}, token: ${token}`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const getDaml = async (lists, origin, appId, branchid, token, dirName) => {
|
|
89
|
+
try {
|
|
90
|
+
lists.forEach(async ({ name, id }) => {
|
|
91
|
+
const request = () =>
|
|
92
|
+
fetch(`${origin}/api/assembler/page/getPageDaml`, {
|
|
93
|
+
headers: {
|
|
94
|
+
accept: "application/json, text/plain, */*",
|
|
95
|
+
"accept-language":
|
|
96
|
+
"zh,ja;q=0.9,zh-CN;q=0.8,en;q=0.7,ko;q=0.6,vi;q=0.5,zh-TW;q=0.4",
|
|
97
|
+
"access-token": token,
|
|
98
|
+
appid: appId,
|
|
99
|
+
branchid: branchid,
|
|
100
|
+
"cache-control": "no-cache",
|
|
101
|
+
"content-type": "application/json",
|
|
102
|
+
pragma: "no-cache",
|
|
103
|
+
"sec-ch-ua":
|
|
104
|
+
'"Chromium";v="134", "Not:A-Brand";v="24", "Google Chrome";v="134"',
|
|
105
|
+
"sec-ch-ua-mobile": "?0",
|
|
106
|
+
"sec-ch-ua-platform": '"Windows"',
|
|
107
|
+
"sec-fetch-dest": "empty",
|
|
108
|
+
"sec-fetch-mode": "cors",
|
|
109
|
+
"sec-fetch-site": "same-origin",
|
|
110
|
+
cookie: "_tea_utm_cache_1229=undefined",
|
|
111
|
+
"Referrer-Policy": "strict-origin-when-cross-origin",
|
|
112
|
+
},
|
|
113
|
+
body: `{\"pageId\":\"${id}\",\"appId\":\"${appId}\"}`,
|
|
114
|
+
method: "POST",
|
|
75
115
|
});
|
|
76
116
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const getDaml = async(lists, origin, appId, branchid, token, dirName) => {
|
|
85
|
-
try {
|
|
86
|
-
lists.forEach(async ({ name, id }) => {
|
|
87
|
-
const request = () =>
|
|
88
|
-
fetch(`${origin}/api/assembler/page/getPageDaml`, {
|
|
89
|
-
headers: {
|
|
90
|
-
accept: "application/json, text/plain, */*",
|
|
91
|
-
"accept-language":
|
|
92
|
-
"zh,ja;q=0.9,zh-CN;q=0.8,en;q=0.7,ko;q=0.6,vi;q=0.5,zh-TW;q=0.4",
|
|
93
|
-
"access-token": token,
|
|
94
|
-
appid: appId,
|
|
95
|
-
branchid: branchid,
|
|
96
|
-
"cache-control": "no-cache",
|
|
97
|
-
"content-type": "application/json",
|
|
98
|
-
pragma: "no-cache",
|
|
99
|
-
"sec-ch-ua":
|
|
100
|
-
'"Chromium";v="134", "Not:A-Brand";v="24", "Google Chrome";v="134"',
|
|
101
|
-
"sec-ch-ua-mobile": "?0",
|
|
102
|
-
"sec-ch-ua-platform": '"Windows"',
|
|
103
|
-
"sec-fetch-dest": "empty",
|
|
104
|
-
"sec-fetch-mode": "cors",
|
|
105
|
-
"sec-fetch-site": "same-origin",
|
|
106
|
-
cookie: "_tea_utm_cache_1229=undefined",
|
|
107
|
-
"Referrer-Policy": "strict-origin-when-cross-origin",
|
|
108
|
-
},
|
|
109
|
-
body: `{\"pageId\":\"${id}\",\"appId\":\"${appId}\"}`,
|
|
110
|
-
method: "POST",
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
log.loading(`正在同步${name}的逻辑器与变量值`)
|
|
114
|
-
request()
|
|
115
|
-
.then((res) => res.json())
|
|
116
|
-
.then(async(res) => {
|
|
117
|
-
const daml = JSON.parse(res.data.daml);
|
|
118
|
-
await generateLogic(dirName, daml, name);
|
|
119
|
-
await generateVariable(dirName, daml, name);
|
|
120
|
-
});
|
|
117
|
+
log.loading(`正在同步${name}的逻辑器与变量值`);
|
|
118
|
+
request()
|
|
119
|
+
.then((res) => res.json())
|
|
120
|
+
.then(async (res) => {
|
|
121
|
+
const daml = JSON.parse(res.data.daml);
|
|
122
|
+
await generateLogic(dirName, daml, name);
|
|
123
|
+
await generateVariable(dirName, daml, name);
|
|
121
124
|
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const generateLogic = async(dirName, daml, name) => {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
content = `/** @file ${name}(逻辑名称:${fileName}) */
|
|
125
|
+
});
|
|
126
|
+
} catch (err) {
|
|
127
|
+
log.error(err);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const generateLogic = async (dirName, daml, name) => {
|
|
132
|
+
try {
|
|
133
|
+
log.loading(`正在同步${name}的逻辑器`);
|
|
134
|
+
const logicDir = `${dirName}/${name}/logic`;
|
|
135
|
+
// 创建逻辑器文件夹
|
|
136
|
+
await fs.mkdirSync(
|
|
137
|
+
`${logicDir}`,
|
|
138
|
+
{ recursive: true },
|
|
139
|
+
{
|
|
140
|
+
cwd: process.cwd(),
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
const pages = daml.app.subapps[0]?.actions?.actionList || [];
|
|
144
|
+
pages.forEach(({ content, name: fileName }) => {
|
|
145
|
+
// 添加标识
|
|
146
|
+
content = `/** @file ${name}(逻辑名称:${fileName}) */
|
|
145
147
|
|
|
146
148
|
${content}`;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
149
|
+
|
|
150
|
+
fs.writeFileSync(`${logicDir}/${fileName}.js`, content, {
|
|
151
|
+
cwd: process.cwd(),
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
log.info(`同步${name}的逻辑器成功`);
|
|
155
|
+
} catch (err) {
|
|
156
|
+
log.loading(`同步${name}的逻辑器失败:${err}`);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const generateVariable = async (dirName, daml, name) => {
|
|
161
|
+
try {
|
|
162
|
+
log.loading(`正在同步${name}的变量值`);
|
|
163
|
+
const variableDir = `${dirName}/${name}/variable`;
|
|
164
|
+
// 创建变量文件夹
|
|
165
|
+
await fs.mkdirSync(
|
|
166
|
+
`${variableDir}`,
|
|
167
|
+
{ recursive: true },
|
|
168
|
+
{
|
|
169
|
+
cwd: process.cwd(),
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
const variables = daml.app.subapps[0].dataSource.dataList || [];
|
|
174
|
+
|
|
175
|
+
variables.forEach(({ key, value: variableValue }) => {
|
|
176
|
+
fs.writeFileSync(
|
|
177
|
+
`${variableDir}/${key}.json`,
|
|
178
|
+
JSON.stringify(
|
|
179
|
+
variableValue,
|
|
180
|
+
(key, value) => {
|
|
181
|
+
if (typeof value === "string") {
|
|
182
|
+
return string2Data(value);
|
|
183
|
+
}
|
|
184
|
+
return value;
|
|
185
|
+
},
|
|
186
|
+
2
|
|
187
|
+
),
|
|
188
|
+
{
|
|
189
|
+
cwd: process.cwd(),
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
});
|
|
193
|
+
log.info(`同步${name}的变量值成功`);
|
|
194
|
+
} catch (err) {
|
|
195
|
+
log.loading(`同步${name}的变量失败:${err}`);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const checkDamlrc = async () => {
|
|
200
|
+
const exist = await fs.existsSync(`${process.cwd()}/.damlrc.json`);
|
|
201
|
+
if (!exist) {
|
|
202
|
+
log.loading(`
|
|
203
|
+
检测到.damlrc文件不存在,
|
|
204
|
+
正在为你创建所需文件,
|
|
205
|
+
`);
|
|
206
|
+
await fs.writeFileSync(
|
|
207
|
+
`${process.cwd()}/.damlrc.json`,
|
|
208
|
+
`
|
|
209
|
+
[
|
|
167
210
|
{
|
|
168
|
-
|
|
211
|
+
"appName": "应用名称",
|
|
212
|
+
"origin": "低代码域名",
|
|
213
|
+
"appId": "应用id",
|
|
214
|
+
"branchid": "应用分支id",
|
|
215
|
+
"token": "你的token"
|
|
169
216
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
217
|
+
]
|
|
218
|
+
`
|
|
219
|
+
);
|
|
220
|
+
log.error("文件创建成功,请打开.damlrc.json补充你的信息后再次执行命令");
|
|
221
|
+
}
|
|
222
|
+
return;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const main = async () => {
|
|
226
|
+
await checkDamlrc();
|
|
227
|
+
const settings = require(`${process.cwd()}/.damlrc.json`) || [];
|
|
228
|
+
const { ignore } = await Prompt.default.prompt(initQuestions());
|
|
229
|
+
settings.forEach(async ({ appName, origin, token, appId, branchid }) => {
|
|
230
|
+
const basePath = `${appName}/${catalogue}`;
|
|
231
|
+
const exist = await fs.existsSync(basePath);
|
|
232
|
+
|
|
233
|
+
if (!exist) {
|
|
234
|
+
log.info(`当前目录${basePath}不存在,开始创建${basePath}文件夹`);
|
|
235
|
+
const hasTopDir = await fs.existsSync(appName);
|
|
236
|
+
if (!hasTopDir) {
|
|
237
|
+
await fs.mkdirSync(String(appName), undefined, {
|
|
238
|
+
cwd: process.cwd(),
|
|
183
239
|
});
|
|
184
|
-
|
|
240
|
+
}
|
|
241
|
+
await fs.mkdirSync(String(basePath), undefined, {
|
|
242
|
+
cwd: process.cwd(),
|
|
243
|
+
});
|
|
185
244
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const { ignore } = await Prompt.default.prompt(initQuestions());
|
|
196
|
-
const basePath = `${appName}/${catalogue}`
|
|
197
|
-
const exist = await fs.existsSync(basePath);
|
|
198
|
-
|
|
199
|
-
if (!exist) {
|
|
200
|
-
log.info(`当前目录${basePath}不存在,开始创建${basePath}文件夹`);
|
|
201
|
-
const hasTopDir = await fs.existsSync(appName);
|
|
202
|
-
if(!hasTopDir) {
|
|
203
|
-
await fs.mkdirSync(String(appName), undefined, {
|
|
204
|
-
cwd: process.cwd(),
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
await fs.mkdirSync(String(basePath), undefined, {
|
|
208
|
-
cwd: process.cwd(),
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
await handleIgnore(ignore, basePath);
|
|
213
|
-
const lists = await getList(origin, appId, branchid, token);
|
|
214
|
-
await getDaml(lists, origin, appId, branchid, token, basePath);
|
|
215
|
-
})
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
module.exports = main
|
|
245
|
+
|
|
246
|
+
await handleIgnore(ignore, basePath);
|
|
247
|
+
const lists = await getList(origin, appId, branchid, token);
|
|
248
|
+
log.info(`请求${appName}页面列表成功,条数为${lists.length}`);
|
|
249
|
+
await getDaml(lists, origin, appId, branchid, token, basePath);
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
module.exports = main;
|
package/lib/server/index.js
CHANGED
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
const { spawn } = require('node:child_process'); // 使用 node: 前缀明确使用核心模块
|
|
2
|
+
const Prompt = require("inquirer");
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
// 可以在https://www.toolhelper.cn/SSL/SSLGenerate生成
|
|
5
|
+
const sslQuestions = () => [
|
|
6
|
+
{
|
|
7
|
+
type: "input",
|
|
8
|
+
name: "cert",
|
|
9
|
+
default: "cert.pem",
|
|
10
|
+
message: `证书地址(完整的绝对路径)`,
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
type: "input",
|
|
14
|
+
name: "private",
|
|
15
|
+
default: "private.key",
|
|
16
|
+
message: `私钥地址(完整的绝对路径)`,
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
const server = async(filePath, argv) => {
|
|
4
21
|
const https = argv.https ?? false;
|
|
5
22
|
const port = argv.port ?? 3000;
|
|
6
23
|
|
|
7
24
|
try {
|
|
8
25
|
const args = [filePath, '-p', port.toString()];
|
|
9
26
|
if (https) {
|
|
10
|
-
|
|
27
|
+
const { cert, private } = await Prompt.default.prompt(sslQuestions());
|
|
28
|
+
args.push('-S', '-C', `${cert}`, '-K', `${private}`);
|
|
11
29
|
}
|
|
12
30
|
|
|
13
31
|
const child = spawn('npx', ['http-server', ...args], {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wagq/wa-cli",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "wa的脚手架",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -37,7 +37,6 @@
|
|
|
37
37
|
"ora": "^4.0.3",
|
|
38
38
|
"xlsx": "^0.18.5"
|
|
39
39
|
},
|
|
40
|
-
"devDependencies": {},
|
|
41
40
|
"directories": {
|
|
42
41
|
"lib": "lib"
|
|
43
42
|
}
|