qdmp-cli 0.0.7 → 0.0.9
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/actions.js +1 -1
- package/package.json +2 -1
- package/utils/common.js +44 -15
package/actions.js
CHANGED
|
@@ -134,7 +134,7 @@ export async function uploadAction(option) {
|
|
|
134
134
|
success(
|
|
135
135
|
`上传成功,版本号:${code},可前往官网进行小程序发布:https://${
|
|
136
136
|
option.env === "dev" ? "dev-" : ""
|
|
137
|
-
}mp.qiandao.com`
|
|
137
|
+
}mp.qiandao.com/apps/${appId}/deploy`
|
|
138
138
|
);
|
|
139
139
|
} catch (e) {
|
|
140
140
|
error(`${e.message}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qdmp-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "qdmp-cli",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"author": "zhangyanran",
|
|
19
19
|
"license": "ISC",
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"adm-zip": "^0.5.16",
|
|
21
22
|
"chalk": "^5.4.1",
|
|
22
23
|
"commander": "^14.0.0",
|
|
23
24
|
"figlet": "^1.8.1",
|
package/utils/common.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { info, error, success } from "./logHandler.js";
|
|
2
|
-
import
|
|
3
|
-
import chalk from "chalk";
|
|
2
|
+
import AdmZip from "adm-zip";
|
|
4
3
|
import { WORKSPACE_DIR } from "../constants.js";
|
|
5
4
|
import fs from "fs";
|
|
6
5
|
import path from "path";
|
|
@@ -48,7 +47,7 @@ export const isUrlAccessible = async (url) => {
|
|
|
48
47
|
export async function renameDistFolder(dirname, newname) {
|
|
49
48
|
try {
|
|
50
49
|
if (fs.existsSync(newname)) return true;
|
|
51
|
-
|
|
50
|
+
fs.renameSync(dirname, newname);
|
|
52
51
|
return true;
|
|
53
52
|
} catch (e) {
|
|
54
53
|
error("重命名文件夹失败:", e);
|
|
@@ -61,8 +60,10 @@ export async function renameDistFolder(dirname, newname) {
|
|
|
61
60
|
export async function createWorkSpaceFolder(dirname = "") {
|
|
62
61
|
info("创建工作区...");
|
|
63
62
|
try {
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
if (fs.existsSync(dirname)) {
|
|
64
|
+
fs.rmSync(dirname, { recursive: true, force: true });
|
|
65
|
+
}
|
|
66
|
+
fs.mkdirSync(dirname, { recursive: true });
|
|
66
67
|
success("创建工作区成功!");
|
|
67
68
|
return true;
|
|
68
69
|
} catch (e) {
|
|
@@ -76,9 +77,16 @@ export async function createWorkSpaceFolder(dirname = "") {
|
|
|
76
77
|
// 压缩项目
|
|
77
78
|
async function compressProject(output, dirname = "") {
|
|
78
79
|
try {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
const zip = new AdmZip();
|
|
81
|
+
const h5Path = path.join(dirname, "h5");
|
|
82
|
+
|
|
83
|
+
if (!fs.existsSync(h5Path)) {
|
|
84
|
+
throw new Error("h5 目录不存在");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// 添加文件夹时指定目标路径为 h5
|
|
88
|
+
zip.addLocalFolder(h5Path, "h5");
|
|
89
|
+
zip.writeZip(path.join(dirname, `${output}.zip`));
|
|
82
90
|
return true;
|
|
83
91
|
} catch (error) {
|
|
84
92
|
return false;
|
|
@@ -89,16 +97,35 @@ async function compressProject(output, dirname = "") {
|
|
|
89
97
|
*/
|
|
90
98
|
async function copyDistFolder(dirname) {
|
|
91
99
|
try {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
info("正在查找 index.html 文件...");
|
|
101
|
+
let indexPath = null;
|
|
102
|
+
function findIndexHtml(dir) {
|
|
103
|
+
const files = fs.readdirSync(dir);
|
|
104
|
+
for (const file of files) {
|
|
105
|
+
const fullPath = path.join(dir, file);
|
|
106
|
+
const stat = fs.statSync(fullPath);
|
|
107
|
+
if (stat.isDirectory()) {
|
|
108
|
+
const found = findIndexHtml(fullPath);
|
|
109
|
+
if (found) return found;
|
|
110
|
+
} else if (file === "index.html") {
|
|
111
|
+
return fullPath;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
indexPath = findIndexHtml(dirname);
|
|
95
117
|
if (!indexPath) {
|
|
96
118
|
throw new Error("未找到index.html文件");
|
|
97
119
|
}
|
|
120
|
+
success("找到 index.html 文件");
|
|
121
|
+
|
|
98
122
|
const parentDir = path.dirname(indexPath);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
123
|
+
const targetDir = path.join(WORKSPACE_DIR, "dist");
|
|
124
|
+
|
|
125
|
+
info("正在复制文件...");
|
|
126
|
+
// 直接复制整个目录
|
|
127
|
+
fs.cpSync(parentDir, targetDir, { recursive: true });
|
|
128
|
+
success("文件复制完成");
|
|
102
129
|
return true;
|
|
103
130
|
} catch (e) {
|
|
104
131
|
error(e);
|
|
@@ -131,7 +158,9 @@ export async function preUpload(targetName) {
|
|
|
131
158
|
*/
|
|
132
159
|
export async function cleanWorkSpaceFolder(dirname) {
|
|
133
160
|
try {
|
|
134
|
-
|
|
161
|
+
if (fs.existsSync(WORKSPACE_DIR)) {
|
|
162
|
+
fs.rmSync(WORKSPACE_DIR, { recursive: true, force: true });
|
|
163
|
+
}
|
|
135
164
|
success("清理工作空间成功!");
|
|
136
165
|
return true;
|
|
137
166
|
} catch (error) {
|