Skip to content

Commit

Permalink
refactor: update script execution and logging process 🔧
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Dec 9, 2024
1 parent fcee692 commit 1f68108
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
3 changes: 1 addition & 2 deletions packages/cli/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { GenerationResult } from "../../core/src/generation"
import { PromptScriptRunOptions } from "../../core/src/server/messages"
import { Worker } from "node:worker_threads"
import { logVerbose } from "../../core/src/util"

/**
* Runs a GenAIScript script with the given files and options.
Expand All @@ -28,7 +27,7 @@ export async function runScript(
}
const worker = new Worker(__filename, { workerData, name: label })
return new Promise((resolve, reject) => {
worker.on("online", () => logVerbose(`worker: online`))
worker.on("online", () => process.stderr.write(`worker: online\n`))
worker.on("message", resolve)
worker.on("error", reject)
})
Expand Down
24 changes: 13 additions & 11 deletions packages/cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import { runScript } from "./api"

export { runScript }

// Initialize global settings or variables for the application
// This might include setting up global error handlers or configurations
installGlobals()

if (workerData) {
// Executes a worker
worker()
} else {
// Execute the command-line interface logic
// This function likely handles parsing input arguments and executing commands
cli()
// if this file is not the entry point, skip cli
if (require.main === module) {
// Initialize global settings or variables for the application
// This might include setting up global error handlers or configurations
installGlobals()
if (workerData) {
// Executes a worker
worker()
} else {
// Execute the command-line interface logic
// This function likely handles parsing input arguments and executing commands
cli()
}
}
3 changes: 2 additions & 1 deletion packages/sample/src/api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ console.log(`loading cli`)
const cli = await import("../../cli/built/genaiscript.cjs")

console.log(cli)
const res = cli.runScript("poem")
const res = await cli.runScript("poem")

console.log(res)

0 comments on commit 1f68108

Please sign in to comment.