@lazycatcloud/lzc-cli 1.3.12 → 1.3.14

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,252 @@
1
+ {
2
+ "lzc_cli": {
3
+ "lib": {
4
+ "app": {
5
+ "apkshell": {
6
+ "trigger_apk_build_failed": "请求按钮应用出错:",
7
+ "trigger_apk_build_failed_tips": "请求生成应用出错! 使用 --apk=n 停止生成APK",
8
+ "trigger_apk_build_ok_tips": "APK构建任务已创建成功,如需使用安卓端,请耐心等待1分钟左右",
9
+ "trigger_apk_build_tips": "APK构建任务已创建成功,如需使用安卓端,请耐心等待1分钟左右",
10
+ "trigger_apk_default_app_name": "懒猫应用",
11
+ "trigger_apk_empty_appid": "Appid 为必填项!"
12
+ },
13
+ "index": {
14
+ "lpk_cmd_app_desc": "应用管理",
15
+ "lpk_cmd_build_args_file_desc": "指定构建的lzc-build.yml文件",
16
+ "lpk_cmd_build_args_output_desc": "输出文件",
17
+ "lpk_cmd_build_desc": "构建",
18
+ "lpk_cmd_create_desc": "创建懒猫云应用",
19
+ "lpk_cmd_devshell_args_apk_desc": "是否生成APK(y/n)",
20
+ "lpk_cmd_devshell_args_config_desc": "devshell配置文件",
21
+ "lpk_cmd_devshell_args_contentdir_desc": "同时打包 lzc-build.yml 中指定的 contentdir 目录",
22
+ "lpk_cmd_devshell_args_force_desc": "强制重新构建",
23
+ "lpk_cmd_devshell_desc": "进入盒子的开发环境",
24
+ "lpk_cmd_index_rags_apk_desc": "是否生成APK(y/n)",
25
+ "lpk_cmd_init_desc": "初始化懒猫云应用(提供最基础的模板)",
26
+ "lpk_cmd_init_success": "应用初始化完成",
27
+ "lpk_cmd_install_desc": "部署应用至设备, pkgPath 可以为路径,或者https://,http://请求地址, 如果不填写,将默认为当前目录下的lpk",
28
+ "lpk_cmd_log_args_follow_desc": "持续输出",
29
+ "lpk_cmd_log_desc": "查看某一个app的日志",
30
+ "lpk_cmd_project_desc": "项目管理",
31
+ "lpk_cmd_status_desc": "获取某一个应用的状态",
32
+ "lpk_cmd_uninstall_desc": "从设备中卸载某一个应用",
33
+ "lpk_cmd_uninstall_rags_delete_data_desc": "删除应用数据 ⚠️ 警告: 应用数据删除后无法恢复"
34
+ },
35
+ "lpk_build": {
36
+ "archive_folder_to_exist_fail": "{{appDir}} 文件夹不存在",
37
+ "exec_ai_pos_service_not_exist": "{{ aiPodService }} 不存在",
38
+ "exec_browser_extension_not_exist": "{{ browserExtension }} 不存在",
39
+ "exec_build_fail": "构建失败",
40
+ "exec_output_lpk_path": "输出lpk包 {{ path }}",
41
+ "exec_pkgout_not_exist": "{{ pkgout }} 不存在",
42
+ "exec_skip_buildscript": "跳过执行 buildscript",
43
+ "exec_skip_copy_contentdir": "跳过拷贝 contentdir 内容",
44
+ "fetch_icon_to_icon_empty_fail": "图标icon 没有指定",
45
+ "fetch_icon_to_icon_extname_fail": "图标icon 不是一个 .png 文件",
46
+ "fetch_icon_to_icon_file_not_exist_fail": "图标icon {{ iconPath }} 不存在",
47
+ "fetch_icon_to_icon_is_png": "图标icon {{ iconPath }} 验证成功(png格式)",
48
+ "fetch_icon_to_icon_not_is_png_fail": "图标icon {{ iconPath }} 验证失败(不是一个png格式)",
49
+ "fetch_lzc_deploy_param_to_exist": "检测当前目录下具有 lzc-deploy-params.yml",
50
+ "fetch_lzc_deploy_param_to_not_exist": "deploy_params {{ deployParamsPath }} 不存在",
51
+ "get_manifest_package_name_fail": "{{ package }} 含有非法字符,请使用正确的包名格式(java的包名格式),如:cloud.lazycat.apps.video",
52
+ "get_manifest_subdomain_empty": "application 模块下的 subdomain 字段不能为空",
53
+ "local_ip_is_windows_fail": "当前 Windows 不支持使用 LocalIP 反代"
54
+ },
55
+ "lpk_create": {
56
+ "ask_lpk_info_message": "请输入应用ID,例如 app-demo1",
57
+ "ask_lpk_info_validate_fail": "允许小写字母或数字或-的组合,但不以数字开头,且不能以 - 开头或结束,也不能有连续的短横线 --",
58
+ "choose_template_message": "选择项目构建模板",
59
+ "exec_init_project_name_exist_tips": "! 检测到相同目录,已自动将旧目录重命名为 {{ renamedFileName }}",
60
+ "exec_init_project_success_tips": "✨ 初始化懒猫云应用",
61
+ "exec_init_project_tips": "✨ 初始化项目 {{ name }}"
62
+ },
63
+ "lpk_create_generator": {
64
+ "app_create_success_tip": "\n✨ 懒猫微服应用已创建成功 !\n✨ 进行下面步骤后即可进入容器开发\n cd {{ name }}\n lzc-cli project devshell\n ",
65
+ "template_config_vue3_green": "\n⚙️ 进入应用容器后执行下面命令:\n npm install\n npm run dev\n🚀 启动应用:\n 进入微服客户端启动器页面点击应用图标来测试应用\n ",
66
+ "write_file_tree_create_file": "创建文件 {{ filePath }}"
67
+ },
68
+ "lpk_devshell": {
69
+ "devshell_build_dockerfile_tips": "开始创建 Dockerfile 文件",
70
+ "devshell_build_field_fail": "devshell 模式下,devshell 字段必须要指定",
71
+ "devshell_build_image_for_box_tips": "开始在盒子中构建 {{ label }} 镜像 from {{ tempDir }}",
72
+ "devshell_build_label_image_box_tips": "开始在盒子中构建 {{ label }} 镜像",
73
+ "devshell_build_routes_not_exists_fail": "devshell 模式下,必须要指定 routes 内容",
74
+ "devshell_build_skip_dependencies_tips": "dependencies 内容为空,跳过 dependencies",
75
+ "sync_project_code_tips": "同步代码: ",
76
+ "sync_project_rsync_tips": "rsync 同步失败"
77
+ },
78
+ "lpk_devshell_docker": {
79
+ "not_exists_dockerfile_fail": "未发现 Dockerfile"
80
+ },
81
+ "lpk_installer": {
82
+ "deploy_not_exists_builder_fail": "deploy 必须传递一个 builder",
83
+ "deploy_start_tips": "开始部署应用",
84
+ "install_form_url_download_lpk_done_tips": "下载完成",
85
+ "install_form_url_download_lpk_tips": "开始下载lpk",
86
+ "install_from_dir_scan_tips": "正在安装自动扫描出来的lpk包({{ lpk }})",
87
+ "install_from_file_done_tips": "👉 请在浏览器中访问 https://{{ subdomain }}.{{ boxname }}.heiyu.space",
88
+ "install_from_file_fail_tips": "安装失败: {{ error }}",
89
+ "install_from_file_gen_apk_error": "生成 APK 失败: ",
90
+ "install_from_file_gen_apk_error_tips": "生成 APK 失败,使用 lzc-cli project devshell --apk n 忽略该错误",
91
+ "install_from_file_gen_apk_tips": "是否生成APK:",
92
+ "install_from_file_login_tips": "👉 并使用微服的用户名和密码登录",
93
+ "install_from_file_lpk_path_fail": "install 必须指定一个 pkg 路径",
94
+ "install_from_file_lpk_path_not_exists_fail": "{{ pkgPath }} 不存在",
95
+ "install_from_file_manifest_not_exists_app_subdomain_fail": "manifest.yml 中的 `application.subdomain` 字段不能为空",
96
+ "install_from_file_start_tips": "开始安装应用",
97
+ "install_from_file_success_tips": "安装成功!"
98
+ }
99
+ },
100
+ "appstore": {
101
+ "index": {
102
+ "appstore_cmd_desc": "应用商店",
103
+ "copy_image_cmd_desc": "复制镜像至懒猫微服官方源",
104
+ "login_cmd_desc": "登录",
105
+ "my_images_cmd_desc": "查看已上传镜像列表",
106
+ "pre_publish_cmd_changelog_desc": "更改日志",
107
+ "pre_publish_cmd_changelog_file_desc": "更改日志文件",
108
+ "pre_publish_cmd_desc": "发布到内测",
109
+ "pre_publish_cmd_gid_desc": "内测组ID",
110
+ "publish_cmd_changelog_desc": "更新日志",
111
+ "publish_cmd_changelog_file_desc": "更新日志文件",
112
+ "publish_cmd_changelog_files_desc": "更新日志本地化语言文件 lang:path 例如 en:changelog.en.md",
113
+ "publish_cmd_changelog_lang_desc": "更新日志语言标识,默认通过当前 shell 语言环境识别",
114
+ "publish_cmd_desc": "发布到商店"
115
+ },
116
+ "login": {
117
+ "login_success_tips": "登录成功!"
118
+ }
119
+ },
120
+ "box": {
121
+ "index": {
122
+ "add_public_key_cmd_apply_tips": "请点击下面的连接,或者复制到浏览器中打开,点击申请完成添加\n-> https://dev.{{ boxname }}.heiyu.space/auth?key={{ pk }}\n",
123
+ "add_public_key_cmd_desc": "添加public-key到开发者工具中",
124
+ "box_cmd_desc": "盒子管理",
125
+ "default_cmd_desc": "输出当前默认的盒子名",
126
+ "list_cmd_box_not_exist_tips": "没有找到任何盒子,赶紧添加一个吧!",
127
+ "list_cmd_desc": "查看盒子列表",
128
+ "list_cmd_table_box_name": "名称",
129
+ "list_cmd_table_is_admin_login": "是否管理员",
130
+ "list_cmd_table_is_default_box": "是否默认盒子",
131
+ "list_cmd_table_login_user": "登录用户",
132
+ "list_cmd_table_status": "状态",
133
+ "list_cmd_verbose_desc": "查看详细输出",
134
+ "switch_cmd_desc": "设置默认的盒子"
135
+ }
136
+ },
137
+ "config": {
138
+ "index": {
139
+ "config_cmd_desc": "配置管理",
140
+ "config_cmd_disable_check_version_tips": "禁用 lzc-cli 的版本更新检测",
141
+ "config_cmd_item_tips": "获取key为foo的配置",
142
+ "config_cmd_list_tips": "列出所有配置",
143
+ "del_cmd_desc": "删除配置",
144
+ "del_cmd_success": "删除 {{ key }} 成功!",
145
+ "get_cmd_desc": "获取配置",
146
+ "set_cmd_desc": "设置配置",
147
+ "set_cmd_key_or_value_is_empty_fail": "key 和 value 不能为空",
148
+ "set_cmd_success_tips": "{{ key }} 配置成功!"
149
+ }
150
+ },
151
+ "debug_bridge": {
152
+ "backend_version_020_no_match_tips": "\n检测到您当前的 lzc-cli 版本较新,而 '懒猫开发者工具' 比较旧,请先到微服的商店升级 '懒猫开发者工具',点击下面的连接跳转:\n\n-> https://appstore.{{boxname}}.heiyu.space/#/shop/detail/cloud.lazycat.developer.tools\n",
153
+ "build_image_fail": "在微服中构建 image 失败",
154
+ "can_public_key_resolve_fail": "域名解析失败,请检查代理软件是否对 *.heiyu.space 拦截",
155
+ "check_dev_tools_fail_tips": "检测懒猫开发者工具失败,请检测您当前的网络或者懒猫微服客户端是否正常启动。",
156
+ "check_dev_tools_not_exist_tips": "检测到你还没有安装 '懒猫开发者工具',请先到商店中搜索安装\n点击直接跳转 https://appstore.{{ boxname }}.heiyu.space/#/shop/detail/cloud.lazycat.developer.tools\n点击打开应用 https://dev.{{ boxname }}.heiyu.space 查看应用状态\n",
157
+ "common_exec_fail": "执行命令 {{ cmd }} {{ args }} 出错\n{{ stdout }}\n{{ stderr }}",
158
+ "common_start_log": "执行命令 {{ cmd }} {{ args }}",
159
+ "install_fail": "install 失败",
160
+ "ssh_apply_grant_not_credible_tips": "您当前机器的公钥未添加到微服({{ boxname }})的信任列表中,请使用微服管理员账号在浏览器中访问以下地址,将您选择的公钥自动添加到信任列表中。(所有操作均只在您微服中进行,包括本开发机在内的任何数据不会泄漏到您的微服之外)\n\n-> https://{{ domain }}/auth?key={{ pk }}\n",
161
+ "ssh_apply_grant_not_exist_tips": "检测到您当前的环境还没有添加 ssh 公钥到 ‘懒猫开发者工具’ 中,请选择您需要添加的公钥类型"
162
+ },
163
+ "docker": {
164
+ "index": {
165
+ "docker_cmd_desc": "微服应用 docker 管理",
166
+ "docker_compose_cmd_desc": "微服应用 docker-compose 管理"
167
+ }
168
+ },
169
+ "login": {
170
+ "ask_user_info_password_prompt": "请输入登录密码",
171
+ "ask_user_info_username_prompt": "请输入登录用户名",
172
+ "auto_login_interactive_login": "token错误,尝试自动登录",
173
+ "auto_login_success": "appstore 已经登录",
174
+ "interactive_login_fail_tips": "登录失败,{{message}}",
175
+ "interactive_login_user_passwd_error_tips": "帐号或者密码错误,请重新输入!",
176
+ "re_login_message_prompt": "检测到已经登录,是否重新登录(y/n):",
177
+ "tips_first_login_tips": "请登录懒猫微服社区账号,账号注册以及开发者权限申请地址: https://developer.lazycat.cloud/manage"
178
+ },
179
+ "pre_publish": {
180
+ "ask_changelog_prompt": "填写 changelog 内容",
181
+ "ask_group_prompt": "选择内测组",
182
+ "publish_done_tips": "应用提交成功! 请在内测工具中查看",
183
+ "publish_fail_tips": "应用提交失败: {{message}}",
184
+ "publish_gid_not_exist_tips": "请选择内测组",
185
+ "publish_pending_tips": "正在提交内测..."
186
+ },
187
+ "publish": {
188
+ "ask_changelog_prompt": "填写 changelog 内容 ({{ locale }})",
189
+ "ask_publish_app_info_author_prompt": "请输入作者名称(原创应用可不填):",
190
+ "ask_publish_app_info_name_prompt": "请输入应用名称:",
191
+ "ask_publish_app_info_name_validate": "应用名称不能为空",
192
+ "ask_publish_app_info_package_prompt": "请输入应用包标识符:",
193
+ "ask_publish_app_info_package_validate": "应用包标识符不符合规范,建议使用反向域名表示法",
194
+ "ask_publish_app_info_source_prompt": "请输入应用来源(原创应用可不填):",
195
+ "ask_whether_create_lpk_continue_prompt": "检测到您当前的应用,还没有在懒猫微服中创建,是否使用当前的安装包中的信息进行创建? [y/n]",
196
+ "ask_whether_create_lpk_fail_tips": "当前想发布的应用没有在 '懒猫微服的开发者中心' 创建,请按照以下步骤创建:\n\n1. 浏览器打开 https://developer.lazycat.cloud/manage\n2. 登录您的开发者帐号\n3. 登录成功后,您可以查看到您帐号中的应用,同时您也可以对您的应用进行管理\n4. 点击 '新增',根据您的应用信息进行填写\n5. 填写完成后,点击创建即可\n6. 创建成功后,您可以通过 'lzc-cli appstore publish' 来发布应用了\n",
197
+ "ask_whether_create_lpk_success_tips": "创建 {{ package }} 应用成功!",
198
+ "check_app_id_exist_fail_tips": "检测应用是否存在出错, 错误状态码为: ",
199
+ "pre_check_fail_tips": "不能发布一个devshell的版本,请重新使用 `lzc-cli project build` 构建",
200
+ "pre_check_icon_not_exist_tips": "icon 必须存在且要求是 png 格式",
201
+ "publish_done_tips": "应用提交成功! 请等待审核结果",
202
+ "publish_fail_tips": "发布应用出错,错误状态码为: ",
203
+ "publish_lpk_fail_tips": "LPK 文件上传失败,err: {{ message }}",
204
+ "publish_pending_tips": "正在提交审核..."
205
+ },
206
+ "shellapi": {
207
+ "init": {
208
+ "conf_file_not_exist_warn": "WARN:: 读取不到以下路径中的文件,无法连接客户端自动判读盒子名称和盒子用户,\n\n{{ addrFile }} 盒子的连接地址\n{{ credFile }} 盒子的连接凭证\n\n但可使用环境变量指定:\n - BOX_NAME=foo 指定盒子的名称\n - BOX_UID=bar 指定盒子的用户\n\nNOTE:在指定环境变量的模式下,有些接口依旧不能访问,为了更好的开发体验,建议尽量在同主机的环境下启动客户端",
209
+ "proxy_env_warn": "WARN:: 当前终端环境已配置 HTTP_PROXY 代理,可能会导致访问懒猫微服失败,如果未影响功能可以忽略该警告"
210
+ },
211
+ "init_box_info": {
212
+ "box_not_exists_fail": "没有默认盒子信息, 请先使用 lzc-cli box switch 设置默认的盒子信息",
213
+ "boxes_list_fail": "获取盒子信息失败,请检查客户端是否已经连接!"
214
+ },
215
+ "set_default_box": {
216
+ "box_not_exists_fail": "{{ boxname }} 盒子不存在"
217
+ }
218
+ },
219
+ "utils": {
220
+ "check_nodejs_version_no_match_tips": "检测到您当前的 nodejs 版本 {{ version }} 不匹配,lzc-cli 最低要求 nodejs 版本为 {{ requiredVersion }}, 请升级",
221
+ "check_rsync_exec_version_log": "执行命令 rsync --version",
222
+ "check_rsync_not_install_fail": "请检查 rsync 是否安装,路径是否正确!",
223
+ "check_rsync_version_fail": "请检查 rsync 安装是否正确,指定 rsync --version 错误",
224
+ "check_rsync_version_no_match_fail": "当前 rsync 版本为:{{ versionMatch }}, 要求 rsync 版本为: 3.2.0+",
225
+ "check_rsync_version_print_log": "当前 rsync 版本为:{{ versionMatch }}",
226
+ "ensure_directory_exists_fail": "创建文件夹{{ filePath }}错误: {{ err }}",
227
+ "find_ssh_public_key_dir_info_get_fail": "不能查询 .ssh 目录",
228
+ "find_ssh_public_key_dir_not_exist_fail": ".ssh 目录不存在, 请确保 ssh 已经安装,以及 ssh-keygen 生成公钥",
229
+ "find_ssh_public_key_files_not_exits_fail": ".ssh 目录没有没有找到任何 .pub 公钥. 请使用 ssh-keygen 生成",
230
+ "find_ssh_public_key_not_is_dir_fail": ".ssh 目前存在,但不是一个正常的目录,请确保 ssh 已经安装,以及 ssh-keygen 生成公钥",
231
+ "get_latest_version_fail_tips": "请求 {{ url }} 失败, error: {{ err }}",
232
+ "get_latest_version_success_tips": "已经在最新版本: {{ latestVersion }}",
233
+ "get_latest_version_tips": "检测到 {{ pkgName }} 最新版本为 {{ latestVersion }},使用 'npm i -g {{ pkgName }}@{{ latestVersion }}' 升级到最新版本!",
234
+ "resolve_domain_fail_tips": "无法解析域名 {{ domain }}: ",
235
+ "select_ssh_public_key_prompt": "选择使用的公钥",
236
+ "unzip_sync_not_exist_fail": "{{ zipPath }} 找不到该文件",
237
+ "unzip_sync_not_exist_file_log": "压缩包中没有找到 {{ entry }} 文件"
238
+ }
239
+ },
240
+ "script": {
241
+ "cli": {
242
+ "help_msg_content": "使用 lzc-cli help 查看更多帮助"
243
+ },
244
+ "lzc_docker": {
245
+ "help_msg_content": "使用 lzc-cli help 查看更多帮助"
246
+ },
247
+ "lzc_docker_compose": {
248
+ "help_msg_content": "使用 lzc-cli help 查看更多帮助"
249
+ }
250
+ }
251
+ }
252
+ }
package/lib/shellapi.js CHANGED
@@ -1,171 +1,147 @@
1
- import grpc from "@grpc/grpc-js"
2
- import protoLoader from "@grpc/proto-loader"
3
- import {
4
- contextDirname,
5
- isMacOs,
6
- isWindows,
7
- isLinux,
8
- isFileExist
9
- } from "./utils.js"
10
- import path from "node:path"
11
- import fs from "node:fs"
12
- import os from "node:os"
13
- import logger from "loglevel"
1
+ import grpc from '@grpc/grpc-js';
2
+ import protoLoader from '@grpc/proto-loader';
3
+ import { contextDirname, isMacOs, isWindows, isLinux, isFileExist } from './utils.js';
4
+ import path from 'node:path';
5
+ import fs from 'node:fs';
6
+ import os from 'node:os';
7
+ import logger from 'loglevel';
8
+ import { t } from './i18n/index.js';
14
9
 
