@unibridge/cli 0.5.0 → 0.8.0
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/LICENSE +21 -0
- package/README.md +74 -0
- package/dist/commands/gameobject.d.ts +49 -0
- package/dist/commands/gameobject.d.ts.map +1 -0
- package/dist/commands/gameobject.js +218 -0
- package/dist/commands/gameobject.js.map +1 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +2 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/logs.d.ts +16 -0
- package/dist/commands/logs.d.ts.map +1 -0
- package/dist/commands/logs.js +62 -0
- package/dist/commands/logs.js.map +1 -0
- package/dist/commands/scene.d.ts +22 -1
- package/dist/commands/scene.d.ts.map +1 -1
- package/dist/commands/scene.js +72 -0
- package/dist/commands/scene.js.map +1 -1
- package/dist/commands/test.d.ts +23 -0
- package/dist/commands/test.d.ts.map +1 -0
- package/dist/commands/test.js +94 -0
- package/dist/commands/test.js.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/preflight.js +1 -1
- package/dist/preflight.js.map +1 -1
- package/package.json +32 -6
- package/src/commands/domain.ts +0 -49
- package/src/commands/execute.ts +0 -48
- package/src/commands/init.ts +0 -56
- package/src/commands/output.ts +0 -29
- package/src/commands/scene.ts +0 -135
- package/src/commands/status.ts +0 -49
- package/src/commands/with-unity-client.ts +0 -47
- package/src/index.ts +0 -29
- package/src/options.ts +0 -11
- package/src/preflight.test.ts +0 -39
- package/src/preflight.ts +0 -23
- package/tsconfig.json +0 -16
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { Command } from 'commander'
|
|
2
|
-
import { createClient } from '@unibridge/sdk'
|
|
3
|
-
import { getGlobalOptions } from '../options.ts'
|
|
4
|
-
import { resolveCommandProject } from '../preflight.ts'
|
|
5
|
-
|
|
6
|
-
interface ClientCommandRequirements {
|
|
7
|
-
requirePlugin: boolean
|
|
8
|
-
requiresExecute?: boolean
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface GlobalCommandContext {
|
|
12
|
-
jsonOutput: boolean
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export async function withUnityClient(
|
|
16
|
-
command: Command,
|
|
17
|
-
requirements: ClientCommandRequirements,
|
|
18
|
-
run: (client: ReturnType<typeof createClient>, ctx: GlobalCommandContext) => Promise<void>,
|
|
19
|
-
): Promise<void> {
|
|
20
|
-
let client: ReturnType<typeof createClient> | undefined
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
const globalOpts = getGlobalOptions(command)
|
|
24
|
-
const envExecute = process.env.UNIBRIDGE_ENABLE_EXECUTE !== '0'
|
|
25
|
-
const executeEnabled = globalOpts.execute !== false && envExecute
|
|
26
|
-
|
|
27
|
-
const projectPath = resolveCommandProject(
|
|
28
|
-
{
|
|
29
|
-
project: globalOpts.project,
|
|
30
|
-
execute: executeEnabled,
|
|
31
|
-
},
|
|
32
|
-
requirements,
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
client = createClient({
|
|
36
|
-
projectPath,
|
|
37
|
-
enableExecute: executeEnabled,
|
|
38
|
-
connectTimeout: 10_000,
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
await run(client, {
|
|
42
|
-
jsonOutput: globalOpts.json === true,
|
|
43
|
-
})
|
|
44
|
-
} finally {
|
|
45
|
-
client?.close()
|
|
46
|
-
}
|
|
47
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { readFileSync } from 'node:fs'
|
|
3
|
-
import path from 'node:path'
|
|
4
|
-
import { program } from 'commander'
|
|
5
|
-
import { registerDomain } from './commands/domain.ts'
|
|
6
|
-
import { registerInit } from './commands/init.ts'
|
|
7
|
-
import { registerExecute } from './commands/execute.ts'
|
|
8
|
-
import { registerStatus } from './commands/status.ts'
|
|
9
|
-
import { registerScene } from './commands/scene.ts'
|
|
10
|
-
|
|
11
|
-
const { version } = JSON.parse(
|
|
12
|
-
readFileSync(path.join(import.meta.dirname, '..', 'package.json'), 'utf-8'),
|
|
13
|
-
) as { version: string }
|
|
14
|
-
|
|
15
|
-
program
|
|
16
|
-
.name('unibridge')
|
|
17
|
-
.description('Bridge between Unity and your code')
|
|
18
|
-
.version(version)
|
|
19
|
-
.option('-p, --project <path>', 'Path to Unity project')
|
|
20
|
-
.option('--json', 'Output result as JSON')
|
|
21
|
-
.option('--no-execute', 'Disable execute tool for this invocation')
|
|
22
|
-
|
|
23
|
-
registerDomain(program)
|
|
24
|
-
registerInit(program)
|
|
25
|
-
registerExecute(program)
|
|
26
|
-
registerStatus(program)
|
|
27
|
-
registerScene(program)
|
|
28
|
-
|
|
29
|
-
program.parse()
|
package/src/options.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Command } from 'commander'
|
|
2
|
-
|
|
3
|
-
export interface GlobalCommandOptions {
|
|
4
|
-
project?: string
|
|
5
|
-
json?: boolean
|
|
6
|
-
execute?: boolean
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function getGlobalOptions(command: Command): GlobalCommandOptions {
|
|
10
|
-
return command.optsWithGlobals() as GlobalCommandOptions
|
|
11
|
-
}
|
package/src/preflight.test.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, it } from 'node:test'
|
|
2
|
-
import assert from 'node:assert/strict'
|
|
3
|
-
import { mkdirSync, rmSync, writeFileSync } from 'node:fs'
|
|
4
|
-
import { resolveCommandProject } from './preflight.ts'
|
|
5
|
-
|
|
6
|
-
const projectPath = '/tmp/unibridge-cli-preflight/My Game'
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
mkdirSync(`${projectPath}/Assets`, { recursive: true })
|
|
10
|
-
mkdirSync(`${projectPath}/ProjectSettings`, { recursive: true })
|
|
11
|
-
mkdirSync(`${projectPath}/Packages`, { recursive: true })
|
|
12
|
-
writeFileSync(`${projectPath}/ProjectSettings/ProjectVersion.txt`, 'm_EditorVersion: 2022.3.10f1\n')
|
|
13
|
-
writeFileSync(`${projectPath}/Packages/manifest.json`, JSON.stringify({ dependencies: {} }, null, 2))
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
afterEach(() => {
|
|
17
|
-
rmSync('/tmp/unibridge-cli-preflight', { recursive: true, force: true })
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
describe('resolveCommandProject', () => {
|
|
21
|
-
it('throws when plugin is missing for command execution', () => {
|
|
22
|
-
assert.throws(
|
|
23
|
-
() => resolveCommandProject({ project: projectPath, execute: true }, { requirePlugin: true, requiresExecute: true }),
|
|
24
|
-
/Run `unibridge init` first/,
|
|
25
|
-
)
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it('throws when execute is disabled', () => {
|
|
29
|
-
writeFileSync(
|
|
30
|
-
`${projectPath}/Packages/manifest.json`,
|
|
31
|
-
JSON.stringify({ dependencies: { 'com.msanatan.unibridge': 'file:../unity' } }, null, 2),
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
assert.throws(
|
|
35
|
-
() => resolveCommandProject({ project: projectPath, execute: false }, { requirePlugin: true, requiresExecute: true }),
|
|
36
|
-
/Execute is disabled/,
|
|
37
|
-
)
|
|
38
|
-
})
|
|
39
|
-
})
|
package/src/preflight.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { findUnityProject, isPluginInstalled } from '@unibridge/sdk'
|
|
2
|
-
|
|
3
|
-
export function resolveCommandProject(
|
|
4
|
-
opts: { project?: string; execute?: boolean },
|
|
5
|
-
config: { requirePlugin: boolean; requiresExecute?: boolean },
|
|
6
|
-
): string {
|
|
7
|
-
let projectPath: string
|
|
8
|
-
try {
|
|
9
|
-
projectPath = findUnityProject(opts.project)
|
|
10
|
-
} catch {
|
|
11
|
-
throw new Error('Unity project not found. Run inside a Unity project or pass --project <path>.')
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (config.requiresExecute && opts.execute === false) {
|
|
15
|
-
throw new Error('Execute is disabled for this invocation (--no-execute).')
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (config.requirePlugin && !isPluginInstalled(projectPath)) {
|
|
19
|
-
throw new Error('com.msanatan.unibridge is not installed. Run `unibridge init` first.')
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return projectPath
|
|
23
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "src",
|
|
5
|
-
"outDir": "dist",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"declarationMap": true,
|
|
8
|
-
"sourceMap": true
|
|
9
|
-
},
|
|
10
|
-
"include": [
|
|
11
|
-
"src/**/*.ts"
|
|
12
|
-
],
|
|
13
|
-
"exclude": [
|
|
14
|
-
"src/**/*.test.ts"
|
|
15
|
-
]
|
|
16
|
-
}
|