@openyida/yidacli 0.1.5 → 0.1.7
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/package.json +1 -2
- package/scripts/build.js +0 -93
- package/scripts/prepublish.js +0 -162
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openyida/yidacli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "宜搭 CLI 工具 - 宜搭平台应用、页面、表单的命令行管理工具",
|
|
5
5
|
"main": "bin/yidacli.js",
|
|
6
6
|
"bin": {
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"bin",
|
|
11
11
|
"dist",
|
|
12
|
-
"scripts",
|
|
13
12
|
"openyida"
|
|
14
13
|
],
|
|
15
14
|
"scripts": {
|
package/scripts/build.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* build.js - 构建脚本
|
|
4
|
-
*
|
|
5
|
-
* 将 src/ 目录下所有 JS 文件用 UglifyJS 压缩后输出到 dist/,
|
|
6
|
-
* 保持原有目录结构。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
"use strict";
|
|
10
|
-
|
|
11
|
-
const fs = require("fs");
|
|
12
|
-
const path = require("path");
|
|
13
|
-
const UglifyJS = require("uglify-js");
|
|
14
|
-
|
|
15
|
-
const YIDA_CLI_DIR = path.resolve(__dirname, "..");
|
|
16
|
-
const SRC_DIR = path.resolve(YIDA_CLI_DIR, "src");
|
|
17
|
-
const DIST_DIR = path.resolve(YIDA_CLI_DIR, "dist");
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 递归收集目录下所有 .js 文件
|
|
21
|
-
*/
|
|
22
|
-
function collectJsFiles(dir, baseDir) {
|
|
23
|
-
const results = [];
|
|
24
|
-
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
25
|
-
const fullPath = path.join(dir, entry.name);
|
|
26
|
-
if (entry.isDirectory()) {
|
|
27
|
-
results.push(...collectJsFiles(fullPath, baseDir));
|
|
28
|
-
} else if (entry.name.endsWith(".js")) {
|
|
29
|
-
results.push(fullPath);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return results;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function main() {
|
|
36
|
-
console.log("=".repeat(50));
|
|
37
|
-
console.log(" build - 构建 yida-cli(uglify src/ → dist/)");
|
|
38
|
-
console.log("=".repeat(50));
|
|
39
|
-
|
|
40
|
-
// 清空并重建 dist 目录
|
|
41
|
-
if (fs.existsSync(DIST_DIR)) {
|
|
42
|
-
fs.rmSync(DIST_DIR, { recursive: true, force: true });
|
|
43
|
-
console.log("\n 🗑️ 已清空旧的 dist/ 目录");
|
|
44
|
-
}
|
|
45
|
-
fs.mkdirSync(DIST_DIR, { recursive: true });
|
|
46
|
-
|
|
47
|
-
const jsFiles = collectJsFiles(SRC_DIR, SRC_DIR);
|
|
48
|
-
console.log(`\n 📦 共发现 ${jsFiles.length} 个源文件,开始压缩...\n`);
|
|
49
|
-
|
|
50
|
-
let successCount = 0;
|
|
51
|
-
let errorCount = 0;
|
|
52
|
-
|
|
53
|
-
for (const srcFile of jsFiles) {
|
|
54
|
-
const relativePath = path.relative(SRC_DIR, srcFile);
|
|
55
|
-
const distFile = path.join(DIST_DIR, relativePath);
|
|
56
|
-
|
|
57
|
-
// 确保目标目录存在
|
|
58
|
-
fs.mkdirSync(path.dirname(distFile), { recursive: true });
|
|
59
|
-
|
|
60
|
-
const sourceCode = fs.readFileSync(srcFile, "utf-8");
|
|
61
|
-
const result = UglifyJS.minify(sourceCode, {
|
|
62
|
-
// 保留 require 调用,不做模块打包
|
|
63
|
-
compress: { passes: 1 },
|
|
64
|
-
mangle: true,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
if (result.error) {
|
|
68
|
-
console.error(` ❌ 压缩失败: ${relativePath}`);
|
|
69
|
-
console.error(` ${result.error.message}`);
|
|
70
|
-
errorCount++;
|
|
71
|
-
// 压缩失败时原样复制,保证可用性
|
|
72
|
-
fs.copyFileSync(srcFile, distFile);
|
|
73
|
-
} else {
|
|
74
|
-
fs.writeFileSync(distFile, result.code, "utf-8");
|
|
75
|
-
console.log(` ✅ ${relativePath}`);
|
|
76
|
-
successCount++;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
console.log("\n" + "=".repeat(50));
|
|
81
|
-
if (errorCount === 0) {
|
|
82
|
-
console.log(`✅ 构建完成,共压缩 ${successCount} 个文件`);
|
|
83
|
-
} else {
|
|
84
|
-
console.log(`⚠️ 构建完成,${successCount} 个成功,${errorCount} 个失败(已原样复制)`);
|
|
85
|
-
}
|
|
86
|
-
console.log("=".repeat(50));
|
|
87
|
-
|
|
88
|
-
if (errorCount > 0) {
|
|
89
|
-
process.exit(1);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
main();
|
package/scripts/prepublish.js
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* prepublish.js - npm 发布前钩子
|
|
4
|
-
*
|
|
5
|
-
* 将项目根目录的 openyida/ 目录完整拷贝到 yida-cli/openyida/,
|
|
6
|
-
* 使其随 npm 包一起发布,供 postinstall 脚本使用。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
"use strict";
|
|
10
|
-
|
|
11
|
-
const fs = require("fs");
|
|
12
|
-
const path = require("path");
|
|
13
|
-
|
|
14
|
-
const YIDA_CLI_DIR = path.resolve(__dirname, "..");
|
|
15
|
-
const SOURCE_DIR = path.resolve(YIDA_CLI_DIR, "..", "openyida");
|
|
16
|
-
const DEST_DIR = path.resolve(YIDA_CLI_DIR, "openyida");
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 递归复制目录(强制覆盖已有文件)
|
|
20
|
-
*/
|
|
21
|
-
function copyDirRecursive(sourceDir, destDir) {
|
|
22
|
-
if (!fs.existsSync(sourceDir)) {
|
|
23
|
-
throw new Error(`源目录不存在: ${sourceDir}`);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
fs.mkdirSync(destDir, { recursive: true });
|
|
27
|
-
|
|
28
|
-
const entries = fs.readdirSync(sourceDir, { withFileTypes: true });
|
|
29
|
-
let copiedCount = 0;
|
|
30
|
-
|
|
31
|
-
for (const entry of entries) {
|
|
32
|
-
const sourcePath = path.join(sourceDir, entry.name);
|
|
33
|
-
const destPath = path.join(destDir, entry.name);
|
|
34
|
-
|
|
35
|
-
if (entry.isDirectory()) {
|
|
36
|
-
copiedCount += copyDirRecursive(sourcePath, destPath);
|
|
37
|
-
} else {
|
|
38
|
-
fs.copyFileSync(sourcePath, destPath);
|
|
39
|
-
console.log(` 复制: ${path.relative(YIDA_CLI_DIR, destPath)}`);
|
|
40
|
-
copiedCount++;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return copiedCount;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 递归收集目录下所有文件的相对路径(相对于 baseDir)。
|
|
49
|
-
* @returns {string[]} 排序后的相对路径列表
|
|
50
|
-
*/
|
|
51
|
-
function collectAllRelativePaths(baseDir, currentDir) {
|
|
52
|
-
const dir = currentDir || baseDir;
|
|
53
|
-
const results = [];
|
|
54
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
55
|
-
|
|
56
|
-
for (const entry of entries) {
|
|
57
|
-
const fullPath = path.join(dir, entry.name);
|
|
58
|
-
if (entry.isDirectory()) {
|
|
59
|
-
results.push(...collectAllRelativePaths(baseDir, fullPath));
|
|
60
|
-
} else {
|
|
61
|
-
results.push(path.relative(baseDir, fullPath));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return results.sort();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* 校验拷贝结果:逐文件对比源目录和目标目录的内容是否完全一致。
|
|
70
|
-
* 有差异则打印详情并抛出错误。
|
|
71
|
-
*/
|
|
72
|
-
function verifyDiff(sourceDir, destDir) {
|
|
73
|
-
const sourcePaths = collectAllRelativePaths(sourceDir);
|
|
74
|
-
const destPaths = collectAllRelativePaths(destDir);
|
|
75
|
-
|
|
76
|
-
const missingInDest = sourcePaths.filter((p) => !destPaths.includes(p));
|
|
77
|
-
const extraInDest = destPaths.filter((p) => !sourcePaths.includes(p));
|
|
78
|
-
const contentMismatches = [];
|
|
79
|
-
|
|
80
|
-
for (const relativePath of sourcePaths) {
|
|
81
|
-
if (missingInDest.includes(relativePath)) continue;
|
|
82
|
-
const sourceContent = fs.readFileSync(path.join(sourceDir, relativePath));
|
|
83
|
-
const destContent = fs.readFileSync(path.join(destDir, relativePath));
|
|
84
|
-
if (!sourceContent.equals(destContent)) {
|
|
85
|
-
contentMismatches.push(relativePath);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const hasErrors = missingInDest.length > 0 || extraInDest.length > 0 || contentMismatches.length > 0;
|
|
90
|
-
|
|
91
|
-
if (!hasErrors) {
|
|
92
|
-
console.log(`\n✅ diff 校验通过,共 ${sourcePaths.length} 个文件内容完全一致`);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
console.error("\n❌ diff 校验失败,拷贝结果与源目录不一致:");
|
|
97
|
-
|
|
98
|
-
if (missingInDest.length > 0) {
|
|
99
|
-
console.error(`\n 缺失文件(源有,目标无):`);
|
|
100
|
-
missingInDest.forEach((p) => console.error(` - ${p}`));
|
|
101
|
-
}
|
|
102
|
-
if (extraInDest.length > 0) {
|
|
103
|
-
console.error(`\n 多余文件(目标有,源无):`);
|
|
104
|
-
extraInDest.forEach((p) => console.error(` + ${p}`));
|
|
105
|
-
}
|
|
106
|
-
if (contentMismatches.length > 0) {
|
|
107
|
-
console.error(`\n 内容不一致的文件:`);
|
|
108
|
-
contentMismatches.forEach((p) => console.error(` ≠ ${p}`));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
throw new Error("openyida 拷贝校验失败,请检查上方 diff 详情");
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function cleanup() {
|
|
115
|
-
console.log("=".repeat(50));
|
|
116
|
-
console.log(" postpublish - 清理临时 openyida 目录");
|
|
117
|
-
console.log("=".repeat(50));
|
|
118
|
-
console.log(`\n 目标目录: ${DEST_DIR}\n`);
|
|
119
|
-
|
|
120
|
-
if (fs.existsSync(DEST_DIR)) {
|
|
121
|
-
fs.rmSync(DEST_DIR, { recursive: true, force: true });
|
|
122
|
-
console.log("✅ 已删除临时 openyida/ 目录");
|
|
123
|
-
} else {
|
|
124
|
-
console.log("⚠️ 目录不存在,无需清理");
|
|
125
|
-
}
|
|
126
|
-
console.log("=".repeat(50));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function main() {
|
|
130
|
-
const isCleanup = process.argv.includes("--cleanup");
|
|
131
|
-
|
|
132
|
-
if (isCleanup) {
|
|
133
|
-
cleanup();
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
console.log("=".repeat(50));
|
|
138
|
-
console.log(" prepublish - 拷贝 openyida 到 yida-cli");
|
|
139
|
-
console.log("=".repeat(50));
|
|
140
|
-
console.log(`\n 源目录: ${SOURCE_DIR}`);
|
|
141
|
-
console.log(` 目标目录: ${DEST_DIR}\n`);
|
|
142
|
-
|
|
143
|
-
if (!fs.existsSync(SOURCE_DIR)) {
|
|
144
|
-
console.error(`❌ 源目录不存在: ${SOURCE_DIR}`);
|
|
145
|
-
console.error(" 请确保在项目根目录下存在 openyida/ 目录");
|
|
146
|
-
process.exit(1);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// 清空目标目录(确保不残留旧文件)
|
|
150
|
-
if (fs.existsSync(DEST_DIR)) {
|
|
151
|
-
fs.rmSync(DEST_DIR, { recursive: true, force: true });
|
|
152
|
-
console.log(" 🗑️ 已清空旧的 openyida/ 目录");
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const copiedCount = copyDirRecursive(SOURCE_DIR, DEST_DIR);
|
|
156
|
-
|
|
157
|
-
console.log(`\n 共复制 ${copiedCount} 个文件,开始 diff 校验...`);
|
|
158
|
-
verifyDiff(SOURCE_DIR, DEST_DIR);
|
|
159
|
-
console.log("=".repeat(50));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
main();
|