fast-cocos 1.1.13 → 1.1.15

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,17 +19,14 @@ 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 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");
25
- const oldMp3 = utils_1.utils.findFiles(outAudioDir, [".mp3"]);
22
+ const { output, script, fileName, ref } = this.getBundleInfo(options, xlsxName);
23
+ const oldMp3 = utils_1.utils.findFiles(output, [".mp3"]);
26
24
  const newMp3 = [];
27
25
  // 读取 Excel 文件
28
26
  const workbook = xlsx_1.default.readFile(filePath);
29
27
  const sheet = workbook.Sheets[workbook.SheetNames[0]];
30
28
  const json = xlsx_1.default.utils.sheet_to_json(sheet);
31
29
  const fileDir = path_1.default.join(dir, xlsxName);
32
- const fileName = xlsxName.charAt(0).toUpperCase() + xlsxName.slice(1) + "Audio";
33
30
  let str = `export const ${fileName} = {`;
34
31
  const lastIndex = json.length - 1;
35
32
  // 将每一行配置转换成资源复制动作和 TS 映射项。
@@ -37,7 +34,7 @@ class Audio {
37
34
  const fileName = item["文件名"];
38
35
  const refName = item["引用名"];
39
36
  const srcPath = path_1.default.join(fileDir, `${fileName}.mp3`);
40
- const dstPath = path_1.default.join(outAudioDir, `${refName}.mp3`);
37
+ const dstPath = path_1.default.join(output, `${refName}.mp3`);
41
38
  if (fs_1.default.existsSync(srcPath)) {
42
39
  utils_1.utils.copyFileSync(srcPath, dstPath);
43
40
  newMp3.push(dstPath);
@@ -46,13 +43,7 @@ class Audio {
46
43
  if (key.includes(".")) {
47
44
  key = `"${refName}"`;
48
45
  }
49
- let value;
50
- if (isAny) {
51
- value = `"${bundle}://res/audio/${refName}"${index === lastIndex ? "" : ","} // ${fileName}`;
52
- }
53
- else {
54
- value = `"${xlsxName}://audio/${refName}"${index === lastIndex ? "" : ","} // ${fileName}`;
55
- }
46
+ const value = `"${ref}/${refName}"${index === lastIndex ? "" : ","} // ${fileName}`;
56
47
  str += `\n ${key}: ${value}`;
57
48
  }
58
49
  else {
@@ -61,8 +52,7 @@ class Audio {
61
52
  });
62
53
  str += "\n};\n";
63
54
  // 导出ts配置文件
64
- const tsFilePath = isAny ? utils_1.utils.stringFormat(options.script, xlsxName, fileName) : path_1.default.join(options.script, xlsxName, "config", `${fileName}.ts`);
65
- utils_1.utils.writeFileSync(tsFilePath, str);
55
+ utils_1.utils.writeFileSync(script, str);
66
56
  // 删除未使用mp3文件
67
57
  oldMp3
68
58
  // 找出本次导出结果中已经不存在的旧音频文件。
@@ -74,6 +64,41 @@ class Audio {
74
64
  });
75
65
  }
76
66
  }
67
+ /**
68
+ * 获取资源包信息
69
+ * @param options 音频导出选项
70
+ * @param xlsxName xlsx文件名
71
+ * @returns 资源包信息
72
+ */
73
+ getBundleInfo(options, xlsxName) {
74
+ const fileName = xlsxName.charAt(0).toUpperCase() + xlsxName.slice(1) + "Audio";
75
+ // 特殊指定的包
76
+ if (options.special[xlsxName]) {
77
+ const { output, script, ref } = options.special[xlsxName];
78
+ return {
79
+ ref,
80
+ fileName,
81
+ output,
82
+ script,
83
+ };
84
+ }
85
+ // 任意包
86
+ if (options.bundle == "{0}") {
87
+ return {
88
+ fileName,
89
+ ref: `${xlsxName}://res/audio/`,
90
+ output: utils_1.utils.stringFormat(options.output, xlsxName),
91
+ script: utils_1.utils.stringFormat(options.script, xlsxName, fileName),
92
+ };
93
+ }
94
+ // 旧版本模式
95
+ return {
96
+ fileName,
97
+ ref: `${options.bundle}://${xlsxName}/audio/`,
98
+ output: path_1.default.join(options.output, xlsxName, "audio"),
99
+ script: path_1.default.join(options.script, xlsxName, "config", `${fileName}.ts`),
100
+ };
101
+ }
77
102
  }
78
103
  exports.Audio = Audio;
79
104
  exports.audio = new Audio();
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const commander_1 = require("commander");
13
13
  const audio_1 = require("./audio");
14
+ const utils_1 = require("../../utils");
14
15
  /**
15
16
  * 解析音频导出命令参数,并启动音频配置生成流程。
16
17
  */
@@ -24,13 +25,15 @@ function main() {
24
25
  .requiredOption("-o, --output <directory>", "output directory")
25
26
  .requiredOption("--script <directory>", "script directory")
26
27
  .option("-b, --bundle <bundle>", "bundle name")
28
+ .option("--special <special>", "special conf")
27
29
  .parse(process.argv);
28
30
  const options = commander_1.program.opts();
29
31
  audio_1.audio.parse({
30
32
  source: options.source,
31
33
  output: options.output,
32
34
  script: options.script,
33
- bundle: options.bundle
35
+ bundle: options.bundle,
36
+ special: JSON.parse(utils_1.utils.decodeBase64(options.special)),
34
37
  });
35
38
  });
36
39
  }
package/dist/utils.js CHANGED
@@ -246,4 +246,12 @@ var utils;
246
246
  return template;
247
247
  }
248
248
  utils.stringFormat = stringFormat;
249
+ function decodeBase64(base64) {
250
+ return Buffer.from(base64, "base64").toString("utf-8");
251
+ }
252
+ utils.decodeBase64 = decodeBase64;
253
+ function encodeBase64(str) {
254
+ return Buffer.from(str).toString("base64");
255
+ }
256
+ utils.encodeBase64 = encodeBase64;
249
257
  })(utils || (exports.utils = utils = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-cocos",
3
- "version": "1.1.13",
3
+ "version": "1.1.15",
4
4
  "scripts": {
5
5
  "clean": "rm -rf dist",
6
6
  "start": "node ./dist/index.js",