@owdproject/cli 0.0.3 → 0.2.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.
Files changed (56) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +50 -16
  3. package/bin/bridge.js +129 -0
  4. package/bin/cli.js +491 -0
  5. package/bin/cp.js +3542 -0
  6. package/bin/desktop.js +5 -0
  7. package/bin/lib/catalog.js +504 -0
  8. package/bin/lib/config.js +173 -0
  9. package/bin/lib/cpAscii.js +39 -0
  10. package/bin/lib/cpFormat.js +343 -0
  11. package/bin/lib/create.js +246 -0
  12. package/bin/lib/desktopConfig.js +48 -0
  13. package/bin/lib/generateTemplate.js +427 -0
  14. package/bin/lib/install.js +521 -0
  15. package/bin/lib/installWizardFlow.js +792 -0
  16. package/bin/lib/migrateModulePlayground.config.mjs +187 -0
  17. package/bin/lib/migrateModulePlayground.mjs +318 -0
  18. package/bin/lib/npmVersions.js +124 -0
  19. package/bin/lib/packageSources.js +375 -0
  20. package/bin/lib/playgroundContext.js +188 -0
  21. package/bin/lib/scaffold.js +205 -0
  22. package/bin/lib/status.js +319 -0
  23. package/bin/lib/validateModule.js +978 -0
  24. package/bin/lib/workspace.js +289 -0
  25. package/bin/owd.js +2 -118
  26. package/go/bridge/bridge.go +220 -0
  27. package/go/desktop-go +0 -0
  28. package/go/go.mod +33 -0
  29. package/go/go.sum +52 -0
  30. package/go/main.go +34 -0
  31. package/go/owd-cli +0 -0
  32. package/go/tui/engine.go +472 -0
  33. package/go/tui/engine_test.go +40 -0
  34. package/go/tui/handlers.go +604 -0
  35. package/go/tui/helpers.go +916 -0
  36. package/go/tui/helpers_test.go +97 -0
  37. package/go/tui/modals.go +423 -0
  38. package/go/tui/resolver.go +377 -0
  39. package/go/tui/resolver_test.go +86 -0
  40. package/go/tui/styles.go +153 -0
  41. package/go/tui/tasks.go +850 -0
  42. package/go/tui/tui.go +869 -0
  43. package/go/tui/tui_test.go +69 -0
  44. package/go/tui/types.go +230 -0
  45. package/go/tui/view.go +812 -0
  46. package/go/tui/workqueue.go +179 -0
  47. package/go/tui/workqueue_test.go +90 -0
  48. package/package.json +33 -22
  49. package/src/commands/create.js +0 -11
  50. package/src/commands/generate.js +0 -12
  51. package/src/commands/installApp.js +0 -9
  52. package/src/commands/installTheme.js +0 -9
  53. package/src/commands/start.js +0 -13
  54. package/src/utils/cloneRepo.js +0 -25
  55. package/src/utils/installPackage.js +0 -15
  56. 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
- # Open Web Desktop CLI
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
- This command-line interface (CLI) provides a set of tools to easily manage your project.
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
- To install the CLI globally, run:
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
- `npm install -g @owdproject/cli`
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, you can use the CLI commands by typing `npx @owdproject/cli` followed by a command.
31
+ Once installed, run the `desktop` command to open the control panel:
14
32
 
15
- ### Available Commands
33
+ ```bash
34
+ pnpm desktop
35
+ ```
16
36
 
17
- - `npx @owdproject/cli create`: Create a new Open Web Desktop project from a template.
18
- - `npx @owdproject/cli start`: Start the project in development mode (runs Nuxt.js).
19
- - `npx @owdproject/cli generate`: Generate the project for static deployment.
37
+ ### CLI Reference
20
38
 
21
- For more information on each command, use:
39
+ #### Dev Server
40
+ Start the development server for the monorepo or automatically detect a module's playground:
41
+ ```bash
42
+ pnpm desktop dev [--playground]
43
+ ```
22
44
 
23
- `npx @owdproject/cli <command> --help`
45
+ #### Add Packages
46
+ Install apps, modules, or themes from npm, local directories, or custom repositories:
47
+ ```bash
48
+ pnpm desktop add app-todo --npm
49
+ pnpm desktop add theme-nova --dev
50
+ pnpm desktop add module-fs --from <github-user>
51
+ ```
24
52
 
25
- ## Features
53
+ #### Scaffold a Project
54
+ Initialize a fresh OWD workspace:
55
+ ```bash
56
+ pnpm desktop init [project-name]
57
+ ```
26
58
 
27
- - Easy setup for new Open Web Desktop projects.
28
- - Allows you to start development mode quickly with `npx @owdproject/cli start`.
29
- - Generates files for static deployment with `npx @owdproject/cli generate`.
59
+ #### Validation
60
+ Check Nuxt module configuration and playground directory structures:
61
+ ```bash
62
+ pnpm desktop validate
63
+ ```
30
64
 
