@wagq/wa-cli 0.6.53 → 0.6.55

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.
@@ -0,0 +1,56 @@
1
+ const { spawn } = require("node:child_process"); // 使用 node: 前缀明确使用核心模块
2
+ const Prompt = require("inquirer");
3
+ const { resolve } = require("node:path");
4
+ const path = require("node:path");
5
+
6
+ // 可以在https://www.toolhelper.cn/SSL/SSLGenerate生成
7
+ const sslQuestions = () => [
8
+ {
9
+ type: "input",
10
+ name: "cert",
11
+ message: `证书地址(完整的绝对路径,不填使用cli自导带证书)`,
12
+ },
13
+ {
14
+ type: "input",
15
+ name: "private",
16
+ message: `私钥地址(完整的绝对路径,不填使用cli自导带证书)`,
17
+ },
18
+ ];
19
+
20
+ const server = async (filePath, argv) => {
21
+ const https = argv.https ?? false;
22
+ const port = argv.port ?? 3000;
23
+
24
+ const currentFilePath = __dirname;
25
+ const dirPath = resolve(currentFilePath, "../../");
26
+
27
+ try {
28
+ const args = [filePath, "-p", port.toString()];
29
+ if (https === "true") {
30
+ const { cert, private } = await Prompt.default.prompt(sslQuestions());
31
+ args.push(
32
+ "-S",
33
+ "-C",
34
+ `${cert || resolve(dirPath, "./config/ssl/cert.pem")}`,
35
+ "-K",
36
+ `${private || resolve(dirPath, "./config/ssl/key.pem")}`
37
+ );
38
+ }
39
+
40
+ const child = spawn(
41
+ `${dirPath}\\node_modules\\.bin\\http-server ${args.join(` `)}`,
42
+ null,
43
+ {
44
+ cwd: process.cwd(),
45
+ stdio: "inherit",
46
+ shell: true,
47
+ }
48
+ );
49
+
50
+ child.on("close", (code) => process.exit(code));
51
+ } catch (error) {
52
+ console.error("启动失败:", error.message);
53
+ }
54
+ };
55
+
56
+ module.exports = server;
@@ -0,0 +1,35 @@
1
+ const { spawn } = require("child_process");
2
+ const Prompt = require("inquirer");
3
+
4
+ const skill = async () => {
5
+ const initQuestions = () => [
6
+ {
7
+ type: "list",
8
+ name: "mode",
9
+ message: `请选择指令`,
10
+ choices: ["getList", "sync"],
11
+ },
12
+ ];
13
+
14
+ const commandConfig = {
15
+ getList: "npx openskills install anthropics/skills",
16
+ sync: "npx openskills sync"
17
+ }
18
+
19
+ const { mode } = await Prompt.default.prompt(initQuestions());
20
+
21
+ const command = commandConfig[mode];
22
+
23
+ if(command) {
24
+ spawn(
25
+ `${command}`,
26
+ {
27
+ cwd: process.cwd(),
28
+ stdio: "inherit",
29
+ shell: true,
30
+ },
31
+ );
32
+ }
33
+ };
34
+
35
+ module.exports = skill;
@@ -0,0 +1,50 @@
1
+ const { exec } = require("child_process");
2
+ const config = require("../../package.json");
3
+ const { compareVersions } = require("compare-versions");
4
+ const log = require("../../utils/log");
5
+ const ora = require("ora");
6
+
7
+ module.exports = (argv) => {
8
+ const cmd = `npm view ${config.name} version --json --registry=http://registry.npmjs.org`;
9
+ const shellUpdate = argv && argv._ && argv._[0] === "update";
10
+ return new Promise((resolve, reject) => {
11
+ exec(cmd, (error, info) => {
12
+ if (error) {
13
+ reject();
14
+ log.error(`${config.name} 信息获取失败, 请尝试在命令前加入sudo`);
15
+ }
16
+ info = info.trim();
17
+ const version = info.substring(1, info.length - 1);
18
+ // 1: 当前版本大于等于最新版本 0: 当前版本等于最新版本 -1: 当前版本小于最新版本
19
+ const compareResult = compareVersions(config.version, version);
20
+ if (compareResult == 1 || compareResult == 0) {
21
+ if (shellUpdate) {
22
+ // shell 执行的,给个信息提示,引入执行不需要
23
+ log.info(`${config.name}@${config.version} 已最新`);
24
+ }
25
+
26
+ resolve({
27
+ needUpdate: false,
28
+ });
29
+ } else {
30
+ log.warn(`${config.name} 需要更新`);
31
+ const spinner = ora(`${config.name} 更新中......`).start();
32
+ const run = `npm install -g ${config.name}@latest --registry=http://registry.npmjs.org`;
33
+ exec(run, (err) => {
34
+ if (err) {
35
+ reject();
36
+ log.error(err);
37
+ }
38
+ if (!shellUpdate) {
39
+ log.info(`${config.name}版本更新,当前版本: ${version}`);
40
+ } else {
41
+ spinner.succeed(`${config.name} 更新结束,当前版本: ${version}`);
42
+ }
43
+ resolve({
44
+ needUpdate: true,
45
+ });
46
+ });
47
+ }
48
+ });
49
+ });
50
+ };
@@ -0,0 +1,43 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const log = require("../../utils/log.js");
4
+
5
+ const settingsContent = {
6
+ "editor.codeActionsOnSave": {
7
+ "source.fixAll": "always",
8
+ "source.fixAll.eslint": "always",
9
+ },
10
+ "eslint.validate": ["typescript", "typescriptreact"],
11
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
12
+ "editor.formatOnSave": true,
13
+ "[typescriptreact]": {
14
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
15
+ },
16
+ "[typescript]": {
17
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
18
+ },
19
+ };
20
+
21
+ const initVsSetting = () => {
22
+ const targetDir = process.cwd()
23
+ try {
24
+ const vscodeDir = path.join(targetDir, ".vscode");
25
+ const settingsPath = path.join(vscodeDir, "settings.json");
26
+
27
+ if (!fs.existsSync(vscodeDir)) {
28
+ fs.mkdirSync(vscodeDir, { recursive: true });
29
+ log.info(".vscode 目录已创建");
30
+ }
31
+
32
+ fs.writeFileSync(
33
+ settingsPath,
34
+ JSON.stringify(settingsContent, null, 2),
35
+ "utf-8",
36
+ );
37
+ log.info(".vscode/settings.json 已写入");
38
+ } catch (error) {
39
+ log.error(error);
40
+ }
41
+ };
42
+
43
+ module.exports = initVsSetting;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wagq/wa-cli",
3
- "version": "0.6.53",
3
+ "version": "0.6.55",
4
4
  "description": "wa的脚手架",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/utils/cwd.js ADDED
