fast-cocos 1.1.8 → 1.1.11

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.
@@ -19,8 +19,9 @@ class Audio {
19
19
  for (const filePath of files) {
20
20
  const dir = path_1.default.dirname(filePath);
21
21
  const xlsxName = path_1.default.basename(filePath, path_1.default.extname(filePath));
22
- const bundle = options.bundle || xlsxName;
23
- const outAudioDir = path_1.default.join(options.output, xlsxName, "audio");
22
+ const isAny = options.bundle == '{0}';
23
+ const bundle = isAny ? xlsxName : options.bundle;
24
+ const outAudioDir = isAny ? utils_1.utils.stringFormat(options.output, xlsxName) : path_1.default.join(options.output, xlsxName, "audio");
24
25
  const oldMp3 = utils_1.utils.findFiles(outAudioDir, [".mp3"]);
25
26
  const newMp3 = [];
26
27
  // 读取 Excel 文件
@@ -46,7 +47,7 @@ class Audio {
46
47
  key = `"${refName}"`;
47
48
  }
48
49
  let value;
49
- if (options.bundle) {
50
+ if (isAny) {
50
51
  value = `"${bundle}://${xlsxName}/audio/${refName}"${index === lastIndex ? "" : ","} // ${fileName}`;
51
52
  }
52
53
  else {
@@ -60,7 +61,7 @@ class Audio {
60
61
  });
61
62
  str += "\n};\n";
62
63
  // 导出ts配置文件
63
- const tsFilePath = path_1.default.join(options.script, xlsxName, "config", `${fileName}.ts`);
64
+ const tsFilePath = isAny ? utils_1.utils.stringFormat(options.script, xlsxName) : path_1.default.join(options.script, xlsxName, "config", `${fileName}.ts`);
64
65
  utils_1.utils.writeFileSync(tsFilePath, str);
65
66
  // 删除未使用mp3文件
66
67
  oldMp3
package/dist/utils.js CHANGED
@@ -227,4 +227,23 @@ var utils;
227
227
  }
228
228
  }
229
229
  utils.rmSync = rmSync;
230
+ /**
231
+ * 字符串格式化
232
+ * @param template
233
+ * @param args
234
+ * @example let str = "my name is {0}, my age is {1}", stringFormat(str,"test",30) => my name is test, my age is 30
235
+ * */
236
+ function stringFormat(template, ...args) {
237
+ if (!template) {
238
+ return "";
239
+ }
240
+ args.forEach((arg, idx) => {
241
+ const reg = new RegExp(`{[${idx}]}`, "gmi");
242
+ template = template.replace(reg, () => {
243
+ return String(arg);
244
+ });
245
+ });
246
+ return template;
247
+ }
248
+ utils.stringFormat = stringFormat;
230
249
  })(utils || (exports.utils = utils = {}));
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.XOR_VERSION = exports.DEFAULT_IMAGE_EXTS = exports.DEFAULT_KEY = exports.DEFAULT_SIGN = void 0;
7
+ exports.xorTransform = xorTransform;
7
8
  exports.encryptFile = encryptFile;
8
9
  exports.decryptFile = decryptFile;
9
10
  exports.batchProcess = batchProcess;
@@ -18,10 +19,15 @@ exports.DEFAULT_KEY = "Xk9#mQ2$vL5@nR8w";
18
19
  /** 默认参与批量处理的图片扩展名 */
19
20
  exports.DEFAULT_IMAGE_EXTS = [".png", ".jpg", ".jpeg", ".webp", ".bmp"];
20
21
  exports.XOR_VERSION = "1.0.0";
21
- function xor(data, key) {
22
- let result = "";
22
+ /**
23
+ * XOR 加密/解密(对称)
24
+ */
25
+ function xorTransform(opts) {
26
+ const { data, key } = opts;
27
+ const result = Buffer.alloc(data.length);
28
+ const keyLen = key.length;
23
29
  for (let i = 0; i < data.length; i++) {
24
- result += String.fromCharCode(data.charCodeAt(i) ^ key.charCodeAt(i % key.length));
30
+ result[i] = data[i] ^ key.charCodeAt(i % keyLen);
25
31
  }
26
32
  return result;
27
33
  }
@@ -46,14 +52,11 @@ function encryptFile(opts) {
46
52
  throw new Error("输出路径解析失败");
47
53
  }
48
54
  const destPath = out;
49
- const rawData = fs_1.default.readFileSync(opts.inputPath, { encoding: "binary" });
50
- const fileSign = rawData.slice(0, finalSign.length);
51
- if (fileSign == finalSign) {
52
- console.log(`跳过(已加密): ${opts.inputPath}`);
53
- return;
54
- }
55
- const encrypted = finalSign + xor(rawData, finalKey);
56
- fs_1.default.writeFileSync(destPath, encrypted, { encoding: "binary" });
55
+ const rawData = fs_1.default.readFileSync(opts.inputPath);
56
+ const encrypted = xorTransform({ data: rawData, key: finalKey });
57
+ const signature = Buffer.from(finalSign, "utf-8");
58
+ const output = Buffer.concat([signature, encrypted]);
59
+ fs_1.default.writeFileSync(destPath, output);
57
60
  console.info("\x1b[32m%s\x1b[0m", `加密: ${opts.inputPath} -> ${destPath} [sign:${finalSign}, key:${finalKey.substring(0, 4)}...]`);
58
61
  }
59
62
  /**
@@ -78,16 +81,16 @@ function decryptFile(opts) {
78
81
  throw new Error("输出路径解析失败");
79
82
  }
80
83
  const destPath = out;
81
- const encryptedData = fs_1.default.readFileSync(opts.inputPath, { encoding: "binary" });
82
- const fileSign = encryptedData.slice(0, finalSign.length);
83
- console.log("文件签名:", fileSign);
84
- if (fileSign != finalSign) {
85
- console.info("\x1b[31m%s\x1b[0m", `跳过(签名不匹配): ${opts.inputPath}`);
84
+ const encryptedData = fs_1.default.readFileSync(opts.inputPath);
85
+ const signBuffer = Buffer.from(finalSign, "utf-8");
86
+ const signSize = signBuffer.length;
87
+ if (encryptedData.length < signSize || !encryptedData.subarray(0, signSize).equals(signBuffer)) {
88
+ console.log(`跳过(签名不匹配): ${path_1.default.basename(opts.inputPath)}`);
86
89
  return false;
87
90
  }
88
- const encrypted = encryptedData.slice(finalSign.length, encryptedData.length);
89
- const decrypted = xor(encrypted, finalKey);
90
- fs_1.default.writeFileSync(destPath, decrypted, { encoding: "binary" });
91
+ const dataWithoutSign = encryptedData.subarray(signSize);
92
+ const decrypted = xorTransform({ data: dataWithoutSign, key: finalKey });
93
+ fs_1.default.writeFileSync(destPath, decrypted);
91
94
  console.info("\x1b[32m%s\x1b[0m", `解密: ${opts.inputPath} -> ${destPath} [sign:${finalSign}, key:${finalKey.substring(0, 4)}...]`);
92
95
  return true;
93
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-cocos",
3
- "version": "1.1.8",
3
+ "version": "1.1.11",
4
4
  "scripts": {
5
5
  "clean": "rm -rf dist",
6
6
  "start": "node ./dist/index.js",