@lazycatcloud/lzc-cli 1.3.12 → 1.3.13

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/changelog.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.3.13](https://gitee.com/linakesi/lzc-cli/compare/v1.3.12...v1.3.13) (2025-12-10)
4
+
5
+
6
+ ### Features
7
+
8
+ * add i18n ([f62c52a](https://gitee.com/linakesi/lzc-cli/commits/f62c52a9b443d2226ffa06d17593f1912b9dc4de))
9
+ * add i18n config ([185418d](https://gitee.com/linakesi/lzc-cli/commits/185418d5e77858d55fca485ff115191c0c95834e))
10
+ * some copywriters provide i18n calls ([54d92f1](https://gitee.com/linakesi/lzc-cli/commits/54d92f17520e6413d735c82d57d3aa3404410add))
11
+
3
12
  ## [1.3.12](https://gitee.com/linakesi/lzc-cli/compare/v1.3.11...v1.3.12) (2025-10-29)
4
13
 
5
14
 
@@ -1,48 +1,45 @@
1
- import fs from "node:fs"
2
- import logger from "loglevel"
3
- import axios from "axios"
1
+ import fs from 'node:fs';
2
+ import logger from 'loglevel';
3
+ import axios from 'axios';
4
+ import { t } from '../i18n/index.js';
4
5
 
5
6
  // 创建 Axios 实例
6
- const api = axios.create()
7
+ const api = axios.create();
7
8
 
8
9
  // 添加响应拦截器
9
10
  api.interceptors.response.use(
10
- (response) => response, // 直接返回响应
11
- (error) => {
12
- if (error.response && error.response.status === 304) {
13
- return Promise.resolve(error.response) // 返回响应以便后续处理
14
- }
15
- return Promise.reject(error) // 其他错误继续抛出
16
- }
17
- )
11
+ (response) => response, // 直接返回响应
12
+ (error) => {
13
+ if (error.response && error.response.status === 304) {
14
+ return Promise.resolve(error.response); // 返回响应以便后续处理
15
+ }
16
+ return Promise.reject(error); // 其他错误继续抛出
17
+ },
18
+ );
18
19
 
19
20
  export async function triggerApk(id, name, iconPath) {
20
- if (!id) {
21
- logger.error("Appid 为必填项!")
22
- return
23
- }
24
- name = name || "懒猫应用"
25
- try {
26
- const form = new FormData()
27
- form.append("app_id", id)
28
- form.append("app_name", name)
29
- if (iconPath) {
30
- form.append("app_icon", new Blob([fs.readFileSync(iconPath)]))
31
- }
32
- const resp = await api.post(
33
- "https://appstore.api.lazycat.cloud/api/trigger_latest_for_app",
34
- form,
35
- { timeout: 5000 }
36
- )
37
- if (resp.status == 304) {
38
- logger.debug(`APK构建任务已创建成功,如需使用安卓端,请耐心等待1分钟左右`)
39
- } else if (resp.status <= 201) {
40
- logger.info(`APK构建任务已创建成功,如需使用安卓端,请耐心等待1分钟左右`)
41
- } else if (resp.status >= 400) {
42
- logger.debug("请求按钮应用出错:", resp)
43
- throw `请求生成应用出错! 使用 --apk=n 停止生成APK`
44
- }
45
- } catch (error) {
46
- logger.debug(error)
47
- }
21
+ if (!id) {
22
+ logger.error(t('lzc_cli.lib.app.apkshell.trigger_apk_empty_appid', 'Appid 为必填项!'));
23
+ return;
24
+ }
25
+ name = name || t('lzc_cli.lib.app.apkshell.trigger_apk_default_app_name', '懒猫应用');
26
+ try {
27
+ const form = new FormData();
28
+ form.append('app_id', id);
29
+ form.append('app_name', name);
30
+ if (iconPath) {
31
+ form.append('app_icon', new Blob([fs.readFileSync(iconPath)]));
32
+ }
33
+ const resp = await api.post('https://appstore.api.lazycat.cloud/api/trigger_latest_for_app', form, { timeout: 5000 });
34
+ if (resp.status == 304) {
35
+ logger.debug(t('lzc_cli.lib.app.apkshell.trigger_apk_build_tips', `APK构建任务已创建成功,如需使用安卓端,请耐心等待1分钟左右`));
36
+ } else if (resp.status <= 201) {
37
+ logger.info(t('lzc_cli.lib.app.apkshell.trigger_apk_build_ok_tips', `APK构建任务已创建成功,如需使用安卓端,请耐心等待1分钟左右`));
38
+ } else if (resp.status >= 400) {
39
+ logger.debug(t('lzc_cli.lib.app.apkshell.trigger_apk_build_failed', '请求按钮应用出错:'), resp);
40
+ throw t('lzc_cli.lib.app.apkshell.trigger_apk_build_failed_tips', `请求生成应用出错! 使用 --apk=n 停止生成APK`);
41
+ }
42
+ } catch (error) {
43
+ logger.debug(error);
44
+ }
48
45
  }
package/lib/app/index.js CHANGED
@@ -1,199 +1,200 @@
1
- import path from "node:path"
2
- import lpkCreate from "./lpk_create.js"
3
- import { LpkBuild } from "./lpk_build.js"
4
- import { AppDevShell } from "./lpk_devshell.js"
5
- import { LpkInstaller, installConfig } from "./lpk_installer.js"
6
- import logger from "loglevel"
7
- import { sleep, checkRsync } from "../utils.js"
8
- import { DebugBridge } from "../debug_bridge.js"
9
- import shellApi from "../shellapi.js"
10
- import { generate } from "./lpk_create_generator.js"
1
+ import path from 'node:path';
2
+ import lpkCreate from './lpk_create.js';
3
+ import { LpkBuild } from './lpk_build.js';
4
+ import { AppDevShell } from './lpk_devshell.js';
5
+ import { LpkInstaller, installConfig } from './lpk_installer.js';
6
+ import logger from 'loglevel';
7
+ import { sleep, checkRsync } from '../utils.js';
8
+ import { DebugBridge } from '../debug_bridge.js';
9
+ import shellApi from '../shellapi.js';
10
+ import { generate } from './lpk_create_generator.js';
11
+ import { t } from '../i18n/index.js';
11
12
 
12
13
  export function lpkProjectCommand(program) {
13
- let subCommands = [
14
- {
15
- command: "init",
16
- desc: "初始化懒猫云应用(提供最基础的模板)",
17
- handler: async () => {
18
- generate("blank", "./")
19
- logger.info("应用初始化完成")
20
- }
21
- },
22
- {
23
- command: "create <name>",
24
- desc: "创建懒猫云应用",
25
- handler: async ({ name }) => {
26
- name = String(name)
27
- await lpkCreate(name)
28
- }
29
- },
30
- {
31
- command: "build [context]",
32
- desc: "构建",
33
- builder: (args) => {
34
- args.option("o", {
35
- alias: "output",
36
- describe: "输出文件",
37
- type: "string"
38
- })
39
- args.option("f", {
40
- alias: "file",
41
- describe: "指定构建的lzc-build.yml文件",
42
- default: "lzc-build.yml",
43
- type: "string"
44
- })
45
- },
46
- handler: async ({ context, output, file }) => {
47
- const lpk = await new LpkBuild(context, file).init()
48
- // 正常的打包逻辑不需要 devshell
49
- lpk.onBeforeBuildPackage(async (options) => {
50
- delete options["devshell"]
14
+ let subCommands = [
15
+ {
16
+ command: 'init',
17
+ desc: t('lzc_cli.lib.app.index.lpk_cmd_init_desc', '初始化懒猫云应用(提供最基础的模板)'),
18
+ handler: async () => {
19
+ generate('blank', './');
20
+ logger.info(t('lzc_cli.lib.app.index.lpk_cmd_init_success', '应用初始化完成'));
21
+ },
22
+ },
23
+ {
24
+ command: 'create <name>',
25
+ desc: t('lzc_cli.lib.app.index.lpk_cmd_create_desc', '创建懒猫云应用'),
26
+ handler: async ({ name }) => {
27
+ name = String(name);
28
+ await lpkCreate(name);
29
+ },
30
+ },
31
+ {
32
+ command: 'build [context]',
33
+ desc: t('lzc_cli.lib.app.index.lpk_cmd_build_desc', '构建'),
34
+ builder: (args) => {
35
+ args.option('o', {
36
+ alias: 'output',
37
+ describe: t('lzc_cli.lib.app.index.lpk_cmd_build_args_output_desc', '输出文件'),
38
+ type: 'string',
39
+ });
40
+ args.option('f', {
41
+ alias: 'file',
42
+ describe: t('lzc_cli.lib.app.index.lpk_cmd_build_args_file_desc', '指定构建的lzc-build.yml文件'),
43
+ default: 'lzc-build.yml',
44
+ type: 'string',
45
+ });
46
+ },
47
+ handler: async ({ context, output, file }) => {
48
+ const lpk = await new LpkBuild(context, file).init();
49
+ // 正常的打包逻辑不需要 devshell
50
+ lpk.onBeforeBuildPackage(async (options) => {
51
+ delete options['devshell'];
51
52
 
52
- if (output) {
53
- options["lpkPath"] = output
54
- }
55
- return options
56
- })
57
- await lpk.exec()
58
- }
59
- },
60
- {
61
- command: "devshell [context]",
62
- desc: "进入盒子的开发环境",
63
- builder: (args) => {
64
- args.option("f", {
65
- alias: "force",
66
- describe: "强制重新构建",
67
- type: "boolean"
68
- })
69
- args.option("c", {
70
- alias: "config",
71
- describe: "devshell配置文件",
72
- type: "string",
73
- default: "lzc-build.yml"
74
- })
75
- args.option("contentdir", {
76
- describe: "同时打包 lzc-build.yml 中指定的 contentdir 目录",
77
- type: "boolean"
78
- })
79
- args.option("apk", {
80
- describe: "是否生成APK(y/n)",
81
- type: "string",
82
- default: "y"
83
- })
84
- },
85
- handler: async ({ context, force, config, contentdir, apk }) => {
86
- await shellApi.init()
87
- // 检测 rsync 满足
88
- await checkRsync()
53
+ if (output) {
54
+ options['lpkPath'] = output;
55
+ }
56
+ return options;
57
+ });
58
+ await lpk.exec();
59
+ },
60
+ },
61
+ {
62
+ command: 'devshell [context]',
63
+ desc: t('lzc_cli.lib.app.index.lpk_cmd_devshell_desc', '进入盒子的开发环境'),
64
+ builder: (args) => {
65
+ args.option('f', {
66
+ alias: 'force',
67
+ describe: t('lzc_cli.lib.app.index.lpk_cmd_devshell_args_force_desc', '强制重新构建'),
68
+ type: 'boolean',
69
+ });
70
+ args.option('c', {
71
+ alias: 'config',
72
+ describe: t('lzc_cli.lib.app.index.lpk_cmd_devshell_args_config_desc', 'devshell配置文件'),
73
+ type: 'string',
74
+ default: 'lzc-build.yml',
75
+ });
76
+ args.option('contentdir', {
77
+ describe: t('lzc_cli.lib.app.index.lpk_cmd_devshell_args_contentdir_desc', '同时打包 lzc-build.yml 中指定的 contentdir 目录'),
78
+ type: 'boolean',
79
+ });
80
+ args.option('apk', {
81
+ describe: t('lzc_cli.lib.app.index.lpk_cmd_devshell_args_apk_desc', '是否生成APK(y/n)'),
82
+ type: 'string',
83
+ default: 'y',
84
+ });
85
+ },
86
+ handler: async ({ context, force, config, contentdir, apk }) => {
87
+ await shellApi.init();
88
+ // 检测 rsync 满足
89
+ await checkRsync();
89
90
 
90
- installConfig.apk = apk == "y"
91
- const cwd = context ? path.resolve(context) : process.cwd()
92
- const lpkBuild = await new LpkBuild(cwd, config).init()
93
- lpkBuild.onBeforeBuildPackage(async (options) => {
94
- // devshell 正常情况下,不需要执行 buildscript 和 contentdir 字段
95
- logger.debug("devshell delete 'buildscript' field")
96
- delete options["buildscript"]
91
+ installConfig.apk = apk == 'y';
92
+ const cwd = context ? path.resolve(context) : process.cwd();
93
+ const lpkBuild = await new LpkBuild(cwd, config).init();
94
+ lpkBuild.onBeforeBuildPackage(async (options) => {
95
+ // devshell 正常情况下,不需要执行 buildscript 和 contentdir 字段
96
+ logger.debug("devshell delete 'buildscript' field");
97
+ delete options['buildscript'];
97
98
 
98
- if (!contentdir) {
99
- logger.debug("devshell delete 'contentdir' field")
100
- delete options["contentdir"]
101
- }
102
- return options
103
- })
104
- const app = new AppDevShell(cwd, lpkBuild, force, config)
105
- await app.init()
106
- await app.build()
107
- await sleep(2000)
108
- await app.rsyncShell()
109
- }
110
- }
111
- ]
112
- program.command({
113
- command: "project",
114
- desc: "项目管理",
115
- builder: (args) => {
116
- args.command(subCommands)
117
- }
118
- })
99
+ if (!contentdir) {
100
+ logger.debug("devshell delete 'contentdir' field");
101
+ delete options['contentdir'];
102
+ }
103
+ return options;
104
+ });
105
+ const app = new AppDevShell(cwd, lpkBuild, force, config);
106
+ await app.init();
107
+ await app.build();
108
+ await sleep(2000);
109
+ await app.rsyncShell();
110
+ },
111
+ },
112
+ ];
113
+ program.command({
114
+ command: 'project',
115
+ desc: t('lzc_cli.lib.app.index.lpk_cmd_project_desc', '项目管理'),
116
+ builder: (args) => {
117
+ args.command(subCommands);
118
+ },
119
+ });
119
120
  }
120
121
 
121
122
  export function lpkAppCommand(program) {
122
- let subCommands = [
123
- {
124
- command: "install [pkgPath]",
125
- desc: "部署应用至设备, pkgPath 可以为路径,或者https://,http://请求地址, 如果不填写,将默认为当前目录下的lpk",
126
- builder: (args) => {
127
- args.option("apk", {
128
- describe: "是否生成APK(y/n)",
129
- type: "string",
130
- default: "y"
131
- })
132
- },
133
- handler: async ({ pkgPath, apk }) => {
134
- await shellApi.init()
135
- installConfig.apk = apk == "y"
123
+ let subCommands = [
124
+ {
125
+ command: 'install [pkgPath]',
126
+ desc: t('lzc_cli.lib.app.index.lpk_cmd_install_desc', '部署应用至设备, pkgPath 可以为路径,或者https://,http://请求地址, 如果不填写,将默认为当前目录下的lpk'),
127
+ builder: (args) => {
128
+ args.option('apk', {
129
+ describe: t('lzc_cli.lib.app.index.lpk_cmd_index_rags_apk_desc', '是否生成APK(y/n)'),
130
+ type: 'string',
131
+ default: 'y',
132
+ });
133
+ },
134
+ handler: async ({ pkgPath, apk }) => {
135
+ await shellApi.init();
136
+ installConfig.apk = apk == 'y';
136
137
 
137
- pkgPath = pkgPath ?? process.cwd()
138
- const installer = new LpkInstaller()
139
- await installer.init()
140
- await installer.install(pkgPath)
141
- }
142
- },
143
- {
144
- command: "uninstall <pkgId>",
145
- desc: "从设备中卸载某一个应用",
146
- builder: (args) => {
147
- args.option("delete-data", {
148
- describe: "删除应用数据 ⚠️ 警告: 应用数据删除后无法恢复",
149
- type: "boolean",
150
- default: false
151
- })
152
- },
153
- handler: async ({ pkgId, deleteData }) => {
154
- await shellApi.init()
138
+ pkgPath = pkgPath ?? process.cwd();
139
+ const installer = new LpkInstaller();
140
+ await installer.init();
141
+ await installer.install(pkgPath);
142
+ },
143
+ },
144
+ {
145
+ command: 'uninstall <pkgId>',
146
+ desc: t('lzc_cli.lib.app.index.lpk_cmd_uninstall_desc', '从设备中卸载某一个应用'),
147
+ builder: (args) => {
148
+ args.option('delete-data', {
149
+ describe: t('lzc_cli.lib.app.index.lpk_cmd_uninstall_rags_delete_data_desc', '删除应用数据 ⚠️ 警告: 应用数据删除后无法恢复'),
150
+ type: 'boolean',
151
+ default: false,
152
+ });
153
+ },
154
+ handler: async ({ pkgId, deleteData }) => {
155
+ await shellApi.init();
155
156
 
156
- const bridge = new DebugBridge()
157
- await bridge.init()
158
- await bridge.uninstall(pkgId, deleteData)
159
- console.log(`默认微服设备: ${bridge.boxname} ,卸载应用 ${pkgId} 完成`)
160
- }
161
- },
162
- {
163
- command: "status <pkgId>",
164
- desc: "获取某一个应用的状态",
165
- handler: async ({ pkgId }) => {
166
- await shellApi.init()
157
+ const bridge = new DebugBridge();
158
+ await bridge.init();
159
+ await bridge.uninstall(pkgId, deleteData);
160
+ logger.debug(`default lcmd device: ${bridge.boxname} , uninstall the app ${pkgId} finish`);
161
+ },
162
+ },
163
+ {
164
+ command: 'status <pkgId>',
165
+ desc: t('lzc_cli.lib.app.index.lpk_cmd_status_desc', '获取某一个应用的状态'),
166
+ handler: async ({ pkgId }) => {
167
+ await shellApi.init();
167
168
 
168
- const bridge = new DebugBridge()
169
- await bridge.init()
170
- const status = await bridge.status(pkgId)
171
- console.log(status)
172
- }
173
- },
174
- {
175
- command: "log <pkgId>",
176
- desc: "查看某一个app的日志",
177
- builder: (args) => {
178
- args.option("f", {
179
- alias: "follow",
180
- describe: "持续输出",
181
- type: "boolean",
182
- default: false
183
- })
184
- },
185
- handler: async () => {
186
- await shellApi.init()
169
+ const bridge = new DebugBridge();
170
+ await bridge.init();
171
+ const status = await bridge.status(pkgId);
172
+ console.log(status);
173
+ },
174
+ },
175
+ {
176
+ command: 'log <pkgId>',
177
+ desc: t('lzc_cli.lib.app.index.lpk_cmd_log_desc', '查看某一个app的日志'),
178
+ builder: (args) => {
179
+ args.option('f', {
180
+ alias: 'follow',
181
+ describe: t('lzc_cli.lib.app.index.lpk_cmd_log_args_follow_desc', '持续输出'),
182
+ type: 'boolean',
183
+ default: false,
184
+ });
185
+ },
186
+ handler: async () => {
187
+ await shellApi.init();
187
188
 
188
- throw "还没有实现"
189
- }
190
- }
191
- ]
192
- program.command({
193
- command: "app",
194
- desc: "应用管理",
195
- builder: async (args) => {
196
- args.command(subCommands)
197
- }
198
- })
189
+ throw 'not yet realized';
190
+ },
191
+ },
192
+ ];
193
+ program.command({
194
+ command: 'app',
195
+ desc: t('lzc_cli.lib.app.index.lpk_cmd_app_desc', '应用管理'),
196
+ builder: async (args) => {
197
+ args.command(subCommands);
198
+ },
199
+ });
199
200
  }