nox-mod-admin-cli-v2 0.0.0-stage → 1.0.1

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
@@ -1,3 +1,109 @@
1
- # Temporary Holding Version
1
+ # nox-mod-admin-cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ CLI tạo các file zip từ resources và (tùy chọn) upload lên S3.
4
+
5
+ - Node.js >= 18
6
+ - Hỗ trợ: macOS, Linux, Windows
7
+
8
+ ## Cài đặt
9
+
10
+ ```bash
11
+ npm install -g nox-mod-admin-cli
12
+ ```
13
+
14
+ Hoặc chạy trực tiếp bằng npx (không cần cài):
15
+
16
+ ```bash
17
+ npx nox-mod-admin-cli <resources_path> <package_name>
18
+ ```
19
+
20
+ ## Lệnh
21
+
22
+ ### Build từ resources zip
23
+
24
+ ```bash
25
+ nox-mod-admin <resources_path> <package_name> [aws-profile-name] [--production | --development]
26
+ ```
27
+
28
+ | Tham số | Bắt buộc | Mô tả |
29
+ |--------|----------|--------|
30
+ | `resources_path` | Có | Đường dẫn file .zip resources (vd: `com.garena.game.kgvn.zip`) |
31
+ | `package_name` | Có | Loại server: `vn`, `tw`, `id`, `th`, `eu`, `jp` |
32
+ | `aws-profile-name` | Không | Tên AWS profile để upload lên S3 sau khi tạo xong file |
33
+ | `--production` | Không | Upload lên bucket `nox-mod-skin-storage` |
34
+ | `--development` | Không | Upload lên bucket `nox-mod-skin-storage-dev` (mặc định) |
35
+
36
+ Không dùng đồng thời `--production` và `--development`.
37
+
38
+ **Ví dụ:**
39
+
40
+ ```bash
41
+ nox-mod-admin com.garena.game.kgvn.zip vn
42
+ nox-mod-admin ./resources.zip tw nms2
43
+ nox-mod-admin com.garena.game.kgvn.zip vn nms2 --development
44
+ nox-mod-admin com.garena.game.kgvn.zip vn nms2 --production
45
+ ```
46
+
47
+ ### Sinh constant từ folder (base paths)
48
+
49
+ ```bash
50
+ nox-mod-admin --gen-base <path_to_folder>
51
+ ```
52
+
53
+ Đọc toàn bộ file và thư mục trong folder, ghi ra `src/base-paths.js` (BASE_PATHS + BASE_DIRS). Dùng khi cập nhật danh sách file cho base.zip.
54
+
55
+ **Ví dụ:**
56
+
57
+ ```bash
58
+ nox-mod-admin --gen-base base
59
+ nox-mod-admin --gen-base ./my-structure
60
+ ```
61
+
62
+ ## File được tạo
63
+
64
+ Mỗi lần chạy dùng thư mục tạm (OS temp) và xóa thư mục này khi kết thúc. Khi chạy không có AWS profile, các file ZIP được lưu vào `.output/` trong thư mục làm việc hiện tại. Các file ZIP tạo ra:
65
+
66
+ | File | Nội dung |
67
+ |------|----------|
68
+ | `base.zip` | File theo BASE_PATHS/BASE_DIRS từ `files/Resources/{version}/`, gồm `Ages/Prefab_Characters/Prefab_Hero/Actor_530_Actions.pkg.bytes` (cam xa v2) |
69
+ | `ages_{server}.zip` | `files/Resources/{version}/Ages/` |
70
+ | `assetbundle_{server}.zip` | `files/Resources/{version}/assetbundle/` |
71
+ | `prefab_characters_all.zip` | `files/Resources/{version}/Prefab_Characters/` |
72
+ | `databin_{server}.zip` | `files/Resources/{version}/Databin/` |
73
+ | `languages_{server}.zip` | `files/Resources/{version}/Languages/` |
74
+ | `fix_permission.zip` | Ages, assetbundle, AssetRefs, Databin, Languages, Prefab_Characters, Sound, Thanos và file StableSystems_3.pkg.bytes |
75
+
76
+ - `{server}` = giá trị `package_name` (vn, tw, id, …).
77
+ - `{version}` = thư mục version trong resources (vd: `1.61.1`).
78
+ - Zip dùng nén **store** (không nén).
79
+
80
+ ## Upload S3
81
+
82
+ Khi truyền `aws-profile-name`:
83
+
84
+ - **Bucket dev (mặc định hoặc `--development`):** `nox-mod-skin-storage-dev`
85
+ - **Bucket prod (`--production`):** `nox-mod-skin-storage`
86
+ - **Prefix (cả hai môi trường):** `servers/{package_folder}/files`
87
+ - **Package folder** (theo `package_name`):
88
+ vn → `com.garena.game.kgvn`, tw → `com.garena.game.kgtw`, id → `com.garena.game.kgid`, th → `com.garena.game.kgth`, eu → `com.ngame.allstar.eu`, jp → `com.tencent.ngjp`
89
+
90
+ Upload gồm: file resources (input) + toàn bộ file zip vừa tạo.
91
+
92
+ Nếu resources chứa `CommonActions.pkg.bytes`, CLI cũng giải nén và upload các file chưa có trên S3 vào `worker-assets/gameresources/CommonActions/` trong bucket đã chọn. Các object đã có được giữ nguyên.
93
+
94
+ Sau khi đồng bộ CommonActions thành công, CLI cập nhật `worker-assets/gameresources/.nox` và `worker-assets/gameresources/CommonActions/.nox` với cùng thời gian upload theo giờ Việt Nam (`YYYY-MM-DD HH:mm:ss`).
95
+
96
+ **Yêu cầu:** Cài [AWS CLI](https://aws.amazon.com/cli/), cấu hình profile tương ứng. CLI dùng endpoint S3 mặc định (cấu hình trong code).
97
+
98
+ ## Development
99
+
100
+ ```bash
101
+ git clone <repo>
102
+ cd nox-mod-admin-cli
103
+ npm install
104
+ node bin/cli.js com.garena.game.kgvn.zip vn
105
+ ```
106
+
107
+ ## License
108
+
109
+ MIT
package/bin/cli.js ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { run, genBasePaths } from "../src/index.js";
4
+
5
+ const args = process.argv.slice(2);
6
+ if (args[0] === "--gen-base") {
7
+ const dir = args[1];
8
+ if (!dir) {
9
+ console.error("Usage: nox-mod-admin --gen-base <path_to_folder>");
10
+ process.exit(1);
11
+ }
12
+ genBasePaths(process.cwd(), dir).catch((err) => {
13
+ console.error(err.message);
14
+ process.exit(1);
15
+ });
16
+ } else {
17
+ const production = args.includes("--production");
18
+ const development = args.includes("--development");
19
+ if (production && development) {
20
+ console.error("Chỉ chọn một trong --production hoặc --development.");
21
+ process.exit(1);
22
+ }
23
+ const rest = args.filter(
24
+ (a) => a !== "--production" && a !== "--development"
25
+ );
26
+ const [resourcesPath, packageName, awsProfileName] = rest;
27
+ if (!resourcesPath || !packageName) {
28
+ console.error(`
29
+ Usage:
30
+ nox-mod-admin --gen-base <path_to_folder>
31
+ Đọc folder, ghi BASE_PATHS + BASE_DIRS vào src/base-paths.js
32
+
33
+ nox-mod-admin <resources_path> <package_name> [aws-profile-name] [--production | --development]
34
+ resources_path Path to .zip file
35
+ package_name vn | tw | id | th | eu | jp
36
+ aws-profile-name (optional) Tên AWS profile để upload lên S3
37
+ --production (optional) Bucket nox-mod-skin-storage
38
+ --development (optional) Bucket nox-mod-skin-storage-dev (mặc định)
39
+ `);
40
+ process.exit(1);
41
+ }
42
+ run({ resourcesPath, packageName, awsProfileName, production }).catch(
43
+ (err) => {
44
+ console.error(err.message);
45
+ process.exit(1);
46
+ }
47
+ );
48
+ }
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
1
  {
2
2
  "name": "nox-mod-admin-cli-v2",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.1",
4
+ "description": "CLI tool with pretty output and progress",
5
+ "type": "module",
6
+ "bin": {
7
+ "nox-mod-admin": "bin/cli.js"
8
+ },
9
+ "engines": {
10
+ "node": ">=18"
11
+ },
12
+ "os": [
13
+ "darwin",
14
+ "linux",
15
+ "win32"
16
+ ],
17
+ "files": [
18
+ "bin",
19
+ "src"
20
+ ],
21
+ "main": "src/index.js",
22
+ "scripts": {
23
+ "start": "node bin/cli.js",
24
+ "cli": "node bin/cli.js"
25
+ },
26
+ "dependencies": {
27
+ "adm-zip": "^0.5.16",
28
+ "chalk": "^5.3.0",
29
+ "cli-progress": "^3.12.0",
30
+ "ora": "^8.1.1"
31
+ }
32
+ }
@@ -0,0 +1,37 @@
1
+ export const BASE_PATHS = [
2
+ "Ages/Prefab_Characters/Prefab_Hero/Actor_530_Actions.pkg.bytes",
3
+ "Ages/Prefab_Characters/Prefab_Hero/CommonActions.pkg.bytes",
4
+ "Databin/Client/Actor/heroSkin.bytes",
5
+ "Databin/Client/Character/ResCharacterComponent.bytes",
6
+ "Databin/Client/Shop/HeroSkinShop.bytes",
7
+ "Databin/Client/Skill/liteBulletCfg.bytes",
8
+ "Databin/Client/Skill/skillmark.bytes",
9
+ "Databin/Client/Sound/BattleBank.bytes",
10
+ "Databin/Client/Sound/ChatSound.bytes",
11
+ "Databin/Client/Sound/CoupleSound.bytes",
12
+ "Databin/Client/Sound/HeroSound.bytes",
13
+ "Databin/Client/Sound/LobbyBank.bytes",
14
+ "Databin/Client/Sound/LobbySound.bytes",
15
+ "Databin/Client/Text/60FPSWhiteList.bytes",
16
+ "Databin/Client/Text/VeryHighFrameModeBlackList.bytes",
17
+ ];
18
+
19
+ export const BASE_DIRS = [
20
+ "Ages",
21
+ "Ages/Prefab_Characters",
22
+ "Ages/Prefab_Characters/Prefab_Hero",
23
+ "AssetRefs",
24
+ "AssetRefs/Hero",
25
+ "Databin",
26
+ "Databin/Client",
27
+ "Databin/Client/Actor",
28
+ "Databin/Client/Character",
29
+ "Databin/Client/Shop",
30
+ "Databin/Client/Skill",
31
+ "Databin/Client/Sound",
32
+ "Databin/Client/Text",
33
+ "Languages",
34
+ "Languages/EN_Garena_VN",
35
+ "Languages/VN_Garena_VN",
36
+ "Prefab_Characters",
37
+ ];
package/src/index.js ADDED
@@ -0,0 +1,583 @@
1
+ import chalk from "chalk";
2
+ import ora from "ora";
3
+ import cliProgress from "cli-progress";
4
+ import { readdir, mkdir, copyFile, rm, readFile, writeFile } from "fs/promises";
5
+ import { join, dirname, basename, resolve } from "path";
6
+ import { fileURLToPath } from "url";
7
+ import os from "os";
8
+ import { randomBytes } from "crypto";
9
+ import { execFileSync } from "child_process";
10
+ import AdmZip from "adm-zip";
11
+ import { BASE_PATHS, BASE_DIRS } from "./base-paths.js";
12
+
13
+ const PACKAGE_TO_FOLDER = {
14
+ vn: "com.garena.game.kgvn",
15
+ tw: "com.garena.game.kgtw",
16
+ id: "com.garena.game.kgid",
17
+ th: "com.garena.game.kgth",
18
+ eu: "com.ngame.allstar.eu",
19
+ jp: "com.tencent.ngjp",
20
+ };
21
+
22
+ const PACKAGE_ENUM = Object.keys(PACKAGE_TO_FOLDER);
23
+
24
+ const S3_ENDPOINT_URL = "https://s3-hcm-r2.s3cloud.vn:443";
25
+ const COMMON_ACTIONS_PATH = "Ages/Prefab_Characters/Prefab_Hero/CommonActions.pkg.bytes";
26
+ const GAME_RESOURCES_PREFIX = "worker-assets/gameresources/";
27
+ const COMMON_ACTIONS_PREFIX = GAME_RESOURCES_PREFIX + "CommonActions/";
28
+
29
+ async function uploadCommonActions(packageData, outDir, bucket, awsOptions) {
30
+ if (!packageData) {
31
+ console.log("CommonActions.pkg.bytes is missing from this resources archive.");
32
+ return;
33
+ }
34
+
35
+ const archive = new AdmZip(packageData);
36
+ const listing = execFileSync("aws", [
37
+ "s3api", "list-objects-v2", "--bucket", bucket,
38
+ "--prefix", COMMON_ACTIONS_PREFIX, "--query", "Contents[].Key",
39
+ "--output", "json", ...awsOptions,
40
+ ], { encoding: "utf8" });
41
+ const existingKeys = new Set(JSON.parse(listing) ?? []);
42
+ const newEntries = archive.getEntries().filter((entry) =>
43
+ !entry.isDirectory && !existingKeys.has(COMMON_ACTIONS_PREFIX + entry.entryName)
44
+ );
45
+ const stagingDir = join(outDir, "worker-common-actions");
46
+ for (const entry of newEntries) {
47
+ const segments = entry.entryName.split("/");
48
+ if (entry.entryName.includes("\\") || segments.some((segment) =>
49
+ !segment || segment === "." || segment === ".."
50
+ )) {
51
+ throw new Error(`Invalid CommonActions entry path: ${entry.entryName}`);
52
+ }
53
+ const destination = join(stagingDir, ...segments);
54
+ await mkdir(dirname(destination), { recursive: true });
55
+ await writeFile(destination, entry.getData());
56
+ }
57
+
58
+ const destination = `s3://${bucket}/${COMMON_ACTIONS_PREFIX}`;
59
+ if (newEntries.length) {
60
+ execFileSync("aws", ["s3", "sync", stagingDir, destination, ...awsOptions],
61
+ { stdio: "inherit" });
62
+ }
63
+ console.log(`Uploaded ${newEntries.length} new CommonActions files to ${destination}`);
64
+
65
+ const timestamp = new Intl.DateTimeFormat("sv-SE", {
66
+ timeZone: "Asia/Ho_Chi_Minh",
67
+ dateStyle: "short",
68
+ timeStyle: "medium",
69
+ }).format(new Date());
70
+ const markerPath = join(outDir, ".nox");
71
+ await writeFile(markerPath, timestamp);
72
+ for (const prefix of [COMMON_ACTIONS_PREFIX, GAME_RESOURCES_PREFIX]) {
73
+ execFileSync("aws", ["s3", "cp", markerPath, `s3://${bucket}/${prefix}.nox`,
74
+ "--content-type", "text/plain", ...awsOptions], { stdio: "inherit" });
75
+ }
76
+ }
77
+
78
+ const FIX_PERMISSION_FOLDERS = [
79
+ "Ages",
80
+ "assetbundle",
81
+ "AssetRefs",
82
+ "Databin",
83
+ "Languages",
84
+ "Prefab_Characters",
85
+ "Sound",
86
+ "Thanos",
87
+ ];
88
+
89
+ const FIX_PERMISSION_FILES = ["StableSystems_3.pkg.bytes"];
90
+
91
+ async function collectRelativeFiles(dir, baseDir, list = []) {
92
+ const entries = await readdir(dir, { withFileTypes: true });
93
+ for (const e of entries) {
94
+ const full = join(dir, e.name);
95
+ const rel = join(baseDir, e.name).replace(/\\/g, "/");
96
+ if (e.isDirectory()) await collectRelativeFiles(full, rel, list);
97
+ else list.push(rel);
98
+ }
99
+ return list;
100
+ }
101
+
102
+ async function collectRelativeDirs(dir, baseDir, list = []) {
103
+ const entries = await readdir(dir, { withFileTypes: true });
104
+ for (const e of entries) {
105
+ if (!e.isDirectory()) continue;
106
+ const full = join(dir, e.name);
107
+ const rel = join(baseDir, e.name).replace(/\\/g, "/");
108
+ list.push(rel);
109
+ await collectRelativeDirs(full, rel, list);
110
+ }
111
+ return list;
112
+ }
113
+
114
+ async function copyDir(src, dest) {
115
+ await mkdir(dest, { recursive: true });
116
+ const entries = await readdir(src, { withFileTypes: true });
117
+ for (const e of entries) {
118
+ const srcPath = join(src, e.name);
119
+ const destPath = join(dest, e.name);
120
+ if (e.isDirectory()) await copyDir(srcPath, destPath);
121
+ else await copyFile(srcPath, destPath);
122
+ }
123
+ }
124
+
125
+ const __dirname = dirname(fileURLToPath(import.meta.url));
126
+
127
+ async function readBasePaths(dirPath) {
128
+ const resolved = join(process.cwd(), dirPath);
129
+ const { stat } = await import("fs/promises").then((fs) =>
130
+ fs
131
+ .stat(resolved)
132
+ .then((stat) => ({ stat }))
133
+ .catch(() => {
134
+ throw new Error("Thư mục không tồn tại: " + dirPath);
135
+ })
136
+ );
137
+ if (!stat.isDirectory()) throw new Error("Phải là thư mục: " + dirPath);
138
+ const list = await collectRelativeFiles(resolved, "");
139
+ return list.sort();
140
+ }
141
+
142
+ async function readBaseDirs(dirPath) {
143
+ const resolved = join(process.cwd(), dirPath);
144
+ const { stat } = await import("fs/promises").then((fs) =>
145
+ fs
146
+ .stat(resolved)
147
+ .then((s) => ({ stat: s }))
148
+ .catch(() => null)
149
+ );
150
+ if (!stat?.isDirectory()) return [];
151
+ const list = await collectRelativeDirs(resolved, "");
152
+ return list.sort();
153
+ }
154
+
155
+ export async function genBasePaths(cwd, dirPath) {
156
+ const outPath = join(__dirname, "base-paths.js");
157
+ const prevCwd = process.cwd();
158
+ try {
159
+ if (cwd) process.chdir(cwd);
160
+ const files = await readBasePaths(dirPath);
161
+ const dirs = await readBaseDirs(dirPath);
162
+ const content =
163
+ "export const BASE_PATHS = [\n" +
164
+ files.map((p) => ' "' + p.replace(/"/g, '\\"') + '",').join("\n") +
165
+ "\n];\n\n" +
166
+ "export const BASE_DIRS = [\n" +
167
+ dirs.map((p) => ' "' + p.replace(/"/g, '\\"') + '",').join("\n") +
168
+ "\n];\n";
169
+ await writeFile(outPath, content, "utf8");
170
+ console.log(
171
+ chalk.green("✓") +
172
+ " " +
173
+ files.length +
174
+ " file, " +
175
+ dirs.length +
176
+ " thư mục rỗng → src/base-paths.js"
177
+ );
178
+ } finally {
179
+ process.chdir(prevCwd);
180
+ }
181
+ }
182
+
183
+ function box(title, content) {
184
+ const line = "─".repeat(50);
185
+ return [
186
+ chalk.cyan("┌" + line + "┐"),
187
+ chalk.cyan("│") +
188
+ " " +
189
+ chalk.bold(title) +
190
+ " ".repeat(Math.max(0, 49 - title.length)) +
191
+ chalk.cyan("│"),
192
+ chalk.cyan("├" + line + "┤"),
193
+ ...content.map(
194
+ (c) =>
195
+ chalk.cyan("│") +
196
+ " " +
197
+ c +
198
+ " ".repeat(Math.max(0, 49 - c.length)) +
199
+ chalk.cyan("│")
200
+ ),
201
+ chalk.cyan("└" + line + "┘"),
202
+ ].join("\n");
203
+ }
204
+
205
+ function findResourcesRoot(extractDir) {
206
+ const resourcesDir = join(extractDir, "files", "Resources");
207
+ return readdir(resourcesDir, { withFileTypes: true }).then((entries) => {
208
+ const dir = entries.find((e) => e.isDirectory() && !e.name.startsWith("."));
209
+ if (!dir) throw new Error("No version folder in files/Resources");
210
+ return join(resourcesDir, dir.name);
211
+ });
212
+ }
213
+
214
+ export async function run({
215
+ resourcesPath,
216
+ packageName,
217
+ awsProfileName,
218
+ production = false,
219
+ }) {
220
+ if (!resourcesPath.toLowerCase().endsWith(".zip")) {
221
+ throw new Error("resources_path must be a .zip file");
222
+ }
223
+ const pkg = packageName.toLowerCase();
224
+ if (!PACKAGE_ENUM.includes(pkg)) {
225
+ throw new Error(`package_name must be one of: ${PACKAGE_ENUM.join(", ")}`);
226
+ }
227
+ const folder = PACKAGE_TO_FOLDER[pkg];
228
+
229
+ console.log();
230
+ console.log(
231
+ box("nox-mod-admin", [
232
+ chalk.gray("resources") + ": " + chalk.white(resourcesPath),
233
+ chalk.gray("package") +
234
+ ": " +
235
+ chalk.yellow(pkg) +
236
+ " → " +
237
+ chalk.white(folder),
238
+ ])
239
+ );
240
+ console.log();
241
+
242
+ const cwd = process.cwd();
243
+ const uniqueId =
244
+ Date.now().toString(36) + "-" + randomBytes(4).toString("hex");
245
+ const outDir = join(os.tmpdir(), "nox-mod-admin-" + uniqueId);
246
+ await mkdir(outDir, { recursive: true });
247
+ const extractDir = join(outDir, "extracted");
248
+ const baseBuildDir = join(outDir, "base");
249
+
250
+ try {
251
+ console.log(
252
+ chalk.gray(" BASE_PATHS: " + BASE_PATHS.length + " path (constant)")
253
+ );
254
+
255
+ const spinnerExtract = ora({
256
+ text: chalk.blue("Bước 2: Giải nén resources..."),
257
+ spinner: "dots12",
258
+ color: "cyan",
259
+ }).start();
260
+ await mkdir(outDir, { recursive: true });
261
+ const resZip = new AdmZip(resourcesPath);
262
+ resZip.extractAllTo(extractDir, true);
263
+ spinnerExtract.succeed(chalk.green("Extracted to .output/extracted"));
264
+
265
+ const resourcesRoot = await findResourcesRoot(extractDir);
266
+
267
+ const bar = new cliProgress.SingleBar({
268
+ format:
269
+ chalk.cyan(" Building base ") +
270
+ "│" +
271
+ chalk.hex("#0ea5e9")("{bar}") +
272
+ "│ " +
273
+ chalk.white("{percentage}%") +
274
+ " │ " +
275
+ chalk.gray("{value}/{total} files"),
276
+ barCompleteChar: "\u2588",
277
+ barIncompleteChar: "\u2591",
278
+ hideCursor: true,
279
+ clearOnComplete: false,
280
+ });
281
+
282
+ for (const rel of BASE_DIRS) {
283
+ await mkdir(join(baseBuildDir, rel), { recursive: true });
284
+ }
285
+ bar.start(BASE_PATHS.length, 0);
286
+ let copied = 0;
287
+ let i = 0;
288
+ for (const relPath of BASE_PATHS) {
289
+ const src = join(resourcesRoot, relPath);
290
+ const dest = join(baseBuildDir, relPath);
291
+ try {
292
+ await mkdir(dirname(dest), { recursive: true });
293
+ await copyFile(src, dest);
294
+ copied++;
295
+ } catch (_) {}
296
+ i++;
297
+ bar.update(i);
298
+ }
299
+ bar.stop();
300
+
301
+ const spinnerZip = ora({
302
+ text: chalk.blue("Writing base.zip..."),
303
+ spinner: "dots12",
304
+ color: "cyan",
305
+ }).start();
306
+ const outZip = new AdmZip();
307
+ outZip.addLocalFolder(baseBuildDir, "");
308
+ outZip.getEntries().forEach((entry) => {
309
+ if (!entry.isDirectory) entry.header.method = 0;
310
+ });
311
+ const baseZipOut = join(outDir, "base.zip");
312
+ outZip.writeZip(baseZipOut);
313
+ spinnerZip.succeed(chalk.green("Created .output/base.zip"));
314
+
315
+ const version = basename(resourcesRoot);
316
+ const agesBuildDir = join(outDir, "ages_build");
317
+ const agesDest = join(agesBuildDir, "files", "Resources", version, "Ages");
318
+ const agesSrc = join(resourcesRoot, "Ages");
319
+ const spinnerAges = ora({
320
+ text: chalk.blue(
321
+ "Tạo ages_" + pkg + ".zip (files/Resources/" + version + "/Ages)..."
322
+ ),
323
+ spinner: "dots12",
324
+ color: "cyan",
325
+ }).start();
326
+ await mkdir(dirname(agesDest), { recursive: true });
327
+ await copyDir(agesSrc, agesDest);
328
+ const agesZip = new AdmZip();
329
+ agesZip.addLocalFolder(agesBuildDir, "");
330
+ agesZip.getEntries().forEach((entry) => {
331
+ if (!entry.isDirectory) entry.header.method = 0;
332
+ });
333
+ const agesZipPath = join(outDir, "ages_" + pkg + ".zip");
334
+ agesZip.writeZip(agesZipPath);
335
+ await rm(agesBuildDir, { recursive: true, force: true });
336
+ spinnerAges.succeed(chalk.green("Created .output/ages_" + pkg + ".zip"));
337
+
338
+ const assetbundleBuildDir = join(outDir, "assetbundle_build");
339
+ const assetbundleDest = join(
340
+ assetbundleBuildDir,
341
+ "files",
342
+ "Resources",
343
+ version,
344
+ "assetbundle"
345
+ );
346
+ const assetbundleSrc = join(resourcesRoot, "assetbundle");
347
+ const spinnerAssetbundle = ora({
348
+ text: chalk.blue(
349
+ "Tạo assetbundle_" +
350
+ pkg +
351
+ ".zip (files/Resources/" +
352
+ version +
353
+ "/assetbundle)..."
354
+ ),
355
+ spinner: "dots12",
356
+ color: "cyan",
357
+ }).start();
358
+ await mkdir(dirname(assetbundleDest), { recursive: true });
359
+ await copyDir(assetbundleSrc, assetbundleDest);
360
+ const assetbundleZip = new AdmZip();
361
+ assetbundleZip.addLocalFolder(assetbundleBuildDir, "");
362
+ assetbundleZip.getEntries().forEach((entry) => {
363
+ if (!entry.isDirectory) entry.header.method = 0;
364
+ });
365
+ const assetbundleZipPath = join(outDir, "assetbundle_" + pkg + ".zip");
366
+ assetbundleZip.writeZip(assetbundleZipPath);
367
+ await rm(assetbundleBuildDir, { recursive: true, force: true });
368
+ spinnerAssetbundle.succeed(
369
+ chalk.green("Created .output/assetbundle_" + pkg + ".zip")
370
+ );
371
+
372
+ const prefabBuildDir = join(outDir, "prefab_build");
373
+ const prefabDest = join(
374
+ prefabBuildDir,
375
+ "files",
376
+ "Resources",
377
+ version,
378
+ "Prefab_Characters"
379
+ );
380
+ const prefabSrc = join(resourcesRoot, "Prefab_Characters");
381
+ const spinnerPrefab = ora({
382
+ text: chalk.blue(
383
+ "Tạo prefab_characters_all.zip (files/Resources/" +
384
+ version +
385
+ "/Prefab_Characters)..."
386
+ ),
387
+ spinner: "dots12",
388
+ color: "cyan",
389
+ }).start();
390
+ await mkdir(dirname(prefabDest), { recursive: true });
391
+ await copyDir(prefabSrc, prefabDest);
392
+ const prefabZip = new AdmZip();
393
+ prefabZip.addLocalFolder(prefabBuildDir, "");
394
+ prefabZip.getEntries().forEach((entry) => {
395
+ if (!entry.isDirectory) entry.header.method = 0;
396
+ });
397
+ const prefabZipPath = join(outDir, "prefab_characters_all.zip");
398
+ prefabZip.writeZip(prefabZipPath);
399
+ await rm(prefabBuildDir, { recursive: true, force: true });
400
+ spinnerPrefab.succeed(
401
+ chalk.green("Created .output/prefab_characters_all.zip")
402
+ );
403
+
404
+ const databinBuildDir = join(outDir, "databin_build");
405
+ const databinDest = join(
406
+ databinBuildDir,
407
+ "files",
408
+ "Resources",
409
+ version,
410
+ "Databin"
411
+ );
412
+ const databinSrc = join(resourcesRoot, "Databin");
413
+ const spinnerDatabin = ora({
414
+ text: chalk.blue(
415
+ "Tạo databin_" +
416
+ pkg +
417
+ ".zip (files/Resources/" +
418
+ version +
419
+ "/Databin)..."
420
+ ),
421
+ spinner: "dots12",
422
+ color: "cyan",
423
+ }).start();
424
+ await mkdir(dirname(databinDest), { recursive: true });
425
+ await copyDir(databinSrc, databinDest);
426
+ const databinZip = new AdmZip();
427
+ databinZip.addLocalFolder(databinBuildDir, "");
428
+ databinZip.getEntries().forEach((entry) => {
429
+ if (!entry.isDirectory) entry.header.method = 0;
430
+ });
431
+ const databinZipPath = join(outDir, "databin_" + pkg + ".zip");
432
+ databinZip.writeZip(databinZipPath);
433
+ await rm(databinBuildDir, { recursive: true, force: true });
434
+ spinnerDatabin.succeed(
435
+ chalk.green("Created .output/databin_" + pkg + ".zip")
436
+ );
437
+
438
+ const languagesBuildDir = join(outDir, "languages_build");
439
+ const languagesDest = join(
440
+ languagesBuildDir,
441
+ "files",
442
+ "Resources",
443
+ version,
444
+ "Languages"
445
+ );
446
+ const languagesSrc = join(resourcesRoot, "Languages");
447
+ const spinnerLanguages = ora({
448
+ text: chalk.blue(
449
+ "Tạo languages_" +
450
+ pkg +
451
+ ".zip (files/Resources/" +
452
+ version +
453
+ "/Languages)..."
454
+ ),
455
+ spinner: "dots12",
456
+ color: "cyan",
457
+ }).start();
458
+ await mkdir(dirname(languagesDest), { recursive: true });
459
+ await copyDir(languagesSrc, languagesDest);
460
+ const languagesZip = new AdmZip();
461
+ languagesZip.addLocalFolder(languagesBuildDir, "");
462
+ languagesZip.getEntries().forEach((entry) => {
463
+ if (!entry.isDirectory) entry.header.method = 0;
464
+ });
465
+ const languagesZipPath = join(outDir, "languages_" + pkg + ".zip");
466
+ languagesZip.writeZip(languagesZipPath);
467
+ await rm(languagesBuildDir, { recursive: true, force: true });
468
+ spinnerLanguages.succeed(
469
+ chalk.green("Created .output/languages_" + pkg + ".zip")
470
+ );
471
+
472
+ const fixPermBuildDir = join(outDir, "fix_permission_build");
473
+ const spinnerFixPerm = ora({
474
+ text: chalk.blue(
475
+ "Tạo fix_permission.zip (" +
476
+ [...FIX_PERMISSION_FOLDERS, ...FIX_PERMISSION_FILES].join(", ") +
477
+ ")..."
478
+ ),
479
+ spinner: "dots12",
480
+ color: "cyan",
481
+ }).start();
482
+ for (const folder of FIX_PERMISSION_FOLDERS) {
483
+ const src = join(resourcesRoot, folder);
484
+ const dest = join(fixPermBuildDir, "files", "Resources", version, folder);
485
+ try {
486
+ await mkdir(dirname(dest), { recursive: true });
487
+ await copyDir(src, dest);
488
+ } catch (_) {}
489
+ }
490
+ for (const file of FIX_PERMISSION_FILES) {
491
+ const dest = join(fixPermBuildDir, "files", "Resources", version, file);
492
+ await mkdir(dirname(dest), { recursive: true });
493
+ await copyFile(join(resourcesRoot, file), dest);
494
+ }
495
+ const fixPermZip = new AdmZip();
496
+ fixPermZip.addLocalFolder(fixPermBuildDir, "");
497
+ fixPermZip.getEntries().forEach((entry) => {
498
+ if (!entry.isDirectory) entry.header.method = 0;
499
+ });
500
+ const fixPermZipPath = join(outDir, "fix_permission.zip");
501
+ fixPermZip.writeZip(fixPermZipPath);
502
+ await rm(fixPermBuildDir, { recursive: true, force: true });
503
+ spinnerFixPerm.succeed(chalk.green("Created .output/fix_permission.zip"));
504
+
505
+ const commonActionsData = awsProfileName
506
+ ? await readFile(join(resourcesRoot, COMMON_ACTIONS_PATH)).catch((error) => {
507
+ if (error.code === "ENOENT") return null;
508
+ throw error;
509
+ })
510
+ : null;
511
+ await rm(extractDir, { recursive: true, force: true });
512
+ await rm(baseBuildDir, { recursive: true, force: true });
513
+
514
+ console.log();
515
+ console.log(
516
+ chalk.green("✓") +
517
+ " " +
518
+ chalk.bold(copied) +
519
+ "/" +
520
+ BASE_PATHS.length +
521
+ " files → " +
522
+ chalk.cyan(".output/base.zip") +
523
+ ", " +
524
+ chalk.cyan(".output/ages_" + pkg + ".zip") +
525
+ ", " +
526
+ chalk.cyan(".output/assetbundle_" + pkg + ".zip") +
527
+ ", " +
528
+ chalk.cyan(".output/prefab_characters_all.zip") +
529
+ ", " +
530
+ chalk.cyan(".output/databin_" + pkg + ".zip") +
531
+ ", " +
532
+ chalk.cyan(".output/languages_" + pkg + ".zip") +
533
+ ", " +
534
+ chalk.cyan(".output/fix_permission.zip")
535
+ );
536
+
537
+ const entries = await readdir(outDir, { withFileTypes: true });
538
+ const outZipNames = entries
539
+ .filter((entry) => entry.isFile() && entry.name.endsWith(".zip"))
540
+ .map((entry) => entry.name);
541
+
542
+ if (awsProfileName) {
543
+ const bucket = production
544
+ ? "nox-mod-skin-storage"
545
+ : "nox-mod-skin-storage-dev";
546
+ const s3Prefix = `s3://${bucket}/servers/${folder}/files`;
547
+ const awsOptions = ["--profile", awsProfileName, "--endpoint-url", S3_ENDPOINT_URL];
548
+ const spinnerS3 = ora({
549
+ text: chalk.blue("Upload lên S3 " + s3Prefix + "..."),
550
+ spinner: "dots12",
551
+ color: "cyan",
552
+ }).start();
553
+ const outZipFiles = outZipNames.map((name) => join(outDir, name));
554
+ const zipFiles = [resolve(cwd, resourcesPath), ...outZipFiles];
555
+ for (const file of zipFiles) {
556
+ execFileSync(
557
+ "aws",
558
+ [
559
+ "s3",
560
+ "cp",
561
+ file,
562
+ s3Prefix + "/",
563
+ ...awsOptions,
564
+ ],
565
+ { stdio: "inherit" }
566
+ );
567
+ }
568
+ spinnerS3.succeed(
569
+ chalk.green("Uploaded " + zipFiles.length + " file → " + s3Prefix)
570
+ );
571
+ await uploadCommonActions(commonActionsData, outDir, bucket, awsOptions);
572
+ } else {
573
+ const localOutputDir = join(cwd, ".output");
574
+ await mkdir(localOutputDir, { recursive: true });
575
+ for (const name of outZipNames) {
576
+ await copyFile(join(outDir, name), join(localOutputDir, name));
577
+ }
578
+ }
579
+ } finally {
580
+ await rm(outDir, { recursive: true, force: true }).catch(() => {});
581
+ }
582
+ console.log();
583
+ }