blokctl 0.6.1 → 0.6.3
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/dist/commands/create/project.js +75 -67
- package/package.json +2 -2
|
@@ -17,7 +17,7 @@ const exec = util.promisify(child_process.exec);
|
|
|
17
17
|
const HOME_DIR = `${os.homedir()}/.blok`;
|
|
18
18
|
const GITHUB_REPO_LOCAL = `${HOME_DIR}/blok`;
|
|
19
19
|
const GITHUB_REPO_REMOTE = "https://github.com/well-prado/blok.git";
|
|
20
|
-
const GITHUB_REPO_RELEASE_TAG = "v0.6.
|
|
20
|
+
const GITHUB_REPO_RELEASE_TAG = "v0.6.3";
|
|
21
21
|
fsExtra.ensureDirSync(HOME_DIR);
|
|
22
22
|
const options = {
|
|
23
23
|
baseDir: HOME_DIR,
|
|
@@ -306,7 +306,8 @@ export async function createProject(opts, version, currentPath = false, localRep
|
|
|
306
306
|
const triggerDestDir = `${dirPath}/src/triggers/${triggerKind}`;
|
|
307
307
|
fsExtra.ensureDirSync(triggerDestDir);
|
|
308
308
|
if (triggerKind === "pubsub" || triggerKind === "queue") {
|
|
309
|
-
const
|
|
309
|
+
const templatePkgDir = triggerKind === "queue" ? "worker" : triggerKind;
|
|
310
|
+
const templateDir = `${repoSource}/triggers/${templatePkgDir}/template/src`;
|
|
310
311
|
if (fsExtra.existsSync(templateDir)) {
|
|
311
312
|
fsExtra.copySync(templateDir, triggerDestDir);
|
|
312
313
|
if (fsExtra.existsSync(`${templateDir}/workflows`)) {
|
|
@@ -325,20 +326,38 @@ export async function createProject(opts, version, currentPath = false, localRep
|
|
|
325
326
|
}
|
|
326
327
|
else {
|
|
327
328
|
const triggerSrcDir = `${repoSource}/triggers/${triggerKind}/src`;
|
|
328
|
-
if (
|
|
329
|
-
fsExtra.
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
329
|
+
if (triggerKind === "sse") {
|
|
330
|
+
const entries = fsExtra.readdirSync(triggerSrcDir, { withFileTypes: true });
|
|
331
|
+
for (const entry of entries) {
|
|
332
|
+
const src = `${triggerSrcDir}/${entry.name}`;
|
|
333
|
+
if (entry.isFile()) {
|
|
334
|
+
if (entry.name.endsWith(".test.ts") || entry.name.endsWith(".integration.test.ts")) {
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
fsExtra.copySync(src, `${triggerDestDir}/${entry.name}`);
|
|
338
|
+
}
|
|
339
|
+
else if (entry.isDirectory()) {
|
|
340
|
+
if (entry.name === "__tests__")
|
|
341
|
+
continue;
|
|
342
|
+
if (entry.name === "workflows") {
|
|
343
|
+
fsExtra.copySync(src, `${dirPath}/src/workflows/${triggerKind}`);
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
fsExtra.copySync(src, `${triggerDestDir}/${entry.name}`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
339
350
|
}
|
|
340
|
-
|
|
341
|
-
fsExtra.
|
|
351
|
+
else {
|
|
352
|
+
if (fsExtra.existsSync(`${triggerSrcDir}/runner`)) {
|
|
353
|
+
fsExtra.copySync(`${triggerSrcDir}/runner`, `${triggerDestDir}/runner`);
|
|
354
|
+
}
|
|
355
|
+
if (fsExtra.existsSync(`${triggerSrcDir}/AppRoutes.ts`)) {
|
|
356
|
+
fsExtra.copySync(`${triggerSrcDir}/AppRoutes.ts`, `${triggerDestDir}/AppRoutes.ts`);
|
|
357
|
+
}
|
|
358
|
+
if (fsExtra.existsSync(`${triggerSrcDir}/workflows`)) {
|
|
359
|
+
fsExtra.copySync(`${triggerSrcDir}/workflows`, `${dirPath}/src/workflows/${triggerKind}`);
|
|
360
|
+
}
|
|
342
361
|
}
|
|
343
362
|
}
|
|
344
363
|
}
|
|
@@ -415,9 +434,9 @@ export async function createProject(opts, version, currentPath = false, localRep
|
|
|
415
434
|
"@blokjs/runner": "core/runner",
|
|
416
435
|
"@blokjs/shared": "core/shared",
|
|
417
436
|
"@blokjs/trigger-pubsub": "triggers/pubsub",
|
|
418
|
-
"@blokjs/trigger-
|
|
437
|
+
"@blokjs/trigger-worker": "triggers/worker",
|
|
419
438
|
};
|
|
420
|
-
const BLOKJS_DEP_RANGE = "^0.6.
|
|
439
|
+
const BLOKJS_DEP_RANGE = "^0.6.3";
|
|
421
440
|
for (const depGroup of ["dependencies", "devDependencies", "peerDependencies"]) {
|
|
422
441
|
const deps = packageJsonContent[depGroup];
|
|
423
442
|
if (!deps)
|
|
@@ -484,12 +503,12 @@ export async function createProject(opts, version, currentPath = false, localRep
|
|
|
484
503
|
if (selectedTriggers.includes("pubsub")) {
|
|
485
504
|
triggerPackageDeps["@blokjs/trigger-pubsub"] = localRepoPath
|
|
486
505
|
? `file:${path.resolve(repoSource, "triggers/pubsub")}`
|
|
487
|
-
:
|
|
506
|
+
: BLOKJS_DEP_RANGE;
|
|
488
507
|
}
|
|
489
508
|
if (selectedTriggers.includes("queue")) {
|
|
490
|
-
triggerPackageDeps["@blokjs/trigger-
|
|
491
|
-
? `file:${path.resolve(repoSource, "triggers/
|
|
492
|
-
:
|
|
509
|
+
triggerPackageDeps["@blokjs/trigger-worker"] = localRepoPath
|
|
510
|
+
? `file:${path.resolve(repoSource, "triggers/worker")}`
|
|
511
|
+
: BLOKJS_DEP_RANGE;
|
|
493
512
|
}
|
|
494
513
|
if (Object.keys(triggerPackageDeps).length > 0) {
|
|
495
514
|
packageJsonContent.dependencies = {
|
|
@@ -611,12 +630,6 @@ function generateSharedNodesFile(triggers, _repoSource) {
|
|
|
611
630
|
nodeImports.add('import type { BlokService } from "@blokjs/runner";');
|
|
612
631
|
nodeExports.set("@blokjs/api-call", "ApiCall");
|
|
613
632
|
nodeExports.set("@blokjs/if-else", "IfElse");
|
|
614
|
-
for (const trigger of triggers) {
|
|
615
|
-
if (trigger === "sse") {
|
|
616
|
-
nodeImports.add('import WelcomeMessage from "./nodes/welcome-message/index";');
|
|
617
|
-
nodeExports.set("welcome-message", "WelcomeMessage");
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
633
|
const importLines = Array.from(nodeImports).join("\n");
|
|
621
634
|
const exportEntries = Array.from(nodeExports.entries())
|
|
622
635
|
.map(([key, value]) => `\t"${key}": ${value},`)
|
|
@@ -635,21 +648,18 @@ function generateSharedWorkflowsFile(triggers) {
|
|
|
635
648
|
const workflowEntries = [];
|
|
636
649
|
for (const trigger of triggers) {
|
|
637
650
|
if (trigger === "http") {
|
|
638
|
-
imports.push("//
|
|
651
|
+
imports.push("// HTTP workflows are auto-discovered from workflows/json/");
|
|
639
652
|
}
|
|
640
653
|
else if (trigger === "sse") {
|
|
641
|
-
imports.push(
|
|
642
|
-
imports.push('import OnSubscribe from "./workflows/sse/notifications/on-subscribe";');
|
|
643
|
-
workflowEntries.push('\t"on-connect": OnConnect,');
|
|
644
|
-
workflowEntries.push('\t"on-subscribe": OnSubscribe,');
|
|
654
|
+
imports.push("// SSE workflows: register in this Workflows record manually");
|
|
645
655
|
}
|
|
646
656
|
else if (trigger === "pubsub") {
|
|
647
657
|
imports.push('import OnPubSubMessage from "./workflows/pubsub/messages/on-message";');
|
|
648
658
|
workflowEntries.push('\t"on-pubsub-message": OnPubSubMessage,');
|
|
649
659
|
}
|
|
650
660
|
else if (trigger === "queue") {
|
|
651
|
-
imports.push('import
|
|
652
|
-
workflowEntries.push('\t"
|
|
661
|
+
imports.push('import ProcessJob from "./workflows/queue/jobs/process-job";');
|
|
662
|
+
workflowEntries.push('\t"process-job": ProcessJob,');
|
|
653
663
|
}
|
|
654
664
|
}
|
|
655
665
|
const importSection = imports.length > 0 ? `${imports.join("\n")}\n` : "";
|
|
@@ -716,10 +726,10 @@ if (process.env.DISABLE_TRIGGER_RUN !== "true") {
|
|
|
716
726
|
if (triggerKind === "sse") {
|
|
717
727
|
return `import { DefaultLogger } from "@blokjs/runner";
|
|
718
728
|
import { type Span, metrics, trace } from "@opentelemetry/api";
|
|
719
|
-
import
|
|
729
|
+
import SSETrigger from "./SSETrigger";
|
|
720
730
|
|
|
721
731
|
export default class App {
|
|
722
|
-
private
|
|
732
|
+
private sseTrigger: SSETrigger = <SSETrigger>{};
|
|
723
733
|
protected trigger_initializer = 0;
|
|
724
734
|
protected initializer = 0;
|
|
725
735
|
protected tracer = trace.getTracer(
|
|
@@ -733,12 +743,12 @@ export default class App {
|
|
|
733
743
|
|
|
734
744
|
constructor() {
|
|
735
745
|
this.initializer = performance.now();
|
|
736
|
-
this.
|
|
746
|
+
this.sseTrigger = new SSETrigger();
|
|
737
747
|
}
|
|
738
748
|
|
|
739
749
|
async run() {
|
|
740
750
|
this.tracer.startActiveSpan("initialization", async (span: Span) => {
|
|
741
|
-
await this.
|
|
751
|
+
await this.sseTrigger.listen();
|
|
742
752
|
this.initializer = performance.now() - this.initializer;
|
|
743
753
|
|
|
744
754
|
this.logger.log(\`Server initialized in \${(this.initializer).toFixed(2)}ms\`);
|
|
@@ -750,13 +760,9 @@ export default class App {
|
|
|
750
760
|
span.end();
|
|
751
761
|
});
|
|
752
762
|
}
|
|
753
|
-
|
|
754
|
-
getApp() {
|
|
755
|
-
return this.sseServer.getApp();
|
|
756
|
-
}
|
|
757
763
|
}
|
|
758
764
|
|
|
759
|
-
{
|
|
765
|
+
if (process.env.DISABLE_TRIGGER_RUN !== "true") {
|
|
760
766
|
new App().run();
|
|
761
767
|
}
|
|
762
768
|
`;
|
|
@@ -808,10 +814,10 @@ if (process.env.DISABLE_TRIGGER_RUN !== "true") {
|
|
|
808
814
|
if (triggerKind === "queue") {
|
|
809
815
|
return `import { DefaultLogger } from "@blokjs/runner";
|
|
810
816
|
import { type Span, metrics, trace } from "@opentelemetry/api";
|
|
811
|
-
import
|
|
817
|
+
import WorkerServer from "./runner/WorkerServer";
|
|
812
818
|
|
|
813
819
|
export default class App {
|
|
814
|
-
private
|
|
820
|
+
private workerServer: WorkerServer = <WorkerServer>{};
|
|
815
821
|
protected trigger_initializer = 0;
|
|
816
822
|
protected initializer = 0;
|
|
817
823
|
protected tracer = trace.getTracer(
|
|
@@ -825,12 +831,12 @@ export default class App {
|
|
|
825
831
|
|
|
826
832
|
constructor() {
|
|
827
833
|
this.initializer = performance.now();
|
|
828
|
-
this.
|
|
834
|
+
this.workerServer = new WorkerServer();
|
|
829
835
|
}
|
|
830
836
|
|
|
831
837
|
async run() {
|
|
832
838
|
this.tracer.startActiveSpan("initialization", async (span: Span) => {
|
|
833
|
-
await this.
|
|
839
|
+
await this.workerServer.listen();
|
|
834
840
|
this.initializer = performance.now() - this.initializer;
|
|
835
841
|
|
|
836
842
|
this.logger.log(\`Queue trigger initialized in \${(this.initializer).toFixed(2)}ms\`);
|
|
@@ -873,26 +879,26 @@ function replaceBlokImportsInDirectory(dirPath) {
|
|
|
873
879
|
}
|
|
874
880
|
}
|
|
875
881
|
function fixRunnerImportPaths(triggerDestDir, triggerKind) {
|
|
876
|
-
const
|
|
882
|
+
const fileFixes = [];
|
|
877
883
|
if (triggerKind === "http") {
|
|
878
|
-
|
|
884
|
+
fileFixes.push({ file: `${triggerDestDir}/runner/HttpTrigger.ts`, up: "../../../" });
|
|
879
885
|
}
|
|
880
886
|
else if (triggerKind === "sse") {
|
|
881
|
-
|
|
887
|
+
fileFixes.push({ file: `${triggerDestDir}/SSETrigger.ts`, up: "../../" });
|
|
882
888
|
}
|
|
883
889
|
else if (triggerKind === "pubsub") {
|
|
884
|
-
|
|
890
|
+
fileFixes.push({ file: `${triggerDestDir}/runner/PubSubServer.ts`, up: "../../../" });
|
|
885
891
|
}
|
|
886
892
|
else if (triggerKind === "queue") {
|
|
887
|
-
|
|
893
|
+
fileFixes.push({ file: `${triggerDestDir}/runner/WorkerServer.ts`, up: "../../../" });
|
|
888
894
|
}
|
|
889
|
-
for (const
|
|
890
|
-
if (!fsExtra.existsSync(
|
|
895
|
+
for (const { file, up } of fileFixes) {
|
|
896
|
+
if (!fsExtra.existsSync(file))
|
|
891
897
|
continue;
|
|
892
|
-
let content = fsExtra.readFileSync(
|
|
893
|
-
content = content.replace(/from ["']\.\.\/Nodes["']/g,
|
|
894
|
-
content = content.replace(/from ["']\.\.\/Workflows["']/g,
|
|
895
|
-
fsExtra.writeFileSync(
|
|
898
|
+
let content = fsExtra.readFileSync(file, "utf8");
|
|
899
|
+
content = content.replace(/from ["']\.\.\/Nodes["']/g, `from "${up}Nodes"`);
|
|
900
|
+
content = content.replace(/from ["']\.\.\/Workflows["']/g, `from "${up}Workflows"`);
|
|
901
|
+
fsExtra.writeFileSync(file, content);
|
|
896
902
|
}
|
|
897
903
|
}
|
|
898
904
|
function updatePubSubProvider(triggerDestDir, provider) {
|
|
@@ -928,7 +934,7 @@ function updatePubSubProvider(triggerDestDir, provider) {
|
|
|
928
934
|
fsExtra.writeFileSync(serverPath, content);
|
|
929
935
|
}
|
|
930
936
|
function updateQueueProvider(triggerDestDir, provider) {
|
|
931
|
-
const serverPath = `${triggerDestDir}/runner/
|
|
937
|
+
const serverPath = `${triggerDestDir}/runner/WorkerServer.ts`;
|
|
932
938
|
if (!fsExtra.existsSync(serverPath))
|
|
933
939
|
return;
|
|
934
940
|
let content = fsExtra.readFileSync(serverPath, "utf8");
|
|
@@ -953,15 +959,17 @@ function updateQueueProvider(triggerDestDir, provider) {
|
|
|
953
959
|
})`,
|
|
954
960
|
},
|
|
955
961
|
redis: {
|
|
956
|
-
importName: "
|
|
957
|
-
init: `new
|
|
958
|
-
|
|
959
|
-
|
|
962
|
+
importName: "BullMQAdapter",
|
|
963
|
+
init: `new BullMQAdapter({
|
|
964
|
+
connection: {
|
|
965
|
+
host: process.env.REDIS_HOST || "localhost",
|
|
966
|
+
port: Number(process.env.REDIS_PORT) || 6379,
|
|
967
|
+
},
|
|
960
968
|
})`,
|
|
961
969
|
},
|
|
962
970
|
nats: {
|
|
963
|
-
importName: "
|
|
964
|
-
init: `new
|
|
971
|
+
importName: "NATSWorkerAdapter",
|
|
972
|
+
init: `new NATSWorkerAdapter({
|
|
965
973
|
servers: (process.env.NATS_SERVERS || "localhost:4222").split(","),
|
|
966
974
|
})`,
|
|
967
975
|
},
|
|
@@ -969,8 +977,8 @@ function updateQueueProvider(triggerDestDir, provider) {
|
|
|
969
977
|
const config = adapterConfigs[provider];
|
|
970
978
|
if (!config)
|
|
971
979
|
return;
|
|
972
|
-
content = content.replace(/import \{ (\w+), (\w+) \} from ["']@blokjs\/trigger-
|
|
973
|
-
content = content.replace(/(export default class \w+ extends
|
|
980
|
+
content = content.replace(/import \{ (\w+), (\w+) \} from ["']@blokjs\/trigger-worker["'];/, `import { ${config.importName}, WorkerTrigger } from "@blokjs/trigger-worker";`);
|
|
981
|
+
content = content.replace(/(export default class \w+ extends WorkerTrigger \{[\s\S]*?)\n\tprotected adapter = new \w+\(\{[\s\S]*?\}\);/, `$1\n\tprotected adapter = ${config.init};`);
|
|
974
982
|
fsExtra.writeFileSync(serverPath, content);
|
|
975
983
|
const workflowPath = `${triggerDestDir}/workflows/messages/on-message.ts`;
|
|
976
984
|
if (fsExtra.existsSync(workflowPath)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "blokctl",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"author": "Deskree Technologies Inc.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"description": "cli for blok",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"keywords": ["blokctl", "cli", "blok", "blok"],
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@ai-sdk/openai": "^1.3.22",
|
|
33
|
-
"@blokjs/runner": "^0.6.
|
|
33
|
+
"@blokjs/runner": "^0.6.3",
|
|
34
34
|
"@clack/prompts": "^1.0.0",
|
|
35
35
|
"ai": "^4.3.16",
|
|
36
36
|
"better-sqlite3": "^12.6.2",
|