cocos2d-cli 1.6.5 → 2.0.0

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.
Files changed (61) hide show
  1. package/dist/bin/cocos2d-cli.js +64 -0
  2. package/dist/src/commands/add-component.js +3 -0
  3. package/dist/src/commands/add.js +3 -0
  4. package/dist/src/commands/build.js +6 -0
  5. package/dist/src/commands/create-scene.js +3 -0
  6. package/dist/src/commands/get.js +3 -0
  7. package/dist/src/commands/prefab-create.js +109 -0
  8. package/dist/src/commands/remove-component.js +3 -0
  9. package/dist/src/commands/remove.js +3 -0
  10. package/dist/src/commands/screenshot.js +41 -0
  11. package/dist/src/commands/set-component.js +3 -0
  12. package/dist/src/commands/set.js +3 -0
  13. package/dist/src/commands/tree.js +24 -0
  14. package/{src → dist/src}/lib/cc/CCButton.js +115 -122
  15. package/{src → dist/src}/lib/cc/CCCamera.js +83 -93
  16. package/{src → dist/src}/lib/cc/CCCanvas.js +49 -54
  17. package/{src → dist/src}/lib/cc/CCColor.js +30 -32
  18. package/{src → dist/src}/lib/cc/CCComponent.js +39 -60
  19. package/{src → dist/src}/lib/cc/CCLabel.js +139 -146
  20. package/{src → dist/src}/lib/cc/CCNode.js +190 -256
  21. package/{src → dist/src}/lib/cc/CCObject.js +19 -23
  22. package/{src → dist/src}/lib/cc/CCPrefab.js +219 -242
  23. package/{src → dist/src}/lib/cc/CCRect.js +30 -32
  24. package/{src → dist/src}/lib/cc/CCRichText.js +38 -44
  25. package/{src → dist/src}/lib/cc/CCScene.js +32 -42
  26. package/dist/src/lib/cc/CCSceneAsset.js +242 -0
  27. package/{src → dist/src}/lib/cc/CCSize.js +22 -26
  28. package/{src → dist/src}/lib/cc/CCSprite.js +82 -94
  29. package/{src → dist/src}/lib/cc/CCTrs.js +49 -74
  30. package/{src → dist/src}/lib/cc/CCVec2.js +22 -26
  31. package/{src → dist/src}/lib/cc/CCVec3.js +26 -29
  32. package/{src → dist/src}/lib/cc/CCWidget.js +94 -98
  33. package/dist/src/lib/fire-utils.js +86 -0
  34. package/dist/src/lib/json-parser.js +114 -0
  35. package/dist/src/lib/node-utils.js +131 -0
  36. package/{src → dist/src}/lib/screenshot-core.js +221 -285
  37. package/dist/src/lib/templates.js +17 -0
  38. package/dist/src/lib/utils.js +81 -0
  39. package/package.json +13 -6
  40. package/bin/cocos2d-cli.js +0 -152
  41. package/src/commands/add-component.js +0 -112
  42. package/src/commands/add.js +0 -177
  43. package/src/commands/build.js +0 -78
  44. package/src/commands/create-scene.js +0 -181
  45. package/src/commands/get.js +0 -108
  46. package/src/commands/prefab-create.js +0 -111
  47. package/src/commands/remove-component.js +0 -111
  48. package/src/commands/remove.js +0 -99
  49. package/src/commands/screenshot.js +0 -108
  50. package/src/commands/set-component.js +0 -119
  51. package/src/commands/set.js +0 -107
  52. package/src/commands/tree.js +0 -29
  53. package/src/lib/cc/CCSceneAsset.js +0 -303
  54. package/src/lib/cc/index.js +0 -42
  55. package/src/lib/fire-utils.js +0 -374
  56. package/src/lib/json-parser.js +0 -185
  57. package/src/lib/node-utils.js +0 -395
  58. package/src/lib/screenshot/favicon.ico +0 -0
  59. package/src/lib/screenshot/index.html +0 -30
  60. package/src/lib/templates.js +0 -49
  61. package/src/lib/utils.js +0 -202
