hiepdh-playable-toolkit 2.1.4 → 2.3.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.
- package/package.json +1 -1
- package/setup.js +45 -20
package/package.json
CHANGED
package/setup.js
CHANGED
|
@@ -123,39 +123,64 @@ function copyFolderRecursive(source, target) {
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
function reviveProject(projectRoot, toolkitRoot, version = "3x") {
|
|
126
|
-
console.log(`
|
|
126
|
+
console.log(` [Toolkit] Bắt đầu hồi sinh môi trường Cocos ${version}...`);
|
|
127
127
|
|
|
128
128
|
const targetPkgPath = path.join(projectRoot, "package.json");
|
|
129
129
|
const targetLockPath = path.join(projectRoot, "package-lock.json");
|
|
130
|
+
const templateDir = path.join(toolkitRoot, version, "templates");
|
|
130
131
|
|
|
132
|
+
// 1. Kiểm tra và khôi phục file lock từ Toolkit nếu project chưa có
|
|
131
133
|
if (!fs.existsSync(targetLockPath)) {
|
|
132
|
-
const sourceLock = path.join(
|
|
133
|
-
toolkitRoot,
|
|
134
|
-
version,
|
|
135
|
-
"templates",
|
|
136
|
-
"package-lock.json"
|
|
137
|
-
);
|
|
134
|
+
const sourceLock = path.join(templateDir, "package-lock.json");
|
|
138
135
|
if (fs.existsSync(sourceLock)) {
|
|
139
136
|
fs.copySync(sourceLock, targetLockPath);
|
|
140
|
-
console.log("
|
|
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
141
|
}
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
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)
|
|
148
|
+
const rootInfo = lockData.packages && lockData.packages[""];
|
|
149
|
+
|
|
150
|
+
if (!rootInfo) {
|
|
151
|
+
console.error(" Lỗi: Cấu trúc file lock không hợp lệ (Thiếu packages['']).");
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 3. Tái tạo nội dung package.json từ file lock
|
|
156
|
+
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
|
+
|
|
161
|
+
// Trộn dependencies từ file lock vào package.json
|
|
162
|
+
targetPkg.dependencies = {
|
|
163
|
+
...rootInfo.dependencies,
|
|
164
|
+
...targetPkg.dependencies
|
|
148
165
|
};
|
|
149
|
-
|
|
150
|
-
|
|
166
|
+
|
|
167
|
+
targetPkg.devDependencies = {
|
|
168
|
+
...rootInfo.devDependencies,
|
|
169
|
+
...targetPkg.devDependencies,
|
|
170
|
+
"fs-extra": "^11.1.0" // Đảm bảo luôn có để toolkit chạy
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// 4. Ghi đè lại package.json hoàn chỉnh
|
|
174
|
+
fs.writeJsonSync(targetPkgPath, targetPkg, { spaces: 2 });
|
|
175
|
+
console.log(" Đã tái tạo package.json khớp 100% với file lock.");
|
|
151
176
|
|
|
177
|
+
// 5. Chạy cài đặt
|
|
152
178
|
try {
|
|
153
|
-
console.log(" Đang
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
);
|
|
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.");
|
|
158
183
|
} catch (e) {
|
|
159
|
-
console.error(" Lỗi khi
|
|
184
|
+
console.error(" Lỗi khi cài đặt: " + e.message);
|
|
160
185
|
}
|
|
161
186
|
}
|