@wagq/wa-cli 0.6.1 → 0.6.2

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/README.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # cli 工具
2
2
 
3
3
  使用方式 全局安装后 可使用 wa [命令]
4
+ - 更多描述可以使用help查看
5
+
6
+ ```
7
+ wa --help
8
+ ```
4
9
 
5
10
  - 初始化项目
6
11
  ```bash
@@ -26,3 +31,8 @@
26
31
  ```bash
27
32
  wa daml
28
33
  ```
34
+
35
+ - 同步远端应用所有页面的低代码配置
36
+ ```bash
37
+ wa damls
38
+ ```
package/config/command.js CHANGED
@@ -2,6 +2,7 @@ const init = require("../lib/init");
2
2
  const server = require("../lib/server");
3
3
  const xlsx2Config = require("../lib/locale/xlsx2Config");
4
4
  const asyncDaml = require('../lib/daml/async')
5
+ const asyncDamlByApp = require('../lib/daml/asyncByApp')
5
6
 
6
7
  const command = [
7
8
  {
@@ -12,6 +13,19 @@ const command = [
12
13
  asyncDaml();
13
14
  },
14
15
  },
16
+ {
17
+ name: "damls",
18
+ description: `从应用同步所有页面的逻辑器与变量值,
19
+ 可将appId,branchid,token配置到~/.damlrc文件中,
20
+ 格式为{"origin":string,"appId":string,"branchid":string,"token":string, "appName": string}[]
21
+ 其中origin为请求域名(/api/assembler/page/list(页面列表)接口域名),
22
+ appId,branchid,token为请求参数,
23
+ appName为应用名称,也是你区分不同应用的标识,所有生成的文件都会放在appName文件夹下`,
24
+ alias: "da",
25
+ action: () => {
26
+ asyncDamlByApp()
27
+ }
28
+ },
15
29
  {
16
30
  name: "init",
17
31
  alias: "i",
@@ -0,0 +1,219 @@
1
+ const fs = require("fs");
2
+ const Prompt = require("inquirer");
3
+ const log = require("../../utils/log");
4
+ const string2Data = require("../../utils/string2Data");
5
+
6
+ const catalogue = 'pages'
7
+
8
+ const initQuestions = () => [
9
+ {
10
+ type: 'list',
11
+ name: "ignore",
12
+ message: "git是否忽略当前目录",
13
+ choices: [true, false],
14
+ default: true
15
+ }
16
+ ]
17
+
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(String(catalogue), undefined, {
24
+ cwd: process.cwd(),
25
+ });
26
+ await fs.writeFileSync(`${process.cwd()}/.gitignore`, '')
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
+ }
34
+ }
35
+
36
+ return Promise.resolve();
37
+ }
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
+ };
76
+ });
77
+
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
+ });
122
+ });
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}) */
146
+
147
+ ${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 },
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(`${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
+ });
184
+ });
185
+ log.info(`同步${name}的变量值成功`);
186
+ }
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wagq/wa-cli",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "wa的脚手架",
5
5
  "main": "index.js",
6
6
  "scripts": {