@wagq/wa-cli 0.5.12 → 0.6.0

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/async.js CHANGED
@@ -5,14 +5,15 @@ const string2Data = require("../../utils/string2Data");
5
5
 
6
6
  const typePath = {
7
7
  "逻辑编辑器": "actions.actionList",
8
- "变量编辑器": "dataSource.dataList"
8
+ "变量编辑器": "dataSource.dataList",
9
+ "变量与逻辑": "变量与逻辑"
9
10
  }
10
11
 
11
12
  const initQuestions = () => [
12
13
  {
13
14
  type: "input",
14
15
  name: "name",
15
- message: "请输入备注信息(会将所有逻辑编辑器文件保存在这个文件夹里)",
16
+ message: "请输入备注信息(会将所有逻辑编辑器文件保存在这个文件夹里,默认值是asyncData)",
16
17
  default: "asyncData"
17
18
  },
18
19
  {
@@ -53,18 +54,34 @@ const getFiles = async () => {
53
54
  return res.json();
54
55
  })
55
56
  .then((res) => {
56
- const daml = JSON.parse(res.data.daml);
57
- const pages = daml.app.subapps[0].actions.actionList;
58
- const variables = daml.app.subapps[0].dataSource.dataList;
59
- switch (type) {
60
- case "逻辑编辑器":
57
+ try{
58
+ const daml = JSON.parse(res.data.daml);
59
+ const pages = daml.app.subapps[0].actions.actionList || [];
60
+ const variables = daml.app.subapps[0].dataSource.dataList || [];
61
+
62
+ let asyncPage = false
63
+ let asyncVariable = false
64
+
65
+ switch (type) {
66
+ case "逻辑编辑器":
67
+ asyncPage = true
68
+ break;
69
+ case "变量编辑器":
70
+ asyncVariable = true
71
+ break;
72
+ case "变量与逻辑":
73
+ asyncPage = true
74
+ asyncVariable = true
75
+ break;
76
+ }
77
+ if(asyncPage) {
61
78
  pages.forEach(({ content, name: fileName }) => {
62
79
  fs.writeFileSync(`${name}/${fileName}.js`, content, {
63
80
  cwd: process.cwd(),
64
81
  });
65
82
  });
66
- break;
67
- case "变量编辑器":
83
+ }
84
+ if(asyncVariable) {
68
85
  variables.forEach(({ key, value: variableValue }) => {
69
86
  fs.writeFileSync(`${name}/${key}.json`, JSON.stringify(variableValue, (key, value) => {
70
87
  if (typeof value === "string") {
@@ -75,7 +92,10 @@ const getFiles = async () => {
75
92
  cwd: process.cwd(),
76
93
  });
77
94
  });
78
- break
95
+ }
96
+ }
97
+ catch(err) {
98
+ log.error("解析daml失败,请检查请求是否过期或无法访问")
79
99
  }
80
100
  });
81
101
  };
@@ -1,23 +1,24 @@
1
- const { spawn, exec, execSync } = require("child_process");
2
- const fs = require("fs");
3
- // minimist(process.argv.slice(2))
1
+ const { spawn } = require('node:child_process'); // 使用 node: 前缀明确使用核心模块
4
2
 
5
3
  const server = (filePath, argv) => {
6
4
  const https = argv.https ?? false;
7
5
  const port = argv.port ?? 3000;
8
6
 
9
7
  try {
10
- const child = spawn(
11
- "http-server",
12
- [filePath, "-p", port, https ? `-S -C cert.pem -K key.pem` : ""],
13
- {
14
- cwd: process.cwd(),
15
- stdio: "inherit",
16
- }
17
- );
18
- child.on("close", (code) => process.exit(code));
8
+ const args = [filePath, '-p', port.toString()];
9
+ if (https) {
10
+ args.push('-S', '-C', 'cert.pem', '-K', 'key.pem');
11
+ }
12
+
13
+ const child = spawn('npx', ['http-server', ...args], {
14
+ cwd: process.cwd(),
15
+ stdio: 'inherit',
16
+ shell: true
17
+ });
18
+
19
+ child.on('close', (code) => process.exit(code));
19
20
  } catch (error) {
20
- console.log(error);
21
+ console.error('启动失败:', error.message);
21
22
  }
22
23
  };
23
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wagq/wa-cli",
3
- "version": "0.5.12",
3
+ "version": "0.6.0",
4
4
  "description": "wa的脚手架",
5
5
  "main": "index.js",
6
6
  "scripts": {