hiepdh-playable-toolkit 3.0.1 → 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 +41 -61
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hiepdh-playable-toolkit",
3
- "version": "3.0.1",
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,70 +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)
149
- ? fs.readJsonSync(targetPkgPath)
150
- : {};
151
-
152
- // Hợp nhất dependencies: Phải có tên ở đây thì npm install mới không xóa file lock
153
- targetPkg.dependencies = {
154
- ...rootInfo.dependencies,
155
- ...targetPkg.dependencies,
156
- };
157
- targetPkg.devDependencies = {
158
- ...rootInfo.devDependencies,
159
- ...targetPkg.devDependencies,
160
- "adm-zip": "^0.5.10",
161
- "fs-extra": "^11.1.0",
162
- };
163
-
164
- // 3. THỰC HIỆN GHI ĐÈ QUYẾT ĐỊNH
165
- console.log("Đang ghi đè package.json package-lock.json...");
166
- fs.writeJsonSync(targetPkgPath, targetPkg, { spaces: 2 });
167
-
168
- // Xóa file v3 hiện tại của project test (nếu có) để tránh xung đột
169
- if (fs.existsSync(targetLockPath)) {
170
- fs.removeSync(targetLockPath);
171
- }
172
- // Copy file v2 từ Toolkit sang làm "gốc"
173
- fs.copySync(sourceLockPath, targetLockPath);
174
-
175
- // 4. CHẠY INSTALL VỚI FLAG CỨNG RẮN
176
- try {
177
- console.log(
178
- " Đang chạy npm install. NPM sẽ tự nâng cấp v2 lên v3 nếu cần..."
179
- );
180
-
181
- // --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+
182
- execSync("npm install --legacy-peer-deps", {
183
- cwd: projectRoot,
184
- stdio: "inherit",
185
- });
186
-
187
- console.log(" THÀNH CÔNG! node_modules đã được hồi sinh hoàn toàn.");
188
- } catch (e) {
189
- console.error(" Lỗi khi cài đặt: " + e.message);
190
- console.log(" Thử lệnh thủ công: cd project-test && npm install");
191
- }
147
+ console.log(" Đã trích xuất được dependencies: " + Object.keys(rootInfo.dependencies).join(", "));
148
+
149
+ // Đọc và ghi đè package.json
150
+ let pkg = fs.readJsonSync(targetPkgPath);
151
+ pkg.dependencies = { ...rootInfo.dependencies, ...pkg.dependencies };
152
+ pkg.devDependencies = { ...rootInfo.devDependencies, ...pkg.devDependencies };
153
+
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ũ 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
+ }
192
172
  }