hiepdh-playable-toolkit 2.0.1 → 2.1.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/2x/templates/package-lock.json +727 -0
- package/3x/templates/package-lock.json +813 -0
- package/package.json +33 -22
- package/setup.js +85 -19
package/package.json
CHANGED
|
@@ -1,22 +1,33 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "hiepdh-playable-toolkit",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"main": "setup.js",
|
|
5
|
-
"dependencies": {
|
|
6
|
-
"fs-extra": "^11.1.0",
|
|
7
|
-
"adm-zip": "^0.5.10"
|
|
8
|
-
},
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "hiepdh-playable-toolkit",
|
|
3
|
+
"version": "2.1.4",
|
|
4
|
+
"main": "setup.js",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"fs-extra": "^11.1.0",
|
|
7
|
+
"adm-zip": "^0.5.10"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"postinstall": "node setup.js",
|
|
11
|
+
"clean": "node -e \"fs.rmSync('./build-templates/web-mobile/application.js', {force:true})\"",
|
|
12
|
+
"fix-unity": "node patch-template-unityReject.js",
|
|
13
|
+
"build-unity": "node build-inline.js unity",
|
|
14
|
+
"build-all": "node build-inline.js all"
|
|
15
|
+
},
|
|
16
|
+
"bin": {
|
|
17
|
+
"hiepdh-setup": "setup.js"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"2x",
|
|
21
|
+
"3x",
|
|
22
|
+
"setup.js",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"keywords": [],
|
|
26
|
+
"author": "HiepDH",
|
|
27
|
+
"license": "ISC",
|
|
28
|
+
"description": "ahihi!",
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"adm-zip": "^0.5.10",
|
|
31
|
+
"fs-extra": "^11.1.0"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/setup.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
const fs = require(
|
|
2
|
-
const path = require(
|
|
3
|
-
const { execSync } = require(
|
|
1
|
+
const fs = require("fs-extra");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const { execSync } = require("child_process");
|
|
4
4
|
|
|
5
5
|
// Xác định thư mục gốc của dự án người dùng
|
|
6
|
-
const projectRoot = process.env.INIT_CWD ||
|
|
6
|
+
const projectRoot = process.env.INIT_CWD || process.cwd();
|
|
7
|
+
const toolkitRoot = __dirname;
|
|
7
8
|
const pkgPath = path.join(projectRoot, "package.json");
|
|
8
9
|
|
|
10
|
+
console.log("--- Đang cài đặt từ: " + toolkitRoot);
|
|
11
|
+
console.log("--- Đích đến: " + projectRoot);
|
|
12
|
+
|
|
9
13
|
console.log("--- HiepDH Playable Toolkit: Khởi tạo cấu hình đa phiên bản ---");
|
|
10
14
|
|
|
11
15
|
if (!fs.existsSync(pkgPath)) {
|
|
@@ -19,9 +23,10 @@ const cocosVer = pkg.creator ? pkg.creator.version : "unknown";
|
|
|
19
23
|
if (cocosVer.startsWith("3")) {
|
|
20
24
|
console.log(` Phát hiện Cocos Creator 3.x (Version: ${cocosVer})`);
|
|
21
25
|
setupForV3(pkg);
|
|
22
|
-
} else if (cocosVer.startsWith("1")) {
|
|
26
|
+
} else if (cocosVer.startsWith("1")) {
|
|
27
|
+
// Sửa từ "1" thành "2"
|
|
23
28
|
console.log(` Phát hiện Cocos Creator 2.x (Version: ${cocosVer})`);
|
|
24
|
-
setupForV2(pkg);
|
|
29
|
+
setupForV2(pkg);
|
|
25
30
|
} else {
|
|
26
31
|
console.warn(" Không xác định được phiên bản. Mặc định cấu hình cho 3.x");
|
|
27
32
|
setupForV3(pkg);
|
|
@@ -33,10 +38,11 @@ function setupForV3(pkg) {
|
|
|
33
38
|
|
|
34
39
|
// 1. Cập nhật Scripts vào package.json
|
|
35
40
|
updateScripts(pkg, {
|
|
36
|
-
|
|
41
|
+
clean:
|
|
42
|
+
"node -e \"fs.rmSync('./build-templates/web-mobile/application.js', {force:true})\"",
|
|
37
43
|
"fix-unity": "node patch-template-unityReject.js",
|
|
38
44
|
"build-unity": "node build-inline.js unity",
|
|
39
|
-
"build-all": "node build-inline.js all"
|
|
45
|
+
"build-all": "node build-inline.js all",
|
|
40
46
|
});
|
|
41
47
|
|
|
42
48
|
// 2. Cài đặt Extension (super-html)
|
|
@@ -47,27 +53,48 @@ function setupForV3(pkg) {
|
|
|
47
53
|
console.log(" Đã cài đặt Extension super-html.");
|
|
48
54
|
// Tự động npm install cho extension
|
|
49
55
|
try {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
} catch(e) {
|
|
56
|
+
console.log(" Đang cài đặt dependencies cho Extension...");
|
|
57
|
+
execSync("npm install", { cwd: extTarget, stdio: "ignore" });
|
|
58
|
+
} catch (e) {
|
|
59
|
+
console.warn(
|
|
60
|
+
" Vui lòng chạy 'npm install' trong folder extension thủ công."
|
|
61
|
+
);
|
|
62
|
+
}
|
|
53
63
|
}
|
|
54
64
|
|
|
55
65
|
// 3. Cài đặt Templates (index.ejs)
|
|
56
|
-
const templateSource = path.join(
|
|
57
|
-
|
|
66
|
+
const templateSource = path.join(
|
|
67
|
+
source3x,
|
|
68
|
+
"build-templates",
|
|
69
|
+
"web-mobile",
|
|
70
|
+
"index.ejs"
|
|
71
|
+
);
|
|
72
|
+
const templateTargetDir = path.join(
|
|
73
|
+
projectRoot,
|
|
74
|
+
"build-templates",
|
|
75
|
+
"web-mobile"
|
|
76
|
+
);
|
|
58
77
|
if (fs.existsSync(templateSource)) {
|
|
59
|
-
if (!fs.existsSync(templateTargetDir))
|
|
78
|
+
if (!fs.existsSync(templateTargetDir))
|
|
79
|
+
fs.mkdirSync(templateTargetDir, { recursive: true });
|
|
60
80
|
fs.copyFileSync(templateSource, path.join(templateTargetDir, "index.ejs"));
|
|
61
81
|
console.log(" Đã cấu hình build-templates/index.ejs.");
|
|
62
82
|
}
|
|
63
83
|
|
|
64
84
|
// 4. Copy các Script xử lý (build-inline.js, patch...) ra gốc dự án
|
|
65
|
-
const files = [
|
|
66
|
-
|
|
85
|
+
const files = [
|
|
86
|
+
"build-inline.js",
|
|
87
|
+
"patch-template-unityReject.js",
|
|
88
|
+
"injectCustomScript.js",
|
|
89
|
+
];
|
|
90
|
+
files.forEach((file) => {
|
|
67
91
|
const src = path.join(source3x, file);
|
|
68
92
|
if (fs.existsSync(src)) fs.copyFileSync(src, path.join(projectRoot, file));
|
|
69
93
|
});
|
|
70
94
|
|
|
95
|
+
// 5. init các package cho Ver
|
|
96
|
+
reviveProject(projectRoot, toolkitRoot, "3x");
|
|
97
|
+
|
|
71
98
|
console.log("\n--- Toolkit 3.x Ready! Let's Cook! ---");
|
|
72
99
|
}
|
|
73
100
|
|
|
@@ -85,11 +112,50 @@ function updateScripts(pkg, newScripts) {
|
|
|
85
112
|
|
|
86
113
|
function copyFolderRecursive(source, target) {
|
|
87
114
|
if (!fs.existsSync(target)) fs.mkdirSync(target, { recursive: true });
|
|
88
|
-
fs.readdirSync(source).forEach(file => {
|
|
115
|
+
fs.readdirSync(source).forEach((file) => {
|
|
89
116
|
const srcFile = path.join(source, file);
|
|
90
117
|
const tgtFile = path.join(target, file);
|
|
91
118
|
if (file === "node_modules") return; // Bỏ qua node_modules
|
|
92
|
-
if (fs.lstatSync(srcFile).isDirectory())
|
|
119
|
+
if (fs.lstatSync(srcFile).isDirectory())
|
|
120
|
+
copyFolderRecursive(srcFile, tgtFile);
|
|
93
121
|
else fs.copyFileSync(srcFile, tgtFile);
|
|
94
122
|
});
|
|
95
|
-
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function reviveProject(projectRoot, toolkitRoot, version = "3x") {
|
|
126
|
+
console.log(` Đang hồi sinh môi trường cho Cocos ${version}...`);
|
|
127
|
+
|
|
128
|
+
const targetPkgPath = path.join(projectRoot, "package.json");
|
|
129
|
+
const targetLockPath = path.join(projectRoot, "package-lock.json");
|
|
130
|
+
|
|
131
|
+
if (!fs.existsSync(targetLockPath)) {
|
|
132
|
+
const sourceLock = path.join(
|
|
133
|
+
toolkitRoot,
|
|
134
|
+
version,
|
|
135
|
+
"templates",
|
|
136
|
+
"package-lock.json"
|
|
137
|
+
);
|
|
138
|
+
if (fs.existsSync(sourceLock)) {
|
|
139
|
+
fs.copySync(sourceLock, targetLockPath);
|
|
140
|
+
console.log(" Đã lấy file lock mẫu từ Toolkit.");
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const pkg = fs.readJsonSync(targetPkgPath);
|
|
145
|
+
const toolkitDeps = {
|
|
146
|
+
"adm-zip": "^0.5.10",
|
|
147
|
+
"fs-extra": "^11.1.0",
|
|
148
|
+
};
|
|
149
|
+
pkg.devDependencies = { ...pkg.devDependencies, ...toolkitDeps };
|
|
150
|
+
fs.writeJsonSync(targetPkgPath, pkg, { spaces: 2 });
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
console.log(" Đang chạy npm install để đồng bộ hóa cấu trúc file lock...");
|
|
154
|
+
execSync("npm install", { cwd: projectRoot, stdio: "inherit" });
|
|
155
|
+
console.log(
|
|
156
|
+
" Hoàn tất! node_modules đã đầy đủ và file lock đã được cập nhật."
|
|
157
|
+
);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
console.error(" Lỗi khi đồng bộ: " + e.message);
|
|
160
|
+
}
|
|
161
|
+
}
|