fast-cocos 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,97 @@
1
+ // 数字序列
2
+ type BuildNumbers<N extends number, Result extends number[] = []> = Result["length"] extends N
3
+ ? never
4
+ : [...Result, Result["length"]] extends [infer _, ...infer Rest]
5
+ ? Result["length"] | BuildNumbers<N, [...Result, Result["length"]]>
6
+ : never;
7
+
8
+ // 生成 1 到 10 的数字
9
+ type NumberRange = Exclude<BuildNumbers<11>, 0>;
10
+
11
+ // Excel版本
12
+ type XlsxVersion = `v${NumberRange}`;
13
+
14
+ // 整数
15
+ export type int = number;
16
+
17
+ // 浮点数
18
+ export type float = number;
19
+
20
+ // Excel工作表数据
21
+ type XlsxData<T = unknown> = { [key: string]: T };
22
+
23
+ // Excel工作表管理
24
+ class Xlsx {
25
+ private static _instance: Xlsx;
26
+ public static get instance(): Xlsx {
27
+ return Xlsx._instance ?? (Xlsx._instance = new Xlsx());
28
+ }
29
+ [key: string]: any;
30
+ private readonly sheetToKey: Map<string, string>;
31
+ {0}
32
+ private constructor() {
33
+ {1}
34
+ this.sheetToKey = new Map();
35
+ const keys = Object.keys(this).filter((it) => it != "sheetToKey");
36
+ const values = Object.values(this);
37
+ for (const value of values) {
38
+ const key = keys.find((key) => this[key] === value);
39
+ key && this.sheetToKey.set(value, key);
40
+ }
41
+ }
42
+
43
+ /**
44
+ * 更新所有数据表
45
+ * @param xlsx 表数据
46
+ */
47
+ public updateXlsx(xlsx: XlsxData): void {
48
+ Object.keys(xlsx).forEach((sheetName) => this.updateSheet(sheetName, xlsx[sheetName]));
49
+ }
50
+
51
+ /**
52
+ * 更新指定的表
53
+ * @param sheetName 表名
54
+ * @param data 表数据
55
+ */
56
+ public updateSheet<T>(sheetName: string, data: T): void {
57
+ const key = this.sheetToKey.get(sheetName);
58
+ if (!key) {
59
+ this[sheetName] = data;
60
+ console.warn(`强制更新表【${sheetName}】`);
61
+ return;
62
+ }
63
+
64
+ if (sheetName.endsWith("KVMap") || (!sheetName.endsWith("VMap") && sheetName.endsWith("Map"))) {
65
+ this[key] = this.toMap(data as { [key: string]: unknown });
66
+ return;
67
+ }
68
+
69
+ this[key] = data;
70
+ }
71
+
72
+ /**
73
+ * 检查没有的配置表
74
+ */
75
+ public checkNotSheet(): string[] {
76
+ return [...this.sheetToKey.keys()].filter((sheetName) => typeof this[sheetName] == "string");
77
+ }
78
+
79
+ /**
80
+ * 对象转map
81
+ * @param obj 对象
82
+ */
83
+ private toMap<T>(obj: { [key: string]: T }): Map<string, T> {
84
+ const entries = Object.entries(obj);
85
+ entries.forEach((entry) => {
86
+ if (/^-?\d+$/.test(entry[0])) {
87
+ (entry[0] as any) = Number(entry[0]);
88
+ }
89
+ });
90
+ return new Map(entries);
91
+ }
92
+ }
93
+
94
+ export const xlsx = Xlsx.instance;
95
+ if (cc.sys.isBrowser) {
96
+ (window as any)["xlsx"] = xlsx;
97
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const commander_1 = require("commander");
16
+ const crypto_1 = __importDefault(require("crypto"));
17
+ const fs_1 = __importDefault(require("fs"));
18
+ /**
19
+ * 生成严格 8-4-2 格式的 XXTEA 密钥
20
+ * @returns {string} 格式如 "7705064d-5c6e-4e" 的密钥
21
+ */
22
+ function generateKey() {
23
+ // 生成各部分随机十六进制字符
24
+ const part1 = crypto_1.default.randomBytes(4).toString("hex"); // 8字符
25
+ const part2 = crypto_1.default.randomBytes(2).toString("hex"); // 4字符
26
+ const part3 = crypto_1.default.randomBytes(1).toString("hex"); // 2字符
27
+ // 组合成 8-4-2 格式
28
+ return `${part1}-${part2}-${part3}`;
29
+ }
30
+ function main() {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ commander_1.program
33
+ .name("xxteakey")
34
+ .description("xxteakey generator")
35
+ .version("1.0.0")
36
+ .requiredOption("-j, --json <json>", "json file path")
37
+ .parse(process.argv);
38
+ const options = commander_1.program.opts();
39
+ // json 文件路径
40
+ const jsonPath = options.json;
41
+ if (!fs_1.default.existsSync(jsonPath)) {
42
+ console.error("json 文件不存在");
43
+ return;
44
+ }
45
+ const data = fs_1.default.readFileSync(jsonPath, { encoding: "utf-8" });
46
+ const json = JSON.parse(data);
47
+ const xxteaKey = generateKey();
48
+ json.xxteaKey = xxteaKey;
49
+ fs_1.default.writeFileSync(jsonPath, JSON.stringify(json, null, 4));
50
+ console.log(`xxteaKey: ${xxteaKey}`);
51
+ });
52
+ }
53
+ void main().catch((err) => {
54
+ console.error(err);
55
+ process.exit(1);
56
+ });
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "fast-cocos",
3
+ "version": "1.0.0",
4
+ "scripts": {
5
+ "clean": "rm -rf dist",
6
+ "start": "node ./dist/index.js",
7
+ "dev": "nodemon",
8
+ "test": "npm run build",
9
+ "build": "npm run clean && tsc && node scripts/copy-assets.js",
10
+ "prepack": "npm run build"
11
+ },
12
+ "main": "./dist/index.js",
13
+ "bin": {
14
+ "fast-cocos": "dist/index.js"
15
+ },
16
+ "files": [
17
+ "bin/",
18
+ "dist/",
19
+ "copy-assets.json",
20
+ "scripts/copy-assets.js"
21
+ ],
22
+ "pkg": {
23
+ "scripts": [
24
+ "dist/*.js"
25
+ ],
26
+ "assets": [
27
+ "dist/*",
28
+ "node_modules/axios/**/*"
29
+ ],
30
+ "targets": [
31
+ "node18-win-x64",
32
+ "node18-macos-x64"
33
+ ],
34
+ "outputPath": "./"
35
+ },
36
+ "keywords": [],
37
+ "author": "",
38
+ "license": "ISC",
39
+ "description": "",
40
+ "devDependencies": {
41
+ "@types/node": "^24.1.0",
42
+ "@types/spritesmith": "^3.4.5",
43
+ "nodemon": "^3.1.10",
44
+ "ts-node": "^10.9.2",
45
+ "typescript": "^5.8.3"
46
+ },
47
+ "dependencies": {
48
+ "axios": "^1.11.0",
49
+ "axios-cookiejar-support": "^5.0.5",
50
+ "commander": "^13.1.0",
51
+ "node-xlsx": "^0.24.0",
52
+ "spritesmith": "^3.4.0",
53
+ "tough-cookie": "^5.1.2"
54
+ }
55
+ }
@@ -0,0 +1,56 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ const root = path.join(__dirname, "..");
5
+ const manifestPath = path.join(root, "copy-assets.json");
6
+
7
+ function fail(msg) {
8
+ console.error(`copy-assets: ${msg}`);
9
+ // process.exit(1);
10
+ }
11
+
12
+ if (!fs.existsSync(manifestPath)) {
13
+ fail(`missing manifest ${manifestPath}`);
14
+ }
15
+
16
+ let manifest;
17
+ try {
18
+ manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
19
+ } catch (e) {
20
+ fail(`invalid JSON in ${manifestPath}: ${e instanceof Error ? e.message : e}`);
21
+ }
22
+
23
+ if (!manifest || !Array.isArray(manifest.copy)) {
24
+ fail(`copy-assets.json must contain a "copy" array`);
25
+ }
26
+
27
+ const distDir = path.join(root, "dist");
28
+ if (!fs.existsSync(distDir)) {
29
+ fail("dist/ is missing; run tsc first.");
30
+ }
31
+
32
+ for (let i = 0; i < manifest.copy.length; i++) {
33
+ const entry = manifest.copy[i];
34
+ if (!entry || typeof entry.from !== "string" || typeof entry.to !== "string") {
35
+ fail(`copy[${i}] needs string "from" and "to"`);
36
+ }
37
+
38
+ const fromAbs = path.join(root, entry.from);
39
+ const toAbs = path.join(root, entry.to);
40
+
41
+ if (!fs.existsSync(fromAbs)) {
42
+ fail(`missing source: ${entry.from}`);
43
+ continue;
44
+ }
45
+
46
+ const st = fs.statSync(fromAbs);
47
+ if (st.isDirectory()) {
48
+ fs.mkdirSync(path.dirname(toAbs), { recursive: true });
49
+ fs.cpSync(fromAbs, toAbs, { recursive: true });
50
+ } else if (st.isFile()) {
51
+ fs.mkdirSync(path.dirname(toAbs), { recursive: true });
52
+ fs.copyFileSync(fromAbs, toAbs);
53
+ } else {
54
+ fail(`unsupported source type for: ${entry.from}`);
55
+ }
56
+ }