onejs-core 3.0.3 → 3.0.5
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/.gitattributes +2 -2
- package/.prettierrc +5 -5
- package/.vscode/settings.json +5 -5
- package/LICENSE +20 -20
- package/README.md +102 -102
- package/bin/oj.js +252 -252
- package/definitions/Assemblies/OneJS.Runtime.Ext.d.ts +6 -6
- package/definitions/Assemblies/OneJS.Runtime.d.ts +826 -826
- package/definitions/Assemblies/OneJS.Samples.d.ts +20 -20
- package/definitions/Assemblies/Unity.Mathematics.d.ts +9221 -9221
- package/definitions/Assemblies/UnityEditor.CoreModule.d.ts +32614 -32614
- package/definitions/Assemblies/UnityEngine.AIModule.d.ts +998 -998
- package/definitions/Assemblies/UnityEngine.AnimationModule.d.ts +3308 -3308
- package/definitions/Assemblies/UnityEngine.AssetBundleModule.d.ts +337 -337
- package/definitions/Assemblies/UnityEngine.AudioModule.d.ts +1154 -1154
- package/definitions/Assemblies/UnityEngine.CoreModule.d.ts +29587 -29587
- package/definitions/Assemblies/UnityEngine.PhysicsModule.d.ts +3137 -3137
- package/definitions/Assemblies/UnityEngine.TerrainModule.d.ts +1270 -1270
- package/definitions/Assemblies/UnityEngine.UIElementsModule.d.ts +32718 -32718
- package/definitions/Assemblies/UnityEngine.UnityAnalyticsCommonModule.d.ts +274 -274
- package/definitions/Assemblies/index.d.ts +16 -16
- package/definitions/Assemblies/mscorlib.d.ts +19416 -19416
- package/definitions/augments.d.ts +66 -66
- package/definitions/globals.d.ts +53 -53
- package/definitions/index.d.ts +11 -11
- package/definitions/jsx.d.ts +570 -570
- package/definitions/modules.d.ts +32 -32
- package/definitions/onejs.d.ts +171 -171
- package/definitions/preact.jsx.d.ts +6 -6
- package/definitions/proto-overrides.d.ts +41 -41
- package/definitions/puerts.d.ts +30 -30
- package/definitions/unity-engine.d.ts +22 -22
- package/dist/dom/document.d.ts +30 -0
- package/dist/dom/document.js +89 -0
- package/dist/dom/dom-style.d.ts +9 -0
- package/dist/dom/dom-style.js +27 -0
- package/dist/dom/dom.d.ts +83 -0
- package/dist/dom/dom.js +313 -0
- package/dist/dom/index.d.ts +4 -0
- package/dist/dom/index.js +4 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +45 -0
- package/dist/math/index.d.ts +86 -0
- package/dist/math/index.js +361 -0
- package/dist/preloads/inject.d.ts +3 -0
- package/dist/preloads/inject.js +36 -0
- package/dist/styling/index.d.ts +10 -0
- package/dist/styling/index.js +28 -0
- package/dist/styling/utils/generateAlphabeticName.d.ts +1 -0
- package/dist/styling/utils/generateAlphabeticName.js +16 -0
- package/dist/styling/utils/generateComponentId.d.ts +1 -0
- package/dist/styling/utils/generateComponentId.js +5 -0
- package/dist/styling/utils/hash.d.ts +5 -0
- package/dist/styling/utils/hash.js +34 -0
- package/dist/utils/arrays.d.ts +1 -0
- package/dist/utils/arrays.js +10 -0
- package/dist/utils/color-palettes.d.ts +2 -0
- package/dist/utils/color-palettes.js +2 -0
- package/dist/utils/color-parser.d.ts +161 -0
- package/dist/utils/color-parser.js +241 -0
- package/dist/utils/float-parser.d.ts +7 -0
- package/dist/utils/float-parser.js +23 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.js +15 -0
- package/dist/utils/subscribe.d.ts +4 -0
- package/dist/utils/subscribe.js +10 -0
- package/dist/utils/system.d.ts +1 -0
- package/dist/utils/system.js +16 -0
- package/dom/document.ts +115 -115
- package/dom/dom-style.ts +36 -36
- package/dom/dom.ts +376 -376
- package/dom/index.ts +3 -3
- package/index.ts +59 -59
- package/jsr.json +9 -9
- package/math/README.md +212 -212
- package/math/index.ts +487 -487
- package/package.json +34 -33
- package/preloads/inject.ts +43 -43
- package/scripts/esbuild/copy-assets.mjs +94 -94
- package/scripts/esbuild/decorator-fix.mjs +17 -17
- package/scripts/esbuild/import-transform.mjs +100 -100
- package/scripts/esbuild/index.mjs +3 -3
- package/scripts/esbuild/watch-output.mjs +38 -38
- package/scripts/postcss/cleanup-plugin.cjs +89 -89
- package/scripts/postcss/onejs-tw-config.cjs +252 -252
- package/scripts/postcss/optional-import-plugin.cjs +26 -26
- package/scripts/postcss/tailwind-logging-plugin.cjs +11 -11
- package/scripts/postcss/unwrap-is-plugin.cjs +16 -16
- package/scripts/postcss/uss-transform-plugin.cjs +92 -92
- package/scripts/switch.cjs +321 -290
- package/styling/index.tsx +32 -32
- package/styling/utils/generateAlphabeticName.ts +20 -20
- package/styling/utils/generateComponentId.ts +5 -5
- package/styling/utils/hash.ts +46 -46
- package/tsconfig.json +24 -24
- package/typings.d.ts +5 -5
- package/utils/arrays.ts +10 -10
- package/utils/color-palettes.ts +2 -2
- package/utils/color-parser.ts +248 -248
- package/utils/float-parser.ts +30 -30
- package/utils/index.ts +15 -15
- package/utils/subscribe.ts +16 -16
- package/utils/system.ts +16 -16
package/bin/oj.js
CHANGED
|
@@ -1,254 +1,254 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
/* eslint-disable no-console */
|
|
3
|
-
"use strict"
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
* OneJS – oj (shadcn-style) CLI
|
|
7
|
-
* A small utility for listing / installing premade UI components
|
|
8
|
-
* shipped inside a <Assets/> Unity project folder.
|
|
9
|
-
*
|
|
10
|
-
* Commands:
|
|
11
|
-
* oj list – show available components inside tarball
|
|
12
|
-
* oj add <name … | all> – install one or many components
|
|
13
|
-
* oj doctor – verify environment (Assets folder + tarball)
|
|
14
|
-
*
|
|
15
|
-
* Global flags:
|
|
16
|
-
* -y, --yes, --force – skip overwrite prompts
|
|
17
|
-
* --dry – dry-run (no filesystem writes)
|
|
18
|
-
* --assets-dir <dir> – override Assets directory auto-detection
|
|
19
|
-
* --tarball <file> – override tarball filename (default premade-uis.tgz.bytes)
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
const fs = require("fs")
|
|
23
|
-
const path = require("path")
|
|
24
|
-
const readline = require("readline")
|
|
25
|
-
const tar = require("tar")
|
|
26
|
-
const { Command } = require("commander")
|
|
27
|
-
const chalk = require("chalk")
|
|
28
|
-
const ora = require("ora")
|
|
29
|
-
|
|
30
|
-
const pkg = require("../package.json")
|
|
31
|
-
|
|
32
|
-
/* ─────────────────────────────── utils ─────────────────────────────── */
|
|
33
|
-
|
|
34
|
-
function findAssetsDir(startDir, explicit) {
|
|
35
|
-
if (explicit) {
|
|
36
|
-
if (fs.existsSync(explicit) && fs.statSync(explicit).isDirectory()) return explicit
|
|
37
|
-
return null
|
|
38
|
-
}
|
|
39
|
-
let dir = path.dirname(startDir) // Up a level, preventing `App/assets` getting returned
|
|
40
|
-
const { root } = path.parse(dir)
|
|
41
|
-
while (dir !== root) {
|
|
42
|
-
const probe = path.join(dir, "Assets")
|
|
43
|
-
if (fs.existsSync(probe) && fs.statSync(probe).isDirectory()) return probe
|
|
44
|
-
dir = path.dirname(dir)
|
|
45
|
-
}
|
|
46
|
-
return null
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function findTarball(assetsDir, tarballName) {
|
|
50
|
-
const stack = [assetsDir]
|
|
51
|
-
while (stack.length) {
|
|
52
|
-
const curr = stack.pop()
|
|
53
|
-
for (const e of fs.readdirSync(curr, { withFileTypes: true })) {
|
|
54
|
-
const p = path.join(curr, e.name)
|
|
55
|
-
if (e.isDirectory()) {
|
|
56
|
-
stack.push(p)
|
|
57
|
-
} else if (e.isFile() && e.name === tarballName) {
|
|
58
|
-
return p
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return null
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async function askYN(prompt) {
|
|
66
|
-
return new Promise((resolve) => {
|
|
67
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
|
|
68
|
-
rl.question(`${prompt} ${chalk.dim("[y/N]")} `, (ans) => {
|
|
69
|
-
rl.close()
|
|
70
|
-
resolve(/^(y|yes)$/i.test(ans.trim()))
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Return Set of top-level component folders inside tarball.
|
|
77
|
-
*/
|
|
78
|
-
async function scanComponents(tarPath) {
|
|
79
|
-
const comps = new Set()
|
|
80
|
-
await tar.t({
|
|
81
|
-
file: tarPath,
|
|
82
|
-
onentry: (entry) => {
|
|
83
|
-
const p = entry.path.replace(/\\/g, "/")
|
|
84
|
-
if (!p.startsWith("comps/")) return
|
|
85
|
-
|
|
86
|
-
// Only treat entries inside a top-level folder under comps/
|
|
87
|
-
// e.g. "comps/button/**" → "button"
|
|
88
|
-
const rest = p.slice("comps/".length)
|
|
89
|
-
const firstSlash = rest.indexOf("/")
|
|
90
|
-
if (firstSlash === -1) return // file directly under comps/ → skip
|
|
91
|
-
|
|
92
|
-
const top = rest.slice(0, firstSlash)
|
|
93
|
-
if (top) comps.add(top)
|
|
94
|
-
},
|
|
95
|
-
})
|
|
96
|
-
return comps
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/* ─────────────────────────────── commander ─────────────────────────────── */
|
|
100
|
-
|
|
101
|
-
const program = new Command()
|
|
102
|
-
|
|
103
|
-
program
|
|
104
|
-
.name("oj")
|
|
105
|
-
.description("OneJS premade UI component manager")
|
|
106
|
-
.version(pkg.version, "-v, --version", "print version")
|
|
107
|
-
|
|
108
|
-
program
|
|
109
|
-
.hook("preAction", (thisCmd, actionCmd) => {
|
|
110
|
-
// Collect global opts and attach to actionCmd for convenience
|
|
111
|
-
actionCmd._globalOpts = {
|
|
112
|
-
yes: thisCmd.opts().yes || thisCmd.opts().force,
|
|
113
|
-
dry: thisCmd.opts().dry,
|
|
114
|
-
assetsDir: thisCmd.opts().assetsDir,
|
|
115
|
-
tarballName: thisCmd.opts().tarball || "premade-uis.tgz.bytes",
|
|
116
|
-
}
|
|
117
|
-
})
|
|
118
|
-
.option("-y, --yes", "skip confirmation prompts")
|
|
119
|
-
.option("--force", "alias for --yes")
|
|
120
|
-
.option("--dry", "dry-run – show actions only")
|
|
121
|
-
.option("--assets-dir <dir>", "override Assets/ directory")
|
|
122
|
-
.option("--tarball <file>", "override tarball filename (default premade-uis.tgz.bytes)")
|
|
123
|
-
|
|
124
|
-
/* ─────────────────────────────── list ─────────────────────────────── */
|
|
125
|
-
|
|
126
|
-
program
|
|
127
|
-
.command("list")
|
|
128
|
-
.description("list available components inside the tarball")
|
|
129
|
-
.action(async function () {
|
|
130
|
-
const { assetsDir, tarballName } = this._globalOpts
|
|
131
|
-
const assets = findAssetsDir(process.cwd(), assetsDir) || findAssetsDir(__dirname, assetsDir)
|
|
132
|
-
if (!assets) {
|
|
133
|
-
console.error(chalk.red("Assets/ folder not found. Are you inside a Unity project?"))
|
|
134
|
-
process.exit(1)
|
|
135
|
-
}
|
|
136
|
-
const tarPath = findTarball(assets, tarballName)
|
|
137
|
-
if (!tarPath) {
|
|
138
|
-
console.error(
|
|
139
|
-
chalk.red(`Tarball '${tarballName}' not found under Assets/. Did you import the OneJS package?`)
|
|
140
|
-
)
|
|
141
|
-
process.exit(1)
|
|
142
|
-
}
|
|
143
|
-
const comps = await scanComponents(tarPath)
|
|
144
|
-
console.log(chalk.bold(`Components in ${path.relative(process.cwd(), tarPath)}:`))
|
|
145
|
-
comps.forEach((c) => console.log(" •", chalk.cyan(c)))
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
/* ─────────────────────────────── doctor ─────────────────────────────── */
|
|
149
|
-
|
|
150
|
-
program
|
|
151
|
-
.command("doctor")
|
|
152
|
-
.description("check Assets directory and tarball presence")
|
|
153
|
-
.action(async function () {
|
|
154
|
-
const { assetsDir, tarballName } = this._globalOpts
|
|
155
|
-
const spinner = ora("Checking environment").start()
|
|
156
|
-
const assets = findAssetsDir(process.cwd(), assetsDir) || findAssetsDir(__dirname, assetsDir)
|
|
157
|
-
if (!assets) {
|
|
158
|
-
spinner.fail("Assets/ folder not found")
|
|
159
|
-
process.exit(1)
|
|
160
|
-
}
|
|
161
|
-
const tarPath = findTarball(assets, tarballName)
|
|
162
|
-
if (!tarPath) {
|
|
163
|
-
spinner.fail(`Tarball '${tarballName}' not found under Assets/`)
|
|
164
|
-
process.exit(1)
|
|
165
|
-
}
|
|
166
|
-
spinner.succeed("Environment OK")
|
|
167
|
-
console.log(`Assets folder : ${chalk.green(path.relative(process.cwd(), assets))}`)
|
|
168
|
-
console.log(`Tarball : ${chalk.green(path.relative(process.cwd(), tarPath))}`)
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
/* ─────────────────────────────── add ─────────────────────────────── */
|
|
172
|
-
|
|
173
|
-
program
|
|
174
|
-
.command("add")
|
|
175
|
-
.argument("<names...>", "component names to add, or 'all'")
|
|
176
|
-
.description("add components into ./comps")
|
|
177
|
-
.action(async function (names) {
|
|
178
|
-
const { yes, dry, assetsDir, tarballName } = this._globalOpts
|
|
179
|
-
const spinner = ora("Preparing").start()
|
|
180
|
-
|
|
181
|
-
const assets = findAssetsDir(process.cwd(), assetsDir) || findAssetsDir(__dirname, assetsDir)
|
|
182
|
-
if (!assets) {
|
|
183
|
-
spinner.fail("Assets/ folder not found")
|
|
184
|
-
process.exit(1)
|
|
185
|
-
}
|
|
186
|
-
const tarPath = findTarball(assets, tarballName)
|
|
187
|
-
if (!tarPath) {
|
|
188
|
-
spinner.fail(`Tarball '${tarballName}' not found`)
|
|
189
|
-
process.exit(1)
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const allComps = await scanComponents(tarPath)
|
|
193
|
-
const targetAll = names.length === 1 && names[0] === "all"
|
|
194
|
-
const targets = targetAll ? Array.from(allComps) : names
|
|
195
|
-
|
|
196
|
-
// validate unknown comps
|
|
197
|
-
const unknown = targets.filter((c) => !allComps.has(c))
|
|
198
|
-
if (unknown.length) {
|
|
199
|
-
spinner.fail(`Unknown component(s): ${unknown.join(", ")}`)
|
|
200
|
-
process.exit(1)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const cwd = process.cwd()
|
|
204
|
-
const compsRoot = path.join(cwd, "comps")
|
|
205
|
-
fs.mkdirSync(compsRoot, { recursive: true })
|
|
206
|
-
|
|
207
|
-
// conflict detect
|
|
208
|
-
const NO_PROMPT = new Set(["LICENSE"])
|
|
209
|
-
const conflicts = targets.filter(
|
|
210
|
-
(comp) => !NO_PROMPT.has(comp) && fs.existsSync(path.join(compsRoot, comp))
|
|
211
|
-
)
|
|
212
|
-
spinner.stop()
|
|
213
|
-
|
|
214
|
-
if (conflicts.length && !yes) {
|
|
215
|
-
for (const c of conflicts) {
|
|
216
|
-
const ok = await askYN(
|
|
217
|
-
`Overwrite existing ${chalk.yellow(`comps/${c}`)}? (backup your changes first)`
|
|
218
|
-
)
|
|
219
|
-
if (!ok) {
|
|
220
|
-
console.log(chalk.yellow("Aborted."))
|
|
221
|
-
process.exit(0)
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (dry) {
|
|
227
|
-
console.log(chalk.green("Dry-run: would install"), targets.join(", "))
|
|
228
|
-
process.exit(0)
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
const extractSpinner = ora("Extracting components").start()
|
|
232
|
-
|
|
233
|
-
const filter = (p) => {
|
|
234
|
-
if (!p.startsWith("comps/")) return false
|
|
235
|
-
const [, comp] = p.split("/")
|
|
236
|
-
return targetAll || targets.includes(comp)
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
try {
|
|
240
|
-
await tar.x({ file: tarPath, cwd, gzip: true, filter })
|
|
241
|
-
extractSpinner.succeed("Done.")
|
|
242
|
-
} catch (err) {
|
|
243
|
-
extractSpinner.fail("Extraction failed")
|
|
244
|
-
console.error(err)
|
|
245
|
-
process.exit(1)
|
|
246
|
-
}
|
|
247
|
-
})
|
|
248
|
-
|
|
249
|
-
/* ─────────────────────────────── go ─────────────────────────────── */
|
|
250
|
-
|
|
251
|
-
program.parseAsync().catch((err) => {
|
|
252
|
-
console.error(err)
|
|
253
|
-
process.exit(1)
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
"use strict"
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* OneJS – oj (shadcn-style) CLI
|
|
7
|
+
* A small utility for listing / installing premade UI components
|
|
8
|
+
* shipped inside a <Assets/> Unity project folder.
|
|
9
|
+
*
|
|
10
|
+
* Commands:
|
|
11
|
+
* oj list – show available components inside tarball
|
|
12
|
+
* oj add <name … | all> – install one or many components
|
|
13
|
+
* oj doctor – verify environment (Assets folder + tarball)
|
|
14
|
+
*
|
|
15
|
+
* Global flags:
|
|
16
|
+
* -y, --yes, --force – skip overwrite prompts
|
|
17
|
+
* --dry – dry-run (no filesystem writes)
|
|
18
|
+
* --assets-dir <dir> – override Assets directory auto-detection
|
|
19
|
+
* --tarball <file> – override tarball filename (default premade-uis.tgz.bytes)
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const fs = require("fs")
|
|
23
|
+
const path = require("path")
|
|
24
|
+
const readline = require("readline")
|
|
25
|
+
const tar = require("tar")
|
|
26
|
+
const { Command } = require("commander")
|
|
27
|
+
const chalk = require("chalk")
|
|
28
|
+
const ora = require("ora")
|
|
29
|
+
|
|
30
|
+
const pkg = require("../package.json")
|
|
31
|
+
|
|
32
|
+
/* ─────────────────────────────── utils ─────────────────────────────── */
|
|
33
|
+
|
|
34
|
+
function findAssetsDir(startDir, explicit) {
|
|
35
|
+
if (explicit) {
|
|
36
|
+
if (fs.existsSync(explicit) && fs.statSync(explicit).isDirectory()) return explicit
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
let dir = path.dirname(startDir) // Up a level, preventing `App/assets` getting returned
|
|
40
|
+
const { root } = path.parse(dir)
|
|
41
|
+
while (dir !== root) {
|
|
42
|
+
const probe = path.join(dir, "Assets")
|
|
43
|
+
if (fs.existsSync(probe) && fs.statSync(probe).isDirectory()) return probe
|
|
44
|
+
dir = path.dirname(dir)
|
|
45
|
+
}
|
|
46
|
+
return null
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function findTarball(assetsDir, tarballName) {
|
|
50
|
+
const stack = [assetsDir]
|
|
51
|
+
while (stack.length) {
|
|
52
|
+
const curr = stack.pop()
|
|
53
|
+
for (const e of fs.readdirSync(curr, { withFileTypes: true })) {
|
|
54
|
+
const p = path.join(curr, e.name)
|
|
55
|
+
if (e.isDirectory()) {
|
|
56
|
+
stack.push(p)
|
|
57
|
+
} else if (e.isFile() && e.name === tarballName) {
|
|
58
|
+
return p
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return null
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function askYN(prompt) {
|
|
66
|
+
return new Promise((resolve) => {
|
|
67
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
|
|
68
|
+
rl.question(`${prompt} ${chalk.dim("[y/N]")} `, (ans) => {
|
|
69
|
+
rl.close()
|
|
70
|
+
resolve(/^(y|yes)$/i.test(ans.trim()))
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Return Set of top-level component folders inside tarball.
|
|
77
|
+
*/
|
|
78
|
+
async function scanComponents(tarPath) {
|
|
79
|
+
const comps = new Set()
|
|
80
|
+
await tar.t({
|
|
81
|
+
file: tarPath,
|
|
82
|
+
onentry: (entry) => {
|
|
83
|
+
const p = entry.path.replace(/\\/g, "/")
|
|
84
|
+
if (!p.startsWith("comps/")) return
|
|
85
|
+
|
|
86
|
+
// Only treat entries inside a top-level folder under comps/
|
|
87
|
+
// e.g. "comps/button/**" → "button"
|
|
88
|
+
const rest = p.slice("comps/".length)
|
|
89
|
+
const firstSlash = rest.indexOf("/")
|
|
90
|
+
if (firstSlash === -1) return // file directly under comps/ → skip
|
|
91
|
+
|
|
92
|
+
const top = rest.slice(0, firstSlash)
|
|
93
|
+
if (top) comps.add(top)
|
|
94
|
+
},
|
|
95
|
+
})
|
|
96
|
+
return comps
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/* ─────────────────────────────── commander ─────────────────────────────── */
|
|
100
|
+
|
|
101
|
+
const program = new Command()
|
|
102
|
+
|
|
103
|
+
program
|
|
104
|
+
.name("oj")
|
|
105
|
+
.description("OneJS premade UI component manager")
|
|
106
|
+
.version(pkg.version, "-v, --version", "print version")
|
|
107
|
+
|
|
108
|
+
program
|
|
109
|
+
.hook("preAction", (thisCmd, actionCmd) => {
|
|
110
|
+
// Collect global opts and attach to actionCmd for convenience
|
|
111
|
+
actionCmd._globalOpts = {
|
|
112
|
+
yes: thisCmd.opts().yes || thisCmd.opts().force,
|
|
113
|
+
dry: thisCmd.opts().dry,
|
|
114
|
+
assetsDir: thisCmd.opts().assetsDir,
|
|
115
|
+
tarballName: thisCmd.opts().tarball || "premade-uis.tgz.bytes",
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
.option("-y, --yes", "skip confirmation prompts")
|
|
119
|
+
.option("--force", "alias for --yes")
|
|
120
|
+
.option("--dry", "dry-run – show actions only")
|
|
121
|
+
.option("--assets-dir <dir>", "override Assets/ directory")
|
|
122
|
+
.option("--tarball <file>", "override tarball filename (default premade-uis.tgz.bytes)")
|
|
123
|
+
|
|
124
|
+
/* ─────────────────────────────── list ─────────────────────────────── */
|
|
125
|
+
|
|
126
|
+
program
|
|
127
|
+
.command("list")
|
|
128
|
+
.description("list available components inside the tarball")
|
|
129
|
+
.action(async function () {
|
|
130
|
+
const { assetsDir, tarballName } = this._globalOpts
|
|
131
|
+
const assets = findAssetsDir(process.cwd(), assetsDir) || findAssetsDir(__dirname, assetsDir)
|
|
132
|
+
if (!assets) {
|
|
133
|
+
console.error(chalk.red("Assets/ folder not found. Are you inside a Unity project?"))
|
|
134
|
+
process.exit(1)
|
|
135
|
+
}
|
|
136
|
+
const tarPath = findTarball(assets, tarballName)
|
|
137
|
+
if (!tarPath) {
|
|
138
|
+
console.error(
|
|
139
|
+
chalk.red(`Tarball '${tarballName}' not found under Assets/. Did you import the OneJS package?`)
|
|
140
|
+
)
|
|
141
|
+
process.exit(1)
|
|
142
|
+
}
|
|
143
|
+
const comps = await scanComponents(tarPath)
|
|
144
|
+
console.log(chalk.bold(`Components in ${path.relative(process.cwd(), tarPath)}:`))
|
|
145
|
+
comps.forEach((c) => console.log(" •", chalk.cyan(c)))
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
/* ─────────────────────────────── doctor ─────────────────────────────── */
|
|
149
|
+
|
|
150
|
+
program
|
|
151
|
+
.command("doctor")
|
|
152
|
+
.description("check Assets directory and tarball presence")
|
|
153
|
+
.action(async function () {
|
|
154
|
+
const { assetsDir, tarballName } = this._globalOpts
|
|
155
|
+
const spinner = ora("Checking environment").start()
|
|
156
|
+
const assets = findAssetsDir(process.cwd(), assetsDir) || findAssetsDir(__dirname, assetsDir)
|
|
157
|
+
if (!assets) {
|
|
158
|
+
spinner.fail("Assets/ folder not found")
|
|
159
|
+
process.exit(1)
|
|
160
|
+
}
|
|
161
|
+
const tarPath = findTarball(assets, tarballName)
|
|
162
|
+
if (!tarPath) {
|
|
163
|
+
spinner.fail(`Tarball '${tarballName}' not found under Assets/`)
|
|
164
|
+
process.exit(1)
|
|
165
|
+
}
|
|
166
|
+
spinner.succeed("Environment OK")
|
|
167
|
+
console.log(`Assets folder : ${chalk.green(path.relative(process.cwd(), assets))}`)
|
|
168
|
+
console.log(`Tarball : ${chalk.green(path.relative(process.cwd(), tarPath))}`)
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
/* ─────────────────────────────── add ─────────────────────────────── */
|
|
172
|
+
|
|
173
|
+
program
|
|
174
|
+
.command("add")
|
|
175
|
+
.argument("<names...>", "component names to add, or 'all'")
|
|
176
|
+
.description("add components into ./comps")
|
|
177
|
+
.action(async function (names) {
|
|
178
|
+
const { yes, dry, assetsDir, tarballName } = this._globalOpts
|
|
179
|
+
const spinner = ora("Preparing").start()
|
|
180
|
+
|
|
181
|
+
const assets = findAssetsDir(process.cwd(), assetsDir) || findAssetsDir(__dirname, assetsDir)
|
|
182
|
+
if (!assets) {
|
|
183
|
+
spinner.fail("Assets/ folder not found")
|
|
184
|
+
process.exit(1)
|
|
185
|
+
}
|
|
186
|
+
const tarPath = findTarball(assets, tarballName)
|
|
187
|
+
if (!tarPath) {
|
|
188
|
+
spinner.fail(`Tarball '${tarballName}' not found`)
|
|
189
|
+
process.exit(1)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const allComps = await scanComponents(tarPath)
|
|
193
|
+
const targetAll = names.length === 1 && names[0] === "all"
|
|
194
|
+
const targets = targetAll ? Array.from(allComps) : names
|
|
195
|
+
|
|
196
|
+
// validate unknown comps
|
|
197
|
+
const unknown = targets.filter((c) => !allComps.has(c))
|
|
198
|
+
if (unknown.length) {
|
|
199
|
+
spinner.fail(`Unknown component(s): ${unknown.join(", ")}`)
|
|
200
|
+
process.exit(1)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const cwd = process.cwd()
|
|
204
|
+
const compsRoot = path.join(cwd, "comps")
|
|
205
|
+
fs.mkdirSync(compsRoot, { recursive: true })
|
|
206
|
+
|
|
207
|
+
// conflict detect
|
|
208
|
+
const NO_PROMPT = new Set(["LICENSE"])
|
|
209
|
+
const conflicts = targets.filter(
|
|
210
|
+
(comp) => !NO_PROMPT.has(comp) && fs.existsSync(path.join(compsRoot, comp))
|
|
211
|
+
)
|
|
212
|
+
spinner.stop()
|
|
213
|
+
|
|
214
|
+
if (conflicts.length && !yes) {
|
|
215
|
+
for (const c of conflicts) {
|
|
216
|
+
const ok = await askYN(
|
|
217
|
+
`Overwrite existing ${chalk.yellow(`comps/${c}`)}? (backup your changes first)`
|
|
218
|
+
)
|
|
219
|
+
if (!ok) {
|
|
220
|
+
console.log(chalk.yellow("Aborted."))
|
|
221
|
+
process.exit(0)
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (dry) {
|
|
227
|
+
console.log(chalk.green("Dry-run: would install"), targets.join(", "))
|
|
228
|
+
process.exit(0)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const extractSpinner = ora("Extracting components").start()
|
|
232
|
+
|
|
233
|
+
const filter = (p) => {
|
|
234
|
+
if (!p.startsWith("comps/")) return false
|
|
235
|
+
const [, comp] = p.split("/")
|
|
236
|
+
return targetAll || targets.includes(comp)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
try {
|
|
240
|
+
await tar.x({ file: tarPath, cwd, gzip: true, filter })
|
|
241
|
+
extractSpinner.succeed("Done.")
|
|
242
|
+
} catch (err) {
|
|
243
|
+
extractSpinner.fail("Extraction failed")
|
|
244
|
+
console.error(err)
|
|
245
|
+
process.exit(1)
|
|
246
|
+
}
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
/* ─────────────────────────────── go ─────────────────────────────── */
|
|
250
|
+
|
|
251
|
+
program.parseAsync().catch((err) => {
|
|
252
|
+
console.error(err)
|
|
253
|
+
process.exit(1)
|
|
254
254
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
declare namespace CS {
|
|
2
|
-
namespace UnityEngine {
|
|
3
|
-
interface Texture2D {
|
|
4
|
-
GetRawDataColor32(): Unity.Collections.NativeArray$1<Color32>
|
|
5
|
-
}
|
|
6
|
-
}
|
|
1
|
+
declare namespace CS {
|
|
2
|
+
namespace UnityEngine {
|
|
3
|
+
interface Texture2D {
|
|
4
|
+
GetRawDataColor32(): Unity.Collections.NativeArray$1<Color32>
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
7
|
}
|