fast-cocos 1.1.3 → 1.1.4

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.
Files changed (2) hide show
  1. package/dist/xor/src/xor.js +26 -26
  2. package/package.json +1 -1
@@ -11,6 +11,7 @@ exports.batchProcess = batchProcess;
11
11
  exports.runXorCommand = runXorCommand;
12
12
  const fs_1 = __importDefault(require("fs"));
13
13
  const path_1 = __importDefault(require("path"));
14
+ const utils_1 = require("../../utils");
14
15
  /** 默认签名(4 字节) */
15
16
  exports.DEFAULT_SIGN = "CrP3";
16
17
  /** 默认密钥(16 字节) */
@@ -56,7 +57,7 @@ function encryptFile(opts) {
56
57
  const signature = Buffer.from(finalSign, "utf-8");
57
58
  const output = Buffer.concat([signature, encrypted]);
58
59
  fs_1.default.writeFileSync(destPath, output);
59
- console.log(`加密: ${path_1.default.basename(opts.inputPath)} -> ${path_1.default.basename(destPath)} [sign:${finalSign}, key:${finalKey.substring(0, 4)}...]`);
60
+ console.info("\x1b[32m%s\x1b[0m", `加密: ${path_1.default.basename(opts.inputPath)} -> ${path_1.default.basename(destPath)} [sign:${finalSign}, key:${finalKey.substring(0, 4)}...]`);
60
61
  }
61
62
  /**
62
63
  * 解密文件(校验签名头 + XOR)
@@ -94,45 +95,44 @@ function decryptFile(opts) {
94
95
  return true;
95
96
  }
96
97
  /**
97
- * 递归批量处理目录(输出与源文件同名,仅目录可不同)
98
+ * 递归批量处理目录(输出与源文件同名;有 outputDir 时保持相对子目录结构)
98
99
  */
99
100
  function batchProcess(opts) {
100
101
  var _a;
101
102
  const { dirPath, mode, outputDir = null, sign = null, key = null } = opts;
102
103
  const extensions = (_a = opts.extensions) !== null && _a !== void 0 ? _a : defaultExtensionsForMode(mode);
103
- if (!fs_1.default.existsSync(dirPath)) {
104
- console.error(`目录不存在: ${dirPath}`);
104
+ const rootDir = path_1.default.resolve(dirPath);
105
+ if (!fs_1.default.existsSync(rootDir)) {
106
+ console.error("\x1b[31m%s\x1b[0m", `目录不存在: ${rootDir}`);
105
107
  return;
106
108
  }
107
- if (outputDir && !fs_1.default.existsSync(outputDir)) {
108
- fs_1.default.mkdirSync(outputDir, { recursive: true });
109
+ const outRoot = outputDir ? path_1.default.resolve(outputDir) : null;
110
+ if (outRoot) {
111
+ utils_1.utils.mkdir(outRoot);
109
112
  }
110
- const files = fs_1.default.readdirSync(dirPath);
113
+ const allFiles = utils_1.utils.findFiles(rootDir, extensions);
111
114
  let processedCount = 0;
112
- for (const file of files) {
113
- const fullPath = path_1.default.join(dirPath, file);
114
- const stat = fs_1.default.statSync(fullPath);
115
- if (stat.isDirectory()) {
116
- const subOutputDir = outputDir ? path_1.default.join(outputDir, file) : null;
117
- batchProcess({ dirPath: fullPath, mode, outputDir: subOutputDir, extensions, sign, key });
115
+ for (const fullPath of allFiles) {
116
+ const absIn = path_1.default.resolve(fullPath);
117
+ let outputFile;
118
+ if (outRoot) {
119
+ const rel = path_1.default.relative(rootDir, absIn);
120
+ outputFile = path_1.default.join(outRoot, rel);
121
+ utils_1.utils.mkdir(path_1.default.dirname(outputFile));
118
122
  }
119
123
  else {
120
- const ext = path_1.default.extname(file).toLowerCase();
121
- if (!extensions.includes(ext)) {
122
- continue;
123
- }
124
- const outputFile = outputDir ? path_1.default.join(outputDir, file) : fullPath;
125
- if (mode === "encrypt") {
126
- encryptFile({ inputPath: fullPath, outputPath: outputFile, sign, key });
127
- processedCount++;
128
- }
129
- else if (decryptFile({ inputPath: fullPath, outputPath: outputFile, sign, key })) {
130
- processedCount++;
131
- }
124
+ outputFile = absIn;
125
+ }
126
+ if (mode === "encrypt") {
127
+ encryptFile({ inputPath: absIn, outputPath: outputFile, sign, key });
128
+ processedCount++;
129
+ }
130
+ else if (decryptFile({ inputPath: absIn, outputPath: outputFile, sign, key })) {
131
+ processedCount++;
132
132
  }
133
133
  }
134
134
  if (processedCount > 0) {
135
- console.log(`\n${mode === "encrypt" ? "加密" : "解密"} 完成,共处理 ${processedCount} 个文件`);
135
+ console.info("\x1b[32m%s\x1b[0m", `\n${mode === "encrypt" ? "加密" : "解密"} 完成,共处理 ${processedCount} 个文件`);
136
136
  }
137
137
  }
138
138
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-cocos",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "scripts": {
5
5
  "clean": "rm -rf dist",
6
6
  "start": "node ./dist/index.js",