onejs-core 0.3.32 → 0.3.34
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 +3 -2
- package/scripts/switch.cjs +79 -5
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onejs-core",
|
|
3
3
|
"description": "The JS part of OneJS, a UI framework and Scripting Engine for Unity.",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.34",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./typings.d.ts",
|
|
7
7
|
"dependencies": {
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"rimraf": "^5.0.7",
|
|
17
17
|
"tailwindcss": "^3.4.1",
|
|
18
18
|
"tar": "^7.2.0",
|
|
19
|
-
"tiny-glob": "^0.2.9"
|
|
19
|
+
"tiny-glob": "^0.2.9",
|
|
20
|
+
"xml2js": "^0.6.2"
|
|
20
21
|
}
|
|
21
22
|
}
|
package/scripts/switch.cjs
CHANGED
|
@@ -3,10 +3,14 @@ const tar = require('tar')
|
|
|
3
3
|
const url = require('url')
|
|
4
4
|
const path = require('path')
|
|
5
5
|
const fse = require('fs-extra')
|
|
6
|
+
const xml2js = require('xml2js')
|
|
6
7
|
const { rimraf } = require('rimraf')
|
|
7
8
|
|
|
8
9
|
const fsp = fs.promises
|
|
9
10
|
|
|
11
|
+
const projectDir = path.resolve(process.cwd(), '..')
|
|
12
|
+
const manifestPath = path.join(projectDir, 'Packages', 'manifest.json')
|
|
13
|
+
|
|
10
14
|
const backends = [
|
|
11
15
|
{ name: "QuickJS", tgzUrl: "https://github.com/Tencent/puerts/releases/download/Unity_v2.1.0/PuerTS_Quickjs_2.1.0.tgz" },
|
|
12
16
|
{ name: "V8", tgzUrl: "https://github.com/Tencent/puerts/releases/download/Unity_v2.1.0/PuerTS_V8_2.1.0.tgz" },
|
|
@@ -50,7 +54,7 @@ async function Process(backend, outputDir) {
|
|
|
50
54
|
await extractTgz(downloadedPath, outputDir)
|
|
51
55
|
|
|
52
56
|
// Safe keep asmdef files
|
|
53
|
-
const onejsDir = getOneJSUnityDir()
|
|
57
|
+
const onejsDir = await getOneJSUnityDir()
|
|
54
58
|
const a = path.join(onejsDir, 'Puerts/Editor/com.tencent.puerts.core.Editor.asmdef')
|
|
55
59
|
const b = path.join(upmDir, 'Editor/com.tencent.puerts.core.Editor.asmdef')
|
|
56
60
|
const c = path.join(onejsDir, 'Puerts/Runtime/com.tencent.puerts.core.asmdef')
|
|
@@ -73,10 +77,80 @@ async function Process(backend, outputDir) {
|
|
|
73
77
|
|
|
74
78
|
// --- Support Functions ---
|
|
75
79
|
|
|
76
|
-
function getOneJSUnityDir() {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
// function getOneJSUnityDir() {
|
|
81
|
+
// var packageJsonPath = path.join(process.cwd(), 'package.json')
|
|
82
|
+
// var json = require(packageJsonPath)
|
|
83
|
+
// return json.onejs["unity-package-path"]
|
|
84
|
+
// }
|
|
85
|
+
|
|
86
|
+
async function getOneJSUnityDir() {
|
|
87
|
+
let oneJSPath = null;
|
|
88
|
+
|
|
89
|
+
// Step 1: Check manifest.json
|
|
90
|
+
if (fs.existsSync(manifestPath)) {
|
|
91
|
+
const manifestContent = fs.readFileSync(manifestPath, 'utf8');
|
|
92
|
+
const manifestJson = JSON.parse(manifestContent);
|
|
93
|
+
|
|
94
|
+
const dependencies = manifestJson.dependencies;
|
|
95
|
+
const oneJSKey = 'com.dragonground.onejs';
|
|
96
|
+
|
|
97
|
+
if (dependencies && dependencies[oneJSKey]) {
|
|
98
|
+
const packagePath = dependencies[oneJSKey]; // e.g., "file:PATH/TO/OneJS"
|
|
99
|
+
if (packagePath.startsWith('file:')) {
|
|
100
|
+
oneJSPath = packagePath.substring(5); // Remove "file:" prefix
|
|
101
|
+
oneJSPath = path.resolve(projectDir, oneJSPath);
|
|
102
|
+
return oneJSPath;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Step 2: If not found, parse OneJS.Runtime.csproj
|
|
108
|
+
if (!oneJSPath) {
|
|
109
|
+
const csprojPath = path.join(projectDir, 'OneJS.Runtime.csproj');
|
|
110
|
+
|
|
111
|
+
if (fs.existsSync(csprojPath)) {
|
|
112
|
+
const csprojContent = fs.readFileSync(csprojPath, 'utf8');
|
|
113
|
+
const parser = new xml2js.Parser();
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
const result = await parser.parseStringPromise(csprojContent);
|
|
117
|
+
|
|
118
|
+
const project = result.Project;
|
|
119
|
+
const itemGroups = project.ItemGroup;
|
|
120
|
+
|
|
121
|
+
if (itemGroups && itemGroups.length > 0) {
|
|
122
|
+
for (const itemGroup of itemGroups) {
|
|
123
|
+
if (itemGroup.Compile) {
|
|
124
|
+
for (const compileItem of itemGroup.Compile) {
|
|
125
|
+
const includePath = compileItem.$.Include;
|
|
126
|
+
|
|
127
|
+
// Normalize path separators for cross-platform compatibility
|
|
128
|
+
const normalizedIncludePath = includePath.replace(/\\/g, '/');
|
|
129
|
+
const searchIndex = normalizedIncludePath.indexOf('Assets/OneJS');
|
|
130
|
+
|
|
131
|
+
if (searchIndex !== -1) {
|
|
132
|
+
oneJSPath = normalizedIncludePath.substring(0, searchIndex + 'Assets/OneJS'.length);
|
|
133
|
+
oneJSPath = path.resolve(projectDir, oneJSPath);
|
|
134
|
+
return oneJSPath;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
console.error('Could not find OneJS path in csproj file.');
|
|
142
|
+
return null;
|
|
143
|
+
} catch (err) {
|
|
144
|
+
console.error('Error parsing csproj file:', err);
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
console.error('OneJS.Runtime.csproj file does not exist.');
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return oneJSPath;
|
|
80
154
|
}
|
|
81
155
|
|
|
82
156
|
function ensureDirectoryExistence(filePath) {
|