@ttmg/cli 0.3.1-unity.8 → 0.3.1-unity.9

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.
@@ -83,12 +83,12 @@ async function compile(context = {}) {
83
83
  chalk.yellow.underline(outputDir),
84
84
  ),
85
85
  );
86
- if (outputDir && fs.existsSync(outputDir)) {
87
- fs.rmSync(outputDir, { recursive: true, force: true });
88
- }
89
- if (outputDir) {
90
- fs.mkdirSync(outputDir, { recursive: true });
91
- }
86
+ // if (outputDir) {
87
+ // if (fs.existsSync(outputDir)) {
88
+ // fs.rmSync(outputDir, { recursive: true, force: true });
89
+ // }
90
+ // fs.mkdirSync(outputDir, { recursive: true });
91
+ // }
92
92
  } catch (e) {
93
93
  // 目录操作失败也上报
94
94
  parentPort?.postMessage({
@@ -100,10 +100,21 @@ async function compile(context = {}) {
100
100
 
101
101
  parentPort?.postMessage({ type: 'status', status: 'start' });
102
102
 
103
+ const outputTempDir = path.join(
104
+ entryDir,
105
+ '__TTMG_TEMP__',
106
+ clientKey + '_compile_' + Date.now().toString(),
107
+ );
108
+ console.log(
109
+ chalk(
110
+ `🔍 Game local debug assets temp directory`,
111
+ chalk.yellow.underline(outputTempDir),
112
+ ),
113
+ );
103
114
  // 调用打包
104
115
  const { isSuccess, errorMsg, packages } = await debugPkgs({
105
116
  entry: entryDir,
106
- output: outputDir,
117
+ output: outputTempDir,
107
118
  dev: {
108
119
  enable: true,
109
120
  port: devPort,
@@ -122,6 +133,15 @@ async function compile(context = {}) {
122
133
  // spawnOptions: { stdio: ['ignore', 'pipe', 'pipe'] },
123
134
  // concurrency: 4,
124
135
  });
136
+ if (fs.existsSync(outputDir)) {
137
+ // 删除旧输出目录
138
+ fs.rmSync(outputDir, { recursive: true, force: true });
139
+ // 复制临时目录到输出目录
140
+ // 直接替换 outputDir 内容,避免生成 __TTMG_TEMP__ 子目录
141
+ fs.cpSync(outputTempDir, outputDir, { recursive: true });
142
+ // 删除临时目录
143
+ fs.rmSync(outputTempDir, { recursive: true, force: true });
144
+ }
125
145
  if (fs.existsSync(path.join(outputDir, '__TTMG_TEMP__'))) {
126
146
  fs.rmSync(path.join(outputDir, '__TTMG_TEMP__'), {
127
147
  recursive: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttmg/cli",
3
- "version": "0.3.1-unity.8",
3
+ "version": "0.3.1-unity.9",
4
4
  "description": "TikTok Mini Game Command Line Tool",
5
5
  "license": "ISC",
6
6
  "bin": {