qdmp-cli 0.0.10 → 0.1.1

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
@@ -27,6 +27,11 @@ npm install -g qdmp-cli
27
27
  ```bash
28
28
  qdmp-cli create [options] <app-name>
29
29
  ```
30
+ ### 拉取配置
31
+ ```bash
32
+ qdmp-cli init
33
+ qdmp-cli init -a appId
34
+ ```
30
35
  ### 查看可选模版
31
36
  ```bash
32
37
  qdmp-cli list
package/actions.js CHANGED
@@ -113,7 +113,7 @@ export async function uploadAction(option) {
113
113
  const loader = remoteApp.loader;
114
114
  // 预上传
115
115
  const targetName = `${appId}_${code}`;
116
- const localPath = await preUpload(loader, targetName);
116
+ const localPath = await preUpload(loader, targetName, appId);
117
117
  if (!localPath) {
118
118
  error("预上传失败");
119
119
  }
@@ -140,3 +140,24 @@ export async function uploadAction(option) {
140
140
  error(`${e.message}`);
141
141
  }
142
142
  }
143
+ export const initConfigAction = async (option) => {
144
+ try {
145
+ const qdmpJsonPath = `${process.cwd()}/qdmp.json`;
146
+ if (fs.existsSync(qdmpJsonPath)) {
147
+ return error("配置文件已存在,请勿重复初始化");
148
+ }
149
+ const appId = option.appId;
150
+ if (!appId) return error("未配置应用ID,请使用-a参数指定应用ID");
151
+ const appInfo = await getAppInfo(appId);
152
+ const config = {
153
+ name: appInfo.name,
154
+ appId: appInfo.appId,
155
+ loader: appInfo.loader,
156
+ latest: appInfo.latest,
157
+ };
158
+ fs.writeFileSync(qdmpJsonPath, JSON.stringify(config, null, 2), "utf8");
159
+ success("qdmp.json 配置文件创建成功");
160
+ } catch (e) {
161
+ error(e.message);
162
+ }
163
+ };
package/index.js CHANGED
@@ -8,6 +8,7 @@ import { fileURLToPath } from "url";
8
8
  import { dirname } from "path";
9
9
  import {
10
10
  initAction,
11
+ initConfigAction,
11
12
  listAction,
12
13
  loginAction,
13
14
  getMyInfoAction,
@@ -40,6 +41,12 @@ program
40
41
  .action(initAction);
41
42
 
42
43
  program.command("list").description("列出可选模版").action(listAction);
44
+ program
45
+ .command("init")
46
+ .description("初始化qdmp.json配置文件")
47
+ .option("-e, --env <env>", "当前环境")
48
+ .option("-a, --appId <appId>", "应用ID")
49
+ .action(initConfigAction);
43
50
  program
44
51
  .command("login")
45
52
  .description("登录")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qdmp-cli",
3
- "version": "0.0.10",
3
+ "version": "0.1.1",
4
4
  "description": "qdmp-cli",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/utils/common.js CHANGED
@@ -75,7 +75,7 @@ export async function createWorkSpaceFolder(dirname = "") {
75
75
  * @param {*} dirname 文件夹名
76
76
  */
77
77
  // 压缩项目
78
- async function compressProject(output, dirname = "", loader) {
78
+ async function compressProject(output, dirname = "", loader, appId) {
79
79
  try {
80
80
  if (loader !== "EMP") {
81
81
  const zip = new AdmZip();
@@ -91,7 +91,7 @@ async function compressProject(output, dirname = "", loader) {
91
91
  } else {
92
92
  // 直接压缩dist
93
93
  const zip = new AdmZip();
94
- zip.addLocalFolder(path.join(dirname, "dist"), "dist");
94
+ zip.addLocalFolder(path.join(dirname, "dist"), `${appId}`);
95
95
  zip.writeZip(path.join(dirname, `${output}.zip`));
96
96
  }
97
97
  return true;
@@ -163,7 +163,7 @@ async function copyEmpDistFolder() {
163
163
  * @param {string} targetName - 目标文件名
164
164
  * @returns {Promise<string|boolean>} 压缩文件路径或操作失败返回false
165
165
  */
166
- export async function preUpload(loader, targetName) {
166
+ export async function preUpload(loader, targetName, appId) {
167
167
  try {
168
168
  // 1. 创建工作空间文件夹
169
169
  if (!(await createWorkSpaceFolder(WORKSPACE_DIR))) {
@@ -183,14 +183,14 @@ export async function preUpload(loader, targetName) {
183
183
  }
184
184
 
185
185
  // 3. 压缩项目
186
- if (!(await compressProject(targetName, WORKSPACE_DIR, loader))) {
186
+ if (!(await compressProject(targetName, WORKSPACE_DIR, loader, appId))) {
187
187
  error("压缩项目失败");
188
188
  return false;
189
189
  }
190
190
 
191
191
  // 4. 返回压缩文件路径
192
192
  const zipFilePath = `./${WORKSPACE_DIR}/${targetName}.zip`;
193
- success(`预上传准备完成,压缩包路径: ${zipFilePath}`);
193
+ success(`预上传准备完成`);
194
194
  return zipFilePath;
195
195
  } catch (error) {
196
196
  error(`预上传过程出错: ${error.message}`);