blokctl 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 (169) hide show
  1. package/dist/commands/build/index.d.ts +2 -0
  2. package/dist/commands/build/index.js +210 -0
  3. package/dist/commands/config/index.d.ts +1 -0
  4. package/dist/commands/config/index.js +46 -0
  5. package/dist/commands/cost/index.d.ts +1 -0
  6. package/dist/commands/cost/index.js +74 -0
  7. package/dist/commands/create/node.d.ts +2 -0
  8. package/dist/commands/create/node.js +541 -0
  9. package/dist/commands/create/project.d.ts +2 -0
  10. package/dist/commands/create/project.js +941 -0
  11. package/dist/commands/create/utils/Examples.d.ts +39 -0
  12. package/dist/commands/create/utils/Examples.js +983 -0
  13. package/dist/commands/create/workflow.d.ts +2 -0
  14. package/dist/commands/create/workflow.js +109 -0
  15. package/dist/commands/deploy/index.d.ts +2 -0
  16. package/dist/commands/deploy/index.js +176 -0
  17. package/dist/commands/dev/index.d.ts +2 -0
  18. package/dist/commands/dev/index.js +190 -0
  19. package/dist/commands/generate/GenerationAnalytics.d.ts +61 -0
  20. package/dist/commands/generate/GenerationAnalytics.js +162 -0
  21. package/dist/commands/generate/GenerationAnalytics.test.d.ts +1 -0
  22. package/dist/commands/generate/GenerationAnalytics.test.js +407 -0
  23. package/dist/commands/generate/NodeFileWriter.d.ts +5 -0
  24. package/dist/commands/generate/NodeFileWriter.js +240 -0
  25. package/dist/commands/generate/NodeGenerator.d.ts +20 -0
  26. package/dist/commands/generate/NodeGenerator.js +181 -0
  27. package/dist/commands/generate/NodeGenerator.test.d.ts +1 -0
  28. package/dist/commands/generate/NodeGenerator.test.js +101 -0
  29. package/dist/commands/generate/PromptVersioning.d.ts +25 -0
  30. package/dist/commands/generate/PromptVersioning.js +71 -0
  31. package/dist/commands/generate/PromptVersioning.test.d.ts +1 -0
  32. package/dist/commands/generate/PromptVersioning.test.js +120 -0
  33. package/dist/commands/generate/RegisterNode.d.ts +3 -0
  34. package/dist/commands/generate/RegisterNode.js +37 -0
  35. package/dist/commands/generate/RuntimeGenerator.d.ts +40 -0
  36. package/dist/commands/generate/RuntimeGenerator.js +369 -0
  37. package/dist/commands/generate/RuntimeGenerator.test.d.ts +1 -0
  38. package/dist/commands/generate/RuntimeGenerator.test.js +553 -0
  39. package/dist/commands/generate/TriggerGenerator.d.ts +22 -0
  40. package/dist/commands/generate/TriggerGenerator.js +220 -0
  41. package/dist/commands/generate/TriggerGenerator.test.d.ts +1 -0
  42. package/dist/commands/generate/TriggerGenerator.test.js +209 -0
  43. package/dist/commands/generate/WorkflowGenerator.d.ts +20 -0
  44. package/dist/commands/generate/WorkflowGenerator.js +131 -0
  45. package/dist/commands/generate/WorkflowGenerator.test.d.ts +1 -0
  46. package/dist/commands/generate/WorkflowGenerator.test.js +77 -0
  47. package/dist/commands/generate/e2e/NodeGenerator.e2e.test.d.ts +1 -0
  48. package/dist/commands/generate/e2e/NodeGenerator.e2e.test.js +216 -0
  49. package/dist/commands/generate/e2e/RuntimeGenerator.e2e.test.d.ts +1 -0
  50. package/dist/commands/generate/e2e/RuntimeGenerator.e2e.test.js +759 -0
  51. package/dist/commands/generate/e2e/TriggerGenerator.e2e.test.d.ts +1 -0
  52. package/dist/commands/generate/e2e/TriggerGenerator.e2e.test.js +295 -0
  53. package/dist/commands/generate/e2e/WorkflowGenerator.e2e.test.d.ts +1 -0
  54. package/dist/commands/generate/e2e/WorkflowGenerator.e2e.test.js +353 -0
  55. package/dist/commands/generate/index.d.ts +1 -0
  56. package/dist/commands/generate/index.js +418 -0
  57. package/dist/commands/generate/prompts/create-fn-node.system.d.ts +5 -0
  58. package/dist/commands/generate/prompts/create-fn-node.system.js +256 -0
  59. package/dist/commands/generate/prompts/create-node-manifest.system.d.ts +4 -0
  60. package/dist/commands/generate/prompts/create-node-manifest.system.js +41 -0
  61. package/dist/commands/generate/prompts/create-node.system.d.ts +5 -0
  62. package/dist/commands/generate/prompts/create-node.system.js +114 -0
  63. package/dist/commands/generate/prompts/create-readme.system.d.ts +4 -0
  64. package/dist/commands/generate/prompts/create-readme.system.js +83 -0
  65. package/dist/commands/generate/prompts/create-runtime.system.d.ts +5 -0
  66. package/dist/commands/generate/prompts/create-runtime.system.js +284 -0
  67. package/dist/commands/generate/prompts/create-trigger.system.d.ts +5 -0
  68. package/dist/commands/generate/prompts/create-trigger.system.js +293 -0
  69. package/dist/commands/generate/prompts/create-workflow.system.d.ts +5 -0
  70. package/dist/commands/generate/prompts/create-workflow.system.js +476 -0
  71. package/dist/commands/generate/prompts/register-node.system.d.ts +4 -0
  72. package/dist/commands/generate/prompts/register-node.system.js +26 -0
  73. package/dist/commands/generate/validators/CompilationValidator.d.ts +9 -0
  74. package/dist/commands/generate/validators/CompilationValidator.js +86 -0
  75. package/dist/commands/generate/validators/CompilationValidator.test.d.ts +1 -0
  76. package/dist/commands/generate/validators/CompilationValidator.test.js +161 -0
  77. package/dist/commands/generate/validators/NodeValidator.d.ts +18 -0
  78. package/dist/commands/generate/validators/NodeValidator.js +217 -0
  79. package/dist/commands/generate/validators/NodeValidator.test.d.ts +1 -0
  80. package/dist/commands/generate/validators/NodeValidator.test.js +281 -0
  81. package/dist/commands/generate/validators/WorkflowValidator.d.ts +6 -0
  82. package/dist/commands/generate/validators/WorkflowValidator.js +301 -0
  83. package/dist/commands/generate/validators/WorkflowValidator.test.d.ts +1 -0
  84. package/dist/commands/generate/validators/WorkflowValidator.test.js +647 -0
  85. package/dist/commands/generate/validators/index.d.ts +4 -0
  86. package/dist/commands/generate/validators/index.js +2 -0
  87. package/dist/commands/graph/index.d.ts +1 -0
  88. package/dist/commands/graph/index.js +69 -0
  89. package/dist/commands/install/index.d.ts +1 -0
  90. package/dist/commands/install/index.js +4 -0
  91. package/dist/commands/install/node.d.ts +4 -0
  92. package/dist/commands/install/node.js +136 -0
  93. package/dist/commands/install/workflow.d.ts +4 -0
  94. package/dist/commands/install/workflow.js +62 -0
  95. package/dist/commands/login/index.d.ts +2 -0
  96. package/dist/commands/login/index.js +77 -0
  97. package/dist/commands/logout/index.d.ts +2 -0
  98. package/dist/commands/logout/index.js +20 -0
  99. package/dist/commands/marketplace/runtime.d.ts +54 -0
  100. package/dist/commands/marketplace/runtime.js +350 -0
  101. package/dist/commands/migrate/index.d.ts +1 -0
  102. package/dist/commands/migrate/index.js +14 -0
  103. package/dist/commands/migrate/node.d.ts +2 -0
  104. package/dist/commands/migrate/node.js +110 -0
  105. package/dist/commands/monitor/index.d.ts +1 -0
  106. package/dist/commands/monitor/index.js +28 -0
  107. package/dist/commands/monitor/monitor-component.d.ts +1 -0
  108. package/dist/commands/monitor/monitor-component.js +271 -0
  109. package/dist/commands/monitor/static/index.html +2124 -0
  110. package/dist/commands/monitor/static-web-server.d.ts +1 -0
  111. package/dist/commands/monitor/static-web-server.js +89 -0
  112. package/dist/commands/profile/index.d.ts +1 -0
  113. package/dist/commands/profile/index.js +112 -0
  114. package/dist/commands/publish/index.d.ts +1 -0
  115. package/dist/commands/publish/index.js +4 -0
  116. package/dist/commands/publish/node.d.ts +4 -0
  117. package/dist/commands/publish/node.js +231 -0
  118. package/dist/commands/publish/workflow.d.ts +4 -0
  119. package/dist/commands/publish/workflow.js +165 -0
  120. package/dist/commands/search/docs.d.ts +17 -0
  121. package/dist/commands/search/docs.js +179 -0
  122. package/dist/commands/search/index.d.ts +1 -0
  123. package/dist/commands/search/index.js +5 -0
  124. package/dist/commands/search/indexer.d.ts +10 -0
  125. package/dist/commands/search/indexer.js +265 -0
  126. package/dist/commands/search/nodes.d.ts +4 -0
  127. package/dist/commands/search/nodes.js +101 -0
  128. package/dist/commands/search/workflow.d.ts +4 -0
  129. package/dist/commands/search/workflow.js +100 -0
  130. package/dist/commands/trace/index.d.ts +1 -0
  131. package/dist/commands/trace/index.js +26 -0
  132. package/dist/commands/trace/startStudio.d.ts +8 -0
  133. package/dist/commands/trace/startStudio.js +116 -0
  134. package/dist/index.d.ts +17 -0
  135. package/dist/index.js +186 -0
  136. package/dist/services/commander.d.ts +9 -0
  137. package/dist/services/commander.js +20 -0
  138. package/dist/services/constants.d.ts +1 -0
  139. package/dist/services/constants.js +3 -0
  140. package/dist/services/local-token-manager.d.ts +14 -0
  141. package/dist/services/local-token-manager.js +99 -0
  142. package/dist/services/non-interactive.d.ts +5 -0
  143. package/dist/services/non-interactive.js +30 -0
  144. package/dist/services/package-manager.d.ts +35 -0
  145. package/dist/services/package-manager.js +111 -0
  146. package/dist/services/posthog.d.ts +31 -0
  147. package/dist/services/posthog.js +159 -0
  148. package/dist/services/registry-manager.d.ts +9 -0
  149. package/dist/services/registry-manager.js +26 -0
  150. package/dist/services/runtime-detector.d.ts +23 -0
  151. package/dist/services/runtime-detector.js +181 -0
  152. package/dist/services/runtime-setup.d.ts +36 -0
  153. package/dist/services/runtime-setup.js +250 -0
  154. package/dist/services/utils.d.ts +2 -0
  155. package/dist/services/utils.js +29 -0
  156. package/dist/services/workflow-loader.d.ts +30 -0
  157. package/dist/services/workflow-loader.js +46 -0
  158. package/dist/studio-dist/assets/charts-Dso0hPUR.js +68 -0
  159. package/dist/studio-dist/assets/graph-CsV2nWGn.js +23 -0
  160. package/dist/studio-dist/assets/icons-zP8LLgPh.js +311 -0
  161. package/dist/studio-dist/assets/index-CLyEkXMx.css +1 -0
  162. package/dist/studio-dist/assets/index-CNXFX_ar.js +27 -0
  163. package/dist/studio-dist/assets/react-vendor--Eh9ivFN.js +17 -0
  164. package/dist/studio-dist/assets/tanstack-query-CiM1U6F5.js +1 -0
  165. package/dist/studio-dist/assets/tanstack-router-Btjy0MKq.js +25 -0
  166. package/dist/studio-dist/assets/tanstack-table-DhwRvuH2.js +22 -0
  167. package/dist/studio-dist/favicon.svg +5 -0
  168. package/dist/studio-dist/index.html +21 -0
  169. package/package.json +75 -0
