@wagq/wa-cli 0.6.21 → 0.6.23
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 +69 -19
- package/package.json +2 -1
- package/utils/cwd.js +5 -0
package/lib/daml/asyncByApp.js
CHANGED
|
@@ -2,6 +2,7 @@ const fs = require("fs");
|
|
|
2
2
|
const Prompt = require("inquirer");
|
|
3
3
|
const log = require("../../utils/log");
|
|
4
4
|
const string2Data = require("../../utils/string2Data");
|
|
5
|
+
const prettier = require("../../node_modules/prettier");
|
|
5
6
|
|
|
6
7
|
const catalogue = "pages";
|
|
7
8
|
|
|
@@ -13,6 +14,13 @@ const initQuestions = () => [
|
|
|
13
14
|
choices: [true, false],
|
|
14
15
|
default: true,
|
|
15
16
|
},
|
|
17
|
+
{
|
|
18
|
+
type: "list",
|
|
19
|
+
name: "prettier",
|
|
20
|
+
message: "是否使用prettier格式化代码",
|
|
21
|
+
choices: [true, false],
|
|
22
|
+
default: true,
|
|
23
|
+
},
|
|
16
24
|
];
|
|
17
25
|
|
|
18
26
|
const handleIgnore = async (ignore, catalogue) => {
|
|
@@ -85,7 +93,15 @@ const getList = async (origin, appId, branchid, token) => {
|
|
|
85
93
|
}
|
|
86
94
|
};
|
|
87
95
|
|
|
88
|
-
const getDaml = async (
|
|
96
|
+
const getDaml = async ({
|
|
97
|
+
lists,
|
|
98
|
+
origin,
|
|
99
|
+
appId,
|
|
100
|
+
branchid,
|
|
101
|
+
token,
|
|
102
|
+
basePath,
|
|
103
|
+
prettier,
|
|
104
|
+
}) => {
|
|
89
105
|
try {
|
|
90
106
|
lists.forEach(async ({ name, id }) => {
|
|
91
107
|
const request = () =>
|
|
@@ -119,8 +135,8 @@ const getDaml = async (lists, origin, appId, branchid, token, dirName) => {
|
|
|
119
135
|
.then((res) => res.json())
|
|
120
136
|
.then(async (res) => {
|
|
121
137
|
const daml = JSON.parse(res.data.daml);
|
|
122
|
-
await generateLogic(
|
|
123
|
-
await generateVariable(
|
|
138
|
+
await generateLogic(basePath, daml, name, prettier);
|
|
139
|
+
await generateVariable(basePath, daml, name);
|
|
124
140
|
});
|
|
125
141
|
});
|
|
126
142
|
} catch (err) {
|
|
@@ -128,7 +144,37 @@ const getDaml = async (lists, origin, appId, branchid, token, dirName) => {
|
|
|
128
144
|
}
|
|
129
145
|
};
|
|
130
146
|
|
|
131
|
-
const
|
|
147
|
+
const addJsDoc = (content, name, fileName) => {
|
|
148
|
+
const hasFileJsDoc = content.includes("@file");
|
|
149
|
+
// 添加标识
|
|
150
|
+
return hasFileJsDoc
|
|
151
|
+
? content
|
|
152
|
+
: `/** @file ${name}(逻辑名称:${fileName}) */
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @type {import("../../../../sass").CustomAction}
|
|
157
|
+
*/
|
|
158
|
+
${content}`;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const formatContent = async (content, filepath) => {
|
|
162
|
+
try {
|
|
163
|
+
const config = await prettier.resolveConfig("path/to/file", {
|
|
164
|
+
useCache: false,
|
|
165
|
+
});
|
|
166
|
+
content = await prettier.format(content, {
|
|
167
|
+
...config,
|
|
168
|
+
semi: false,
|
|
169
|
+
filepath,
|
|
170
|
+
});
|
|
171
|
+
return content;
|
|
172
|
+
} catch (err) {
|
|
173
|
+
return content;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const generateLogic = async (dirName, daml, name, prettier) => {
|
|
132
178
|
try {
|
|
133
179
|
log.loading(`正在同步${name}的逻辑器`);
|
|
134
180
|
const logicDir = `${dirName}/${name}/logic`;
|
|
@@ -141,20 +187,16 @@ const generateLogic = async (dirName, daml, name) => {
|
|
|
141
187
|
}
|
|
142
188
|
);
|
|
143
189
|
const pages = daml.app.subapps[0]?.actions?.actionList || [];
|
|
144
|
-
pages.forEach(({ content, name: fileName }) => {
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* @type {import("../../../../sass").CustomAction}
|
|
154
|
-
*/
|
|
155
|
-
${content}`;
|
|
190
|
+
pages.forEach(async ({ content, name: fileName }) => {
|
|
191
|
+
const filePath = `${logicDir}/${fileName}.js`;
|
|
192
|
+
if (prettier) {
|
|
193
|
+
// 添加标识
|
|
194
|
+
content = addJsDoc(content, name, fileName);
|
|
195
|
+
// 格式化
|
|
196
|
+
content = await formatContent(content, filePath);
|
|
197
|
+
}
|
|
156
198
|
|
|
157
|
-
fs.writeFileSync(
|
|
199
|
+
fs.writeFileSync(filePath, content, {
|
|
158
200
|
cwd: process.cwd(),
|
|
159
201
|
});
|
|
160
202
|
});
|
|
@@ -232,7 +274,7 @@ const checkDamlrc = async () => {
|
|
|
232
274
|
const main = async () => {
|
|
233
275
|
await checkDamlrc();
|
|
234
276
|
const settings = require(`${process.cwd()}/.damlrc.json`) || [];
|
|
235
|
-
const { ignore } = await Prompt.default.prompt(initQuestions());
|
|
277
|
+
const { ignore, prettier } = await Prompt.default.prompt(initQuestions());
|
|
236
278
|
settings.forEach(async ({ appName, origin, token, appId, branchid }) => {
|
|
237
279
|
const basePath = `${appName}/${catalogue}`;
|
|
238
280
|
const exist = await fs.existsSync(basePath);
|
|
@@ -253,7 +295,15 @@ const main = async () => {
|
|
|
253
295
|
await handleIgnore(ignore, basePath);
|
|
254
296
|
const lists = await getList(origin, appId, branchid, token);
|
|
255
297
|
log.info(`请求${appName}页面列表成功,条数为${lists.length}`);
|
|
256
|
-
await getDaml(
|
|
298
|
+
await getDaml({
|
|
299
|
+
lists,
|
|
300
|
+
origin,
|
|
301
|
+
appId,
|
|
302
|
+
branchid,
|
|
303
|
+
token,
|
|
304
|
+
basePath,
|
|
305
|
+
prettier,
|
|
306
|
+
});
|
|
257
307
|
});
|
|
258
308
|
};
|
|
259
309
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wagq/wa-cli",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.23",
|
|
4
4
|
"description": "wa的脚手架",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"inquirer": "^12.4.1",
|
|
36
36
|
"minimist": "^1.2.8",
|
|
37
37
|
"ora": "^4.0.3",
|
|
38
|
+
"prettier": "^3.5.3",
|
|
38
39
|
"xlsx": "^0.18.5"
|
|
39
40
|
},
|
|
40
41
|
"directories": {
|