fast-cocos 1.1.12 → 1.1.14

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}://${xlsxName}/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}.ts`) : 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();
@@ -24,13 +24,15 @@ function main() {
24
24
  .requiredOption("-o, --output <directory>", "output directory")
25
25
  .requiredOption("--script <directory>", "script directory")
26
26
  .option("-b, --bundle <bundle>", "bundle name")
27
+ .option("--special <special>", "special conf")
27
28
  .parse(process.argv);
28
29
  const options = commander_1.program.opts();
29
30
  audio_1.audio.parse({
30
31
  source: options.source,
31
32
  output: options.output,
32
33
  script: options.script,
33
- bundle: options.bundle
34
+ bundle: options.bundle,
35
+ special: JSON.parse(options.special),
34
36
  });
35
37
  });
36
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-cocos",
3
- "version": "1.1.12",
3
+ "version": "1.1.14",
4
4
  "scripts": {
5
5
  "clean": "rm -rf dist",
6
6
  "start": "node ./dist/index.js",