@@ -0,0 +1,111 @@
1
+ import { exec as _exec } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ const executor = promisify(_exec);
4
+ const isWindows = process.platform === "win32";
5
+ export var VersionUpdateType;
6
+ (function (VersionUpdateType) {
7
+ VersionUpdateType["PATCH"] = "patch";
8
+ VersionUpdateType["MINOR"] = "minor";
9
+ VersionUpdateType["MAJOR"] = "major";
10
+ })(VersionUpdateType || (VersionUpdateType = {}));
11
+ const COMMANDS = {
12
+ bun: {
13
+ INSTALL: "bun install",
14
+ BUILD: "bun run build",
15
+ PUBLISH: () => {
16
+ return "bun publish --access public";
17
+ },
18
+ INSTALL_NODE: (opts) => {
19
+ return `bun add ${opts.node}`;
20
+ },
21
+ UPDATE_VERSION: (opts) => {
22
+ return `bun version ${opts.type}`;
23
+ },
24
+ },
25
+ pnpm: {
26
+ INSTALL: "pnpm install",
27
+ BUILD: "pnpm run build",
28
+ PUBLISH: () => {
29
+ return "pnpm publish --access public";
30
+ },
31
+ INSTALL_NODE: (opts) => {
32
+ return `pnpm install ${opts.node}`;
33
+ },
34
+ UPDATE_VERSION: (opts) => {
35
+ return `pnpm version ${opts.type}`;
36
+ },
37
+ },
38
+ yarn: {
39
+ INSTALL: "yarn install",
40
+ BUILD: "yarn run build",
41
+ PUBLISH: () => {
42
+ return "yarn publish --access public";
43
+ },
44
+ INSTALL_NODE: (opts) => {
45
+ return `yarn add ${opts.node}`;
46
+ },
47
+ UPDATE_VERSION: (opts) => {
48
+ return `yarn version --${opts.type}`;
49
+ },
50
+ },
51
+ npm: {
52
+ INSTALL: "npm install",
53
+ BUILD: "npm run build",
54
+ PUBLISH: (opts) => {
55
+ return `npm publish --registry=${opts.registry} --userconfig ${opts.npmrcDir} --json`;
56
+ },
57
+ INSTALL_NODE: (opts) => {
58
+ return `npm install ${opts.node}`;
59
+ },
60
+ UPDATE_VERSION: (opts) => {
61
+ return `npm version ${opts.type}`;
62
+ },
63
+ },
64
+ };
65
+ const PACKAGE_MANAGERS = Object.keys(COMMANDS);
66
+ class PackageManager {
67
+ static instance;
68
+ detectedManager = null;
69
+ constructor() { }
70
+ static getInstance() {
71
+ if (!PackageManager.instance) {
72
+ PackageManager.instance = new PackageManager();
73
+ }
74
+ return PackageManager.instance;
75
+ }
76
+ async isAvailable(cmd) {
77
+ const checkCmd = isWindows ? `where ${cmd}` : `which ${cmd}`;
78
+ try {
79
+ await executor(checkCmd);
80
+ return true;
81
+ }
82
+ catch {
83
+ return false;
84
+ }
85
+ }
86
+ async getAvailableManagers() {
87
+ const availableManagers = [];
88
+ for (const manager of PACKAGE_MANAGERS) {
89
+ if (await this.isAvailable(manager)) {
90
+ availableManagers.push(manager);
91
+ }
92
+ }
93
+ return availableManagers;
94
+ }
95
+ async getManager(preferedManager) {
96
+ if (preferedManager)
97
+ return COMMANDS[preferedManager];
98
+ if (this.detectedManager)
99
+ return COMMANDS[this.detectedManager];
100
+ for (const manager of PACKAGE_MANAGERS) {
101
+ if (await this.isAvailable(manager)) {
102
+ this.detectedManager = manager;
103
+ return COMMANDS[manager];
104
+ }
105
+ }
106
+ throw new Error("No supported package manager found.");
107
+ }
108
+ }
109
+ export default PackageManager;
110
+ const manager = PackageManager.getInstance();
111
+ export { manager };
@@ -0,0 +1,31 @@
1
+ export declare class PosthogAnalytics {
2
+ private sessionId;
3
+ private client?;
4
+ private distinctId;
5
+ private version;
6
+ constructor({ version, apiKey, host, cliConfigPath, }: {
7
+ version: string;
8
+ apiKey?: string;
9
+ host?: string;
10
+ cliConfigPath: string;
11
+ });
12
+ private writeCliConfig;
13
+ private initializePostHog;
14
+ private isTelemetryEnabled;
15
+ private getDistinctId;
16
+ private getSystemProperties;
17
+ private captureSessionStart;
18
+ trackCommand(options: {
19
+ command: string;
20
+ args?: Record<string, unknown>;
21
+ durationMs?: number;
22
+ status?: "success" | "error";
23
+ error?: string;
24
+ }): void;
25
+ trackCommandExecution<T>({ command, args, execution, }: {
26
+ command: string;
27
+ args: Record<string, unknown>;
28
+ execution: () => Promise<T>;
29
+ }): Promise<T>;
30
+ shutdown(): Promise<void>;
31
+ }
@@ -0,0 +1,159 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
3
+ import os from "node:os";
4
+ import { PostHog } from "posthog-node";
5
+ export class PosthogAnalytics {
6
+ sessionId;
7
+ client;
8
+ distinctId;
9
+ version;
10
+ constructor({ version, apiKey = "phc_2xrtQviE7fuks4uth84sqTIq7gOErCX7FOATRjHjzBa", host = "https://us.i.posthog.com", cliConfigPath, }) {
11
+ this.version = version;
12
+ if (existsSync(cliConfigPath)) {
13
+ try {
14
+ const { distinctId, sessionId } = JSON.parse(readFileSync(cliConfigPath, "utf-8"));
15
+ this.distinctId = distinctId;
16
+ this.sessionId = sessionId;
17
+ }
18
+ catch (e) {
19
+ this.sessionId = randomUUID();
20
+ this.distinctId = this.getDistinctId();
21
+ }
22
+ this.writeCliConfig({
23
+ distinctId: this.distinctId,
24
+ sessionId: this.sessionId,
25
+ }, cliConfigPath);
26
+ }
27
+ else {
28
+ this.sessionId = randomUUID();
29
+ this.distinctId = this.getDistinctId();
30
+ this.writeCliConfig({
31
+ distinctId: this.distinctId,
32
+ sessionId: this.sessionId,
33
+ }, cliConfigPath);
34
+ }
35
+ if (this.isTelemetryEnabled()) {
36
+ this.initializePostHog(apiKey, host);
37
+ }
38
+ }
39
+ writeCliConfig({ distinctId, sessionId }, cliConfigPath) {
40
+ try {
41
+ writeFileSync(cliConfigPath, JSON.stringify({ distinctId, sessionId }));
42
+ }
43
+ catch (e) {
44
+ }
45
+ }
46
+ initializePostHog(apiKey, host) {
47
+ this.client = new PostHog(apiKey, {
48
+ host,
49
+ flushAt: 1,
50
+ flushInterval: 0,
51
+ });
52
+ this.captureSessionStart();
53
+ process.on("exit", () => {
54
+ this.client?.flush();
55
+ });
56
+ }
57
+ isTelemetryEnabled() {
58
+ if (process.env.NO_NANOCTL_TELEMETRY) {
59
+ return false;
60
+ }
61
+ return true;
62
+ }
63
+ getDistinctId() {
64
+ const machineId = os.hostname();
65
+ return `blokctl-${machineId}`;
66
+ }
67
+ getSystemProperties() {
68
+ return {
69
+ os: process.platform,
70
+ os_version: os.release(),
71
+ node_version: process.version,
72
+ platform: process.arch,
73
+ session_id: this.sessionId,
74
+ cli_version: this.version || "unknown",
75
+ machine_id: os.hostname(),
76
+ };
77
+ }
78
+ captureSessionStart() {
79
+ if (!this.client) {
80
+ return;
81
+ }
82
+ this.client.capture({
83
+ distinctId: this.distinctId,
84
+ event: "cli_session_start",
85
+ properties: {
86
+ ...this.getSystemProperties(),
87
+ },
88
+ });
89
+ }
90
+ trackCommand(options) {
91
+ try {
92
+ if (!this.client) {
93
+ console.log("CLIENT NOT FOUND");
94
+ return;
95
+ }
96
+ const commandData = {
97
+ command: options.command,
98
+ status: options.status || "success",
99
+ };
100
+ if (options.args) {
101
+ commandData.args = options.args;
102
+ }
103
+ if (options.durationMs) {
104
+ commandData.durationMs = options.durationMs;
105
+ }
106
+ if (options.error) {
107
+ commandData.error = options.error;
108
+ }
109
+ this.client.capture({
110
+ distinctId: this.distinctId,
111
+ event: "cli_command",
112
+ properties: {
113
+ ...this.getSystemProperties(),
114
+ ...commandData,
115
+ },
116
+ });
117
+ }
118
+ catch (e) {
119
+ console.log("ERROR", e);
120
+ }
121
+ }
122
+ async trackCommandExecution({ command, args, execution, }) {
123
+ const startTime = process.hrtime();
124
+ try {
125
+ const result = await execution();
126
+ const [seconds, nanoseconds] = process.hrtime(startTime);
127
+ const durationMs = seconds * 1000 + nanoseconds / 1000000;
128
+ this.trackCommand({
129
+ command,
130
+ args,
131
+ durationMs,
132
+ status: "success",
133
+ });
134
+ return result;
135
+ }
136
+ catch (error) {
137
+ const [seconds, nanoseconds] = process.hrtime(startTime);
138
+ const durationMs = seconds * 1000 + nanoseconds / 1000000;
139
+ this.trackCommand({
140
+ command,
141
+ args,
142
+ durationMs,
143
+ status: "error",
144
+ error: error instanceof Error ? error.message : String(error),
145
+ });
146
+ throw error;
147
+ }
148
+ }
149
+ async shutdown() {
150
+ if (!this.client) {
151
+ return;
152
+ }
153
+ try {
154
+ await this.client.shutdown();
155
+ }
156
+ catch (e) {
157
+ }
158
+ }
159
+ }
@@ -0,0 +1,9 @@
1
+ export default class RegistryManager {
2
+ private registry;
3
+ constructor();
4
+ setRegistry(url: string): void;
5
+ getRegistry(): string;
6
+ getRegistryToken(accessToken: string): Promise<any>;
7
+ }
8
+ declare const registryManager: RegistryManager;
9
+ export { registryManager };
@@ -0,0 +1,26 @@
1
+ import { BLOK_URL } from "./constants.js";
2
+ export default class RegistryManager {
3
+ registry;
4
+ constructor() {
5
+ this.registry = "https://registry.npmjs.org/";
6
+ }
7
+ setRegistry(url) {
8
+ this.registry = url;
9
+ }
10
+ getRegistry() {
11
+ return this.registry;
12
+ }
13
+ async getRegistryToken(accessToken) {
14
+ const response = await fetch(`${BLOK_URL}/repository-token`, {
15
+ method: "GET",
16
+ headers: {
17
+ Authorization: `Bearer ${accessToken}`,
18
+ "Content-Type": "application/json",
19
+ },
20
+ });
21
+ const data = await response.json();
22
+ return data;
23
+ }
24
+ }
25
+ const registryManager = new RegistryManager();
26
+ export { registryManager };
@@ -0,0 +1,23 @@
1
+ export interface RuntimeInfo {
2
+ kind: string;
3
+ label: string;
4
+ available: boolean;
5
+ version?: string;
6
+ installHint: string;
7
+ defaultPort: number;
8
+ commands: string[];
9
+ toolchain: string;
10
+ installDeps: string;
11
+ startCmd: string;
12
+ sdkDir: string;
13
+ secondaryTool?: {
14
+ name: string;
15
+ command: string;
16
+ available?: boolean;
17
+ version?: string;
18
+ installHint: string;
19
+ };
20
+ }
21
+ export declare function detectRuntimes(): Promise<RuntimeInfo[]>;
22
+ export declare function getRuntimeDefinition(kind: string): Omit<RuntimeInfo, "available" | "version"> | undefined;
23
+ export declare function getAllRuntimeDefinitions(): Omit<RuntimeInfo, "available" | "version">[];
@@ -0,0 +1,181 @@
1
+ import child_process from "node:child_process";
2
+ import util from "node:util";
3
+ const exec = util.promisify(child_process.exec);
4
+ const RUNTIME_DEFINITIONS = [
5
+ {
6
+ kind: "python3",
7
+ label: "Python 3",
8
+ installHint: "Install Python: https://python.org/downloads/",
9
+ defaultPort: 9007,
10
+ commands: ["python3 --version"],
11
+ toolchain: "python3",
12
+ installDeps: "pip3 install -r requirements.txt",
13
+ startCmd: "python3 bin/serve.py",
14
+ sdkDir: "python3",
15
+ },
16
+ {
17
+ kind: "go",
18
+ label: "Go",
19
+ installHint: "Install Go: https://go.dev/dl/",
20
+ defaultPort: 9001,
21
+ commands: ["go version"],
22
+ toolchain: "go",
23
+ installDeps: "go mod download",
24
+ startCmd: "go run ./cmd/server",
25
+ sdkDir: "go",
26
+ },
27
+ {
28
+ kind: "rust",
29
+ label: "Rust",
30
+ installHint: "Install Rust: https://rustup.rs/",
31
+ defaultPort: 9002,
32
+ commands: ["rustc --version"],
33
+ toolchain: "rustc + cargo",
34
+ installDeps: "cargo build --release",
35
+ startCmd: "cargo run",
36
+ sdkDir: "rust",
37
+ },
38
+ {
39
+ kind: "java",
40
+ label: "Java",
41
+ installHint: "Install JDK 17+: https://adoptium.net/",
42
+ defaultPort: 9003,
43
+ commands: [
44
+ "java --version",
45
+ "/opt/homebrew/opt/openjdk/bin/java --version",
46
+ "/usr/libexec/java_home -v 17+ 2>/dev/null && java --version",
47
+ ],
48
+ toolchain: "java + mvn",
49
+ installDeps: "mvn package -q -DskipTests",
50
+ startCmd: "java -jar target/blok-java-1.0.0.jar",
51
+ sdkDir: "java",
52
+ secondaryTool: {
53
+ name: "Maven",
54
+ command: "mvn --version",
55
+ installHint: "Install Maven: https://maven.apache.org/install.html",
56
+ },
57
+ },
58
+ {
59
+ kind: "csharp",
60
+ label: "C# / .NET",
61
+ installHint: "Install .NET SDK: https://dotnet.microsoft.com/download",
62
+ defaultPort: 9004,
63
+ commands: ["dotnet --version"],
64
+ toolchain: "dotnet",
65
+ installDeps: "dotnet restore",
66
+ startCmd: "dotnet run --project src/Blok.Core",
67
+ sdkDir: "csharp",
68
+ },
69
+ {
70
+ kind: "php",
71
+ label: "PHP",
72
+ installHint: "Install PHP 8.2+: https://php.net/downloads",
73
+ defaultPort: 9005,
74
+ commands: ["php --version"],
75
+ toolchain: "php + composer",
76
+ installDeps: "composer install",
77
+ startCmd: "php bin/serve.php",
78
+ sdkDir: "php",
79
+ secondaryTool: {
80
+ name: "Composer",
81
+ command: "composer --version",
82
+ installHint: "Install Composer: https://getcomposer.org/download/",
83
+ },
84
+ },
85
+ {
86
+ kind: "ruby",
87
+ label: "Ruby",
88
+ installHint: "Install Ruby 3.2+: https://ruby-lang.org/en/downloads/",
89
+ defaultPort: 9006,
90
+ commands: ["ruby --version", "/opt/homebrew/opt/ruby/bin/ruby --version"],
91
+ toolchain: "ruby + bundler",
92
+ installDeps: "bundle install",
93
+ startCmd: "bundle exec rackup --host 0.0.0.0 config.ru",
94
+ sdkDir: "ruby",
95
+ secondaryTool: {
96
+ name: "Bundler",
97
+ command: "bundle --version",
98
+ installHint: "Install Bundler: gem install bundler",
99
+ },
100
+ },
101
+ ];
102
+ async function tryExec(command) {
103
+ try {
104
+ const { stdout } = await exec(command, { timeout: 5000 });
105
+ return stdout.trim();
106
+ }
107
+ catch {
108
+ return null;
109
+ }
110
+ }
111
+ function parseVersion(output, kind) {
112
+ switch (kind) {
113
+ case "go": {
114
+ const match = output.match(/go(\d+\.\d+(?:\.\d+)?)/);
115
+ return match ? match[1] : undefined;
116
+ }
117
+ case "rust": {
118
+ const match = output.match(/rustc\s+(\d+\.\d+\.\d+)/);
119
+ return match ? match[1] : undefined;
120
+ }
121
+ case "java": {
122
+ const match = output.match(/(?:openjdk|java)\s+(\d+[\d.]*)/);
123
+ return match ? match[1] : undefined;
124
+ }
125
+ case "csharp": {
126
+ const match = output.match(/(\d+\.\d+\.\d+)/);
127
+ return match ? match[1] : undefined;
128
+ }
129
+ case "php": {
130
+ const match = output.match(/PHP\s+(\d+\.\d+\.\d+)/);
131
+ return match ? match[1] : undefined;
132
+ }
133
+ case "ruby": {
134
+ const match = output.match(/ruby\s+(\d+\.\d+\.\d+)/);
135
+ return match ? match[1] : undefined;
136
+ }
137
+ case "python3": {
138
+ const match = output.match(/Python\s+(\d+\.\d+\.\d+)/);
139
+ return match ? match[1] : undefined;
140
+ }
141
+ default:
142
+ return undefined;
143
+ }
144
+ }
145
+ export async function detectRuntimes() {
146
+ const results = [];
147
+ for (const def of RUNTIME_DEFINITIONS) {
148
+ const info = {
149
+ ...def,
150
+ available: false,
151
+ version: undefined,
152
+ };
153
+ for (const cmd of def.commands) {
154
+ const output = await tryExec(cmd);
155
+ if (output) {
156
+ info.available = true;
157
+ info.version = parseVersion(output, def.kind);
158
+ break;
159
+ }
160
+ }
161
+ if (def.secondaryTool) {
162
+ const secondaryOutput = await tryExec(def.secondaryTool.command);
163
+ info.secondaryTool = {
164
+ ...def.secondaryTool,
165
+ available: secondaryOutput !== null,
166
+ version: secondaryOutput ?? undefined,
167
+ };
168
+ if (info.available && !info.secondaryTool.available) {
169
+ info.available = false;
170
+ }
171
+ }
172
+ results.push(info);
173
+ }
174
+ return results;
175
+ }
176
+ export function getRuntimeDefinition(kind) {
177
+ return RUNTIME_DEFINITIONS.find((r) => r.kind === kind);
178
+ }
179
+ export function getAllRuntimeDefinitions() {
180
+ return [...RUNTIME_DEFINITIONS];
181
+ }
@@ -0,0 +1,36 @@
1
+ import type { RuntimeInfo } from "./runtime-detector.js";
2
+ type SpinnerHandler = {
3
+ start: (msg?: string) => void;
4
+ stop: (msg?: string, code?: number) => void;
5
+ message: (msg?: string) => void;
6
+ };
7
+ export interface RuntimeConfig {
8
+ port: number;
9
+ startCmd: string;
10
+ cwd: string;
11
+ kind: string;
12
+ label: string;
13
+ }
14
+ export interface TriggerConfig {
15
+ kind: string;
16
+ label: string;
17
+ port: number;
18
+ entryPoint: string;
19
+ startCmd: string;
20
+ }
21
+ export interface ProjectConfig {
22
+ triggers?: Record<string, TriggerConfig>;
23
+ runtimes?: Record<string, RuntimeConfig>;
24
+ }
25
+ export type ProjectRuntimeConfig = ProjectConfig;
26
+ export declare function setupRuntime(runtime: RuntimeInfo, githubRepoLocal: string, projectDir: string, spinner: SpinnerHandler): Promise<RuntimeConfig>;
27
+ export declare function writeProjectConfig(projectDir: string, runtimeConfigs: RuntimeConfig[], triggerConfigs?: TriggerConfig[]): void;
28
+ export declare function readProjectConfig(projectDir: string): ProjectConfig | null;
29
+ export declare function generateRuntimeEnvVars(runtimeConfigs: RuntimeConfig[]): string;
30
+ export declare function generateSupervisordConfig(runtimeConfigs: RuntimeConfig[]): string;
31
+ export declare function getTriggerPort(triggerKind: string): number;
32
+ export declare function getTriggerLabel(triggerKind: string): string;
33
+ export declare function createTriggerConfig(triggerKind: string): TriggerConfig;
34
+ export declare function generateTriggerEnvVars(triggerConfigs: TriggerConfig[]): string;
35
+ export declare function generateTriggerSupervisordConfig(triggerConfigs: TriggerConfig[]): string;
36
+ export {};