hiepdh-playable-toolkit 2.3.4 → 2.4.4

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 (2) hide show
  1. package/package.json +1 -1
  2. package/setup.js +35 -33
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hiepdh-playable-toolkit",
3
- "version": "2.3.4",
3
+ "version": "2.4.4",
4
4
  "main": "setup.js",
5
5
  "dependencies": {
6
6
  "fs-extra": "^11.1.0",
package/setup.js CHANGED
@@ -123,64 +123,66 @@ function copyFolderRecursive(source, target) {
123
123
  }
124
124
 
125
125
  function reviveProject(projectRoot, toolkitRoot, version = "3x") {
126
- console.log(` [Toolkit] Bắt đầu hồi sinh môi trường Cocos ${version}...`);
126
+ console.log(`🛠️ [Toolkit] Đang xử đồng bộ lockfile (v2 -> v3)...`);
127
127
 
128
128
  const targetPkgPath = path.join(projectRoot, "package.json");
129
129
  const targetLockPath = path.join(projectRoot, "package-lock.json");
130
130
  const templateDir = path.join(toolkitRoot, version, "templates");
131
+ const sourceLockPath = path.join(templateDir, "package-lock.json");
131
132
 
132
- // 1. Kiểm tra và khôi phục file lock từ Toolkit nếu project chưa có
133
- if (!fs.existsSync(targetLockPath)) {
134
- const sourceLock = path.join(templateDir, "package-lock.json");
135
- if (fs.existsSync(sourceLock)) {
136
- fs.copySync(sourceLock, targetLockPath);
137
- console.log(" Đã copy package-lock.json mẫu vào dự án.");
138
- } else {
139
- console.error(" Lỗi: Không tìm thấy file lock mẫu trong Toolkit!");
140
- return;
141
- }
133
+ if (!fs.existsSync(sourceLockPath)) {
134
+ console.error(" ❌ Lỗi: Không tìm thấy file lock mẫu trong Toolkit!");
135
+ return;
142
136
  }
143
137
 
144
- // 2. Đọc dữ liệu từ file lock để trích xuất dependencies
145
- const lockData = fs.readJsonSync(targetLockPath);
146
-
147
- // Lấy thông tin từ node "packages" gốc (Trường "" đại diện cho package.json)
138
+ // 1. Đọc dữ liệu từ file lock mẫu (v2) của Toolkit
139
+ const lockData = fs.readJsonSync(sourceLockPath);
148
140
  const rootInfo = lockData.packages && lockData.packages[""];
149
-
141
+
150
142
  if (!rootInfo) {
151
- console.error(" Lỗi: Cấu trúc file lock không hợp lệ (Thiếu packages['']).");
152
- return;
143
+ console.error("Lỗi: File lock mẫu không cấu trúc packages['']!");
144
+ return;
153
145
  }
154
146
 
155
- // 3. Tái tạo nội dung package.json từ file lock
147
+ // 2. Chuẩn bị package.json mới dựa trên "linh hồn" của file lock mẫu
156
148
  let targetPkg = fs.existsSync(targetPkgPath) ? fs.readJsonSync(targetPkgPath) : {};
157
-
158
- targetPkg.name = targetPkg.name || rootInfo.name || "MergeDino";
159
- targetPkg.version = targetPkg.version || rootInfo.version || "1.0.0";
160
149
 
161
- // Trộn dependencies từ file lock vào package.json
150
+ // Hợp nhất dependencies: Phải có tên ở đây thì npm install mới không xóa file lock
162
151
  targetPkg.dependencies = {
163
152
  ...rootInfo.dependencies,
164
153
  ...targetPkg.dependencies
165
154
  };
166
-
167
155
  targetPkg.devDependencies = {
168
156
  ...rootInfo.devDependencies,
169
157
  ...targetPkg.devDependencies,
170
- "fs-extra": "^11.1.0" // Đảm bảo luôn có để toolkit chạy
158
+ "adm-zip": "^0.5.10",
159
+ "fs-extra": "^11.1.0"
171
160
  };
172
161
 
173
- // 4. Ghi đè lại package.json hoàn chỉnh
162
+ // 3. THỰC HIỆN GHI ĐÈ QUYẾT ĐỊNH
163
+ console.log(" 📝 Đang ghi đè package.json và package-lock.json...");
174
164
  fs.writeJsonSync(targetPkgPath, targetPkg, { spaces: 2 });
175
- console.log(" Đã tái tạo package.json khớp 100% với file lock.");
165
+
166
+ // Xóa file v3 hiện tại của project test (nếu có) để tránh xung đột
167
+ if (fs.existsSync(targetLockPath)) {
168
+ fs.removeSync(targetLockPath);
169
+ }
170
+ // Copy file v2 từ Toolkit sang làm "gốc"
171
+ fs.copySync(sourceLockPath, targetLockPath);
176
172
 
177
- // 5. Chạy cài đặt
173
+ // 4. CHẠY INSTALL VỚI FLAG CỨNG RẮN
178
174
  try {
179
- console.log(" Đang nạp node_modules từ Internet (npm install)...");
180
- // Sử dụng --prefer-offline để tận dụng cache nếu đã từng cài
181
- execSync("npm install --prefer-offline", { cwd: projectRoot, stdio: "inherit" });
182
- console.log(" Hồi sinh thành công! Folder node_modules đã sẵn sàng.");
175
+ console.log(" Đang chạy npm install. NPM sẽ tự nâng cấp v2 lên v3 nếu cần...");
176
+
177
+ // --legacy-peer-deps giúp tránh các lỗi xung đột phiên bản quá khắt khe của npm 7+
178
+ execSync("npm install --legacy-peer-deps", {
179
+ cwd: projectRoot,
180
+ stdio: "inherit"
181
+ });
182
+
183
+ console.log(" 🚀 THÀNH CÔNG! node_modules đã được hồi sinh hoàn toàn.");
183
184
  } catch (e) {
184
- console.error(" Lỗi khi cài đặt: " + e.message);
185
+ console.error(" Lỗi khi cài đặt: " + e.message);
186
+ console.log(" 💡 Thử lệnh thủ công: cd project-test && npm install");
185
187
  }
186
188
  }