qdmp-cli 0.1.0 → 0.1.2

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,10 @@ 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 -a appId
33
+ ```
30
34
  ### 查看可选模版
31
35
  ```bash
32
36
  qdmp-cli list
@@ -41,6 +45,10 @@ qdmp-cli login -e dev //登录开发环境
41
45
  qdmp-cli getMe
42
46
  qdmp-cli getMe -e dev //查看开发环境用户
43
47
  ```
48
+ ### 打包
49
+ ```bash
50
+ qdmp-cli upload -t emp //目前仅支持taro类型的emp
51
+ ```
44
52
  ### 上传版本
45
53
  ```bash
46
54
  qdmp-cli upload
package/actions.js CHANGED
@@ -140,3 +140,50 @@ 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
+ };
164
+ export const buildAction = async (option) => {
165
+ try {
166
+ switch (option.type) {
167
+ case "emp":
168
+ info("开始构建...");
169
+ const buildResult = shell.exec("taro build --type weapp");
170
+ if (buildResult.code !== 0) {
171
+ throw new Error("构建失败");
172
+ }
173
+ shell.cd("dist");
174
+ const dmccResult = shell.exec("dmcc build --no-app-id-dir");
175
+ if (dmccResult.code !== 0) {
176
+ throw new Error("dmcc 构建失败");
177
+ }
178
+ shell.cd("..");
179
+ success("构建完成");
180
+ break;
181
+
182
+ default:
183
+ error("不支持的构建类型");
184
+ break;
185
+ }
186
+ } catch (e) {
187
+ error(e?.message || "构建过程出错");
188
+ }
189
+ };
package/index.js CHANGED
@@ -8,10 +8,12 @@ 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,
14
15
  uploadAction,
16
+ buildAction,
15
17
  } from "./actions.js";
16
18
  import { printLogo } from "./utils/logHandler.js";
17
19
  // import.meta.url: esm模块化中的属性,获取模块文件的绝对地址
@@ -40,6 +42,12 @@ program
40
42
  .action(initAction);
41
43
 
42
44
  program.command("list").description("列出可选模版").action(listAction);
45
+ program
46
+ .command("init")
47
+ .description("初始化qdmp.json配置文件")
48
+ .option("-e, --env <env>", "当前环境")
49
+ .option("-a, --appId <appId>", "应用ID")
50
+ .action(initConfigAction);
43
51
  program
44
52
  .command("login")
45
53
  .description("登录")
@@ -50,6 +58,11 @@ program
50
58
  .description("查看登录用户")
51
59
  .option("-e, --env <env>", "当前环境")
52
60
  .action(getMyInfoAction);
61
+ program
62
+ .command("build")
63
+ .description("部署项目")
64
+ .option("-t, --type <type>", "部署类型")
65
+ .action(buildAction);
53
66
  program
54
67
  .command("upload")
55
68
  .description("上传项目")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qdmp-cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "qdmp-cli",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/utils/common.js CHANGED
@@ -3,6 +3,7 @@ import AdmZip from "adm-zip";
3
3
  import { WORKSPACE_DIR } from "../constants.js";
4
4
  import fs from "fs";
5
5
  import path from "path";
6
+ import child_process from "child_process";
6
7
 
7
8
  /** 获取上传链接
8
9
  * @param {*} appId 文件
@@ -229,3 +230,14 @@ export async function cleanWorkSpaceFolder(dirname) {
229
230
  return false;
230
231
  }
231
232
  }
233
+ export async function execSync(cmd) {
234
+ return new Promise((resolve, reject) => {
235
+ child_process.exec(cmd, function (err, stdout, stderr) {
236
+ if (err) {
237
+ reject(new Error(stderr || err.message));
238
+ return;
239
+ }
240
+ resolve(stdout);
241
+ });
242
+ });
243
+ }
package/utils/gitClone.js CHANGED
@@ -1,4 +1,3 @@
1
- import child_process from "child_process";
2
1
  import ora from "ora";
3
2
  import path from "path";
4
3
  import chalk from "chalk";
@@ -6,6 +5,7 @@ import { rm } from "fs/promises";
6
5
  import { existsSync } from "fs";
7
6
  import { inquirerConfirm } from "./interactive.js";
8
7
  import { error } from "./logHandler.js";
8
+ import { execSync } from "./common.js";
9
9
  /**
10
10
  * 下载项目
11
11
  * @param {string} projectName - 项目名称
@@ -35,18 +35,6 @@ export const download = async (projectName, repo) => {
35
35
  }
36
36
  };
37
37
 
38
- const execSync = async (cmd) => {
39
- return new Promise((resolve, reject) => {
40
- child_process.exec(cmd, function (err, stdout, stderr) {
41
- if (err) {
42
- reject(new Error(stderr || err.message));
43
- return;
44
- }
45
- resolve(stdout);
46
- });
47
- });
48
- };
49
-
50
38
  const clone = async (repo, name) => {
51
39
  const spinner = ora("正在拉取项目......").start();
52
40
  try {