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.
- package/package.json +1 -1
- package/setup.js +39 -55
package/package.json
CHANGED
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
if (!rootInfo || !rootInfo.dependencies) {
|
|
143
|
+
console.error(" FILE LOCK MẪU KHÔNG CÓ DỮ LIỆU DEPENDENCIES Ở MỤC packages['']!");
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
146
|
|
|
147
|
-
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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 và 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
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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ũ 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
|
}
|