@wagq/wa-cli 0.6.3 → 0.6.5

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.
Files changed (2) hide show
  1. package/lib/daml/asyncByApp.js +233 -199
  2. package/package.json +1 -2
@@ -3,217 +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 = 'pages'
6
+ const catalogue = "pages";
7
7
 
8
8
  const initQuestions = () => [
9
- {
10
- type: 'list',
11
- name: "ignore",
12
- message: "git是否忽略当前目录",
13
- choices: [true, false],
14
- default: true
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
- try {
20
- if(ignore){
21
- const ignoreExist = await fs.existsSync(`${process.cwd()}/.gitignore`);
22
- if(!ignoreExist){
23
- await fs.mkdirSync(`${process.cwd()}/.gitignore`, undefined, {
24
- cwd: process.cwd(),
25
- });
26
- await fs.writeFileSync(`${process.cwd()}/.gitignore`, `${catalogue}`)
27
- }
28
- else {
29
- const hasCatalogue = await fs.readFileSync(`${process.cwd()}/.gitignore`).toString().includes(catalogue);
30
- if(!hasCatalogue) {
31
- await fs.appendFileSync(`${process.cwd()}/.gitignore`, `\n${catalogue}`)
32
- }
33
- }
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
+ );
34
36
  }
35
-
36
- return Promise.resolve();
37
+ }
37
38
  }
