drgame-cc 1.0.16 → 1.0.17
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 +2 -2
- package/scripts/sync-back.js +85 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drgame-cc",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "道然游戏适配包",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"drres/**/*",
|
|
43
43
|
"drscript/**/*",
|
|
44
44
|
"build-templates/**/*",
|
|
45
|
-
"scripts
|
|
45
|
+
"scripts/**/*",
|
|
46
46
|
"bin/**/*"
|
|
47
47
|
],
|
|
48
48
|
"engines": {
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const fse = require('fs-extra');
|
|
6
|
+
|
|
7
|
+
// ============================================================
|
|
8
|
+
// 1. 包自身根目录 / 宿主项目根目录
|
|
9
|
+
// ============================================================
|
|
10
|
+
const pkgRoot = path.resolve(__dirname, '..');
|
|
11
|
+
const projectRoot = path.resolve(__dirname, '..', '..', '..');
|
|
12
|
+
|
|
13
|
+
// ============================================================
|
|
14
|
+
// 2. 解析命令行参数(与 postinstall.js 一致)
|
|
15
|
+
// 支持: <path> | --cocos-path <path> | --cocos-path=<path> | -p <path>
|
|
16
|
+
// ============================================================
|
|
17
|
+
function resolveCocosPath(argv) {
|
|
18
|
+
const args = argv.slice(2);
|
|
19
|
+
for (let i = 0; i < args.length; i++) {
|
|
20
|
+
const a = args[i];
|
|
21
|
+
if (a.startsWith('--cocos-path=')) {
|
|
22
|
+
return a.slice('--cocos-path='.length);
|
|
23
|
+
}
|
|
24
|
+
if (a === '--cocos-path' || a === '-p') {
|
|
25
|
+
const next = args[i + 1];
|
|
26
|
+
if (next && !next.startsWith('-')) {
|
|
27
|
+
return next;
|
|
28
|
+
}
|
|
29
|
+
} else if (!a.startsWith('-') && a.length > 0) {
|
|
30
|
+
return a;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const argPath = resolveCocosPath(process.argv);
|
|
37
|
+
let COCOS_ROOT = argPath || projectRoot;
|
|
38
|
+
if (!path.isAbsolute(COCOS_ROOT)) {
|
|
39
|
+
COCOS_ROOT = path.resolve(process.cwd(), COCOS_ROOT);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log('开始反向同步(Cocos 项目 -> npm 包)');
|
|
43
|
+
console.log(`源目录(宿主): ${COCOS_ROOT}`);
|
|
44
|
+
console.log(`目标目录(包): ${pkgRoot}`);
|
|
45
|
+
console.log(`Cocos 路径来源: ${argPath ? '命令行参数' : '默认(node_modules 父目录)'}`);
|
|
46
|
+
|
|
47
|
+
// ============================================================
|
|
48
|
+
// 3. 反向拷贝:与 postinstall.js 完全对称
|
|
49
|
+
// COCOS_ROOT/build-templates -> pkgRoot/build-templates
|
|
50
|
+
// COCOS_ROOT/assets/resources/drres -> pkgRoot/drres
|
|
51
|
+
// COCOS_ROOT/assets/drscript -> pkgRoot/drscript
|
|
52
|
+
// ============================================================
|
|
53
|
+
const jobs = [
|
|
54
|
+
{
|
|
55
|
+
name: 'build-templates',
|
|
56
|
+
src: path.join(COCOS_ROOT, 'build-templates'),
|
|
57
|
+
dest: path.join(pkgRoot, 'build-templates'),
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: 'drres',
|
|
61
|
+
src: path.join(COCOS_ROOT, 'assets', 'resources', 'drres'),
|
|
62
|
+
dest: path.join(pkgRoot, 'drres'),
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'drscript',
|
|
66
|
+
src: path.join(COCOS_ROOT, 'assets', 'drscript'),
|
|
67
|
+
dest: path.join(pkgRoot, 'drscript'),
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
for (const job of jobs) {
|
|
73
|
+
if (fs.existsSync(job.src)) {
|
|
74
|
+
fse.copySync(job.src, job.dest, { overwrite: true });
|
|
75
|
+
console.log(`[OK] ${job.name} 反向同步完成`);
|
|
76
|
+
} else {
|
|
77
|
+
console.log(`[SKIP] 源目录不存在,跳过: ${job.src}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
console.log('反向同步完成!');
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error('反向同步失败:', error.message);
|
|
83
|
+
console.error(error.stack);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|