hiepdh-playable-toolkit 2.4.4 → 3.0.2

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 +39 -55
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hiepdh-playable-toolkit",
3
- "version": "2.4.4",
3
+ "version": "3.0.2",
4
4
  "main": "setup.js",
5
5
  "dependencies": {
6
6
  "fs-extra": "^11.1.0",
package/setup.js CHANGED
@@ -123,66 +123,50 @@ function copyFolderRecursive(source, target) {
123
123
  }
124
124
 
125
125
  function reviveProject(projectRoot, toolkitRoot, version = "3x") {
126
- console.log(`🛠️ [Toolkit] Đang xử đồng bộ lockfile (v2 -> v3)...`);
126
+ console.log(`\n--- [DEBUG] KHỞI ĐỘNG HÀM REVIVE ---`);
127
+
128
+ const targetPkgPath = path.join(projectRoot, "package.json");
129
+ const sourceLockPath = path.join(toolkitRoot, version, "templates", "package-lock.json");
127
130
 
128
- const targetPkgPath = path.join(projectRoot, "package.json");
129
- const targetLockPath = path.join(projectRoot, "package-lock.json");
130
- const templateDir = path.join(toolkitRoot, version, "templates");
131
- const sourceLockPath = path.join(templateDir, "package-lock.json");
131
+ console.log(" Đang tìm file lock mẫu tại: " + sourceLockPath);
132
132
 
133
- if (!fs.existsSync(sourceLockPath)) {
134
- console.error(" Lỗi: Không tìm thấy file lock mẫu trong Toolkit!");
135
- return;
136
- }
133
+ if (!fs.existsSync(sourceLockPath)) {
134
+ console.error(" KHÔNG TÌM THẤY FILE LOCK MẪU!");
135
+ return;
136
+ }
137
137
 
138
- // 1. Đọc dữ liệu từ file lock mẫu (v2) của Toolkit
139
- const lockData = fs.readJsonSync(sourceLockPath);
140
- const rootInfo = lockData.packages && lockData.packages[""];
138
+ const lockData = fs.readJsonSync(sourceLockPath);
139
+ // Lưu ý: File lock bạn gửi có mục packages[""] chứa dependencies
140
+ const rootInfo = lockData.packages && lockData.packages[""];
141
141
 
142
- if (!rootInfo) {
143
- console.error(" Lỗi: File lock mẫu không cấu trúc packages['']!");
144
- return;
145
- }
142
+ if (!rootInfo || !rootInfo.dependencies) {
143
+ console.error(" FILE LOCK MẪU KHÔNG DỮ LIỆU DEPENDENCIES MỤC packages['']!");
144
+ return;
145
+ }
146
146
 
147
- // 2. Chuẩn bị package.json mới dựa trên "linh hồn" của file lock mẫu
148
- let targetPkg = fs.existsSync(targetPkgPath) ? fs.readJsonSync(targetPkgPath) : {};
149
-
150
- // Hợp nhất dependencies: Phải có tên ở đây thì npm install mới không xóa file lock
151
- targetPkg.dependencies = {
152
- ...rootInfo.dependencies,
153
- ...targetPkg.dependencies
154
- };
155
- targetPkg.devDependencies = {
156
- ...rootInfo.devDependencies,
157
- ...targetPkg.devDependencies,
158
- "adm-zip": "^0.5.10",
159
- "fs-extra": "^11.1.0"
160
- };
161
-
162
- // 3. THỰC HIỆN GHI ĐÈ QUYẾT ĐỊNH
163
- console.log(" 📝 Đang ghi đè package.json và package-lock.json...");
164
- fs.writeJsonSync(targetPkgPath, targetPkg, { spaces: 2 });
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);
147
+ console.log(" Đã trích xuất được dependencies: " + Object.keys(rootInfo.dependencies).join(", "));
172
148
 
173
- // 4. CHẠY INSTALL VỚI FLAG CỨNG RẮN
174
- try {
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
- });
149
+ // Đọc ghi đè package.json
150
+ let pkg = fs.readJsonSync(targetPkgPath);
151
+ pkg.dependencies = { ...rootInfo.dependencies, ...pkg.dependencies };
152
+ pkg.devDependencies = { ...rootInfo.devDependencies, ...pkg.devDependencies };
182
153
 
183
- console.log(" 🚀 THÀNH CÔNG! node_modules đã được hồi sinh hoàn toàn.");
184
- } catch (e) {
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");
187
- }
154
+ fs.writeJsonSync(targetPkgPath, pkg, { spaces: 2 });
155
+ console.log(" Đã cập nhật file package.json tại dự án Test.");
156
+
157
+ // Xóa file lock của dự án Test để NPM tạo lại từ đầu (tránh xung đột v2/v3)
158
+ const targetLockPath = path.join(projectRoot, "package-lock.json");
159
+ if (fs.existsSync(targetLockPath)) {
160
+ fs.removeSync(targetLockPath);
161
+ console.log(" Đã xóa package-lock.json cũ để làm mới.");
162
+ }
163
+
164
+ try {
165
+ console.log(" Đang chạy 'npm install'... Vui lòng đợi bảng log của NPM hiện ra.");
166
+ // Lưu ý dùng stdio: "inherit" để thấy lỗi của npm nếu có
167
+ execSync("npm install", { cwd: projectRoot, stdio: "inherit" });
168
+ console.log(" HỒI SINH THÀNH CÔNG!");
169
+ } catch (e) {
170
+ console.error(" LỆNH NPM INSTALL BỊ LỖI: " + e.message);
171
+ }
188
172
  }