@playcraft/build 0.1.54 → 0.1.56-beta
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/README.md
CHANGED
|
@@ -84,6 +84,9 @@ export class GenericAdapter {
|
|
|
84
84
|
{ file: 'pnpm-lock.yaml', manager: 'pnpm' },
|
|
85
85
|
{ file: 'yarn.lock', manager: 'yarn' },
|
|
86
86
|
{ file: 'package-lock.json', manager: 'npm' },
|
|
87
|
+
{ file: 'npm-shrinkwrap.json', manager: 'npm' },
|
|
88
|
+
{ file: 'bun.lock', manager: 'bun' },
|
|
89
|
+
{ file: 'bun.lockb', manager: 'bun' },
|
|
87
90
|
];
|
|
88
91
|
for (const { file, manager } of lockFiles) {
|
|
89
92
|
try {
|
|
@@ -174,7 +177,7 @@ export class GenericAdapter {
|
|
|
174
177
|
*/
|
|
175
178
|
async runNpmBuild(packageManager, script) {
|
|
176
179
|
const cmd = packageManager === 'npm' ? 'npm' : packageManager;
|
|
177
|
-
const args = packageManager === 'npm' ? ['run', script] : [script];
|
|
180
|
+
const args = packageManager === 'npm' || packageManager === 'bun' ? ['run', script] : [script];
|
|
178
181
|
console.log(`[GenericAdapter] 运行: ${cmd} ${args.join(' ')}`);
|
|
179
182
|
await this.runCommandWithTimeout(cmd, args, {
|
|
180
183
|
cwd: this.projectDir,
|
|
@@ -342,6 +345,12 @@ export class GenericAdapter {
|
|
|
342
345
|
const entries = await fs.readdir(src, { withFileTypes: true });
|
|
343
346
|
for (const entry of entries) {
|
|
344
347
|
const srcPath = path.join(src, entry.name);
|
|
348
|
+
if (entry.name === '.playcraft.json')
|
|
349
|
+
continue;
|
|
350
|
+
if (path.basename(src) === '.playcraft' && ['skills', 'skill-artifacts', 'video-replication', 'workspace-context.json'].includes(entry.name))
|
|
351
|
+
continue;
|
|
352
|
+
if (entry.name === 'user_uploads' && path.basename(src) === '.tmp')
|
|
353
|
+
continue;
|
|
345
354
|
const destPath = path.join(dest, entry.name);
|
|
346
355
|
// 安全检查:确保目标路径在输出目录内
|
|
347
356
|
const resolvedDest = path.resolve(destPath);
|
|
@@ -36,6 +36,15 @@ export declare class PlayableScriptsAdapter {
|
|
|
36
36
|
* devkit 是 PlayCraft 平台内置的构建工具。
|
|
37
37
|
*/
|
|
38
38
|
baseBuild(): Promise<BaseBuildOutput>;
|
|
39
|
+
/**
|
|
40
|
+
* 记录构建期间会被改写的项目文件,返回还原函数。
|
|
41
|
+
*
|
|
42
|
+
* mergeConfig 会把 builds.config.js 包一层并生成 .bak,ensureBuildScripts 会改写 package.json。
|
|
43
|
+
* 平台导出在项目副本里构建,不受影响;但直接在用户目录执行 `playcraft build`(本地开发、
|
|
44
|
+
* 云工作区 Agent 在终端里验证)时,这些改写会留在仓库里,再构建一次还会再包一层。
|
|
45
|
+
*/
|
|
46
|
+
private snapshotProjectFiles;
|
|
47
|
+
private runBaseBuild;
|
|
39
48
|
/**
|
|
40
49
|
* 扫描项目中的可用主题
|
|
41
50
|
* 主题目录: src/theme/ 下的子目录(排除 index.ts 等文件)
|
|
@@ -136,6 +136,47 @@ export class PlayableScriptsAdapter {
|
|
|
136
136
|
*/
|
|
137
137
|
async baseBuild() {
|
|
138
138
|
console.log('[PlayableScriptsAdapter] 开始 playable-scripts 构建(使用平台内置 devkit)');
|
|
139
|
+
// 构建会就地改写项目文件;结束后(无论成败)还原,避免改写被提交进用户仓库
|
|
140
|
+
const restoreProjectFiles = await this.snapshotProjectFiles();
|
|
141
|
+
try {
|
|
142
|
+
return await this.runBaseBuild();
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
await restoreProjectFiles();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* 记录构建期间会被改写的项目文件,返回还原函数。
|
|
150
|
+
*
|
|
151
|
+
* mergeConfig 会把 builds.config.js 包一层并生成 .bak,ensureBuildScripts 会改写 package.json。
|
|
152
|
+
* 平台导出在项目副本里构建,不受影响;但直接在用户目录执行 `playcraft build`(本地开发、
|
|
153
|
+
* 云工作区 Agent 在终端里验证)时,这些改写会留在仓库里,再构建一次还会再包一层。
|
|
154
|
+
*/
|
|
155
|
+
async snapshotProjectFiles() {
|
|
156
|
+
const files = ['builds.config.js', 'builds.config.js.bak', 'package.json'].map((name) => path.join(this.projectDir, name));
|
|
157
|
+
const snapshot = await Promise.all(files.map(async (file) => {
|
|
158
|
+
try {
|
|
159
|
+
return { file, content: await fs.readFile(file) };
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return { file, content: null };
|
|
163
|
+
}
|
|
164
|
+
}));
|
|
165
|
+
return async () => {
|
|
166
|
+
for (const { file, content } of snapshot) {
|
|
167
|
+
try {
|
|
168
|
+
if (content === null)
|
|
169
|
+
await fs.rm(file, { force: true });
|
|
170
|
+
else
|
|
171
|
+
await fs.writeFile(file, content);
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
console.warn(`[PlayableScriptsAdapter] ⚠️ 无法还原 ${path.relative(this.projectDir, file)}: ${error.message}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
async runBaseBuild() {
|
|
139
180
|
// 1. 合并配置
|
|
140
181
|
await this.mergeConfig();
|
|
141
182
|
// 2. 构建 CLI 参数
|