drgame-cc 1.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.
@@ -0,0 +1,186 @@
1
+ /**
2
+ * 资源类型定义
3
+ */
4
+ /** 资源类型枚举 */
5
+ export declare enum AssetType {
6
+ PREFAB = "prefab",
7
+ SCENE = "scene",
8
+ IMAGE = "image",
9
+ AUDIO = "audio",
10
+ SCRIPT = "script",
11
+ ANIMATION = "animation",
12
+ FONT = "font",
13
+ MATERIAL = "material",
14
+ MESH = "mesh",
15
+ PARTICLE = "particle",
16
+ SPINE = "spine",
17
+ TILEDMAP = "tiledmap",
18
+ UNKNOWN = "unknown"
19
+ }
20
+ /** 图片资源支持的格式 */
21
+ export type ImageFormat = 'png' | 'jpg' | 'jpeg' | 'webp' | 'gif' | 'bmp' | 'tga' | 'psd';
22
+ /** 音频资源支持的格式 */
23
+ export type AudioFormat = 'mp3' | 'ogg' | 'wav' | 'm4a' | 'wma' | 'aac';
24
+ /** 资源信息接口 */
25
+ export interface AssetInfo {
26
+ /** 资源唯一ID */
27
+ uuid: string;
28
+ /** 资源名称 */
29
+ name: string;
30
+ /** 资源路径 */
31
+ path: string;
32
+ /** 资源类型 */
33
+ type: AssetType;
34
+ /** 文件扩展名 */
35
+ extension: string;
36
+ /** 文件大小(字节) */
37
+ size: number;
38
+ /** 最后修改时间 */
39
+ modifiedTime: Date;
40
+ /** 依赖的资源UUID列表 */
41
+ dependencies?: string[];
42
+ /** 元数据 */
43
+ meta?: Record<string, unknown>;
44
+ }
45
+ /** 预制体资源接口 */
46
+ export interface PrefabAsset extends AssetInfo {
47
+ type: AssetType.PREFAB;
48
+ /** 预制体包含的节点数量 */
49
+ nodeCount?: number;
50
+ /** 预制体引用的脚本组件 */
51
+ scriptComponents?: string[];
52
+ }
53
+ /** 图片资源接口 */
54
+ export interface ImageAsset extends AssetInfo {
55
+ type: AssetType.IMAGE;
56
+ /** 图片宽度 */
57
+ width: number;
58
+ /** 图片高度 */
59
+ height: number;
60
+ /** 图片格式 */
61
+ format: ImageFormat;
62
+ /** 是否包含透明通道 */
63
+ hasAlpha: boolean;
64
+ }
65
+ /** 音频资源接口 */
66
+ export interface AudioAsset extends AssetInfo {
67
+ type: AssetType.AUDIO;
68
+ /** 音频格式 */
69
+ format: AudioFormat;
70
+ /** 音频时长(秒) */
71
+ duration?: number;
72
+ /** 采样率 */
73
+ sampleRate?: number;
74
+ /** 声道数 */
75
+ channels?: number;
76
+ /** 是否循环播放 */
77
+ loop?: boolean;
78
+ }
79
+ /** 场景资源接口 */
80
+ export interface SceneAsset extends AssetInfo {
81
+ type: AssetType.SCENE;
82
+ /** 场景包含的节点数量 */
83
+ nodeCount?: number;
84
+ }
85
+ /** 脚本资源接口 */
86
+ export interface ScriptAsset extends AssetInfo {
87
+ type: AssetType.SCRIPT;
88
+ /** 脚本语言类型 */
89
+ language: 'typescript' | 'javascript';
90
+ }
91
+ /** 动画资源接口 */
92
+ export interface AnimationAsset extends AssetInfo {
93
+ type: AssetType.ANIMATION;
94
+ /** 动画时长(秒) */
95
+ duration: number;
96
+ /** 动画帧率 */
97
+ frameRate: number;
98
+ /** 动画片段数量 */
99
+ clipCount: number;
100
+ }
101
+ /** 字体资源接口 */
102
+ export interface FontAsset extends AssetInfo {
103
+ type: AssetType.FONT;
104
+ /** 字体格式 */
105
+ fontFormat: 'ttf' | 'otf' | 'woff' | 'woff2' | 'bitmap';
106
+ }
107
+ /** 材质资源接口 */
108
+ export interface MaterialAsset extends AssetInfo {
109
+ type: AssetType.MATERIAL;
110
+ /** 使用的Shader名称 */
111
+ shaderName?: string;
112
+ }
113
+ /** 导出配置接口 */
114
+ export interface ExportConfig {
115
+ /** 源资源目录 */
116
+ sourceDir: string;
117
+ /** 输出目录 */
118
+ outputDir: string;
119
+ /** 要导出的资源类型列表 */
120
+ assetTypes?: AssetType[];
121
+ /** 是否包含依赖资源 */
122
+ includeDependencies?: boolean;
123
+ /** 是否压缩输出 */
124
+ compress?: boolean;
125
+ /** 图片导出配置 */
126
+ imageConfig?: ImageExportConfig;
127
+ /** 音频导出配置 */
128
+ audioConfig?: AudioExportConfig;
129
+ /** 自定义过滤器 */
130
+ filter?: (asset: AssetInfo) => boolean;
131
+ }
132
+ /** 图片导出配置 */
133
+ export interface ImageExportConfig {
134
+ /** 目标格式 */
135
+ targetFormat?: ImageFormat;
136
+ /** 最大宽度 */
137
+ maxWidth?: number;
138
+ /** 最大高度 */
139
+ maxHeight?: number;
140
+ /** 压缩质量 (0-1) */
141
+ quality?: number;
142
+ /** 是否生成图集 */
143
+ packAtlas?: boolean;
144
+ }
145
+ /** 音频导出配置 */
146
+ export interface AudioExportConfig {
147
+ /** 目标格式 */
148
+ targetFormat?: AudioFormat;
149
+ /** 压缩比特率 */
150
+ bitrate?: number;
151
+ /** 是否压缩 */
152
+ compress?: boolean;
153
+ }
154
+ /** 导出结果接口 */
155
+ export interface ExportResult {
156
+ /** 导出的资源列表 */
157
+ assets: AssetInfo[];
158
+ /** 导出成功的数量 */
159
+ successCount: number;
160
+ /** 导出失败的数量 */
161
+ failCount: number;
162
+ /** 跳过的数量 */
163
+ skipCount: number;
164
+ /** 错误信息列表 */
165
+ errors: string[];
166
+ /** 导出耗时(毫秒) */
167
+ duration: number;
168
+ /** 输出目录 */
169
+ outputDir: string;
170
+ }
171
+ /** 资源包接口 */
172
+ export interface AssetBundle {
173
+ /** 包名称 */
174
+ name: string;
175
+ /** 包版本 */
176
+ version: string;
177
+ /** 包含的资源列表 */
178
+ assets: AssetInfo[];
179
+ /** 包总大小(字节) */
180
+ totalSize: number;
181
+ /** 创建时间 */
182
+ createdAt: Date;
183
+ /** 包描述 */
184
+ description?: string;
185
+ }
186
+ //# sourceMappingURL=asset-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset-types.d.ts","sourceRoot":"","sources":["../src/asset-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,aAAa;AACb,oBAAY,SAAS;IACjB,MAA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,EAAE,MAAM,CAAC;IAClB,aAAa;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,eAAe;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW;IACX,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,YAAY;AACZ,MAAM,WAAW,WAAW;IACxB,UAAU;IACV,IAAI,EAAE,MAAM,CAAC;IACb,UAAU;IACV,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc;IACd,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,eAAe;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW;IACX,SAAS,EAAE,IAAI,CAAC;IAChB,UAAU;IACV,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /**
3
+ * 资源类型定义
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AssetType = void 0;
7
+ /** 资源类型枚举 */
8
+ var AssetType;
9
+ (function (AssetType) {
10
+ AssetType["PREFAB"] = "prefab";
11
+ AssetType["SCENE"] = "scene";
12
+ AssetType["IMAGE"] = "image";
13
+ AssetType["AUDIO"] = "audio";
14
+ AssetType["SCRIPT"] = "script";
15
+ AssetType["ANIMATION"] = "animation";
16
+ AssetType["FONT"] = "font";
17
+ AssetType["MATERIAL"] = "material";
18
+ AssetType["MESH"] = "mesh";
19
+ AssetType["PARTICLE"] = "particle";
20
+ AssetType["SPINE"] = "spine";
21
+ AssetType["TILEDMAP"] = "tiledmap";
22
+ AssetType["UNKNOWN"] = "unknown";
23
+ })(AssetType || (exports.AssetType = AssetType = {}));
24
+ //# sourceMappingURL=asset-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset-types.js","sourceRoot":"","sources":["../src/asset-types.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,aAAa;AACb,IAAY,SAcX;AAdD,WAAY,SAAS;IACjB,8BAAiB,CAAA;IACjB,4BAAe,CAAA;IACf,4BAAe,CAAA;IACf,4BAAe,CAAA;IACf,8BAAiB,CAAA;IACjB,oCAAuB,CAAA;IACvB,0BAAa,CAAA;IACb,kCAAqB,CAAA;IACrB,0BAAa,CAAA;IACb,kCAAqB,CAAA;IACrB,4BAAe,CAAA;IACf,kCAAqB,CAAA;IACrB,gCAAmB,CAAA;AACvB,CAAC,EAdW,SAAS,yBAAT,SAAS,QAcpB"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Cocos Creator 资源导出工具包
3
+ * 支持导出预制体、图片、音乐等资源
4
+ */
5
+ export * from './asset-exporter';
6
+ export * from './asset-types';
7
+ export * from './utils';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /**
3
+ * Cocos Creator 资源导出工具包
4
+ * 支持导出预制体、图片、音乐等资源
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ __exportStar(require("./asset-exporter"), exports);
22
+ __exportStar(require("./asset-types"), exports);
23
+ __exportStar(require("./utils"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;AAEH,mDAAiC;AACjC,gDAA8B;AAC9B,0CAAwB"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * 工具函数
3
+ */
4
+ import { AssetType, ImageFormat, AudioFormat } from './asset-types';
5
+ /**
6
+ * 根据文件路径获取资源类型
7
+ * @param filePath 文件路径
8
+ * @returns 资源类型
9
+ */
10
+ export declare function getAssetType(filePath: string): AssetType;
11
+ /**
12
+ * 获取文件扩展名对应的图片格式
13
+ * @param filePath 文件路径
14
+ * @returns 图片格式或 undefined
15
+ */
16
+ export declare function getImageFormat(filePath: string): ImageFormat | undefined;
17
+ /**
18
+ * 获取文件扩展名对应的音频格式
19
+ * @param filePath 文件路径
20
+ * @returns 音频格式或 undefined
21
+ */
22
+ export declare function getAudioFormat(filePath: string): AudioFormat | undefined;
23
+ /**
24
+ * 生成UUID
25
+ * @returns UUID字符串
26
+ */
27
+ export declare function generateUUID(): string;
28
+ /**
29
+ * 确保目录存在,如果不存在则创建
30
+ * @param dirPath 目录路径
31
+ */
32
+ export declare function ensureDir(dirPath: string): void;
33
+ /**
34
+ * 递归获取目录下的所有文件
35
+ * @param dirPath 目录路径
36
+ * @param extensions 可选的文件扩展名过滤列表
37
+ * @returns 文件路径列表
38
+ */
39
+ export declare function getAllFiles(dirPath: string, extensions?: string[]): string[];
40
+ /**
41
+ * 获取文件大小
42
+ * @param filePath 文件路径
43
+ * @returns 文件大小(字节),如果文件不存在返回 -1
44
+ */
45
+ export declare function getFileSize(filePath: string): number;
46
+ /**
47
+ * 格式化文件大小为可读字符串
48
+ * @param bytes 字节数
49
+ * @returns 格式化后的字符串
50
+ */
51
+ export declare function formatFileSize(bytes: number): string;
52
+ /**
53
+ * 复制文件
54
+ * @param src 源文件路径
55
+ * @param dest 目标文件路径
56
+ * @returns 是否复制成功
57
+ */
58
+ export declare function copyFile(src: string, dest: string): boolean;
59
+ /**
60
+ * 读取JSON文件
61
+ * @param filePath 文件路径
62
+ * @returns JSON对象,失败返回 null
63
+ */
64
+ export declare function readJSON<T = unknown>(filePath: string): T | null;
65
+ /**
66
+ * 写入JSON文件
67
+ * @param filePath 文件路径
68
+ * @param data 数据对象
69
+ * @param pretty 是否格式化输出
70
+ * @returns 是否写入成功
71
+ */
72
+ export declare function writeJSON(filePath: string, data: unknown, pretty?: boolean): boolean;
73
+ /**
74
+ * 检查路径是否为Cocos Creator项目目录
75
+ * @param dirPath 目录路径
76
+ * @returns 是否为有效的Cocos Creator项目
77
+ */
78
+ export declare function isCocosProject(dirPath: string): boolean;
79
+ /**
80
+ * 获取Cocos Creator项目的资源目录
81
+ * @param projectPath 项目路径
82
+ * @returns 资源目录路径,如果找不到返回 null
83
+ */
84
+ export declare function getAssetsDir(projectPath: string): string | null;
85
+ /**
86
+ * 延迟函数
87
+ * @param ms 毫秒数
88
+ * @returns Promise
89
+ */
90
+ export declare function sleep(ms: number): Promise<void>;
91
+ /**
92
+ * 批量处理函数
93
+ * @param items 待处理项列表
94
+ * @param processor 处理函数
95
+ * @param batchSize 批处理大小
96
+ * @returns 处理结果
97
+ */
98
+ export declare function batchProcess<T, R>(items: T[], processor: (item: T) => Promise<R> | R, batchSize?: number): Promise<R[]>;
99
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AA2CpE;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAcxD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,GAAG,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AAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EACtC,SAAS,SAAK,GACf,OAAO,CAAC,CAAC,EAAE,CAAC,CAUd"}
package/dist/utils.js ADDED
@@ -0,0 +1,324 @@
1
+ "use strict";
2
+ /**
3
+ * 工具函数
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getAssetType = getAssetType;
40
+ exports.getImageFormat = getImageFormat;
41
+ exports.getAudioFormat = getAudioFormat;
42
+ exports.generateUUID = generateUUID;
43
+ exports.ensureDir = ensureDir;
44
+ exports.getAllFiles = getAllFiles;
45
+ exports.getFileSize = getFileSize;
46
+ exports.formatFileSize = formatFileSize;
47
+ exports.copyFile = copyFile;
48
+ exports.readJSON = readJSON;
49
+ exports.writeJSON = writeJSON;
50
+ exports.isCocosProject = isCocosProject;
51
+ exports.getAssetsDir = getAssetsDir;
52
+ exports.sleep = sleep;
53
+ exports.batchProcess = batchProcess;
54
+ const fs = __importStar(require("fs"));
55
+ const path = __importStar(require("path"));
56
+ const asset_types_1 = require("./asset-types");
57
+ /** 图片扩展名映射 */
58
+ const IMAGE_EXTENSIONS = {
59
+ '.png': 'png',
60
+ '.jpg': 'jpg',
61
+ '.jpeg': 'jpeg',
62
+ '.webp': 'webp',
63
+ '.gif': 'gif',
64
+ '.bmp': 'bmp',
65
+ '.tga': 'tga',
66
+ '.psd': 'psd'
67
+ };
68
+ /** 音频扩展名映射 */
69
+ const AUDIO_EXTENSIONS = {
70
+ '.mp3': 'mp3',
71
+ '.ogg': 'ogg',
72
+ '.wav': 'wav',
73
+ '.m4a': 'm4a',
74
+ '.wma': 'wma',
75
+ '.aac': 'aac'
76
+ };
77
+ /** 资源类型扩展名映射 */
78
+ const ASSET_TYPE_EXTENSIONS = {
79
+ '.prefab': asset_types_1.AssetType.PREFAB,
80
+ '.scene': asset_types_1.AssetType.SCENE,
81
+ '.ts': asset_types_1.AssetType.SCRIPT,
82
+ '.js': asset_types_1.AssetType.SCRIPT,
83
+ '.anim': asset_types_1.AssetType.ANIMATION,
84
+ '.ttf': asset_types_1.AssetType.FONT,
85
+ '.otf': asset_types_1.AssetType.FONT,
86
+ '.woff': asset_types_1.AssetType.FONT,
87
+ '.woff2': asset_types_1.AssetType.FONT,
88
+ '.fnt': asset_types_1.AssetType.FONT,
89
+ '.mat': asset_types_1.AssetType.MATERIAL,
90
+ '.mesh': asset_types_1.AssetType.MESH,
91
+ '.plist': asset_types_1.AssetType.PARTICLE,
92
+ '.json': asset_types_1.AssetType.SPINE,
93
+ '.tmx': asset_types_1.AssetType.TILEDMAP
94
+ };
95
+ /**
96
+ * 根据文件路径获取资源类型
97
+ * @param filePath 文件路径
98
+ * @returns 资源类型
99
+ */
100
+ function getAssetType(filePath) {
101
+ const ext = path.extname(filePath).toLowerCase();
102
+ if (IMAGE_EXTENSIONS[ext]) {
103
+ return asset_types_1.AssetType.IMAGE;
104
+ }
105
+ if (AUDIO_EXTENSIONS[ext]) {
106
+ return asset_types_1.AssetType.AUDIO;
107
+ }
108
+ if (ASSET_TYPE_EXTENSIONS[ext]) {
109
+ return ASSET_TYPE_EXTENSIONS[ext];
110
+ }
111
+ return asset_types_1.AssetType.UNKNOWN;
112
+ }
113
+ /**
114
+ * 获取文件扩展名对应的图片格式
115
+ * @param filePath 文件路径
116
+ * @returns 图片格式或 undefined
117
+ */
118
+ function getImageFormat(filePath) {
119
+ const ext = path.extname(filePath).toLowerCase();
120
+ return IMAGE_EXTENSIONS[ext];
121
+ }
122
+ /**
123
+ * 获取文件扩展名对应的音频格式
124
+ * @param filePath 文件路径
125
+ * @returns 音频格式或 undefined
126
+ */
127
+ function getAudioFormat(filePath) {
128
+ const ext = path.extname(filePath).toLowerCase();
129
+ return AUDIO_EXTENSIONS[ext];
130
+ }
131
+ /**
132
+ * 生成UUID
133
+ * @returns UUID字符串
134
+ */
135
+ function generateUUID() {
136
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
137
+ const r = Math.random() * 16 | 0;
138
+ const v = c === 'x' ? r : (r & 0x3 | 0x8);
139
+ return v.toString(16);
140
+ });
141
+ }
142
+ /**
143
+ * 确保目录存在,如果不存在则创建
144
+ * @param dirPath 目录路径
145
+ */
146
+ function ensureDir(dirPath) {
147
+ if (!fs.existsSync(dirPath)) {
148
+ fs.mkdirSync(dirPath, { recursive: true });
149
+ }
150
+ }
151
+ /**
152
+ * 递归获取目录下的所有文件
153
+ * @param dirPath 目录路径
154
+ * @param extensions 可选的文件扩展名过滤列表
155
+ * @returns 文件路径列表
156
+ */
157
+ function getAllFiles(dirPath, extensions) {
158
+ const files = [];
159
+ if (!fs.existsSync(dirPath)) {
160
+ return files;
161
+ }
162
+ const items = fs.readdirSync(dirPath);
163
+ for (const item of items) {
164
+ const fullPath = path.join(dirPath, item);
165
+ const stat = fs.statSync(fullPath);
166
+ if (stat.isDirectory()) {
167
+ // 跳过隐藏目录和 node_modules
168
+ if (item.startsWith('.') || item === 'node_modules') {
169
+ continue;
170
+ }
171
+ files.push(...getAllFiles(fullPath, extensions));
172
+ }
173
+ else if (stat.isFile()) {
174
+ if (!extensions || extensions.length === 0) {
175
+ files.push(fullPath);
176
+ }
177
+ else {
178
+ const ext = path.extname(fullPath).toLowerCase();
179
+ if (extensions.includes(ext)) {
180
+ files.push(fullPath);
181
+ }
182
+ }
183
+ }
184
+ }
185
+ return files;
186
+ }
187
+ /**
188
+ * 获取文件大小
189
+ * @param filePath 文件路径
190
+ * @returns 文件大小(字节),如果文件不存在返回 -1
191
+ */
192
+ function getFileSize(filePath) {
193
+ try {
194
+ const stat = fs.statSync(filePath);
195
+ return stat.isFile() ? stat.size : -1;
196
+ }
197
+ catch {
198
+ return -1;
199
+ }
200
+ }
201
+ /**
202
+ * 格式化文件大小为可读字符串
203
+ * @param bytes 字节数
204
+ * @returns 格式化后的字符串
205
+ */
206
+ function formatFileSize(bytes) {
207
+ if (bytes === 0)
208
+ return '0 B';
209
+ const units = ['B', 'KB', 'MB', 'GB', 'TB'];
210
+ const k = 1024;
211
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
212
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + units[i];
213
+ }
214
+ /**
215
+ * 复制文件
216
+ * @param src 源文件路径
217
+ * @param dest 目标文件路径
218
+ * @returns 是否复制成功
219
+ */
220
+ function copyFile(src, dest) {
221
+ try {
222
+ ensureDir(path.dirname(dest));
223
+ fs.copyFileSync(src, dest);
224
+ return true;
225
+ }
226
+ catch (error) {
227
+ console.error(`复制文件失败: ${src} -> ${dest}`, error);
228
+ return false;
229
+ }
230
+ }
231
+ /**
232
+ * 读取JSON文件
233
+ * @param filePath 文件路径
234
+ * @returns JSON对象,失败返回 null
235
+ */
236
+ function readJSON(filePath) {
237
+ try {
238
+ const content = fs.readFileSync(filePath, 'utf-8');
239
+ return JSON.parse(content);
240
+ }
241
+ catch (error) {
242
+ console.error(`读取JSON文件失败: ${filePath}`, error);
243
+ return null;
244
+ }
245
+ }
246
+ /**
247
+ * 写入JSON文件
248
+ * @param filePath 文件路径
249
+ * @param data 数据对象
250
+ * @param pretty 是否格式化输出
251
+ * @returns 是否写入成功
252
+ */
253
+ function writeJSON(filePath, data, pretty = true) {
254
+ try {
255
+ ensureDir(path.dirname(filePath));
256
+ const content = pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data);
257
+ fs.writeFileSync(filePath, content, 'utf-8');
258
+ return true;
259
+ }
260
+ catch (error) {
261
+ console.error(`写入JSON文件失败: ${filePath}`, error);
262
+ return false;
263
+ }
264
+ }
265
+ /**
266
+ * 检查路径是否为Cocos Creator项目目录
267
+ * @param dirPath 目录路径
268
+ * @returns 是否为有效的Cocos Creator项目
269
+ */
270
+ function isCocosProject(dirPath) {
271
+ // 检查是否存在项目配置文件
272
+ const projectFiles = ['project.json', 'package.json'];
273
+ const assetDirs = ['assets', 'Assets'];
274
+ for (const file of projectFiles) {
275
+ if (fs.existsSync(path.join(dirPath, file))) {
276
+ for (const dir of assetDirs) {
277
+ if (fs.existsSync(path.join(dirPath, dir))) {
278
+ return true;
279
+ }
280
+ }
281
+ }
282
+ }
283
+ return false;
284
+ }
285
+ /**
286
+ * 获取Cocos Creator项目的资源目录
287
+ * @param projectPath 项目路径
288
+ * @returns 资源目录路径,如果找不到返回 null
289
+ */
290
+ function getAssetsDir(projectPath) {
291
+ const assetDirs = ['assets', 'Assets'];
292
+ for (const dir of assetDirs) {
293
+ const fullPath = path.join(projectPath, dir);
294
+ if (fs.existsSync(fullPath)) {
295
+ return fullPath;
296
+ }
297
+ }
298
+ return null;
299
+ }
300
+ /**
301
+ * 延迟函数
302
+ * @param ms 毫秒数
303
+ * @returns Promise
304
+ */
305
+ function sleep(ms) {
306
+ return new Promise(resolve => setTimeout(resolve, ms));
307
+ }
308
+ /**
309
+ * 批量处理函数
310
+ * @param items 待处理项列表
311
+ * @param processor 处理函数
312
+ * @param batchSize 批处理大小
313
+ * @returns 处理结果
314
+ */
315
+ async function batchProcess(items, processor, batchSize = 10) {
316
+ const results = [];
317
+ for (let i = 0; i < items.length; i += batchSize) {
318
+ const batch = items.slice(i, i + batchSize);
319
+ const batchResults = await Promise.all(batch.map(processor));
320
+ results.push(...batchResults);
321
+ }
322
+ return results;
323
+ }
324
+ //# sourceMappingURL=utils.js.map