38
- finally {
39
- return Promise.resolve();
40
- }
41
- }
42
-
43
- const getList = async(origin, appId, branchid, token) => {
44
- try {
45
- const request = () => fetch(`${origin}/api/assembler/page/list`, {
46
- headers: {
47
- accept: "application/json, text/plain, */*",
48
- "accept-language":
49
- "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",
50
- "access-token": token,
51
- appid: appId,
52
- branchid: branchid,
53
- "cache-control": "no-cache",
54
- "content-type": "application/json",
55
- pragma: "no-cache",
56
- "sec-ch-ua":
57
- '"Chromium";v="134", "Not:A-Brand";v="24", "Google Chrome";v="134"',
58
- "sec-ch-ua-mobile": "?0",
59
- "sec-ch-ua-platform": '"Windows"',
60
- "sec-fetch-dest": "empty",
61
- "sec-fetch-mode": "cors",
62
- "sec-fetch-site": "same-origin",
63
- },
64
- body: `{"current":1,"size":1000,"name":"","path":"","type":"","appId":${appId}}`,
65
- method: "POST",
66
- });
67
- log.loading('请求页面列表,条数为1000,这个数量应该是够了的')
68
- const res = await request().then(res => res.json());
69
- log.info(`请求页面列表成功,条数为${res.data.total}`)
70
-
71
- const lists = res.data.records.map((i) => {
72
- return {
73
- id: i.id,
74
- name: `${i.name}(${i.path.replace(/\//g, '_')})`,
75
- };
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",
76
115
  });
77
116
 
78
- return lists || []
79
- }
80
- catch(err) {
81
- log.error(`请求页面列表失败,请检查参数是否正确, origin:${origin}, appId: ${appId}, branchid: ${branchid}, token: ${token}`)
82
- }
83
- }
84
-
85
- const getDaml = async(lists, origin, appId, branchid, token, dirName) => {
86
- try {
87
- lists.forEach(async ({ name, id }) => {
88
- const request = () =>
89
- fetch(`${origin}/api/assembler/page/getPageDaml`, {
90
- headers: {
91
- accept: "application/json, text/plain, */*",
92
- "accept-language":
93
- "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",
94
- "access-token": token,
95
- appid: appId,
96
- branchid: branchid,
97
- "cache-control": "no-cache",
98
- "content-type": "application/json",
99
- pragma: "no-cache",
100
- "sec-ch-ua":
101
- '"Chromium";v="134", "Not:A-Brand";v="24", "Google Chrome";v="134"',
102
- "sec-ch-ua-mobile": "?0",
103
- "sec-ch-ua-platform": '"Windows"',
104
- "sec-fetch-dest": "empty",
105
- "sec-fetch-mode": "cors",
106
- "sec-fetch-site": "same-origin",
107
- cookie: "_tea_utm_cache_1229=undefined",
108
- "Referrer-Policy": "strict-origin-when-cross-origin",
109
- },
110
- body: `{\"pageId\":\"${id}\",\"appId\":\"${appId}\"}`,
111
- method: "POST",
112
- });
113
-
114
- log.loading(`正在同步${name}的逻辑器与变量值`)
115
- request()
116
- .then((res) => res.json())
117
- .then(async(res) => {
118
- const daml = JSON.parse(res.data.daml);
119
- await generateLogic(dirName, daml, name);
120
- await generateVariable(dirName, daml, name);
121
- });
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);
122
124
  });
123
- }
124
- catch(err) {
125
- log.error(err)
126
- }
127
- }
128
-
129
- const generateLogic = async(dirName, daml, name) => {
130
- try {
131
- log.loading(`正在同步${name}的逻辑器`)
132
- const logicDir = `${dirName}/${name}/logic`
133
- // 创建逻辑器文件夹
134
- await fs.mkdirSync(
135
- `${logicDir}`,
136
- { recursive: true },
137
- {
138
- cwd: process.cwd(),
139
- }
140
- );
141
- const pages = daml.app.subapps[0]?.actions?.actionList || [];
142
- pages.forEach(({ content, name: fileName }) => {
143
-
144
- // 添加标识
145
- 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}) */
146
147
 
147
148
  ${content}`;
148
-
149
- fs.writeFileSync(`${logicDir}/${fileName}.js`, content, {
150
- cwd: process.cwd(),
151
- });
152
- });
153
- log.info(`同步${name}的逻辑器成功`);
154
- }
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 },
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
+ [
168
210
  {
169
- cwd: process.cwd(),
211
+ "appName": "应用名称",
212
+ "origin": "低代码域名",
213
+ "appId": "应用id",
214
+ "branchid": "应用分支id",
215
+ "token": "你的token"
170
216
  }
171
- );
172
-
173
- const variables = daml.app.subapps[0].dataSource.dataList || [];
174
-
175
- variables.forEach(({ key, value: variableValue }) => {
176
- fs.writeFileSync(`${variableDir}/${key}.json`, JSON.stringify(variableValue, (key, value) => {
177
- if (typeof value === "string") {
178
- return string2Data(value);
179
- }
180
- return value;
181
- }, 2) , {
182
- cwd: process.cwd(),
183
- });
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(),
184
239
  });
185
- log.info(`同步${name}的变量值成功`);
240
+ }
241
+ await fs.mkdirSync(String(basePath), undefined, {
242
+ cwd: process.cwd(),
243
+ });
186
244
  }
187
- catch(err) {
188
- log.loading(`同步${name}的变量失败:${err}`)
189
- }
190
- }
191
-
192
- const main = async() => {
193
- const settings = require(`${process.cwd()}/.damlrc`) || [];
194
- const { origin, token, appId, branchid } = settings;
195
- settings.forEach(async({appName, origin, token, appId, branchid}) => {
196
- const { ignore } = await Prompt.default.prompt(initQuestions());
197
- const basePath = `${appName}/${catalogue}`
198
- const exist = await fs.existsSync(basePath);
199
-
200
- if (!exist) {
201
- log.info(`当前目录${basePath}不存在,开始创建${basePath}文件夹`);
202
- const hasTopDir = await fs.existsSync(appName);
203
- if(!hasTopDir) {
204
- await fs.mkdirSync(String(appName), undefined, {
205
- cwd: process.cwd(),
206
- });
207
- }
208
- await fs.mkdirSync(String(basePath), undefined, {
209
- cwd: process.cwd(),
210
- });
211
- }
212
-
213
- await handleIgnore(ignore, basePath);
214
- const lists = await getList(origin, appId, branchid, token);
215
- await getDaml(lists, origin, appId, branchid, token, basePath);
216
- })
217
- }
218
-
219
- 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wagq/wa-cli",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
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
  }