fast-cocos 1.1.7 → 1.1.10
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/dist/audio/src/audio.js +5 -4
- package/dist/utils.js +19 -0
- package/dist/xor/src/xor.js +13 -23
- package/package.json +1 -1
package/dist/audio/src/audio.js
CHANGED
|
@@ -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
|
|
23
|
-
const
|
|
22
|
+
const isAny = options.bundle == '*';
|
|
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 (
|
|
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 = {}));
|
package/dist/xor/src/xor.js
CHANGED
|
@@ -31,13 +31,6 @@ function xorTransform(opts) {
|
|
|
31
31
|
}
|
|
32
32
|
return result;
|
|
33
33
|
}
|
|
34
|
-
function xor(data, key) {
|
|
35
|
-
let result = "";
|
|
36
|
-
for (let i = 0; i < data.length; i++) {
|
|
37
|
-
result += String.fromCharCode(data.charCodeAt(i) ^ key.charCodeAt(i % key.length));
|
|
38
|
-
}
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
34
|
/**
|
|
42
35
|
* 加密文件(签名头 + XOR),输出文件名与源文件 basename 相同(通常配合输出目录使用)
|
|
43
36
|
*/
|
|
@@ -59,14 +52,11 @@ function encryptFile(opts) {
|
|
|
59
52
|
throw new Error("输出路径解析失败");
|
|
60
53
|
}
|
|
61
54
|
const destPath = out;
|
|
62
|
-
const rawData = fs_1.default.readFileSync(opts.inputPath
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
const encrypted = finalSign + xor(rawData, finalKey);
|
|
69
|
-
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);
|
|
70
60
|
console.info("\x1b[32m%s\x1b[0m", `加密: ${opts.inputPath} -> ${destPath} [sign:${finalSign}, key:${finalKey.substring(0, 4)}...]`);
|
|
71
61
|
}
|
|
72
62
|
/**
|
|
@@ -91,16 +81,16 @@ function decryptFile(opts) {
|
|
|
91
81
|
throw new Error("输出路径解析失败");
|
|
92
82
|
}
|
|
93
83
|
const destPath = out;
|
|
94
|
-
const encryptedData = fs_1.default.readFileSync(opts.inputPath
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
console.
|
|
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)}`);
|
|
99
89
|
return false;
|
|
100
90
|
}
|
|
101
|
-
const
|
|
102
|
-
const decrypted =
|
|
103
|
-
fs_1.default.writeFileSync(destPath, decrypted
|
|
91
|
+
const dataWithoutSign = encryptedData.subarray(signSize);
|
|
92
|
+
const decrypted = xorTransform({ data: dataWithoutSign, key: finalKey });
|
|
93
|
+
fs_1.default.writeFileSync(destPath, decrypted);
|
|
104
94
|
console.info("\x1b[32m%s\x1b[0m", `解密: ${opts.inputPath} -> ${destPath} [sign:${finalSign}, key:${finalKey.substring(0, 4)}...]`);
|
|
105
95
|
return true;
|
|
106
96
|
}
|