31
65
  ## License
32
66
 
33
- This project is released under the [MIT License](LICENSE).
67
+ This package is released under the [MIT License](LICENSE).
package/bin/bridge.js ADDED
@@ -0,0 +1,129 @@
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
+ resolveConfigPathForWrite
17
+ } from './lib/config.js'
18
+ import { loadCatalog, mergeInstalled } from './lib/catalog.js'
19
+ import { resolveDevTarget } from './lib/playgroundContext.js'
20
+ import {
21
+ resolveDesktopConfigPath,
22
+ desktopConfigWritePath
23
+ } from './lib/desktopConfig.js'
24
+
25
+ function getWorkspaceContext() {
26
+ const workspaceRoot = findWorkspaceRoot()
27
+ if (!workspaceRoot) {
28
+ throw new Error('Not inside an OWD workspace')
29
+ }
30
+
31
+ const devTarget = resolveDevTarget(process.cwd(), workspaceRoot)
32
+ let paths
33
+
34
+ if (devTarget && devTarget.mode === 'playground') {
35
+ const playgroundDir = devTarget.playgroundDir
36
+ const resolved = resolveDesktopConfigPath(playgroundDir)
37
+ const configWrite = desktopConfigWritePath(playgroundDir)
38
+ paths = {
39
+ desktop: playgroundDir,
40
+ config: resolved?.path ?? configWrite,
41
+ configWrite,
42
+ configLegacy: resolved?.legacy ?? false,
43
+ packageJson: join(playgroundDir, 'package.json'),
44
+ isPlayground: true,
45
+ packageName: devTarget.packageName,
46
+ packageDir: devTarget.packageDir,
47
+ metaDir: join(playgroundDir, '.desktop'),
48
+ }
49
+ } else {
50
+ paths = {
51
+ ...desktopPaths(workspaceRoot),
52
+ isPlayground: false,
53
+ metaDir: join(workspaceRoot, '.desktop'),
54
+ }
55
+ }
56
+
57
+ const settings = loadSettings(workspaceRoot, paths.metaDir)
58
+
59
+ let config = { theme: null, apps: [], modules: [] }
60
+ try {
61
+ config = readDesktopConfig(paths.config, workspaceRoot)
62
+ } catch (err) {
63
+ console.error('Config load error:', err)
64
+ }
65
+ const deps = readDesktopDependencies(paths.packageJson)
66
+ return { workspaceRoot, settings, paths, config, deps }
67
+ }
68
+
69
+ async function main() {
70
+ const args = process.argv.slice(2)
71
+ const cmd = args[0]
72
+
73
+ try {
74
+ if (cmd === '--read') {
75
+ const ctx = getWorkspaceContext()
76
+ console.log(JSON.stringify({
77
+ workspaceRoot: ctx.workspaceRoot,
78
+ settings: ctx.settings,
79
+ config: ctx.config,
80
+ deps: ctx.deps,
81
+ paths: ctx.paths,
82
+ }, null, 2))
83
+ } else if (cmd === '--catalog') {
84
+ const ctx = getWorkspaceContext()
85
+ const force = args.includes('--force')
86
+ const catalog = await loadCatalog(ctx.workspaceRoot, ctx.settings, { force })
87
+ catalog.entries = mergeInstalled(catalog.entries, ctx.config, ctx.deps, ctx.workspaceRoot)
88
+ console.log(JSON.stringify(catalog, null, 2))
89
+ } else if (cmd === '--write') {
90
+ const ctx = getWorkspaceContext()
91
+
92
+ // Read JSON payload from stdin
93
+ let input = ''
94
+ for await (const chunk of process.stdin) {
95
+ input += chunk
96
+ }
97
+
98
+ const payload = JSON.parse(input)
99
+ // payload = { config: { theme, apps, modules }, depsToAdd: { name: version }, depsToRemove: [name], settings?: { ... } }
100
+
101
+ if (payload.config) {
102
+ const configPath = resolveConfigPathForWrite(ctx.paths)
103
+ writeDesktopConfig(configPath, ctx.workspaceRoot, payload.config)
104
+ }
105
+
106
+ if (payload.depsToAdd || payload.depsToRemove) {
107
+ writeDesktopDependencies(
108
+ ctx.paths.packageJson,
109
+ payload.depsToAdd || {},
110
+ payload.depsToRemove || []
111
+ )
112
+ }
113
+
114
+ if (payload.settings) {
115
+ saveSettings(ctx.workspaceRoot, payload.settings, ctx.paths.metaDir)
116
+ }
117
+
118
+ console.log(JSON.stringify({ success: true }))
119
+ } else {
120
+ console.error('Usage: node bridge.js [--read|--catalog [--force]|--write]')
121
+ process.exit(1)
122
+ }
123
+ } catch (err) {
124
+ console.error(JSON.stringify({ error: err.message }))
125
+ process.exit(1)
126
+ }
127
+ }
128
+
129
+ main()