kubetsx 0.1.2 → 0.1.4

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/src/cli.ts DELETED
@@ -1,111 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * 🎯 Kubetsx CLI
4
- *
5
- * Run Kubernetes config files written in TSX
6
- * Validates output is clean YAML before emitting
7
- */
8
-
9
- import { spawn } from 'child_process';
10
- import { resolve, dirname } from 'path';
11
- import { fileURLToPath } from 'url';
12
- import { existsSync } from 'fs';
13
- import { parse as parseYAML } from 'yaml';
14
-
15
- const __dirname = dirname(fileURLToPath(import.meta.url));
16
-
17
- const args = process.argv.slice(2);
18
-
19
- if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
20
- console.log(`
21
- 🎯 Kubetsx - The Declarative Kubernetes Framework
22
-
23
- Usage:
24
- kubetsx <file.tsx> [options] Run a TSX config file
25
- kubetsx --help Show this help message
26
- kubetsx --version Show version
27
-
28
- Examples:
29
- kubetsx config.tsx Generate YAML from config.tsx
30
- kubetsx config.tsx > k8s.yaml Save output to file
31
- kubetsx config.tsx | kubectl apply -f - Apply directly to cluster
32
- `);
33
- process.exit(0);
34
- }
35
-
36
- if (args.includes('--version') || args.includes('-v')) {
37
- console.log('kubetsx v0.1.2');
38
- process.exit(0);
39
- }
40
-
41
- // Find tsx CLI
42
- const tsxCliPath = resolve(__dirname, '..', 'node_modules', 'tsx', 'dist', 'cli.mjs');
43
- const tsxPath = existsSync(tsxCliPath) ? tsxCliPath : null;
44
-
45
- // Run tsx and capture output
46
- const child = spawn(
47
- tsxPath ? process.execPath : 'npx',
48
- tsxPath ? [tsxCliPath, ...args] : ['tsx', ...args],
49
- {
50
- stdio: ['inherit', 'pipe', 'pipe'],
51
- }
52
- );
53
-
54
- let stdout = '';
55
- let stderr = '';
56
-
57
- child.stdout?.on('data', (data) => {
58
- stdout += data.toString();
59
- });
60
-
61
- child.stderr?.on('data', (data) => {
62
- stderr += data.toString();
63
- });
64
-
65
- child.on('close', (code) => {
66
- // Always pass through stderr
67
- if (stderr) {
68
- process.stderr.write(stderr);
69
- }
70
-
71
- if (code !== 0) {
72
- process.exit(code ?? 1);
73
- }
74
-
75
- // Validate the output is valid YAML
76
- const trimmedOutput = stdout.trim();
77
-
78
- if (!trimmedOutput) {
79
- process.stderr.write('Error: No output generated. Make sure your config calls render().\n');
80
- process.exit(1);
81
- }
82
-
83
- // Try to parse as YAML to validate
84
- try {
85
- // Split by document separator and parse each
86
- const documents = trimmedOutput.split(/^---$/m).filter(d => d.trim());
87
-
88
- for (const doc of documents) {
89
- const parsed = parseYAML(doc);
90
-
91
- // Check it looks like a K8s resource
92
- if (parsed && typeof parsed === 'object') {
93
- if (!('apiVersion' in parsed) || !('kind' in parsed)) {
94
- throw new Error('Output does not appear to be a valid Kubernetes resource (missing apiVersion or kind)');
95
- }
96
- }
97
- }
98
-
99
- // Valid YAML - output it
100
- process.stdout.write(trimmedOutput + '\n');
101
-
102
- } catch (err) {
103
- process.stderr.write('\n❌ Error: Output is not valid Kubernetes YAML.\n\n');
104
- process.stderr.write('This usually happens when your config file has console.log() statements.\n');
105
- process.stderr.write('Use console.error() instead for debug output.\n\n');
106
- process.stderr.write('--- Raw output ---\n');
107
- process.stderr.write(stdout);
108
- process.stderr.write('------------------\n');
109
- process.exit(1);
110
- }
111
- });
@@ -1,241 +0,0 @@
1
- /**
2
- * 🎯 Kubetsx - Component Definitions
3
- *
4
- * All Kubernetes resource components as JSX elements
5
- */
6
-
7
- import { h } from '../jsx-runtime.js';
8
- import type {
9
- KubexElement,
10
- KubexNode,
11
- ManifestProps,
12
- ClusterProps,
13
- NamespaceProps,
14
- DeploymentProps,
15
- ContainerProps,
16
- PortProps,
17
- EnvProps,
18
- SecretRefProps,
19
- ConfigMapRefProps,
20
- ResourcesProps,
21
- ProbeProps,
22
- HttpProbeProps,
23
- TcpProbeProps,
24
- ExecProbeProps,
25
- ServiceProps,
26
- IngressProps,
27
- IngressHostProps,
28
- RouteProps,
29
- ConfigMapProps,
30
- SecretProps,
31
- VolumeProps,
32
- VolumeMountProps,
33
- EmptyDirProps,
34
- PvcVolumeProps,
35
- ConfigMapVolumeProps,
36
- SecretVolumeProps,
37
- PvcProps,
38
- HpaProps,
39
- JobProps,
40
- CronJobProps,
41
- ServiceAccountProps,
42
- RoleProps,
43
- ClusterRoleProps,
44
- RoleBindingProps,
45
- ClusterRoleBindingProps,
46
- } from '../types.js';
47
-
48
- // Helper to get children array
49
- function getChildren(children: KubexNode | undefined): KubexNode[] {
50
- if (!children) return [];
51
- return Array.isArray(children) ? children : [children];
52
- }
53
-
54
- // Cast helper
55
- function toProps(props: object): Record<string, unknown> {
56
- return props as Record<string, unknown>;
57
- }
58
-
59
- // ============================================================================
60
- // Manifest (Fragment alternative - groups multiple resources)
61
- // ============================================================================
62
-
63
- export function Manifest(props: ManifestProps): KubexElement {
64
- return h('Manifest', toProps(props), ...getChildren(props.children));
65
- }
66
-
67
- // ============================================================================
68
- // Cluster & Namespace
69
- // ============================================================================
70
-
71
- export function Cluster(props: ClusterProps): KubexElement {
72
- return h('Cluster', toProps(props), ...getChildren(props.children));
73
- }
74
-
75
- export function Namespace(props: NamespaceProps): KubexElement {
76
- return h('Namespace', toProps(props), ...getChildren(props.children));
77
- }
78
-
79
- // ============================================================================
80
- // Workloads
81
- // ============================================================================
82
-
83
- export function Deployment(props: DeploymentProps): KubexElement {
84
- return h('Deployment', toProps(props), ...getChildren(props.children));
85
- }
86
-
87
- export function Container(props: ContainerProps & { children?: KubexNode }): KubexElement {
88
- return h('Container', toProps(props), ...getChildren(props.children));
89
- }
90
-
91
- export function Job(props: JobProps): KubexElement {
92
- return h('Job', toProps(props), ...getChildren(props.children));
93
- }
94
-
95
- export function CronJob(props: CronJobProps): KubexElement {
96
- return h('CronJob', toProps(props), ...getChildren(props.children));
97
- }
98
-
99
- // ============================================================================
100
- // Container Configuration
101
- // ============================================================================
102
-
103
- export function Port(props: PortProps): KubexElement {
104
- return h('Port', toProps(props));
105
- }
106
-
107
- export function Env(props: EnvProps): KubexElement {
108
- return h('Env', toProps(props), ...getChildren(props.children));
109
- }
110
-
111
- export function SecretRef(props: SecretRefProps): KubexElement {
112
- return h('SecretRef', toProps(props));
113
- }
114
-
115
- export function ConfigMapRef(props: ConfigMapRefProps): KubexElement {
116
- return h('ConfigMapRef', toProps(props));
117
- }
118
-
119
- export function Resources(props: ResourcesProps): KubexElement {
120
- return h('Resources', toProps(props));
121
- }
122
-
123
- // ============================================================================
124
- // Probes
125
- // ============================================================================
126
-
127
- export function Probe(props: ProbeProps): KubexElement {
128
- return h('Probe', toProps(props), ...getChildren(props.children));
129
- }
130
-
131
- export function HttpProbe(props: HttpProbeProps): KubexElement {
132
- return h('HttpProbe', toProps(props));
133
- }
134
-
135
- export function TcpProbe(props: TcpProbeProps): KubexElement {
136
- return h('TcpProbe', toProps(props));
137
- }
138
-
139
- export function ExecProbe(props: ExecProbeProps): KubexElement {
140
- return h('ExecProbe', toProps(props));
141
- }
142
-
143
- // ============================================================================
144
- // Networking
145
- // ============================================================================
146
-
147
- export function Service(props: ServiceProps): KubexElement {
148
- return h('Service', toProps(props));
149
- }
150
-
151
- export function Ingress(props: IngressProps & { host?: string }): KubexElement {
152
- return h('Ingress', toProps(props), ...getChildren(props.children));
153
- }
154
-
155
- export function IngressHost(props: IngressHostProps): KubexElement {
156
- return h('IngressHost', toProps(props), ...getChildren(props.children));
157
- }
158
-
159
- export function Route(props: RouteProps): KubexElement {
160
- return h('Route', toProps(props));
161
- }
162
-
163
- // ============================================================================
164
- // Configuration
165
- // ============================================================================
166
-
167
- export function ConfigMap(props: ConfigMapProps): KubexElement {
168
- return h('ConfigMap', toProps(props));
169
- }
170
-
171
- export function Secret(props: SecretProps): KubexElement {
172
- return h('Secret', toProps(props));
173
- }
174
-
175
- // ============================================================================
176
- // Volumes
177
- // ============================================================================
178
-
179
- export function Volume(props: VolumeProps): KubexElement {
180
- return h('Volume', toProps(props), ...getChildren(props.children));
181
- }
182
-
183
- export function VolumeMount(props: VolumeMountProps): KubexElement {
184
- return h('VolumeMount', toProps(props));
185
- }
186
-
187
- export function EmptyDir(props: EmptyDirProps = {}): KubexElement {
188
- return h('EmptyDir', toProps(props));
189
- }
190
-
191
- export function PvcVolume(props: PvcVolumeProps): KubexElement {
192
- return h('PvcVolume', toProps(props));
193
- }
194
-
195
- export function ConfigMapVolume(props: ConfigMapVolumeProps): KubexElement {
196
- return h('ConfigMapVolume', toProps(props));
197
- }
198
-
199
- export function SecretVolume(props: SecretVolumeProps): KubexElement {
200
- return h('SecretVolume', toProps(props));
201
- }
202
-
203
- // ============================================================================
204
- // Storage
205
- // ============================================================================
206
-
207
- export function Pvc(props: PvcProps): KubexElement {
208
- return h('Pvc', toProps(props));
209
- }
210
-
211
- // ============================================================================
212
- // Autoscaling
213
- // ============================================================================
214
-
215
- export function Hpa(props: HpaProps): KubexElement {
216
- return h('Hpa', toProps(props));
217
- }
218
-
219
- // ============================================================================
220
- // RBAC & Service Accounts
221
- // ============================================================================
222
-
223
- export function ServiceAccount(props: ServiceAccountProps): KubexElement {
224
- return h('ServiceAccount', toProps(props));
225
- }
226
-
227
- export function Role(props: RoleProps): KubexElement {
228
- return h('Role', toProps(props));
229
- }
230
-
231
- export function ClusterRole(props: ClusterRoleProps): KubexElement {
232
- return h('ClusterRole', toProps(props));
233
- }
234
-
235
- export function RoleBinding(props: RoleBindingProps): KubexElement {
236
- return h('RoleBinding', toProps(props));
237
- }
238
-
239
- export function ClusterRoleBinding(props: ClusterRoleBindingProps): KubexElement {
240
- return h('ClusterRoleBinding', toProps(props));
241
- }
package/src/index.ts DELETED
@@ -1,123 +0,0 @@
1
- /**
2
- * 🎯 Kubetsx - The Declarative Kubernetes Framework
3
- *
4
- * Write K8s configs with JSX. Yes, really.
5
- */
6
-
7
- // JSX Runtime
8
- export { h, Fragment, jsx, jsxs, jsxDEV } from './jsx-runtime.js';
9
-
10
- // Render Engine
11
- export { render } from './render.js';
12
-
13
- // Components
14
- export {
15
- // Manifest (groups multiple resources)
16
- Manifest,
17
-
18
- // Cluster & Namespace
19
- Cluster,
20
- Namespace,
21
-
22
- // Workloads
23
- Deployment,
24
- Container,
25
- Job,
26
- CronJob,
27
-
28
- // Container Configuration
29
- Port,
30
- Env,
31
- SecretRef,
32
- ConfigMapRef,
33
- Resources,
34
-
35
- // Probes
36
- Probe,
37
- HttpProbe,
38
- TcpProbe,
39
- ExecProbe,
40
-
41
- // Networking
42
- Service,
43
- Ingress,
44
- IngressHost,
45
- Route,
46
-
47
- // Configuration
48
- ConfigMap,
49
- Secret,
50
-
51
- // Volumes
52
- Volume,
53
- VolumeMount,
54
- EmptyDir,
55
- PvcVolume,
56
- ConfigMapVolume,
57
- SecretVolume,
58
-
59
- // Storage
60
- Pvc,
61
-
62
- // Autoscaling
63
- Hpa,
64
-
65
- // RBAC
66
- ServiceAccount,
67
- Role,
68
- ClusterRole,
69
- RoleBinding,
70
- ClusterRoleBinding,
71
- } from './components/index.js';
72
-
73
- // Types
74
- export type {
75
- // Core
76
- KubexElement,
77
- KubexNode,
78
- KubexComponent,
79
- RenderOptions,
80
-
81
- // K8s Types
82
- K8sMetadata,
83
- K8sResource,
84
-
85
- // Component Props
86
- ManifestProps,
87
- ClusterProps,
88
- NamespaceProps,
89
- DeploymentProps,
90
- ContainerProps,
91
- PortProps,
92
- EnvProps,
93
- SecretRefProps,
94
- ConfigMapRefProps,
95
- ResourcesProps,
96
- ProbeProps,
97
- HttpProbeProps,
98
- TcpProbeProps,
99
- ExecProbeProps,
100
- ServiceProps,
101
- IngressProps,
102
- IngressHostProps,
103
- RouteProps,
104
- ConfigMapProps,
105
- SecretProps,
106
- VolumeProps,
107
- VolumeMountProps,
108
- EmptyDirProps,
109
- PvcVolumeProps,
110
- ConfigMapVolumeProps,
111
- SecretVolumeProps,
112
- PvcProps,
113
- HpaProps,
114
- JobProps,
115
- CronJobProps,
116
- ServiceAccountProps,
117
- RoleProps,
118
- ClusterRoleProps,
119
- RoleBindingProps,
120
- ClusterRoleBindingProps,
121
- RoleRule,
122
- } from './types.js';
123
-
@@ -1,71 +0,0 @@
1
- /**
2
- * 🎯 Kubetsx - JSX Runtime
3
- *
4
- * Custom JSX factory for Kubernetes components
5
- */
6
-
7
- import type { KubexElement, KubexNode, KubexComponent } from './types.js';
8
-
9
- // Helper to flatten children
10
- function flattenChildren(children: KubexNode[]): KubexNode[] {
11
- const result: KubexNode[] = [];
12
- for (const child of children) {
13
- if (Array.isArray(child)) {
14
- result.push(...flattenChildren(child));
15
- } else {
16
- result.push(child);
17
- }
18
- }
19
- return result;
20
- }
21
-
22
- /**
23
- * JSX Element Factory
24
- */
25
- export function h(
26
- type: string | KubexComponent,
27
- props: Record<string, unknown> | null,
28
- ...children: KubexNode[]
29
- ): KubexElement {
30
- return {
31
- type,
32
- props: props || {},
33
- children: flattenChildren(children),
34
- };
35
- }
36
-
37
- /**
38
- * Fragment support
39
- */
40
- export function Fragment(props: { children?: KubexNode }): KubexElement {
41
- const children = props.children;
42
- return {
43
- type: 'Fragment',
44
- props: {},
45
- children: Array.isArray(children) ? children : children ? [children] : [],
46
- };
47
- }
48
-
49
- /**
50
- * JSX automatic runtime exports
51
- */
52
- export function jsx(
53
- type: string | KubexComponent,
54
- props: Record<string, unknown> & { children?: KubexNode }
55
- ): KubexElement {
56
- const { children, ...restProps } = props;
57
- const childArray = children !== undefined
58
- ? (Array.isArray(children) ? children : [children])
59
- : [];
60
- return {
61
- type,
62
- props: restProps,
63
- children: flattenChildren(childArray),
64
- };
65
- }
66
-
67
- export const jsxs = jsx;
68
- export const jsxDEV = jsx;
69
-
70
- // Default export for compatibility
71
- export default { h, Fragment, jsx, jsxs, jsxDEV };