15
10
  /**
16
11
  * @link {https://www.npmjs.com/package/appdirs}
17
12
  */
18
13
  function getShellAPIConfigDir() {
19
- const home = os.homedir()
20
- let suffix = "/.config/hportal-client"
21
- if (isMacOs) {
22
- suffix = "/Library/Application Support/hportal-client"
23
- } else if (isWindows) {
24
- suffix = "\\AppData\\Roaming\\hportal-client"
25
- }
26
- const SHELLAPI_CONFIG_DIR = path.join(home, suffix)
27
- return SHELLAPI_CONFIG_DIR
14
+ const home = os.homedir();
15
+ let suffix = '/.config/hportal-client';
16
+ if (isMacOs) {
17
+ suffix = '/Library/Application Support/hportal-client';
18
+ } else if (isWindows) {
19
+ suffix = '\\AppData\\Roaming\\hportal-client';
20
+ }
21
+ const SHELLAPI_CONFIG_DIR = path.join(home, suffix);
22
+ return SHELLAPI_CONFIG_DIR;
28
23
  }
29
24
 
30
25
  class ShellApi {
31
- constructor() {}
26
+ constructor() { }
32
27
 
33
- async init() {
34
- // 检查当前 shell 环境上下文是否配置 HTTP_PROXY
35
- if (this.checkEnvProxy()) {
36
- logger.warn(
37
- `WARN:: 当前终端环境已配置 HTTP_PROXY 代理,可能会导致访问懒猫微服失败,如果未影响功能可以忽略该警告`
38
- )
39
- }
28
+ async init() {
29
+ // 检查当前 shell 环境上下文是否配置 HTTP_PROXY
30
+ if (this.checkEnvProxy()) {
31
+ logger.warn(t('lzc_cli.lib.shellapi.init.proxy_env_warn', `WARN:: 当前终端环境已配置 HTTP_PROXY 代理,可能会导致访问懒猫微服失败,如果未影响功能可以忽略该警告`));
32
+ }
40
33
 
41
- const SHELLAPI_CONFIG_DIR = getShellAPIConfigDir()
42
- const addrFile = path.resolve(SHELLAPI_CONFIG_DIR, "shellapi_addr")
43
- const credFile = path.resolve(SHELLAPI_CONFIG_DIR, "shellapi_cred")
44
- if (!isFileExist(addrFile) || !isFileExist(credFile)) {
45
- logger.warn(`WARN:: 读取不到以下路径中的文件,无法连接客户端自动判读盒子名称和盒子用户,
34
+ const SHELLAPI_CONFIG_DIR = getShellAPIConfigDir();
35
+ const addrFile = path.resolve(SHELLAPI_CONFIG_DIR, 'shellapi_addr');
36
+ const credFile = path.resolve(SHELLAPI_CONFIG_DIR, 'shellapi_cred');
37
+ if (!isFileExist(addrFile) || !isFileExist(credFile)) {
38
+ logger.warn(
39
+ t(
40
+ 'lzc_cli.lib.shellapi.init.conf_file_not_exist_warn',
41
+ `WARN:: 读取不到以下路径中的文件,无法连接客户端自动判读盒子名称和盒子用户,
46
42
 
47
- ${addrFile} 盒子的连接地址
48
- ${credFile} 盒子的连接凭证
43
+ {{ addrFile }} 盒子的连接地址
44
+ {{ credFile }} 盒子的连接凭证
49
45
 
50
46
  但可使用环境变量指定:
51
47
  - BOX_NAME=foo 指定盒子的名称
52
48
  - BOX_UID=bar 指定盒子的用户
53
49
 
54
- NOTE:在指定环境变量的模式下,有些接口依旧不能访问,为了更好的开发体验,建议尽量在同主机的环境下启动客户端`)
55
- const md = new grpc.Metadata()
56
- md.add("lzc-shellapi-cred", "fakecred")
57
- this.metadata = md
58
- const boxUid = process.env.BOX_UID
59
- const boxName = process.env.BOX_NAME
60
- if (!boxUid || !boxName) {
61
- process.exit(1)
62
- return
63
- }
64
- this.info = { uid: boxUid, boxname: boxName }
65
- } else {
66
- const pbShell = this.initShell()
67
- const { addr, cred } = this.readShellApiInfo()
68
- this.client = new pbShell.ShellCore(
69
- addr,
70
- grpc.credentials.createInsecure()
71
- )
72
- const md = new grpc.Metadata()
73
- md.add("lzc-shellapi-cred", cred)
74
- this.metadata = md
75
- this.info = await this.initBoxInfo()
76
- }
77
- }
50
+ NOTE:在指定环境变量的模式下,有些接口依旧不能访问,为了更好的开发体验,建议尽量在同主机的环境下启动客户端`,
51
+ { addrFile, credFile, interpolation: { escapeValue: false } },
52
+ ),
53
+ );
54
+ const md = new grpc.Metadata();
55
+ md.add('lzc-shellapi-cred', 'fakecred');
56
+ this.metadata = md;
57
+ const boxUid = process.env.BOX_UID;
58
+ const boxName = process.env.BOX_NAME;
59
+ if (!boxUid || !boxName) {
60
+ process.exit(1);
61
+ return;
62
+ }
63
+ this.info = { uid: boxUid, boxname: boxName };
64
+ } else {
65
+ const pbShell = this.initShell();
66
+ const { addr, cred } = this.readShellApiInfo();
67
+ this.client = new pbShell.ShellCore(addr, grpc.credentials.createInsecure());
68
+ const md = new grpc.Metadata();
69
+ md.add('lzc-shellapi-cred', cred);
70
+ this.metadata = md;
71
+ this.info = await this.initBoxInfo();
72
+ }
73
+ }
78
74
 
79
- get boxname() {
80
- return this.info.boxname
81
- }
82
- get uid() {
83
- return this.info.uid
84
- }
75
+ get boxname() {
76
+ return this.info.boxname;
77
+ }
78
+ get uid() {
79
+ return this.info.uid;
80
+ }
85
81
 
86
- readShellApiInfo() {
87
- const SHELLAPI_CONFIG_DIR = getShellAPIConfigDir()
88
- const addr = fs.readFileSync(
89
- path.resolve(SHELLAPI_CONFIG_DIR, "shellapi_addr"),
90
- { encoding: "utf-8" }
91
- )
92
- const cred = fs.readFileSync(
93
- path.resolve(SHELLAPI_CONFIG_DIR, "shellapi_cred"),
94
- { encoding: "utf-8" }
95
- )
96
- return { addr, cred }
97
- }
82
+ readShellApiInfo() {
83
+ const SHELLAPI_CONFIG_DIR = getShellAPIConfigDir();
84
+ const addr = fs.readFileSync(path.resolve(SHELLAPI_CONFIG_DIR, 'shellapi_addr'), { encoding: 'utf-8' });
85
+ const cred = fs.readFileSync(path.resolve(SHELLAPI_CONFIG_DIR, 'shellapi_cred'), { encoding: 'utf-8' });
86
+ return { addr, cred };
87
+ }
98
88
 
99
- initShell() {
100
- const coreDefinition = protoLoader.loadSync(
101
- path.join(contextDirname(), "./shellapi.proto"),
102
- {
103
- keepCase: true,
104
- longs: String,
105
- enums: String,
106
- defaults: true,
107
- oneofs: true
108
- }
109
- )
110
- return grpc.loadPackageDefinition(coreDefinition).space.heiyu.hportal.shell
111
- }
89
+ initShell() {
90
+ const coreDefinition = protoLoader.loadSync(path.join(contextDirname(), './shellapi.proto'), {
91
+ keepCase: true,
92
+ longs: String,
93
+ enums: String,
94
+ defaults: true,
95
+ oneofs: true,
96
+ });
97
+ return grpc.loadPackageDefinition(coreDefinition).space.heiyu.hportal.shell;
98
+ }
112
99
 
113
- async boxList() {
114
- return new Promise((resolve, reject) => {
115
- this.client.queryBoxList({}, this.metadata, function (err, response) {
116
- if (err) {
117
- reject(err)
118
- return
119
- }
120
- resolve(response.boxes)
121
- })
122
- })
123
- }
100
+ async boxList() {
101
+ return new Promise((resolve, reject) => {
102
+ this.client.queryBoxList({}, this.metadata, function (err, response) {
103
+ if (err) {
104
+ reject(err);
105
+ return;
106
+ }
107
+ resolve(response.boxes);
108
+ });
109
+ });
110
+ }
124
111
 
125
- async initBoxInfo() {
126
- try {
127
- const boxes = await this.boxList()
128
- const box = boxes.find((b) => b.is_default_box)
129
- if (box) {
130
- return { uid: box.login_user, boxname: box.box_name }
131
- }
132
- } catch (e) {
133
- logger.debug("Error: ", e)
134
- throw "获取盒子信息失败,请检查客户端是否已经连接!"
135
- }
136
- throw "没有默认盒子信息, 请先使用 lzc-cli box switch 设置默认的盒子信息"
137
- }
112
+ async initBoxInfo() {
113
+ try {
114
+ const boxes = await this.boxList();
115
+ const box = boxes.find((b) => b.is_default_box);
116
+ if (box) {
117
+ return { uid: box.login_user, boxname: box.box_name };
118
+ }
119
+ } catch (e) {
120
+ logger.debug('Error: ', e);
121
+ throw t('lzc_cli.lib.shellapi.init_box_info.boxes_list_fail', '获取盒子信息失败,请检查客户端是否已经连接!');
122
+ }
123
+ throw t('lzc_cli.lib.shellapi.init_box_info.box_not_exists_fail', '没有默认盒子信息, 请先使用 lzc-cli box switch 设置默认的盒子信息');
124
+ }
138
125
 
139
- checkEnvProxy() {
140
- if (
141
- process.env.HTTPS_PROXY ||
142
- process.env.HTTP_PROXY ||
143
- process.env.ALL_PROXY ||
144
- process.env.https_proxy ||
145
- process.env.http_proxy ||
146
- process.env.all_proxy
147
- ) {
148
- return true
149
- }
150
- return false
151
- }
126
+ checkEnvProxy() {
127
+ if (process.env.HTTPS_PROXY || process.env.HTTP_PROXY || process.env.ALL_PROXY || process.env.https_proxy || process.env.http_proxy || process.env.all_proxy) {
128
+ return true;
129
+ }
130
+ return false;
131
+ }
152
132
 
153
- async setDefaultBox(boxname) {
154
- const boxes = await this.boxList()
155
- const box = boxes.find((b) => b.box_name === boxname)
156
- if (!box) {
157
- throw `${boxname} 盒子不存在`
158
- }
159
- return new Promise((resolve, reject) => {
160
- this.client.modifyBoxConfig(
161
- { id: box.id, name: box.box_name, set_as_default_box: true },
162
- this.metadata,
163
- function (err) {
164
- err ? reject(err) : resolve()
165
- }
166
- )
167
- })
168
- }
133
+ async setDefaultBox(boxname) {
134
+ const boxes = await this.boxList();
135
+ const box = boxes.find((b) => b.box_name === boxname);
136
+ if (!box) {
137
+ throw t('lzc_cli.lib.shellapi.set_default_box.box_not_exists_fail', '{{ boxname }} 盒子不存在', { boxname });
138
+ }
139
+ return new Promise((resolve, reject) => {
140
+ this.client.modifyBoxConfig({ id: box.id, name: box.box_name, set_as_default_box: true }, this.metadata, function (err) {
141
+ err ? reject(err) : resolve();
142
+ });
143
+ });
144
+ }
169
145
  }
170
146
 
171
- export default new ShellApi()
147
+ export default new ShellApi();