@coze-arch/cli 0.0.36-alpha.3ab612 → 0.0.36-alpha.4e6503
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 +104 -68
- package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +19 -80
- package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +1 -1
- package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +1 -1
- package/lib/__templates__/expo/client/metro.config.js +1 -3
- package/lib/__templates__/expo/pnpm-lock.yaml +5 -5
- package/lib/__templates__/expo/server/package.json +2 -2
- package/lib/__templates__/expo/server/src/index.ts +1 -1
- package/lib/__templates__/expo/template.config.js +2 -11
- package/lib/__templates__/native-static/.coze +0 -2
- package/lib/__templates__/nextjs/.coze +0 -5
- package/lib/__templates__/nextjs/package.json +1 -1
- package/lib/__templates__/nextjs/pnpm-lock.yaml +5 -5
- package/lib/__templates__/nextjs/scripts/dev.sh +7 -205
- package/lib/__templates__/nextjs/template.config.js +2 -4
- package/lib/__templates__/nuxt-vue/.coze +0 -5
- package/lib/__templates__/nuxt-vue/package.json +1 -1
- package/lib/__templates__/nuxt-vue/pnpm-lock.yaml +5 -5
- package/lib/__templates__/nuxt-vue/scripts/dev.sh +1 -82
- package/lib/__templates__/pi-agent/package.json +1 -1
- package/lib/__templates__/pi-agent/pnpm-lock.yaml +5 -5
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +1 -1
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +68 -150
- package/lib/__templates__/taro/AGENTS.md +7 -11
- package/lib/__templates__/taro/README.md +4 -4
- package/lib/__templates__/taro/config/index.ts +2 -10
- package/lib/__templates__/taro/pnpm-lock.yaml +5 -5
- package/lib/__templates__/taro/server/package.json +1 -1
- package/lib/__templates__/taro/server/src/main.ts +2 -8
- package/lib/__templates__/templates.json +1 -51
- package/lib/__templates__/vite/package.json +1 -1
- package/lib/__templates__/vite/pnpm-lock.yaml +5 -5
- package/lib/__templates__/vite/scripts/build.ps1 +1 -1
- package/lib/__templates__/vite/scripts/dev.ps1 +65 -9
- package/lib/__templates__/vite/scripts/dev.sh +1 -82
- package/lib/__templates__/vite/scripts/start.ps1 +8 -2
- package/lib/__templates__/vite/template.config.js +2 -4
- package/lib/cli.js +204 -3590
- package/package.json +3 -5
- package/docs/deploy.md +0 -179
- package/lib/__templates__/native-static/scripts/serve.ps1 +0 -7
- package/lib/__templates__/nextjs/scripts/build.ps1 +0 -16
- package/lib/__templates__/nextjs/scripts/dev.ps1 +0 -63
- package/lib/__templates__/nextjs/scripts/prepare.ps1 +0 -18
- package/lib/__templates__/nextjs/scripts/start.ps1 +0 -11
- package/lib/__templates__/nextjs/scripts/validate.ps1 +0 -8
- package/lib/__templates__/nuxt-vue/scripts/build.ps1 +0 -12
- package/lib/__templates__/nuxt-vue/scripts/dev.ps1 +0 -63
- package/lib/__templates__/nuxt-vue/scripts/prepare.ps1 +0 -12
- package/lib/__templates__/nuxt-vue/scripts/start.ps1 +0 -11
- package/lib/__templates__/nuxt-vue/scripts/validate.ps1 +0 -8
- package/lib/__templates__/phaser/.coze +0 -18
- package/lib/__templates__/phaser/README.md +0 -45
- package/lib/__templates__/phaser/_gitignore +0 -23
- package/lib/__templates__/phaser/_npmrc +0 -14
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0001.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0002.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0003.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0004.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0005.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0006.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0007.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0008.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0009.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0010.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0011.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0012.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0013.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0014.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0015.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0016.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0017.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0018.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0019.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0020.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0021.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0022.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0023.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/frame_0024.png +0 -0
- package/lib/__templates__/phaser/assets/image_sequence/coze-game-loading/manifest.json +0 -11
- package/lib/__templates__/phaser/debug-runtime/flow-graph.json +0 -20
- package/lib/__templates__/phaser/index.html +0 -12
- package/lib/__templates__/phaser/package.json +0 -31
- package/lib/__templates__/phaser/pnpm-lock.yaml +0 -661
- package/lib/__templates__/phaser/scripts/build.ps1 +0 -12
- package/lib/__templates__/phaser/scripts/build.sh +0 -8
- package/lib/__templates__/phaser/scripts/dev.ps1 +0 -49
- package/lib/__templates__/phaser/scripts/dev.sh +0 -82
- package/lib/__templates__/phaser/scripts/prepare.ps1 +0 -8
- package/lib/__templates__/phaser/scripts/prepare.sh +0 -7
- package/lib/__templates__/phaser/scripts/spawn-detached.cjs +0 -29
- package/lib/__templates__/phaser/scripts/start.ps1 +0 -49
- package/lib/__templates__/phaser/scripts/start.sh +0 -82
- package/lib/__templates__/phaser/scripts/validate.ps1 +0 -7
- package/lib/__templates__/phaser/scripts/validate.sh +0 -7
- package/lib/__templates__/phaser/src/assets.ts +0 -15
- package/lib/__templates__/phaser/src/global.d.ts +0 -39
- package/lib/__templates__/phaser/src/main.ts +0 -28
- package/lib/__templates__/phaser/src/scene/BootScene.ts +0 -213
- package/lib/__templates__/phaser/src/scene/DevLoadingScene.ts +0 -69
- package/lib/__templates__/phaser/src/style.css +0 -28
- package/lib/__templates__/phaser/src/types.ts +0 -32
- package/lib/__templates__/phaser/src/utils/asset-loader.ts +0 -319
- package/lib/__templates__/phaser/src/utils/index.ts +0 -2
- package/lib/__templates__/phaser/src/utils/mark-editable.ts +0 -13
- package/lib/__templates__/phaser/template.config.js +0 -43
- package/lib/__templates__/phaser/tsconfig.json +0 -23
- package/lib/__templates__/phaser/vite.config.ts +0 -96
- package/lib/__templates__/phaser-static/.coze +0 -15
- package/lib/__templates__/phaser-static/README.md +0 -40
- package/lib/__templates__/phaser-static/_gitignore +0 -6
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0001.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0002.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0003.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0004.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0005.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0006.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0007.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0008.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0009.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0010.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0011.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0012.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0013.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0014.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0015.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0016.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0017.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0018.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0019.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0020.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0021.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0022.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0023.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/frame_0024.png +0 -0
- package/lib/__templates__/phaser-static/assets/image_sequence/coze-game-loading/manifest.json +0 -11
- package/lib/__templates__/phaser-static/debug-runtime/flow-graph.json +0 -20
- package/lib/__templates__/phaser-static/index.html +0 -17
- package/lib/__templates__/phaser-static/scripts/serve.ps1 +0 -7
- package/lib/__templates__/phaser-static/src/assets.js +0 -15
- package/lib/__templates__/phaser-static/src/main.js +0 -26
- package/lib/__templates__/phaser-static/src/phaser.js +0 -7
- package/lib/__templates__/phaser-static/src/scene/BootScene.js +0 -205
- package/lib/__templates__/phaser-static/src/scene/DevLoadingScene.js +0 -67
- package/lib/__templates__/phaser-static/src/style.css +0 -28
- package/lib/__templates__/phaser-static/src/utils/asset-loader.js +0 -267
- package/lib/__templates__/phaser-static/src/utils/index.js +0 -2
- package/lib/__templates__/phaser-static/src/utils/mark-editable.js +0 -3
- package/lib/__templates__/phaser-static/template.config.js +0 -35
- package/lib/deploy/package-project.js +0 -244
- package/lib/deploy/package-project.py +0 -183
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import { AUDIOS, IMAGES, IMAGE_SEQUENCES, VIDEOS } from '../assets.js';
|
|
2
|
-
|
|
3
|
-
const FRAME_KEY_MARKER = ':frame:';
|
|
4
|
-
const MANIFEST_KEY_SUFFIX = ':manifest';
|
|
5
|
-
|
|
6
|
-
const getFrameKey = (assetKey, frameIndex) =>
|
|
7
|
-
assetKey +
|
|
8
|
-
FRAME_KEY_MARKER +
|
|
9
|
-
String(frameIndex + 1).padStart(4, '0');
|
|
10
|
-
|
|
11
|
-
const getManifestKey = assetKey => assetKey + MANIFEST_KEY_SUFFIX;
|
|
12
|
-
|
|
13
|
-
const getFrameSource = (directory, frameIndex) =>
|
|
14
|
-
directory + '/frame_' + String(frameIndex + 1).padStart(4, '0') + '.png';
|
|
15
|
-
|
|
16
|
-
export const resolveAssetUrl = source => new URL(source, document.baseURI).href;
|
|
17
|
-
|
|
18
|
-
const isImageSequenceManifest = value => {
|
|
19
|
-
if (!value || typeof value !== 'object') {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
value.type === 'image_sequence' &&
|
|
25
|
-
typeof value.name === 'string' &&
|
|
26
|
-
typeof value.properties?.fps === 'number' &&
|
|
27
|
-
typeof value.properties.frame_count === 'number' &&
|
|
28
|
-
value.properties.frame_count > 0
|
|
29
|
-
);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const getImageSequenceManifest = (scene, assetKey) => {
|
|
33
|
-
const manifest = scene.cache.json.get(getManifestKey(assetKey));
|
|
34
|
-
if (!isImageSequenceManifest(manifest)) {
|
|
35
|
-
throw new Error('Invalid image sequence manifest: ' + assetKey);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return manifest;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const queueImageSequenceFrames = (scene, assetKey, directory, manifest) => {
|
|
42
|
-
Array.from(
|
|
43
|
-
{ length: manifest.properties.frame_count },
|
|
44
|
-
(_value, frameIndex) => {
|
|
45
|
-
scene.load.image(
|
|
46
|
-
getFrameKey(assetKey, frameIndex),
|
|
47
|
-
resolveAssetUrl(getFrameSource(directory, frameIndex)),
|
|
48
|
-
);
|
|
49
|
-
},
|
|
50
|
-
);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const queueImages = (scene, images) => {
|
|
54
|
-
Object.entries(images).forEach(([assetKey, source]) => {
|
|
55
|
-
scene.load.image(assetKey, resolveAssetUrl(source));
|
|
56
|
-
});
|
|
57
|
-
return Object.keys(images).length;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const queueVideos = (scene, videos) => {
|
|
61
|
-
Object.entries(videos).forEach(([assetKey, source]) => {
|
|
62
|
-
scene.load.video(assetKey, resolveAssetUrl(source));
|
|
63
|
-
});
|
|
64
|
-
return Object.keys(videos).length;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const queueAudios = (scene, audios) => {
|
|
68
|
-
Object.entries(audios).forEach(([assetKey, source]) => {
|
|
69
|
-
scene.load.audio(assetKey, resolveAssetUrl(source));
|
|
70
|
-
});
|
|
71
|
-
return Object.keys(audios).length;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const queueImageSequences = (scene, imageSequences) =>
|
|
75
|
-
Object.entries(imageSequences).reduce(
|
|
76
|
-
(fileCount, [assetKey, directory]) => {
|
|
77
|
-
const manifestKey = getManifestKey(assetKey);
|
|
78
|
-
const cachedManifest = scene.cache.json.get(manifestKey);
|
|
79
|
-
|
|
80
|
-
if (isImageSequenceManifest(cachedManifest)) {
|
|
81
|
-
queueImageSequenceFrames(scene, assetKey, directory, cachedManifest);
|
|
82
|
-
return fileCount + cachedManifest.properties.frame_count;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
scene.load.once(
|
|
86
|
-
'filecomplete-json-' + manifestKey,
|
|
87
|
-
(_key, _type, data) => {
|
|
88
|
-
if (!isImageSequenceManifest(data)) {
|
|
89
|
-
throw new Error('Invalid image sequence manifest: ' + assetKey);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
queueImageSequenceFrames(scene, assetKey, directory, data);
|
|
93
|
-
},
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
scene.load.json(
|
|
97
|
-
manifestKey,
|
|
98
|
-
resolveAssetUrl(directory + '/manifest.json'),
|
|
99
|
-
);
|
|
100
|
-
return fileCount + 1;
|
|
101
|
-
},
|
|
102
|
-
0,
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
export const loadAssets = (scene, collections) =>
|
|
106
|
-
queueImages(scene, collections.images ?? {}) +
|
|
107
|
-
queueImageSequences(scene, collections.imageSequences ?? {}) +
|
|
108
|
-
queueVideos(scene, collections.videos ?? {}) +
|
|
109
|
-
queueAudios(scene, collections.audios ?? {});
|
|
110
|
-
|
|
111
|
-
export const getImageSequenceRuntimeKeys = assetKey => ({
|
|
112
|
-
texture: getFrameKey(assetKey, 0),
|
|
113
|
-
animation: assetKey + ':animation',
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
export const getAssetKeyFromFileKey = fileKey =>
|
|
117
|
-
fileKey.split(FRAME_KEY_MARKER)[0]?.replace(MANIFEST_KEY_SUFFIX, '') ??
|
|
118
|
-
fileKey;
|
|
119
|
-
|
|
120
|
-
export const getAssetLabelFromFileKey = (fileKey, collections) => {
|
|
121
|
-
const assetKey = getAssetKeyFromFileKey(fileKey);
|
|
122
|
-
|
|
123
|
-
if (assetKey in (collections.images ?? {})) {
|
|
124
|
-
return '图片 ' + assetKey;
|
|
125
|
-
}
|
|
126
|
-
if (assetKey in (collections.imageSequences ?? {})) {
|
|
127
|
-
return '帧动画 ' + assetKey;
|
|
128
|
-
}
|
|
129
|
-
if (assetKey in (collections.videos ?? {})) {
|
|
130
|
-
return '视频 ' + assetKey;
|
|
131
|
-
}
|
|
132
|
-
if (assetKey in (collections.audios ?? {})) {
|
|
133
|
-
return '音频 ' + assetKey;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return assetKey;
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
export const registerImageSequenceAnimations = (scene, imageSequences) => {
|
|
140
|
-
Object.keys(imageSequences).forEach(assetKey => {
|
|
141
|
-
const manifest = getImageSequenceManifest(scene, assetKey);
|
|
142
|
-
const animationKey = getImageSequenceRuntimeKeys(assetKey).animation;
|
|
143
|
-
if (scene.anims.exists(animationKey)) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
scene.anims.create({
|
|
148
|
-
key: animationKey,
|
|
149
|
-
frames: Array.from(
|
|
150
|
-
{ length: manifest.properties.frame_count },
|
|
151
|
-
(_value, frameIndex) => ({ key: getFrameKey(assetKey, frameIndex) }),
|
|
152
|
-
),
|
|
153
|
-
frameRate: manifest.properties.fps,
|
|
154
|
-
repeat: -1,
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
const findAsset = assetKey => {
|
|
160
|
-
const matches = [];
|
|
161
|
-
|
|
162
|
-
if (Object.hasOwn(IMAGES, assetKey)) {
|
|
163
|
-
matches.push({
|
|
164
|
-
collections: { images: { [assetKey]: IMAGES[assetKey] } },
|
|
165
|
-
loadedAsset: { kind: 'image', key: assetKey },
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
if (Object.hasOwn(IMAGE_SEQUENCES, assetKey)) {
|
|
169
|
-
matches.push({
|
|
170
|
-
collections: {
|
|
171
|
-
imageSequences: { [assetKey]: IMAGE_SEQUENCES[assetKey] },
|
|
172
|
-
},
|
|
173
|
-
loadedAsset: {
|
|
174
|
-
kind: 'image-sequence',
|
|
175
|
-
key: assetKey,
|
|
176
|
-
...getImageSequenceRuntimeKeys(assetKey),
|
|
177
|
-
},
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
if (Object.hasOwn(VIDEOS, assetKey)) {
|
|
181
|
-
matches.push({
|
|
182
|
-
collections: { videos: { [assetKey]: VIDEOS[assetKey] } },
|
|
183
|
-
loadedAsset: { kind: 'video', key: assetKey },
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
if (Object.hasOwn(AUDIOS, assetKey)) {
|
|
187
|
-
matches.push({
|
|
188
|
-
collections: { audios: { [assetKey]: AUDIOS[assetKey] } },
|
|
189
|
-
loadedAsset: { kind: 'audio', key: assetKey },
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (matches.length === 0) {
|
|
194
|
-
throw new Error('Asset not found: ' + assetKey);
|
|
195
|
-
}
|
|
196
|
-
if (matches.length > 1) {
|
|
197
|
-
throw new Error('Duplicate asset key: ' + assetKey);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return matches[0];
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
const isAssetLoaded = (scene, loadedAsset) => {
|
|
204
|
-
switch (loadedAsset.kind) {
|
|
205
|
-
case 'image':
|
|
206
|
-
return scene.textures.exists(loadedAsset.key);
|
|
207
|
-
case 'image-sequence':
|
|
208
|
-
return scene.anims.exists(loadedAsset.animation);
|
|
209
|
-
case 'video':
|
|
210
|
-
return scene.cache.video.exists(loadedAsset.key);
|
|
211
|
-
case 'audio':
|
|
212
|
-
return scene.cache.audio.exists(loadedAsset.key);
|
|
213
|
-
default:
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
export const loadAsset = async (scene, assetKey) => {
|
|
219
|
-
const { collections, loadedAsset } = findAsset(assetKey);
|
|
220
|
-
if (isAssetLoaded(scene, loadedAsset)) {
|
|
221
|
-
return loadedAsset;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
return new Promise((resolve, reject) => {
|
|
225
|
-
const cleanup = () => {
|
|
226
|
-
scene.load.off('complete', onComplete);
|
|
227
|
-
scene.load.off('loaderror', onLoadError);
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
const onComplete = () => {
|
|
231
|
-
cleanup();
|
|
232
|
-
try {
|
|
233
|
-
if (loadedAsset.kind === 'image-sequence') {
|
|
234
|
-
registerImageSequenceAnimations(
|
|
235
|
-
scene,
|
|
236
|
-
collections.imageSequences ?? {},
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
resolve(loadedAsset);
|
|
240
|
-
} catch (error) {
|
|
241
|
-
reject(error);
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
const onLoadError = file => {
|
|
246
|
-
if (getAssetKeyFromFileKey(file.key) !== assetKey) {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
cleanup();
|
|
251
|
-
reject(new Error('Failed to load asset: ' + assetKey));
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
scene.load.once('complete', onComplete);
|
|
255
|
-
scene.load.on('loaderror', onLoadError);
|
|
256
|
-
|
|
257
|
-
try {
|
|
258
|
-
loadAssets(scene, collections);
|
|
259
|
-
if (!scene.load.isLoading()) {
|
|
260
|
-
scene.load.start();
|
|
261
|
-
}
|
|
262
|
-
} catch (error) {
|
|
263
|
-
cleanup();
|
|
264
|
-
reject(error);
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export const paramsSchema = {
|
|
10
|
-
type: 'object',
|
|
11
|
-
properties: {
|
|
12
|
-
appName: {
|
|
13
|
-
type: 'string',
|
|
14
|
-
minLength: 1,
|
|
15
|
-
pattern: '^[a-z0-9-]+$',
|
|
16
|
-
description:
|
|
17
|
-
'Application name (lowercase, alphanumeric and hyphens only)',
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
required: [],
|
|
21
|
-
additionalProperties: false,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const config = {
|
|
25
|
-
description:
|
|
26
|
-
'Phaser Static(纯静态 2D 游戏):coze-dev init ${COZE_WORKSPACE_PATH} --template phaser-static\n' +
|
|
27
|
-
'- 适用:浏览器原生 JavaScript ESM 的 Phaser 3 游戏。\n' +
|
|
28
|
-
'- Phaser 与 Phaser Bridge 从 CDN 加载;无需 npm、Vite 或 TypeScript。',
|
|
29
|
-
paramsSchema,
|
|
30
|
-
defaultParams: {
|
|
31
|
-
appName: 'phaser-static-game',
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export default config;
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Create the source tar.gz consumed by CreateDeployHistoryV2.
|
|
5
|
-
*
|
|
6
|
-
* Keep this implementation behaviorally aligned with package-project.py, which
|
|
7
|
-
* remains in this directory as the Python reference/backup implementation.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
'use strict';
|
|
11
|
-
|
|
12
|
-
const {
|
|
13
|
-
existsSync,
|
|
14
|
-
mkdirSync,
|
|
15
|
-
readFileSync,
|
|
16
|
-
readdirSync,
|
|
17
|
-
statSync,
|
|
18
|
-
} = require('node:fs');
|
|
19
|
-
const path = require('node:path');
|
|
20
|
-
const { spawnSync } = require('node:child_process');
|
|
21
|
-
|
|
22
|
-
const TOML = require('@iarna/toml');
|
|
23
|
-
const tar = require('tar');
|
|
24
|
-
|
|
25
|
-
const EXCLUDED_PARTS = new Set([
|
|
26
|
-
'.codegraph',
|
|
27
|
-
'.next',
|
|
28
|
-
'.venv',
|
|
29
|
-
'__pycache__',
|
|
30
|
-
'node_modules',
|
|
31
|
-
'site-packages',
|
|
32
|
-
]);
|
|
33
|
-
const LOCAL_METADATA_FILES = new Set([
|
|
34
|
-
'.coze-deploy-upload.json',
|
|
35
|
-
'.host.json',
|
|
36
|
-
]);
|
|
37
|
-
const UPLOAD_SESSION_TEMP_PREFIX = '.coze-deploy-upload-';
|
|
38
|
-
const REPRODUCIBLE_ARCHIVE_MTIME = new Date(0);
|
|
39
|
-
const PROJECT_METADATA_FILE_MODE = 0o644;
|
|
40
|
-
|
|
41
|
-
const parseArguments = argv => {
|
|
42
|
-
const positional = [];
|
|
43
|
-
let pages = false;
|
|
44
|
-
for (const argument of argv) {
|
|
45
|
-
if (argument === '--pages') {
|
|
46
|
-
pages = true;
|
|
47
|
-
} else if (argument.startsWith('-')) {
|
|
48
|
-
throw new Error(`Unknown argument: ${argument}`);
|
|
49
|
-
} else {
|
|
50
|
-
positional.push(argument);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (positional.length !== 2) {
|
|
54
|
-
throw new Error(
|
|
55
|
-
'Usage: package-project.js <source_dir> <output_path> [--pages]',
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
sourceDir: path.resolve(positional[0]),
|
|
60
|
-
outputPath: path.resolve(positional[1]),
|
|
61
|
-
pages,
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const buildCommandEnv = () => {
|
|
66
|
-
const env = { ...process.env };
|
|
67
|
-
const cliBinDir = path.resolve(__dirname, '..', '..', 'node_modules', '.bin');
|
|
68
|
-
env.PATH = env.PATH
|
|
69
|
-
? `${cliBinDir}${path.delimiter}${env.PATH}`
|
|
70
|
-
: cliBinDir;
|
|
71
|
-
return env;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const readCozeConfig = sourceDir => {
|
|
75
|
-
const cozePath = path.join(sourceDir, '.coze');
|
|
76
|
-
if (!existsSync(cozePath)) {
|
|
77
|
-
return {};
|
|
78
|
-
}
|
|
79
|
-
return TOML.parse(readFileSync(cozePath, 'utf8'));
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const readCommand = (config, section, key) => {
|
|
83
|
-
const command = config[section]?.[key];
|
|
84
|
-
if (command === undefined) {
|
|
85
|
-
return undefined;
|
|
86
|
-
}
|
|
87
|
-
if (
|
|
88
|
-
!Array.isArray(command) ||
|
|
89
|
-
!command.every(part => typeof part === 'string' && part.length > 0)
|
|
90
|
-
) {
|
|
91
|
-
throw new Error(`.coze ${section}.${key} must be a string array`);
|
|
92
|
-
}
|
|
93
|
-
return command;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const readPlatformCommand = (config, section, key) => {
|
|
97
|
-
const defaultCommand = readCommand(config, section, key);
|
|
98
|
-
const windowsCommand = process.platform === 'win32'
|
|
99
|
-
? readCommand(config, section, `${key}_win`)
|
|
100
|
-
: undefined;
|
|
101
|
-
|
|
102
|
-
if (windowsCommand?.length) {
|
|
103
|
-
return { command: windowsCommand, key: `${key}_win` };
|
|
104
|
-
}
|
|
105
|
-
return defaultCommand?.length ? { command: defaultCommand, key } : undefined;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const runCommand = (command, sourceDir, env) => {
|
|
109
|
-
const result = spawnSync(command[0], command.slice(1), {
|
|
110
|
-
cwd: sourceDir,
|
|
111
|
-
env,
|
|
112
|
-
stdio: 'inherit',
|
|
113
|
-
});
|
|
114
|
-
if (result.error) {
|
|
115
|
-
throw result.error;
|
|
116
|
-
}
|
|
117
|
-
if (result.status !== 0) {
|
|
118
|
-
throw new Error(
|
|
119
|
-
`Command ${command.join(' ')} exited with code ${String(result.status)}`,
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const runPackCommand = sourceDir => {
|
|
125
|
-
const configuredCommand = readPlatformCommand(
|
|
126
|
-
readCozeConfig(sourceDir),
|
|
127
|
-
'dev',
|
|
128
|
-
'pack',
|
|
129
|
-
);
|
|
130
|
-
if (configuredCommand) {
|
|
131
|
-
process.stderr.write(
|
|
132
|
-
`[package] Running dev.${configuredCommand.key}: ${configuredCommand.command.join(' ')}\n`,
|
|
133
|
-
);
|
|
134
|
-
runCommand(configuredCommand.command, sourceDir, buildCommandEnv());
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const hasIndexHtml = directory =>
|
|
139
|
-
existsSync(path.join(directory, 'index.html')) &&
|
|
140
|
-
statSync(path.join(directory, 'index.html')).isFile();
|
|
141
|
-
|
|
142
|
-
const preparePagesOutput = sourceDir => {
|
|
143
|
-
if (hasIndexHtml(sourceDir)) {
|
|
144
|
-
process.stderr.write(`[package] Pages static source: ${sourceDir}\n`);
|
|
145
|
-
return sourceDir;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const cozePath = path.join(sourceDir, '.coze');
|
|
149
|
-
if (!existsSync(cozePath)) {
|
|
150
|
-
throw new Error(
|
|
151
|
-
'Pages source contains neither index.html nor a .coze file. ' +
|
|
152
|
-
'Add index.html or configure a Next.js build in .coze.',
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const config = readCozeConfig(sourceDir);
|
|
157
|
-
const template = config.project?.template;
|
|
158
|
-
if (typeof template !== 'string' || template.trim().toLowerCase() !== 'nextjs') {
|
|
159
|
-
throw new Error(
|
|
160
|
-
'Pages source contains no index.html; .coze project.template must be "nextjs"',
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
if (!readCommand(config, 'deploy', 'build')) {
|
|
164
|
-
throw new Error(
|
|
165
|
-
'Pages source contains no index.html; .coze deploy.build is required',
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
process.stderr.write(`[package] Pages Next.js source: ${sourceDir}\n`);
|
|
169
|
-
return sourceDir;
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
const shouldInclude = (archivePath, excludeCozeFile = false) => {
|
|
173
|
-
const parts = archivePath.split(/[\\/]/u);
|
|
174
|
-
if (
|
|
175
|
-
parts.some(
|
|
176
|
-
part =>
|
|
177
|
-
LOCAL_METADATA_FILES.has(part) ||
|
|
178
|
-
(part.startsWith(UPLOAD_SESSION_TEMP_PREFIX) && part.endsWith('.tmp')),
|
|
179
|
-
)
|
|
180
|
-
) {
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
if (parts.includes('.env')) {
|
|
184
|
-
return false;
|
|
185
|
-
}
|
|
186
|
-
if (excludeCozeFile && parts.includes('.coze')) {
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
if (parts.some(part => part.startsWith('.git'))) {
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
return !parts.some(part => EXCLUDED_PARTS.has(part));
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
const createTarGzWithoutRoot = async (sourceDir, outputPath, excludeCozeFile = false) => {
|
|
196
|
-
if (!existsSync(sourceDir) || !statSync(sourceDir).isDirectory()) {
|
|
197
|
-
throw new Error(`source directory does not exist: ${sourceDir}`);
|
|
198
|
-
}
|
|
199
|
-
mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
200
|
-
process.stderr.write(`[package] Creating archive from: ${sourceDir}\n`);
|
|
201
|
-
const resolvedOutputPath = path.resolve(outputPath);
|
|
202
|
-
const entries = readdirSync(sourceDir)
|
|
203
|
-
.filter(entry =>
|
|
204
|
-
entry !== '.codegraph' &&
|
|
205
|
-
path.resolve(sourceDir, entry) !== resolvedOutputPath,
|
|
206
|
-
)
|
|
207
|
-
.sort();
|
|
208
|
-
await tar.create(
|
|
209
|
-
{
|
|
210
|
-
cwd: sourceDir,
|
|
211
|
-
file: outputPath,
|
|
212
|
-
filter: archivePath => shouldInclude(archivePath, excludeCozeFile),
|
|
213
|
-
gzip: true,
|
|
214
|
-
mtime: REPRODUCIBLE_ARCHIVE_MTIME,
|
|
215
|
-
onWriteEntry: entry => {
|
|
216
|
-
if (entry.path === '.coze' && entry.stat?.isFile()) {
|
|
217
|
-
entry.stat.mode = PROJECT_METADATA_FILE_MODE;
|
|
218
|
-
}
|
|
219
|
-
},
|
|
220
|
-
portable: true,
|
|
221
|
-
},
|
|
222
|
-
entries,
|
|
223
|
-
);
|
|
224
|
-
const size = statSync(outputPath).size;
|
|
225
|
-
if (size <= 0) {
|
|
226
|
-
throw new Error('source archive is empty');
|
|
227
|
-
}
|
|
228
|
-
process.stderr.write(`[package] Archive ready: ${String(size)} bytes\n`);
|
|
229
|
-
return size;
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
const main = async () => {
|
|
233
|
-
const { sourceDir, outputPath, pages } = parseArguments(process.argv.slice(2));
|
|
234
|
-
const packageDir = pages
|
|
235
|
-
? preparePagesOutput(sourceDir)
|
|
236
|
-
: (runPackCommand(sourceDir), sourceDir);
|
|
237
|
-
const size = await createTarGzWithoutRoot(packageDir, outputPath, pages);
|
|
238
|
-
process.stdout.write(`${String(size)}\n`);
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
main().catch(error => {
|
|
242
|
-
process.stderr.write(`${error instanceof Error ? error.stack : String(error)}\n`);
|
|
243
|
-
process.exitCode = 1;
|
|
244
|
-
});
|