@@ -1,285 +1,221 @@
1
- /**
2
- * Screenshot Core Module
3
- * 渲染 JSON 数据并使用 Playwright 截图
4
- */
5
-
6
- const { chromium } = require('playwright');
7
- const fs = require('fs').promises;
8
- const path = require('path');
9
- const http = require('http');
10
- const url = require('url');
11
- const os = require('os');
12
-
13
- // 默认配置
14
- const DEFAULT_CONFIG = {
15
- jsonPath: null,
16
- outputDir: process.cwd(),
17
- viewport: { width: 750, height: 1334 },
18
- fullPage: true,
19
- debugBounds: false,
20
- timeout: 30000,
21
- waitTime: 1000
22
- };
23
-
24
- // 获取内置资源目录
25
- function getAssetsDir() {
26
- return path.join(__dirname, 'screenshot');
27
- }
28
-
29
- // 创建临时工作目录
30
- async function createTempWorkDir() {
31
- const tempBase = os.tmpdir();
32
- const timestamp = Date.now();
33
- const tempDir = path.join(tempBase, `cocos2d-screenshot-${timestamp}`);
34
- await fs.mkdir(tempDir, { recursive: true });
35
- return tempDir;
36
- }
37
-
38
- // 复制内置资源到临时目录
39
- async function copyBuiltInAssets(tempDir, logs) {
40
- const assetsDir = getAssetsDir();
41
- const assets = ['index.html', 'favicon.ico'];
42
-
43
- for (const asset of assets) {
44
- const src = path.join(assetsDir, asset);
45
- const dest = path.join(tempDir, asset);
46
- try {
47
- await fs.copyFile(src, dest);
48
- } catch (err) {
49
- logs.push({
50
- timestamp: new Date().toISOString(),
51
- type: 'warning',
52
- text: `Could not copy ${asset}: ${err.message}`
53
- });
54
- }
55
- }
56
- }
57
-
58
- // 静态文件服务器
59
- async function startServer(staticDir, logs) {
60
- return new Promise((resolve, reject) => {
61
- const server = http.createServer(async (req, res) => {
62
- try {
63
- const parsedUrl = url.parse(req.url);
64
- let filePath = path.join(staticDir, parsedUrl.pathname);
65
-
66
- if (parsedUrl.pathname === '/') {
67
- filePath = path.join(staticDir, 'index.html');
68
- }
69
-
70
- const data = await fs.readFile(filePath);
71
-
72
- const ext = path.extname(filePath).toLowerCase();
73
- const contentTypes = {
74
- '.html': 'text/html',
75
- '.htm': 'text/html',
76
- '.json': 'application/json',
77
- '.js': 'application/javascript',
78
- '.mjs': 'application/javascript',
79
- '.css': 'text/css',
80
- '.png': 'image/png',
81
- '.jpg': 'image/jpeg',
82
- '.jpeg': 'image/jpeg',
83
- '.gif': 'image/gif',
84
- '.svg': 'image/svg+xml',
85
- '.ico': 'image/x-icon',
86
- '.txt': 'text/plain',
87
- '.xml': 'application/xml'
88
- };
89
-
90
- res.writeHead(200, {
91
- 'Content-Type': contentTypes[ext] || 'application/octet-stream',
92
- 'Access-Control-Allow-Origin': '*'
93
- });
94
- res.end(data);
95
-
96
- } catch (err) {
97
- if (err.code === 'ENOENT') {
98
- res.writeHead(404);
99
- res.end();
100
- } else {
101
- logs.push({
102
- timestamp: new Date().toISOString(),
103
- type: 'server-error',
104
- text: `${req.url}: ${err.message}`
105
- });
106
- res.writeHead(500);
107
- res.end();
108
- }
109
- }
110
- });
111
-
112
- server.listen(0, '127.0.0.1', () => resolve(server));
113
- });
114
- }
115
-
116
- // 递归删除目录
117
- async function removeDir(dirPath, logs) {
118
- try {
119
- await fs.rm(dirPath, { recursive: true, force: true });
120
- } catch (err) {
121
- if (logs) {
122
- logs.push({
123
- timestamp: new Date().toISOString(),
124
- type: 'warning',
125
- text: `Could not remove temp dir: ${err.message}`
126
- });
127
- }
128
- }
129
- }
130
-
131
- /**
132
- * 截图核心函数
133
- * @param {Object} userConfig - 配置选项
134
- * @param {string} userConfig.jsonPath - JSON 文件路径
135
- * @param {string} userConfig.outputDir - 输出目录
136
- * @param {Object} userConfig.viewport - 视口大小 {width, height}
137
- * @param {boolean} userConfig.fullPage - 是否全页截图
138
- * @param {number} userConfig.timeout - 超时时间(毫秒)
139
- * @param {number} userConfig.waitTime - 等待时间(毫秒)
140
- * @returns {Promise<{screenshotPath: string, logs: Array}>}
141
- */
142
- async function takeScreenshot(userConfig = {}) {
143
- const config = { ...DEFAULT_CONFIG, ...userConfig };
144
-
145
- if (!config.jsonPath) {
146
- throw new Error('JSON file path is required');
147
- }
148
-
149
- let server = null;
150
- let browser = null;
151
- let tempDir = null;
152
- const logs = [];
153
- let screenshotPath = null;
154
- let logDir = null;
155
-
156
- const addLog = (type, text, extra = {}) => {
157
- logs.push({
158
- timestamp: new Date().toISOString(),
159
- type,
160
- text,
161
- ...extra
162
- });
163
- };
164
-
165
- try {
166
- const timestamp = Date.now();
167
-
168
- // 检查 JSON 文件是否存在
169
- try {
170
- await fs.access(config.jsonPath);
171
- } catch (error) {
172
- throw new Error(`JSON file not found: ${config.jsonPath}`);
173
- }
174
-
175
- // 确保输出目录存在
176
- await fs.mkdir(config.outputDir, { recursive: true });
177
-
178
- // 创建临时工作目录
179
- tempDir = await createTempWorkDir();
180
- addLog('info', `Temp dir: ${tempDir}`);
181
-
182
- // 复制内置资源到临时目录
183
- await copyBuiltInAssets(tempDir, logs);
184
-
185
- // 复制用户的 JSON 文件到临时目录
186
- const destJsonPath = path.join(tempDir, 'data.json');
187
- await fs.copyFile(config.jsonPath, destJsonPath);
188
- addLog('info', `JSON: ${config.jsonPath}`);
189
-
190
- // 截图输出路径
191
- screenshotPath = path.join(config.outputDir, `screenshot-${timestamp}.png`);
192
-
193
- // 启动HTTP服务器
194
- addLog('info', 'Starting Server');
195
- server = await startServer(tempDir, logs);
196
- const serverUrl = `http://127.0.0.1:${server.address().port}`;
197
- addLog('info', `Server: ${serverUrl}`);
198
-
199
- // 启动浏览器
200
- addLog('info', 'Launching Browser');
201
- browser = await chromium.launch({
202
- headless: true
203
- });
204
- addLog('info', 'Browser launched');
205
-
206
- const page = await browser.newPage({
207
- viewport: config.viewport
208
- });
209
-
210
- // 监听浏览器控制台日志
211
- page.on('console', msg => {
212
- const text = msg.text();
213
- addLog(msg.type(), text);
214
- });
215
-
216
- page.on('pageerror', error => {
217
- addLog('pageerror', error.message);
218
- });
219
-
220
- page.on('requestfailed', request => {
221
- const failure = request.failure();
222
- const errorText = failure ? failure.errorText : 'Unknown error';
223
- addLog('requestfailed', request.url(), { error: errorText });
224
- });
225
-
226
- // 加载页面
227
- addLog('info', 'Loading Page');
228
- const pageUrl = config.debugBounds
229
- ? `${serverUrl}/index.html?debugBounds=true`
230
- : `${serverUrl}/index.html`;
231
- await page.goto(pageUrl, {
232
- waitUntil: 'networkidle',
233
- timeout: config.timeout
234
- });
235
- addLog('info', 'Page loaded');
236
-
237
- // 等待渲染
238
- addLog('info', 'Waiting for Render');
239
- await page.waitForTimeout(config.waitTime);
240
- addLog('info', 'Wait complete');
241
-
242
- // 截图
243
- addLog('info', 'Taking Screenshot');
244
- await page.screenshot({
245
- path: screenshotPath,
246
- fullPage: config.fullPage
247
- });
248
- addLog('info', `Screenshot saved: ${screenshotPath}`);
249
- addLog('info', 'Done');
250
-
251
- return { screenshotPath, logs };
252
-
253
- } catch (error) {
254
- addLog('error', error.message);
255
- try {
256
- logDir = path.join(config.outputDir, `screenshot-logs-${Date.now()}`);
257
- await fs.mkdir(logDir, { recursive: true });
258
- await fs.writeFile(
259
- path.join(logDir, 'logs.json'),
260
- JSON.stringify({
261
- error: error.message,
262
- jsonPath: config.jsonPath,
263
- outputDir: config.outputDir,
264
- viewport: config.viewport,
265
- fullPage: config.fullPage,
266
- debugBounds: config.debugBounds,
267
- timeout: config.timeout,
268
- waitTime: config.waitTime,
269
- screenshotPath,
270
- logs
271
- }, null, 2),
272
- 'utf8'
273
- );
274
- } catch (_) {}
275
- error.logDir = logDir;
276
- throw error;
277
- } finally {
278
- // 清理资源
279
- if (browser) await browser.close().catch(() => {});
280
- if (server) server.close();
281
- if (tempDir) await removeDir(tempDir, logs);
282
- }
283
- }
284
-
285
- module.exports = { takeScreenshot };
1
+ import { chromium } from 'playwright';
2
+ import * as fs from 'fs/promises';
3
+ import * as path from 'path';
4
+ import * as http from 'http';
5
+ import { fileURLToPath } from 'url';
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
+ const DEFAULT_CONFIG = {
8
+ outputDir: process.cwd(),
9
+ viewport: { width: 750, height: 1334 },
10
+ fullPage: true,
11
+ debugBounds: false,
12
+ timeout: 30000,
13
+ waitTime: 1000
14
+ };
15
+ function getAssetsDir() {
16
+ const projectRoot = process.cwd();
17
+ return path.join(projectRoot, 'src', 'lib', 'screenshot');
18
+ }
19
+ async function createTempWorkDir() {
20
+ const tempBase = process.env.TEMP || process.env.TMP || '/tmp';
21
+ const timestamp = Date.now();
22
+ const tempDir = path.join(tempBase, `cocos2d-screenshot-${timestamp}`);
23
+ await fs.mkdir(tempDir, { recursive: true });
24
+ return tempDir;
25
+ }
26
+ async function copyBuiltInAssets(tempDir, logs) {
27
+ const assetsDir = getAssetsDir();
28
+ const assets = ['index.html', 'favicon.ico'];
29
+ for (const asset of assets) {
30
+ const src = path.join(assetsDir, asset);
31
+ const dest = path.join(tempDir, asset);
32
+ try {
33
+ await fs.copyFile(src, dest);
34
+ }
35
+ catch (err) {
36
+ logs.push({
37
+ timestamp: new Date().toISOString(),
38
+ type: 'warning',
39
+ text: `Could not copy ${asset}: ${err.message}`
40
+ });
41
+ }
42
+ }
43
+ }
44
+ async function startServer(staticDir, logs) {
45
+ return new Promise((resolve, reject) => {
46
+ const server = http.createServer(async (req, res) => {
47
+ try {
48
+ const reqUrl = new URL(req.url || '/', `http://${req.headers.host}`);
49
+ let filePath = path.join(staticDir, reqUrl.pathname);
50
+ if (reqUrl.pathname === '/') {
51
+ filePath = path.join(staticDir, 'index.html');
52
+ }
53
+ const data = await fs.readFile(filePath);
54
+ const ext = path.extname(filePath).toLowerCase();
55
+ const contentTypes = {
56
+ '.html': 'text/html',
57
+ '.htm': 'text/html',
58
+ '.json': 'application/json',
59
+ '.js': 'application/javascript',
60
+ '.mjs': 'application/javascript',
61
+ '.css': 'text/css',
62
+ '.png': 'image/png',
63
+ '.jpg': 'image/jpeg',
64
+ '.jpeg': 'image/jpeg',
65
+ '.gif': 'image/gif',
66
+ '.svg': 'image/svg+xml',
67
+ '.ico': 'image/x-icon',
68
+ '.txt': 'text/plain',
69
+ '.xml': 'application/xml'
70
+ };
71
+ res.writeHead(200, {
72
+ 'Content-Type': contentTypes[ext] || 'application/octet-stream',
73
+ 'Access-Control-Allow-Origin': '*'
74
+ });
75
+ res.end(data);
76
+ }
77
+ catch (err) {
78
+ if (err.code === 'ENOENT') {
79
+ res.writeHead(404);
80
+ res.end();
81
+ }
82
+ else {
83
+ logs.push({
84
+ timestamp: new Date().toISOString(),
85
+ type: 'server-error',
86
+ text: `${req.url}: ${err.message}`
87
+ });
88
+ res.writeHead(500);
89
+ res.end();
90
+ }
91
+ }
92
+ });
93
+ server.listen(0, '127.0.0.1', () => resolve(server));
94
+ });
95
+ }
96
+ async function removeDir(dirPath, logs) {
97
+ try {
98
+ await fs.rm(dirPath, { recursive: true, force: true });
99
+ }
100
+ catch (err) {
101
+ if (logs) {
102
+ logs.push({
103
+ timestamp: new Date().toISOString(),
104
+ type: 'warning',
105
+ text: `Could not remove temp dir: ${err.message}`
106
+ });
107
+ }
108
+ }
109
+ }
110
+ export async function takeScreenshot(userConfig = {}) {
111
+ const config = { ...DEFAULT_CONFIG, ...userConfig };
112
+ if (!config.jsonPath) {
113
+ throw new Error('JSON file path is required');
114
+ }
115
+ let server = null;
116
+ let browser = null;
117
+ let tempDir = null;
118
+ const logs = [];
119
+ let screenshotPath = null;
120
+ let logDir = null;
121
+ const addLog = (type, text, extra = {}) => {
122
+ logs.push({
123
+ timestamp: new Date().toISOString(),
124
+ type,
125
+ text,
126
+ ...extra
127
+ });
128
+ };
129
+ try {
130
+ const timestamp = Date.now();
131
+ try {
132
+ await fs.access(config.jsonPath);
133
+ }
134
+ catch (error) {
135
+ throw new Error(`JSON file not found: ${config.jsonPath}`);
136
+ }
137
+ await fs.mkdir(config.outputDir, { recursive: true });
138
+ tempDir = await createTempWorkDir();
139
+ addLog('info', `Temp dir: ${tempDir}`);
140
+ await copyBuiltInAssets(tempDir, logs);
141
+ const destJsonPath = path.join(tempDir, 'data.json');
142
+ await fs.copyFile(config.jsonPath, destJsonPath);
143
+ addLog('info', `JSON: ${config.jsonPath}`);
144
+ screenshotPath = path.join(config.outputDir, `screenshot-${timestamp}.png`);
145
+ addLog('info', 'Starting Server');
146
+ server = await startServer(tempDir, logs);
147
+ const address = server.address();
148
+ const serverUrl = `http://127.0.0.1:${address.port}`;
149
+ addLog('info', `Server: ${serverUrl}`);
150
+ addLog('info', 'Launching Browser');
151
+ browser = await chromium.launch({
152
+ headless: true
153
+ });
154
+ addLog('info', 'Browser launched');
155
+ const page = await browser.newPage({
156
+ viewport: config.viewport
157
+ });
158
+ page.on('console', (msg) => {
159
+ const text = msg.text();
160
+ addLog(msg.type(), text);
161
+ });
162
+ page.on('pageerror', (error) => {
163
+ addLog('pageerror', error.message);
164
+ });
165
+ page.on('requestfailed', (request) => {
166
+ const failure = request.failure();
167
+ const errorText = failure ? failure.errorText : 'Unknown error';
168
+ addLog('requestfailed', request.url(), { error: errorText });
169
+ });
170
+ addLog('info', 'Loading Page');
171
+ const pageUrl = config.debugBounds
172
+ ? `${serverUrl}/index.html?debugBounds=true`
173
+ : `${serverUrl}/index.html`;
174
+ await page.goto(pageUrl, {
175
+ waitUntil: 'networkidle',
176
+ timeout: config.timeout
177
+ });
178
+ addLog('info', 'Page loaded');
179
+ addLog('info', 'Waiting for Render');
180
+ await page.waitForTimeout(config.waitTime);
181
+ addLog('info', 'Wait complete');
182
+ addLog('info', 'Taking Screenshot');
183
+ await page.screenshot({
184
+ path: screenshotPath,
185
+ fullPage: config.fullPage
186
+ });
187
+ addLog('info', `Screenshot saved: ${screenshotPath}`);
188
+ addLog('info', 'Done');
189
+ return { screenshotPath, logs };
190
+ }
191
+ catch (error) {
192
+ addLog('error', error.message);
193
+ try {
194
+ logDir = path.join(config.outputDir, `screenshot-logs-${Date.now()}`);
195
+ await fs.mkdir(logDir, { recursive: true });
196
+ await fs.writeFile(path.join(logDir, 'logs.json'), JSON.stringify({
197
+ error: error.message,
198
+ jsonPath: config.jsonPath,
199
+ outputDir: config.outputDir,
200
+ viewport: config.viewport,
201
+ fullPage: config.fullPage,
202
+ debugBounds: config.debugBounds,
203
+ timeout: config.timeout,
204
+ waitTime: config.waitTime,
205
+ screenshotPath,
206
+ logs
207
+ }, null, 2), 'utf8');
208
+ }
209
+ catch (_) { }
210
+ error.logDir = logDir;
211
+ throw error;
212
+ }
213
+ finally {
214
+ if (browser)
215
+ await browser.close().catch(() => { });
216
+ if (server)
217
+ server.close();
218
+ if (tempDir)
219
+ await removeDir(tempDir, logs);
220
+ }
221
+ }
@@ -0,0 +1,17 @@
1
+ import CCNode from './cc/CCNode.js';
2
+ import CCScene from './cc/CCScene.js';
3
+ import CCSceneAsset from './cc/CCSceneAsset.js';
4
+ import { CCPrefab, CCPrefabInfo } from './cc/CCPrefab.js';
5
+ export function createPrefab(name = 'Prefab') {
6
+ const prefab = new CCPrefab();
7
+ const root = new CCNode(name);
8
+ prefab.setRoot(root);
9
+ return prefab;
10
+ }
11
+ export function createScene(name = 'NewScene') {
12
+ const asset = new CCSceneAsset();
13
+ const scene = new CCScene(name);
14
+ asset._scene = scene;
15
+ return asset;
16
+ }
17
+ export { CCNode, CCScene, CCSceneAsset, CCPrefab, CCPrefabInfo };
@@ -0,0 +1,81 @@
1
+ import * as crypto from 'crypto';
2
+ export function parseColor(color) {
3
+ if (!color)
4
+ return null;
5
+ if (color.startsWith('#')) {
6
+ const hex = color.slice(1);
7
+ if (hex.length === 6 || hex.length === 8) {
8
+ return {
9
+ r: parseInt(hex.slice(0, 2), 16),
10
+ g: parseInt(hex.slice(2, 4), 16),
11
+ b: parseInt(hex.slice(4, 6), 16),
12
+ a: hex.length === 8 ? parseInt(hex.slice(6, 8), 16) : 255
13
+ };
14
+ }
15
+ }
16
+ const rgbMatch = color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);
17
+ if (rgbMatch) {
18
+ return {
19
+ r: parseInt(rgbMatch[1]),
20
+ g: parseInt(rgbMatch[2]),
21
+ b: parseInt(rgbMatch[3]),
22
+ a: rgbMatch[4] ? Math.round(parseFloat(rgbMatch[4]) * 255) : 255
23
+ };
24
+ }
25
+ return null;
26
+ }
27
+ export function parseColorToCcColor(color) {
28
+ const parsed = parseColor(color);
29
+ if (!parsed)
30
+ return null;
31
+ return { __type__: 'cc.Color', ...parsed };
32
+ }
33
+ export function colorToHex(r, g, b, a = 255) {
34
+ return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}${a !== 255 ? a.toString(16).padStart(2, '0') : ''}`;
35
+ }
36
+ export function generateUUID() {
37
+ return crypto.randomUUID().replace(/-/g, '');
38
+ }
39
+ export function compressUUID(uuid) {
40
+ const hex = uuid.replace(/-/g, '');
41
+ const bytes = Buffer.from(hex, 'hex');
42
+ return bytes.toString('base64url').slice(0, 22);
43
+ }
44
+ export function generateCompressedUUID() {
45
+ return compressUUID(generateUUID());
46
+ }
47
+ export function generateId() {
48
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
49
+ let result = '';
50
+ for (let i = 0; i < 22; i++) {
51
+ result += chars.charAt(Math.floor(Math.random() * chars.length));
52
+ }
53
+ return result;
54
+ }
55
+ export function parseOptions(args) {
56
+ const options = {};
57
+ for (let i = 0; i < args.length; i++) {
58
+ const arg = args[i];
59
+ if (arg.startsWith('--')) {
60
+ const key = arg.slice(2);
61
+ const nextArg = args[i + 1];
62
+ if (nextArg && !nextArg.startsWith('--')) {
63
+ options[key] = nextArg;
64
+ i++;
65
+ }
66
+ else {
67
+ options[key] = true;
68
+ }
69
+ }
70
+ }
71
+ return options;
72
+ }
73
+ export function outputJson(data) {
74
+ console.log(JSON.stringify(data, null, 2));
75
+ }
76
+ export function outputError(message) {
77
+ console.log(JSON.stringify({ error: message }));
78
+ }
79
+ export function outputSuccess(message) {
80
+ console.log(JSON.stringify({ success: message }));
81
+ }
package/package.json CHANGED
@@ -1,17 +1,20 @@
1
1
  {
2
2
  "name": "cocos2d-cli",
3
- "version": "1.6.5",
3
+ "version": "2.0.0",
4
4
  "description": "Command-line tools for AI to read and manipulate Cocos Creator 2.4.x project scenes",
5
- "main": "bin/cocos2d-cli.js",
5
+ "type": "module",
6
+ "main": "dist/bin/cocos2d-cli.js",
6
7
  "bin": {
7
- "cocos2d-cli": "bin/cocos2d-cli.js"
8
+ "cocos2d-cli": "dist/bin/cocos2d-cli.js"
8
9
  },
9
10
  "files": [
10
- "bin",
11
- "src",
11
+ "dist",
12
12
  "data"
13
13
  ],
14
14
  "scripts": {
15
+ "build": "tsc",
16
+ "watch": "tsc --watch",
17
+ "prepare": "npm run build",
15
18
  "test": "echo \"No tests specified\" && exit 1"
16
19
  },
17
20
  "keywords": [
@@ -25,9 +28,13 @@
25
28
  "author": "",
26
29
  "license": "MIT",
27
30
  "engines": {
28
- "node": ">=14.0.0"
31
+ "node": ">=18.0.0"
29
32
  },
30
33
  "dependencies": {
31
34
  "playwright": "^1.58.2"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^22.15.17",
38
+ "typescript": "^5.9.3"
32
39
  }
33
40
  }