@@ -0,0 +1,5 @@
1
+ const currentFilePath = __dirname;
2
+
3
+ const cliCwd = currentFilePath;
4
+
5
+ module.exports = { cliCwd };
package/utils/log.js ADDED
@@ -0,0 +1,32 @@
1
+ const chalk = require("chalk");
2
+
3
+ const log = {
4
+ info(msg) {
5
+ msg = `\n[Info]: ${msg}\n`;
6
+ process.stdout.write(chalk.green(msg));
7
+ },
8
+ warn(msg) {
9
+ msg = `\n[Warn]: ${msg}\n`;
10
+ process.stdout.write(chalk.yellow(msg));
11
+ },
12
+ loading(msg) {
13
+ msg = `\n[Loading]: ${msg}\n`;
14
+ process.stdout.write(chalk.white(msg));
15
+ },
16
+ error(err) {
17
+ if (!(err instanceof Error)) {
18
+ err.message && (err = err.message);
19
+ err = new Error(err.message || err.toString());
20
+ }
21
+ if (exports.alert) {
22
+ err.message += "\u0007";
23
+ }
24
+
25
+ const msg = `\n[Error]: ${err.message}\n`;
26
+ process.stdout.write(chalk.red(msg));
27
+
28
+ process.exit(1);
29
+ },
30
+ };
31
+
32
+ module.exports = log;
@@ -0,0 +1,20 @@
1
+ const fs = require("fs");
2
+
3
+ const getPackageInfo = () => {
4
+ const packageJson = require("./package.json");
5
+ return packageJson;
6
+ };
7
+
8
+ const getPackageTxt = () => {
9
+ return fs.readFileSync("./package.json", "utf-8");
10
+ };
11
+
12
+ const writePackageTxt = (content) => {
13
+ return fs.writeFileSync("./package.json", content, "utf-8");
14
+ };
15
+
16
+ module.exports = {
17
+ getPackageInfo,
18
+ getPackageTxt,
19
+ writePackageTxt,
20
+ };
@@ -0,0 +1,7 @@
1
+ module.exports = (str) => {
2
+ try {
3
+ return new Function('return ' + str)();
4
+ } catch (error) {
5
+ return str;
6
+ }
7
+ }