sealos-cli 0.1.0 → 1.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/README.md +77 -76
- package/dist/bin/cli.cjs +5120 -775
- package/dist/bin/cli.mjs +5120 -775
- package/dist/main.cjs +5116 -775
- package/dist/main.mjs +5120 -775
- package/package.json +6 -5
- package/src/commands/app/index.ts +5 -4
- package/src/commands/database/index.ts +12 -12
- package/src/commands/devbox/index.ts +676 -183
- package/src/commands/quota/index.ts +4 -3
- package/src/commands/s3/index.ts +5 -5
- package/src/commands/template/index.ts +107 -41
- package/src/commands/workspace/index.ts +49 -39
- package/src/docs/database_openapi.json +21 -38
- package/src/docs/devbox_openapi.json +5760 -0
- package/src/docs/template_openapi.json +2661 -1
- package/src/generated/database.ts +1 -5
- package/src/generated/devbox.ts +2500 -0
- package/src/generated/template.ts +228 -0
- package/src/lib/api-client.ts +19 -1
- package/src/lib/auth.ts +17 -8
- package/src/lib/errors.ts +1 -1
- package/src/lib/output.ts +5 -6
- package/src/main.ts +4 -11
- package/src/types/index.ts +0 -12
- package/src/commands/config/index.ts +0 -54
- package/src/lib/api.ts +0 -83
- package/src/lib/config.ts +0 -134
package/src/lib/config.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { homedir } from 'node:os'
|
|
2
|
-
import { join } from 'node:path'
|
|
3
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs'
|
|
4
|
-
import type { SealosConfig, Context } from '../types/index.ts'
|
|
5
|
-
|
|
6
|
-
const CONFIG_DIR = join(homedir(), '.sealos')
|
|
7
|
-
const CONFIG_FILE = join(CONFIG_DIR, 'config.json')
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Ensure config directory exists
|
|
11
|
-
*/
|
|
12
|
-
export function ensureConfigDir (): void {
|
|
13
|
-
if (!existsSync(CONFIG_DIR)) {
|
|
14
|
-
mkdirSync(CONFIG_DIR, { recursive: true })
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Read config file
|
|
20
|
-
*/
|
|
21
|
-
export function readConfig (): SealosConfig {
|
|
22
|
-
ensureConfigDir()
|
|
23
|
-
|
|
24
|
-
if (!existsSync(CONFIG_FILE)) {
|
|
25
|
-
const defaultConfig: SealosConfig = {
|
|
26
|
-
currentContext: '',
|
|
27
|
-
contexts: []
|
|
28
|
-
}
|
|
29
|
-
return defaultConfig
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
const content = readFileSync(CONFIG_FILE, 'utf-8')
|
|
34
|
-
return JSON.parse(content) as SealosConfig
|
|
35
|
-
} catch (error) {
|
|
36
|
-
throw new Error(`Failed to read config file: ${error}`)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Write config file
|
|
42
|
-
*/
|
|
43
|
-
export function writeConfig (config: SealosConfig): void {
|
|
44
|
-
ensureConfigDir()
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), 'utf-8')
|
|
48
|
-
} catch (error) {
|
|
49
|
-
throw new Error(`Failed to write config file: ${error}`)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Get current context
|
|
55
|
-
*/
|
|
56
|
-
export function getCurrentContext (): Context | null {
|
|
57
|
-
const config = readConfig()
|
|
58
|
-
if (!config.currentContext) {
|
|
59
|
-
return null
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const context = config.contexts.find(ctx => ctx.name === config.currentContext)
|
|
63
|
-
return context || null
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Set current context
|
|
68
|
-
*/
|
|
69
|
-
export function setCurrentContext (name: string): void {
|
|
70
|
-
const config = readConfig()
|
|
71
|
-
const context = config.contexts.find(ctx => ctx.name === name)
|
|
72
|
-
|
|
73
|
-
if (!context) {
|
|
74
|
-
throw new Error(`Context "${name}" not found`)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
config.currentContext = name
|
|
78
|
-
writeConfig(config)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Add or update context
|
|
83
|
-
*/
|
|
84
|
-
export function upsertContext (context: Context): void {
|
|
85
|
-
const config = readConfig()
|
|
86
|
-
const existingIndex = config.contexts.findIndex(ctx => ctx.name === context.name)
|
|
87
|
-
|
|
88
|
-
if (existingIndex >= 0) {
|
|
89
|
-
config.contexts[existingIndex] = context
|
|
90
|
-
} else {
|
|
91
|
-
config.contexts.push(context)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// If this is the first context, set it as current automatically
|
|
95
|
-
if (!config.currentContext) {
|
|
96
|
-
config.currentContext = context.name
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
writeConfig(config)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Remove context
|
|
104
|
-
*/
|
|
105
|
-
export function removeContext (name: string): void {
|
|
106
|
-
const config = readConfig()
|
|
107
|
-
config.contexts = config.contexts.filter(ctx => ctx.name !== name)
|
|
108
|
-
|
|
109
|
-
// If removing current context, clear currentContext
|
|
110
|
-
if (config.currentContext === name) {
|
|
111
|
-
config.currentContext = config.contexts[0]?.name || ''
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
writeConfig(config)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Get config value
|
|
119
|
-
*/
|
|
120
|
-
export function getConfigValue (key: string): string | undefined {
|
|
121
|
-
const config = readConfig()
|
|
122
|
-
// TODO: Implement nested key access, e.g. "contexts.0.name"
|
|
123
|
-
return (config as unknown as Record<string, unknown>)[key] as string | undefined
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Set config value
|
|
128
|
-
*/
|
|
129
|
-
export function setConfigValue (key: string, value: string): void {
|
|
130
|
-
const config = readConfig()
|
|
131
|
-
// TODO: Implement nested key setting
|
|
132
|
-
;(config as unknown as Record<string, unknown>)[key] = value
|
|
133
|
-
writeConfig(config)
|
|
134
|
-
}
|