@owdproject/cli 0.0.2 → 0.1.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 +20 -0
- package/README.md +50 -16
- package/bin/bridge.js +127 -0
- package/bin/cli.js +433 -0
- package/bin/cp.js +3523 -0
- package/bin/desktop.js +5 -0
- package/bin/lib/catalog.js +501 -0
- package/bin/lib/config.js +130 -0
- package/bin/lib/cpAscii.js +39 -0
- package/bin/lib/cpFormat.js +343 -0
- package/bin/lib/desktopConfig.js +8 -0
- package/bin/lib/generateTemplate.js +426 -0
- package/bin/lib/install.js +525 -0
- package/bin/lib/installWizardFlow.js +726 -0
- package/bin/lib/migrateModulePlayground.config.mjs +187 -0
- package/bin/lib/migrateModulePlayground.mjs +318 -0
- package/bin/lib/npmVersions.js +124 -0
- package/bin/lib/packageSources.js +365 -0
- package/bin/lib/playgroundContext.js +188 -0
- package/bin/lib/scaffold.js +205 -0
- package/bin/lib/status.js +317 -0
- package/bin/lib/validateModule.js +868 -0
- package/bin/lib/workspace.js +222 -0
- package/bin/owd.js +2 -118
- package/go/bridge/bridge.go +200 -0
- package/go/desktop-go +0 -0
- package/go/go.mod +26 -0
- package/go/go.sum +37 -0
- package/go/main.go +30 -0
- package/go/tui/tui.go +3014 -0
- package/package.json +33 -23
- package/src/commands/create.js +0 -11
- package/src/commands/generate.js +0 -12
- package/src/commands/installApp.js +0 -9
- package/src/commands/installTheme.js +0 -9
- package/src/commands/start.js +0 -13
- package/src/utils/cloneRepo.js +0 -25
- package/src/utils/installPackage.js +0 -15
- package/src/utils/logging.js +0 -15
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Open Web Desktop Team ~ github.com/owdproject
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
19
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
20
|
+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,33 +1,67 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img width="160" height="160" src="https://avatars.githubusercontent.com/u/65117737?s=160&v=4" />
|
|
3
|
+
</p>
|
|
4
|
+
<h1 align="center">CLI</h1>
|
|
5
|
+
<h3 align="center">
|
|
6
|
+
Control Panel and Command Line Interface for Open Web Desktop.
|
|
7
|
+
</h3>
|
|
2
8
|
|
|
3
|
-
|
|
9
|
+
<br />
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
This package provides the official `desktop` (and legacy `owd`) CLI tool for Open Web Desktop. It features a rich Terminal User Interface (TUI) Control Panel to manage your running local OWD dev server, install/remove apps, modules, and themes, configure workspace settings, and scaffold new OWD components.
|
|
4
14
|
|
|
5
15
|
## Installation
|
|
6
16
|
|
|
7
|
-
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add -g @owdproject/cli
|
|
19
|
+
```
|
|
20
|
+
*Note: You can also install it as a devDependency in your OWD workspace project and run it via `pnpm desktop`.*
|
|
8
21
|
|
|
9
|
-
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
- **Control Panel (TUI)**: An interactive terminal interface for managing OWD projects.
|
|
25
|
+
- **Scaffolding**: Instantly initialize new workspaces or scaffold new apps and themes.
|
|
26
|
+
- **Package Management**: Install and validate OWD modules from npm, local directories, or custom Git repositories.
|
|
27
|
+
- **Graceful Fallback**: The interactive Control Panel compiles a fast Go-based TUI locally, falling back seamlessly to a JavaScript runner if Go is not available.
|
|
10
28
|
|
|
11
29
|
## Usage
|
|
12
30
|
|
|
13
|
-
Once installed,
|
|
31
|
+
Once installed, run the `desktop` command to open the control panel:
|
|
14
32
|
|
|
15
|
-
|
|
33
|
+
```bash
|
|
34
|
+
desktop
|
|
35
|
+
```
|
|
16
36
|
|
|
17
|
-
|
|
18
|
-
- `npx owd start`: Start the project in development mode (runs Nuxt.js).
|
|
19
|
-
- `npx owd generate`: Generate the project for static deployment.
|
|
37
|
+
### CLI Reference
|
|
20
38
|
|
|
21
|
-
|
|
39
|
+
#### Dev Server
|
|
40
|
+
Start the development server for the monorepo or automatically detect a module's playground:
|
|
41
|
+
```bash
|
|
42
|
+
desktop dev [--playground]
|
|
43
|
+
```
|
|
22
44
|
|
|
23
|
-
|
|
45
|
+
#### Add Packages
|
|
46
|
+
Install apps, modules, or themes from npm, local directories, or custom repositories:
|
|
47
|
+
```bash
|
|
48
|
+
desktop add app-todo --npm
|
|
49
|
+
desktop add theme-nova --dev
|
|
50
|
+
desktop add module-fs --from <github-user>
|
|
51
|
+
```
|
|
24
52
|
|
|
25
|
-
|
|
53
|
+
#### Scaffold a Project
|
|
54
|
+
Initialize a fresh OWD workspace:
|
|
55
|
+
```bash
|
|
56
|
+
desktop init [project-name]
|
|
57
|
+
```
|
|
26
58
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
59
|
+
#### Validation
|
|
60
|
+
Check Nuxt module configuration and playground directory structures:
|
|
61
|
+
```bash
|
|
62
|
+
desktop validate
|
|
63
|
+
```
|
|
30
64
|
|
|
31
65
|
## License
|
|
32
66
|
|
|
33
|
-
This
|
|
67
|
+
This package is released under the [MIT License](LICENSE).
|
package/bin/bridge.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { writeFileSync, readFileSync } from 'node:fs'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import {
|
|
6
|
+
findWorkspaceRoot,
|
|
7
|
+
loadSettings,
|
|
8
|
+
desktopPaths,
|
|
9
|
+
saveSettings
|
|
10
|
+
} from './lib/workspace.js'
|
|
11
|
+
import {
|
|
12
|
+
readDesktopConfig,
|
|
13
|
+
writeDesktopConfig,
|
|
14
|
+
readDesktopDependencies,
|
|
15
|
+
writeDesktopDependencies
|
|
16
|
+
} from './lib/config.js'
|
|
17
|
+
import { loadCatalog, mergeInstalled } from './lib/catalog.js'
|
|
18
|
+
import { resolveDevTarget } from './lib/playgroundContext.js'
|
|
19
|
+
import {
|
|
20
|
+
resolveDesktopConfigPath,
|
|
21
|
+
desktopConfigWritePath
|
|
22
|
+
} from './lib/desktopConfig.js'
|
|
23
|
+
|
|
24
|
+
function getWorkspaceContext() {
|
|
25
|
+
const workspaceRoot = findWorkspaceRoot()
|
|
26
|
+
if (!workspaceRoot) {
|
|
27
|
+
throw new Error('Not inside an OWD workspace')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const devTarget = resolveDevTarget(process.cwd(), workspaceRoot)
|
|
31
|
+
let paths
|
|
32
|
+
|
|
33
|
+
if (devTarget && devTarget.mode === 'playground') {
|
|
34
|
+
const playgroundDir = devTarget.playgroundDir
|
|
35
|
+
const resolved = resolveDesktopConfigPath(playgroundDir)
|
|
36
|
+
const configWrite = desktopConfigWritePath(playgroundDir)
|
|
37
|
+
paths = {
|
|
38
|
+
desktop: playgroundDir,
|
|
39
|
+
config: resolved?.path ?? configWrite,
|
|
40
|
+
configWrite,
|
|
41
|
+
configLegacy: resolved?.legacy ?? false,
|
|
42
|
+
packageJson: join(playgroundDir, 'package.json'),
|
|
43
|
+
isPlayground: true,
|
|
44
|
+
packageName: devTarget.packageName,
|
|
45
|
+
packageDir: devTarget.packageDir,
|
|
46
|
+
metaDir: join(playgroundDir, '.desktop'),
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
paths = {
|
|
50
|
+
...desktopPaths(workspaceRoot),
|
|
51
|
+
isPlayground: false,
|
|
52
|
+
metaDir: join(workspaceRoot, '.desktop'),
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const settings = loadSettings(workspaceRoot, paths.metaDir)
|
|
57
|
+
|
|
58
|
+
let config = { theme: null, apps: [], modules: [] }
|
|
59
|
+
try {
|
|
60
|
+
config = readDesktopConfig(paths.config, workspaceRoot)
|
|
61
|
+
} catch (err) {
|
|
62
|
+
console.error('Config load error:', err)
|
|
63
|
+
}
|
|
64
|
+
const deps = readDesktopDependencies(paths.packageJson)
|
|
65
|
+
return { workspaceRoot, settings, paths, config, deps }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function main() {
|
|
69
|
+
const args = process.argv.slice(2)
|
|
70
|
+
const cmd = args[0]
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
if (cmd === '--read') {
|
|
74
|
+
const ctx = getWorkspaceContext()
|
|
75
|
+
console.log(JSON.stringify({
|
|
76
|
+
workspaceRoot: ctx.workspaceRoot,
|
|
77
|
+
settings: ctx.settings,
|
|
78
|
+
config: ctx.config,
|
|
79
|
+
deps: ctx.deps,
|
|
80
|
+
paths: ctx.paths,
|
|
81
|
+
}, null, 2))
|
|
82
|
+
} else if (cmd === '--catalog') {
|
|
83
|
+
const ctx = getWorkspaceContext()
|
|
84
|
+
const force = args.includes('--force')
|
|
85
|
+
const catalog = await loadCatalog(ctx.workspaceRoot, ctx.settings, { force })
|
|
86
|
+
catalog.entries = mergeInstalled(catalog.entries, ctx.config, ctx.deps, ctx.workspaceRoot)
|
|
87
|
+
console.log(JSON.stringify(catalog, null, 2))
|
|
88
|
+
} else if (cmd === '--write') {
|
|
89
|
+
const ctx = getWorkspaceContext()
|
|
90
|
+
|
|
91
|
+
// Read JSON payload from stdin
|
|
92
|
+
let input = ''
|
|
93
|
+
for await (const chunk of process.stdin) {
|
|
94
|
+
input += chunk
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const payload = JSON.parse(input)
|
|
98
|
+
// payload = { config: { theme, apps, modules }, depsToAdd: { name: version }, depsToRemove: [name], settings?: { ... } }
|
|
99
|
+
|
|
100
|
+
if (payload.config) {
|
|
101
|
+
writeDesktopConfig(ctx.paths.config, ctx.workspaceRoot, payload.config)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (payload.depsToAdd || payload.depsToRemove) {
|
|
105
|
+
writeDesktopDependencies(
|
|
106
|
+
ctx.paths.packageJson,
|
|
107
|
+
payload.depsToAdd || {},
|
|
108
|
+
payload.depsToRemove || []
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (payload.settings) {
|
|
113
|
+
saveSettings(ctx.workspaceRoot, payload.settings, ctx.paths.metaDir)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
console.log(JSON.stringify({ success: true }))
|
|
117
|
+
} else {
|
|
118
|
+
console.error('Usage: node bridge.js [--read|--catalog [--force]|--write]')
|
|
119
|
+
process.exit(1)
|
|
120
|
+
}
|
|
121
|
+
} catch (err) {
|
|
122
|
+
console.error(JSON.stringify({ error: err.message }))
|
|
123
|
+
process.exit(1)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
main()
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import { spawn, execSync } from 'node:child_process'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
import { runDevForeground } from './lib/status.js'
|
|
4
|
+
import { existsSync } from 'node:fs'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
import getopts from 'getopts'
|
|
7
|
+
import {
|
|
8
|
+
resolveSource,
|
|
9
|
+
printPlan,
|
|
10
|
+
printNextSteps,
|
|
11
|
+
runWorkspaceInstall,
|
|
12
|
+
runNpmInstall,
|
|
13
|
+
} from './lib/install.js'
|
|
14
|
+
import { findWorkspaceRoot, inferKind } from './lib/workspace.js'
|
|
15
|
+
import { resolveDevTarget } from './lib/playgroundContext.js'
|
|
16
|
+
import { scaffoldProject } from './lib/scaffold.js'
|
|
17
|
+
|
|
18
|
+
const SCOPE = '@owdproject/'
|
|
19
|
+
|
|
20
|
+
/** @type {Record<string, { configKey: string, workspaceDir: string, nx: string, label: string }>} */
|
|
21
|
+
const KINDS = {
|
|
22
|
+
app: {
|
|
23
|
+
label: 'app',
|
|
24
|
+
configKey: 'apps',
|
|
25
|
+
workspaceDir: 'apps',
|
|
26
|
+
nx: 'desktop:install-app',
|
|
27
|
+
},
|
|
28
|
+
module: {
|
|
29
|
+
label: 'module',
|
|
30
|
+
configKey: 'modules',
|
|
31
|
+
workspaceDir: 'packages',
|
|
32
|
+
nx: 'desktop:install-module',
|
|
33
|
+
},
|
|
34
|
+
theme: {
|
|
35
|
+
label: 'theme',
|
|
36
|
+
configKey: 'theme',
|
|
37
|
+
workspaceDir: 'themes',
|
|
38
|
+
nx: 'desktop:install-theme',
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const LEGACY_COMMANDS = {
|
|
43
|
+
'install-app': 'app',
|
|
44
|
+
'install-module': 'module',
|
|
45
|
+
'install-theme': 'theme',
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** @type {string} */
|
|
49
|
+
let commandName = 'desktop'
|
|
50
|
+
|
|
51
|
+
function buildHelp(name) {
|
|
52
|
+
return `
|
|
53
|
+
${name} — add apps, modules, and themes to your Open Web Desktop
|
|
54
|
+
|
|
55
|
+
USAGE
|
|
56
|
+
${name} Open the control panel (interactive TUI)
|
|
57
|
+
${name} dev [--playground] Start dev server (auto-detects module playground)
|
|
58
|
+
|
|
59
|
+
CONTROL PANEL (TUI)
|
|
60
|
+
m Open command menu (all actions)
|
|
61
|
+
s Start the Nuxt dev server
|
|
62
|
+
x Stop the Nuxt dev server
|
|
63
|
+
R Reboot the Nuxt dev server (stop + start)
|
|
64
|
+
w Save catalog/theme changes to desktop.config.ts
|
|
65
|
+
1 / 2 / 3 Apps / Modules / Themes catalog tabs
|
|
66
|
+
o / O Cycle sort (o) or open sort picker (O)
|
|
67
|
+
i Open in-app docs (when module-docs is installed)
|
|
68
|
+
g Settings (GitHub user, SSH, trusted orgs)
|
|
69
|
+
r Refresh package list from GitHub (detects new modules)
|
|
70
|
+
b Run pnpm run generate
|
|
71
|
+
q / Esc Quit
|
|
72
|
+
${name} init [dir] Create a new OWD project (then opens the control panel)
|
|
73
|
+
${name} add <package> [options]
|
|
74
|
+
${name} add <kind> <name> [options]
|
|
75
|
+
${name} validate [path...] Check Nuxt module + playground layout
|
|
76
|
+
${name} template [--dry-run] [--check] Regenerate client/template/ (maintainers)
|
|
77
|
+
|
|
78
|
+
TEMPLATE (monorepo maintainers)
|
|
79
|
+
${name} template Write template/ from blueprint + desktop/ + latest npm versions
|
|
80
|
+
${name} template --dry-run Show planned @owdproject/* and starter versions
|
|
81
|
+
${name} template --check Fail if committed template/ differs (CI)
|
|
82
|
+
|
|
83
|
+
VALIDATE
|
|
84
|
+
${name} validate Validate cwd package, or all apps/themes/modules at repo root
|
|
85
|
+
${name} validate . Validate explicit package directory
|
|
86
|
+
${name} validate apps Validate every @owdproject/* module under apps/
|
|
87
|
+
--json Machine-readable output
|
|
88
|
+
--strict Treat warnings as failures
|
|
89
|
+
--smoke Run dev:prepare + nuxt build playground (slow, CI)
|
|
90
|
+
|
|
91
|
+
INSTALL SOURCES (control panel or CLI)
|
|
92
|
+
npm registry (default for desktop add)
|
|
93
|
+
--dev clone github.com/owdproject/<package>
|
|
94
|
+
--from <user> clone from GitHub user or full git URL (SSH supported)
|
|
95
|
+
|
|
96
|
+
EXAMPLES
|
|
97
|
+
pnpm ${name} # control panel
|
|
98
|
+
pnpm ${name} dev # monorepo desktop (from repo root)
|
|
99
|
+
cd apps/app-about && pnpm ${name} dev # app-about playground
|
|
100
|
+
pnpm ${name} dev --playground # force playground when cwd is in a module
|
|
101
|
+
${name} init my-desktop # scaffold + pnpm install + control panel
|
|
102
|
+
${name} add app-todo --npm
|
|
103
|
+
${name} add app-todo --dev
|
|
104
|
+
${name} add module-persistence --from dxlliv
|
|
105
|
+
|
|
106
|
+
KINDS (optional — inferred from the package name)
|
|
107
|
+
app app-* → apps/
|
|
108
|
+
module module-* → packages/ (kit-* and *-template are not listed in the control panel)
|
|
109
|
+
theme theme-* → themes/
|
|
110
|
+
|
|
111
|
+
OPTIONS
|
|
112
|
+
--playground Start the module playground dev server (when cwd is inside an @owdproject/* package with playground/)
|
|
113
|
+
--from <source> Git source (user, user/repo, or URL)
|
|
114
|
+
--branch <name> Git branch to clone
|
|
115
|
+
--npm Install from npm (default when --from is omitted)
|
|
116
|
+
--dev, --workspace Clone from github.com/owdproject/<package>
|
|
117
|
+
--protocol https|ssh With --from <user>, use HTTPS (default) or SSH clone URL
|
|
118
|
+
--dry-run Print the plan without changing anything
|
|
119
|
+
-h, --help Show this help
|
|
120
|
+
|
|
121
|
+
--from <source>
|
|
122
|
+
(omit) npm registry (default)
|
|
123
|
+
npm npm registry
|
|
124
|
+
owdproject Clone official repo (monorepo only)
|
|
125
|
+
<github-user> Clone github.com/<user>/<package> (your fork)
|
|
126
|
+
<user>/<repo> Explicit GitHub repo
|
|
127
|
+
<git-url> Full clone URL
|
|
128
|
+
|
|
129
|
+
LEGACY (still supported)
|
|
130
|
+
${name} install-app @owdproject/app-todo
|
|
131
|
+
→ prefer: ${name} add app-todo
|
|
132
|
+
`
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function openControlPanel(name) {
|
|
136
|
+
const cliDir = join(fileURLToPath(import.meta.url), '..')
|
|
137
|
+
const goDir = join(cliDir, '../go')
|
|
138
|
+
const binaryPath = join(goDir, 'desktop-go')
|
|
139
|
+
|
|
140
|
+
// Compile the Go Control Panel if binary doesn't exist
|
|
141
|
+
if (!existsSync(binaryPath)) {
|
|
142
|
+
console.log('Go Control Panel binary not found. Compiling...')
|
|
143
|
+
try {
|
|
144
|
+
execSync('go build -o desktop-go .', { cwd: goDir, stdio: 'inherit' })
|
|
145
|
+
console.log('Go Control Panel compiled successfully!')
|
|
146
|
+
} catch (err) {
|
|
147
|
+
console.warn('Failed to compile Go Control Panel, falling back to legacy CP:', err.message)
|
|
148
|
+
const { runCp } = await import('./cp.js')
|
|
149
|
+
await runCp(name)
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Execute Go TUI
|
|
155
|
+
const child = spawn(binaryPath, [], { stdio: 'inherit' })
|
|
156
|
+
child.on('exit', (code) => {
|
|
157
|
+
process.exit(code ?? 0)
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function fail(message, hint) {
|
|
162
|
+
console.error(`\n✗ ${message}`)
|
|
163
|
+
if (hint) console.error(` ${hint}`)
|
|
164
|
+
console.error(`\nRun \`${commandName} --help\` for usage.\n`)
|
|
165
|
+
process.exit(1)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function warn(message) {
|
|
169
|
+
console.warn(`\n⚠ ${message}\n`)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @param {string} input
|
|
174
|
+
* @param {string | undefined} explicitKind
|
|
175
|
+
*/
|
|
176
|
+
function normalizePackage(input, explicitKind) {
|
|
177
|
+
let raw = input.trim()
|
|
178
|
+
if (raw.startsWith(SCOPE)) raw = raw.slice(SCOPE.length)
|
|
179
|
+
|
|
180
|
+
if (!raw) {
|
|
181
|
+
fail('Package name is required.', `Example: ${commandName} add app-todo`)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const kind = explicitKind ?? inferKind(raw)
|
|
185
|
+
|
|
186
|
+
if (explicitKind) {
|
|
187
|
+
const prefixes = {
|
|
188
|
+
app: 'app-',
|
|
189
|
+
theme: 'theme-',
|
|
190
|
+
module: ['module-', 'kit-'],
|
|
191
|
+
}
|
|
192
|
+
const expected = prefixes[explicitKind]
|
|
193
|
+
const list = Array.isArray(expected) ? expected : [expected]
|
|
194
|
+
if (!list.some((p) => raw.startsWith(p))) {
|
|
195
|
+
raw = `${list[0]}${raw}`
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return { pkgName: `${SCOPE}${raw}`, shortName: raw, kind }
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function mapLegacyFlags(parsed) {
|
|
203
|
+
const { dev, workspace, fork, repo, branch, from, npm } = parsed
|
|
204
|
+
let mappedFrom = from
|
|
205
|
+
let mappedNpm = npm
|
|
206
|
+
const forceDev = dev || workspace
|
|
207
|
+
|
|
208
|
+
if (fork || repo) {
|
|
209
|
+
warn('`--fork` and `--repo` are deprecated — use `--from` instead.')
|
|
210
|
+
mappedFrom = repo || fork
|
|
211
|
+
}
|
|
212
|
+
if (forceDev && !mappedFrom && !mappedNpm) {
|
|
213
|
+
mappedFrom = 'owdproject'
|
|
214
|
+
}
|
|
215
|
+
if (mappedNpm) mappedFrom = 'npm'
|
|
216
|
+
|
|
217
|
+
return { from: mappedFrom, branch, npm: mappedNpm, dev: forceDev }
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function parseAddArgs(positionals) {
|
|
221
|
+
const kindNames = Object.keys(KINDS)
|
|
222
|
+
if (positionals.length === 0) {
|
|
223
|
+
fail('Missing package name.', `Example: ${commandName} add app-todo`)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (kindNames.includes(positionals[0])) {
|
|
227
|
+
const kind = positionals[0]
|
|
228
|
+
const name = positionals[1]
|
|
229
|
+
if (!name) {
|
|
230
|
+
fail(`Missing name for kind "${kind}".`, `Example: ${commandName} add ${kind} todo`)
|
|
231
|
+
}
|
|
232
|
+
return normalizePackage(name, kind)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return normalizePackage(positionals[0])
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function parseLegacyInstall(cmd, positionals) {
|
|
239
|
+
const kind = LEGACY_COMMANDS[cmd]
|
|
240
|
+
const raw = positionals[0]
|
|
241
|
+
if (!raw) {
|
|
242
|
+
fail('Missing package name.', `Example: ${commandName} ${cmd} ${SCOPE}app-todo`)
|
|
243
|
+
}
|
|
244
|
+
warn(`\`${cmd}\` is deprecated — use \`${commandName} add …\` instead.`)
|
|
245
|
+
return normalizePackage(raw, kind)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* @param {string} name CLI binary name (`desktop` or deprecated `owd`)
|
|
250
|
+
* @param {string[]} argv Arguments (without node and script path)
|
|
251
|
+
* @param {{ deprecated?: boolean }} [options]
|
|
252
|
+
*/
|
|
253
|
+
export async function runCli(name, argv, options = {}) {
|
|
254
|
+
commandName = name
|
|
255
|
+
|
|
256
|
+
if (options.deprecated) {
|
|
257
|
+
warn('The `owd` command is deprecated. Use `desktop` instead.')
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const parsed = getopts(argv, {
|
|
261
|
+
alias: { h: 'help', b: 'branch' },
|
|
262
|
+
boolean: ['help', 'npm', 'dry-run', 'dev', 'workspace', 'playground', 'json', 'strict', 'smoke', 'check'],
|
|
263
|
+
string: ['from', 'branch', 'fork', 'repo', 'protocol'],
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
const { _, help, npm: npmFlag } = parsed
|
|
267
|
+
const dryRun = parsed['dry-run'] === true
|
|
268
|
+
const { from, branch, npm: npmFromLegacy, dev: devFlag } = mapLegacyFlags(parsed)
|
|
269
|
+
const protocol = parsed.protocol === 'ssh' ? 'ssh' : 'https'
|
|
270
|
+
const useNpm = npmFlag || npmFromLegacy || (!from && !devFlag)
|
|
271
|
+
|
|
272
|
+
if (help || _[0] === 'help') {
|
|
273
|
+
console.log(buildHelp(name))
|
|
274
|
+
process.exit(0)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const cmd = _[0]
|
|
278
|
+
|
|
279
|
+
if (cmd === 'init') {
|
|
280
|
+
const projectDir = (_[1] || 'owd-client').trim()
|
|
281
|
+
const cwd = process.cwd()
|
|
282
|
+
|
|
283
|
+
if (findWorkspaceRoot(cwd)) {
|
|
284
|
+
fail(
|
|
285
|
+
'Already inside an OWD workspace.',
|
|
286
|
+
`Use \`${name}\` to manage this project, or run init from a parent directory.`,
|
|
287
|
+
)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
try {
|
|
291
|
+
await scaffoldProject({ dir: projectDir, cwd, commandName: name })
|
|
292
|
+
} catch (error) {
|
|
293
|
+
fail(error.message ?? String(error))
|
|
294
|
+
}
|
|
295
|
+
return
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const workspaceRoot = findWorkspaceRoot()
|
|
299
|
+
|
|
300
|
+
if (cmd === 'dev') {
|
|
301
|
+
if (!workspaceRoot) {
|
|
302
|
+
fail(
|
|
303
|
+
'Not inside an OWD workspace.',
|
|
304
|
+
'Run from the client repo, or try: desktop · desktop add <package>',
|
|
305
|
+
)
|
|
306
|
+
}
|
|
307
|
+
const forcePlayground = parsed.playground === true
|
|
308
|
+
const devTarget = resolveDevTarget(process.cwd(), workspaceRoot, { forcePlayground })
|
|
309
|
+
if (forcePlayground && !devTarget) {
|
|
310
|
+
fail(
|
|
311
|
+
'No @owdproject module with playground/desktop.config.ts found from this directory.',
|
|
312
|
+
'Run from an app/theme/module package (e.g. apps/app-about), or omit --playground for the monorepo desktop.',
|
|
313
|
+
)
|
|
314
|
+
}
|
|
315
|
+
runDevForeground(devTarget)
|
|
316
|
+
return
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (cmd === 'validate') {
|
|
320
|
+
const { runValidateCli, formatValidationReport } = await import('./lib/validateModule.js')
|
|
321
|
+
const strict = parsed.strict === true
|
|
322
|
+
const json = parsed.json === true
|
|
323
|
+
const smoke = parsed.smoke === true
|
|
324
|
+
const paths = _.slice(1).map(String)
|
|
325
|
+
const { exitCode, results } = runValidateCli(paths, {
|
|
326
|
+
workspaceRoot,
|
|
327
|
+
json,
|
|
328
|
+
strict,
|
|
329
|
+
smoke,
|
|
330
|
+
})
|
|
331
|
+
for (const result of results) {
|
|
332
|
+
console.log(formatValidationReport(result, { json }))
|
|
333
|
+
if (!json) console.log('')
|
|
334
|
+
}
|
|
335
|
+
process.exit(exitCode)
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (cmd === 'template') {
|
|
339
|
+
if (!workspaceRoot) {
|
|
340
|
+
fail(
|
|
341
|
+
'Not inside an OWD workspace.',
|
|
342
|
+
`Run from the client monorepo root to regenerate template/.`,
|
|
343
|
+
)
|
|
344
|
+
}
|
|
345
|
+
const { runGenerateTemplateCli } = await import('./lib/generateTemplate.js')
|
|
346
|
+
await runGenerateTemplateCli({
|
|
347
|
+
workspaceRoot,
|
|
348
|
+
dryRun: parsed['dry-run'] === true,
|
|
349
|
+
check: parsed.check === true,
|
|
350
|
+
})
|
|
351
|
+
return
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (!cmd) {
|
|
355
|
+
if (!workspaceRoot) {
|
|
356
|
+
fail(
|
|
357
|
+
'Not inside an OWD workspace.',
|
|
358
|
+
'Run from the client repo, or try: desktop · desktop add <package>',
|
|
359
|
+
)
|
|
360
|
+
}
|
|
361
|
+
await openControlPanel(name)
|
|
362
|
+
return
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (cmd === 'ui') {
|
|
366
|
+
fail('The `ui` subcommand was removed.', `Use \`${name}\` to open the control panel.`)
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (!workspaceRoot) {
|
|
370
|
+
fail(
|
|
371
|
+
'Not inside an OWD workspace.',
|
|
372
|
+
'Run from the client repo (needs pnpm-workspace.yaml + nx.json), or use a generated project with the same layout.',
|
|
373
|
+
)
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
let pkgInfo
|
|
377
|
+
|
|
378
|
+
if (cmd === 'add') {
|
|
379
|
+
pkgInfo = parseAddArgs(_.slice(1))
|
|
380
|
+
} else if (LEGACY_COMMANDS[cmd]) {
|
|
381
|
+
pkgInfo = parseLegacyInstall(cmd, _.slice(1))
|
|
382
|
+
} else {
|
|
383
|
+
fail(`Unknown command: ${cmd}`, `Use \`${name}\`, \`${name} dev\`, or \`${name} add <package>\`.`)
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const { pkgName, shortName, kind } = pkgInfo
|
|
387
|
+
const inMonorepo = Boolean(workspaceRoot)
|
|
388
|
+
let resolvedFrom = useNpm ? 'npm' : from
|
|
389
|
+
if (
|
|
390
|
+
!useNpm &&
|
|
391
|
+
resolvedFrom &&
|
|
392
|
+
resolvedFrom !== 'npm' &&
|
|
393
|
+
resolvedFrom !== 'owdproject' &&
|
|
394
|
+
resolvedFrom !== 'official' &&
|
|
395
|
+
protocol === 'ssh' &&
|
|
396
|
+
!/[@/]/.test(resolvedFrom)
|
|
397
|
+
) {
|
|
398
|
+
resolvedFrom = `git@github.com:${resolvedFrom}/${shortName}.git`
|
|
399
|
+
}
|
|
400
|
+
const source = resolveSource(resolvedFrom, shortName, inMonorepo, {
|
|
401
|
+
npm: useNpm,
|
|
402
|
+
dev: devFlag,
|
|
403
|
+
})
|
|
404
|
+
|
|
405
|
+
if (source.mode === 'npm') {
|
|
406
|
+
if (dryRun) {
|
|
407
|
+
printPlan({
|
|
408
|
+
pkgName,
|
|
409
|
+
kind,
|
|
410
|
+
targetDir: '(npm → node_modules)',
|
|
411
|
+
source,
|
|
412
|
+
branch: null,
|
|
413
|
+
dryRun: true,
|
|
414
|
+
})
|
|
415
|
+
process.exit(0)
|
|
416
|
+
}
|
|
417
|
+
runNpmInstall(kind, pkgName, workspaceRoot)
|
|
418
|
+
} else {
|
|
419
|
+
try {
|
|
420
|
+
await runWorkspaceInstall({
|
|
421
|
+
pkgName,
|
|
422
|
+
shortName,
|
|
423
|
+
kind,
|
|
424
|
+
workspaceRoot,
|
|
425
|
+
source,
|
|
426
|
+
branch,
|
|
427
|
+
dryRun,
|
|
428
|
+
})
|
|
429
|
+
} catch (error) {
|
|
430
|
+
fail(error.message ?? String(error))
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|