@openworkflow/cli 0.4.0 → 0.4.2
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/cli.js +5 -0
- package/dist/commands.d.ts +18 -7
- package/dist/commands.d.ts.map +1 -1
- package/dist/commands.js +37 -21
- package/dist/config.d.ts +7 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +40 -13
- package/dist/templates.d.ts +1 -1
- package/dist/templates.d.ts.map +1 -1
- package/dist/templates.js +5 -1
- package/package.json +7 -6
package/dist/cli.js
CHANGED
|
@@ -8,16 +8,19 @@ const program = new Command();
|
|
|
8
8
|
program
|
|
9
9
|
.name("openworkflow")
|
|
10
10
|
.description("OpenWorkflow CLI - learn more at https://openworkflow.dev")
|
|
11
|
+
.usage("<command> [options]")
|
|
11
12
|
.version(getVersion());
|
|
12
13
|
// init
|
|
13
14
|
program
|
|
14
15
|
.command("init")
|
|
15
16
|
.description("initialize OpenWorkflow")
|
|
17
|
+
.option("--config <path>", "path to OpenWorkflow config file")
|
|
16
18
|
.action(withErrorHandling(init));
|
|
17
19
|
// doctor
|
|
18
20
|
program
|
|
19
21
|
.command("doctor")
|
|
20
22
|
.description("check configuration and list available workflows")
|
|
23
|
+
.option("--config <path>", "path to OpenWorkflow config file")
|
|
21
24
|
.action(withErrorHandling(doctor));
|
|
22
25
|
// worker
|
|
23
26
|
const workerCmd = program.command("worker").description("manage workers");
|
|
@@ -26,10 +29,12 @@ workerCmd
|
|
|
26
29
|
.command("start")
|
|
27
30
|
.description("start a worker to process workflows")
|
|
28
31
|
.option("-c, --concurrency <number>", "number of concurrent workflows to process", Number.parseInt)
|
|
32
|
+
.option("--config <path>", "path to OpenWorkflow config file")
|
|
29
33
|
.action(withErrorHandling(workerStart));
|
|
30
34
|
// dashboard
|
|
31
35
|
program
|
|
32
36
|
.command("dashboard")
|
|
33
37
|
.description("start the dashboard to view workflow runs")
|
|
38
|
+
.option("--config <path>", "path to OpenWorkflow config file")
|
|
34
39
|
.action(withErrorHandling(dashboard));
|
|
35
40
|
await program.parseAsync(process.argv);
|
package/dist/commands.d.ts
CHANGED
|
@@ -1,23 +1,34 @@
|
|
|
1
1
|
import { WorkerConfig } from "./config.js";
|
|
2
|
+
interface CommandOptions {
|
|
3
|
+
config?: string;
|
|
4
|
+
}
|
|
2
5
|
/**
|
|
3
6
|
* openworkflow -V | --version
|
|
4
7
|
* @returns the version string, or "-" if it cannot be determined
|
|
5
8
|
*/
|
|
6
9
|
export declare function getVersion(): string;
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* openworkflow init
|
|
12
|
+
* @param options - Command options
|
|
13
|
+
*/
|
|
14
|
+
export declare function init(options?: CommandOptions): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* openworkflow doctor
|
|
17
|
+
* @param options - Command options
|
|
18
|
+
*/
|
|
19
|
+
export declare function doctor(options?: CommandOptions): Promise<void>;
|
|
20
|
+
export type WorkerStartOptions = WorkerConfig & CommandOptions;
|
|
11
21
|
/**
|
|
12
22
|
* openworkflow worker start
|
|
13
|
-
* @param
|
|
23
|
+
* @param options - Worker config and command options
|
|
14
24
|
*/
|
|
15
|
-
export declare function workerStart(
|
|
25
|
+
export declare function workerStart(options?: WorkerStartOptions): Promise<void>;
|
|
16
26
|
/**
|
|
17
27
|
* openworkflow dashboard
|
|
18
28
|
* Starts the dashboard by delegating to `@openworkflow/dashboard` via npx.
|
|
29
|
+
* @param options - Command options
|
|
19
30
|
*/
|
|
20
|
-
export declare function dashboard(): Promise<void>;
|
|
31
|
+
export declare function dashboard(options?: CommandOptions): Promise<void>;
|
|
21
32
|
/**
|
|
22
33
|
* Discover workflow files from directories. Recursively scans directories for
|
|
23
34
|
* workflow files with supported extensions (.ts, .js, .mjs, .cjs).
|
package/dist/commands.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAkC,MAAM,aAAa,CAAC;AAiC3E,UAAU,cAAc;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAoBnC;AAED;;;GAGG;AACH,wBAAsB,IAAI,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAoItE;AAED;;;GAGG;AACH,wBAAsB,MAAM,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmDxE;AAED,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,cAAc,CAAC;AAE/D;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAuEf;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2D3E;AAwOD;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE,MAAM,EACf,cAAc,GAAE,MAAM,EAAO,GAC5B,MAAM,EAAE,CA4CV;AAiWD,UAAU,oBAAoB;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C;AAsBD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,QAAQ,CAAC,oBAAoB,CAAC,GAAG,IAAI,GACjD,MAAM,CAMR;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,WAAW,EAAE,QAAQ,CAAC,oBAAoB,CAAC,GAAG,IAAI,GACjD,MAAM,CAKR;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,WAAW,EAAE,QAAQ,CAAC,oBAAoB,CAAC,GAAG,IAAI,GACjD,MAAM,CAKR;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,QAAQ,CAAC,oBAAoB,CAAC,GAAG,IAAI,GACjD,MAAM,CAKR"}
|
package/dist/commands.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { loadConfig } from "./config.js";
|
|
1
|
+
import { loadConfig, loadConfigFromPath } from "./config.js";
|
|
2
2
|
import { CLIError } from "./errors.js";
|
|
3
3
|
import { CONFIG, HELLO_WORLD_RUNNER, HELLO_WORLD_WORKFLOW, POSTGRES_CLIENT, POSTGRES_PROD_SQLITE_DEV_CLIENT, SQLITE_CLIENT, } from "./templates.js";
|
|
4
4
|
import * as p from "@clack/prompts";
|
|
@@ -36,10 +36,14 @@ export function getVersion() {
|
|
|
36
36
|
}
|
|
37
37
|
return "-";
|
|
38
38
|
}
|
|
39
|
-
/**
|
|
40
|
-
|
|
39
|
+
/**
|
|
40
|
+
* openworkflow init
|
|
41
|
+
* @param options - Command options
|
|
42
|
+
*/
|
|
43
|
+
export async function init(options = {}) {
|
|
44
|
+
const configPath = options.config;
|
|
41
45
|
p.intro("Initializing OpenWorkflow...");
|
|
42
|
-
const { configFile } = await loadConfigWithEnv();
|
|
46
|
+
const { configFile } = await loadConfigWithEnv(configPath);
|
|
43
47
|
let configFileToDelete = null;
|
|
44
48
|
if (configFile) {
|
|
45
49
|
const shouldOverride = await p.confirm({
|
|
@@ -89,7 +93,7 @@ export async function init() {
|
|
|
89
93
|
if (!packageJson) {
|
|
90
94
|
throw new CLIError("No package.json found.", "Please create a package.json file first by running `npm init` or `npm init -y`.");
|
|
91
95
|
}
|
|
92
|
-
const configFileName = getConfigFileName(packageJson);
|
|
96
|
+
const configFileName = configPath ?? getConfigFileName(packageJson);
|
|
93
97
|
const clientFileName = getClientFileName(packageJson);
|
|
94
98
|
const exampleWorkflowFileName = getExampleWorkflowFileName(packageJson);
|
|
95
99
|
const runFileName = getRunFileName(packageJson);
|
|
@@ -141,10 +145,14 @@ export async function init() {
|
|
|
141
145
|
p.note(`➡️ Start a worker:\n$ npx @openworkflow/cli worker start\n\n➡️ Run the example workflow:\n$ ${runCommand}\n\n➡️ View the dashboard:\n$ npx @openworkflow/cli dashboard`, "Next steps");
|
|
142
146
|
p.outro("✅ Setup complete!");
|
|
143
147
|
}
|
|
144
|
-
/**
|
|
145
|
-
|
|
148
|
+
/**
|
|
149
|
+
* openworkflow doctor
|
|
150
|
+
* @param options - Command options
|
|
151
|
+
*/
|
|
152
|
+
export async function doctor(options = {}) {
|
|
153
|
+
const configPath = options.config;
|
|
146
154
|
consola.start("Running OpenWorkflow doctor...");
|
|
147
|
-
const { config, configFile } = await loadConfigWithEnv();
|
|
155
|
+
const { config, configFile } = await loadConfigWithEnv(configPath);
|
|
148
156
|
if (!configFile) {
|
|
149
157
|
throw new CLIError("No config file found.", "Run `npx @openworkflow/cli init` to create a config file.");
|
|
150
158
|
}
|
|
@@ -181,11 +189,12 @@ export async function doctor() {
|
|
|
181
189
|
}
|
|
182
190
|
/**
|
|
183
191
|
* openworkflow worker start
|
|
184
|
-
* @param
|
|
192
|
+
* @param options - Worker config and command options
|
|
185
193
|
*/
|
|
186
|
-
export async function workerStart(
|
|
194
|
+
export async function workerStart(options = {}) {
|
|
195
|
+
const { config: configPath, ...workerConfig } = options;
|
|
187
196
|
consola.start("Starting worker...");
|
|
188
|
-
const { config, configFile } = await loadConfigWithEnv();
|
|
197
|
+
const { config, configFile } = await loadConfigWithEnv(configPath);
|
|
189
198
|
if (!configFile) {
|
|
190
199
|
throw new CLIError("No config file found.", "Run `npx @openworkflow/cli init` to create a config file.");
|
|
191
200
|
}
|
|
@@ -216,7 +225,7 @@ export async function workerStart(cliOptions) {
|
|
|
216
225
|
consola.info(`Found ${String(files.length)} workflow file(s)`);
|
|
217
226
|
consola.success(`Loaded ${String(workflows.length)} workflow(s): ${workflows.map((w) => w.spec.name).join(", ")}`);
|
|
218
227
|
assertNoDuplicateWorkflows(workflows);
|
|
219
|
-
const workerOptions = mergeDefinedOptions(config.worker,
|
|
228
|
+
const workerOptions = mergeDefinedOptions(config.worker, workerConfig);
|
|
220
229
|
if (workerOptions.concurrency !== undefined) {
|
|
221
230
|
assertPositiveInteger("concurrency", workerOptions.concurrency);
|
|
222
231
|
}
|
|
@@ -238,10 +247,12 @@ export async function workerStart(cliOptions) {
|
|
|
238
247
|
/**
|
|
239
248
|
* openworkflow dashboard
|
|
240
249
|
* Starts the dashboard by delegating to `@openworkflow/dashboard` via npx.
|
|
250
|
+
* @param options - Command options
|
|
241
251
|
*/
|
|
242
|
-
export async function dashboard() {
|
|
252
|
+
export async function dashboard(options = {}) {
|
|
253
|
+
const configPath = options.config;
|
|
243
254
|
consola.start("Starting dashboard...");
|
|
244
|
-
const { configFile } = await loadConfigWithEnv();
|
|
255
|
+
const { configFile } = await loadConfigWithEnv(configPath);
|
|
245
256
|
if (!configFile) {
|
|
246
257
|
throw new CLIError("No config file found.", "Run `npx @openworkflow/cli init` to create a config file before starting the dashboard.");
|
|
247
258
|
}
|
|
@@ -596,7 +607,9 @@ function getDevDependenciesToInstall() {
|
|
|
596
607
|
function createConfigFile(configFileName) {
|
|
597
608
|
const spinner = p.spinner();
|
|
598
609
|
spinner.start("Writing config...");
|
|
599
|
-
const configDestPath = path.
|
|
610
|
+
const configDestPath = path.resolve(process.cwd(), configFileName);
|
|
611
|
+
// mkdir if the user specified a config file, and they want it in a dir
|
|
612
|
+
mkdirSync(path.dirname(configDestPath), { recursive: true });
|
|
600
613
|
writeFileSync(configDestPath, CONFIG, "utf8");
|
|
601
614
|
spinner.stop(`Config written to ${configDestPath}`);
|
|
602
615
|
}
|
|
@@ -673,10 +686,10 @@ function updateGitignoreForSqlite() {
|
|
|
673
686
|
const gitignorePath = path.join(process.cwd(), ".gitignore");
|
|
674
687
|
const spinner = p.spinner();
|
|
675
688
|
spinner.start("Updating .gitignore...");
|
|
676
|
-
const result = ensureGitignoreEntry(gitignorePath, "openworkflow/backend.db");
|
|
689
|
+
const result = ensureGitignoreEntry(gitignorePath, "openworkflow/backend.db*");
|
|
677
690
|
spinner.stop(result.added
|
|
678
|
-
? "Added openworkflow/backend.db to .gitignore"
|
|
679
|
-
: "openworkflow/backend.db already in .gitignore");
|
|
691
|
+
? "Added openworkflow/backend.db* to .gitignore"
|
|
692
|
+
: "openworkflow/backend.db* already in .gitignore");
|
|
680
693
|
}
|
|
681
694
|
/**
|
|
682
695
|
* Add worker script to package.json.
|
|
@@ -704,7 +717,7 @@ function addWorkerScriptToPackageJson() {
|
|
|
704
717
|
* Ensure a specific entry exists in a .gitignore file. Creates the file if it
|
|
705
718
|
* doesn't exist, appends the entry if not present.
|
|
706
719
|
* @param gitignorePath - Path to the .gitignore file
|
|
707
|
-
* @param entry - The entry to add (e.g. "openworkflow/backend.db")
|
|
720
|
+
* @param entry - The entry to add (e.g. "openworkflow/backend.db*")
|
|
708
721
|
* @returns Object indicating whether the entry was added or already existed
|
|
709
722
|
*/
|
|
710
723
|
function ensureGitignoreEntry(gitignorePath, entry) {
|
|
@@ -747,12 +760,15 @@ function updateEnvForPostgres() {
|
|
|
747
760
|
}
|
|
748
761
|
/**
|
|
749
762
|
* Load CLI config after loading .env, and wrap errors for user-facing output.
|
|
763
|
+
* @param configPath - Optional explicit config file path
|
|
750
764
|
* @returns Loaded config and metadata.
|
|
751
765
|
*/
|
|
752
|
-
async function loadConfigWithEnv() {
|
|
766
|
+
async function loadConfigWithEnv(configPath) {
|
|
753
767
|
loadDotenv({ quiet: true });
|
|
754
768
|
try {
|
|
755
|
-
return
|
|
769
|
+
return configPath
|
|
770
|
+
? await loadConfigFromPath(configPath)
|
|
771
|
+
: await loadConfig();
|
|
756
772
|
}
|
|
757
773
|
catch (error) {
|
|
758
774
|
const message = error instanceof Error ? error.message : String(error);
|
package/dist/config.d.ts
CHANGED
|
@@ -30,6 +30,13 @@ interface LoadedConfig {
|
|
|
30
30
|
config: OpenWorkflowConfig;
|
|
31
31
|
configFile: string | undefined;
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Load OpenWorkflow config from an explicit path.
|
|
35
|
+
* @param configPath - Explicit config file path
|
|
36
|
+
* @param startDir - Optional base directory for resolving relative paths
|
|
37
|
+
* @returns The loaded configuration and metadata
|
|
38
|
+
*/
|
|
39
|
+
export declare function loadConfigFromPath(configPath: string, startDir?: string): Promise<LoadedConfig>;
|
|
33
40
|
/**
|
|
34
41
|
* Load the OpenWorkflow config at openworkflow.config.{ts,mts,cts,js,mjs,cjs}.
|
|
35
42
|
* Searches up the directory tree from the starting directory to find the
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;AAE9D;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,kBAAkB,CAE3E;AAED,UAAU,YAAY;IACpB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC;AAMD;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;AAE9D;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,kBAAkB,CAE3E;AAED,UAAU,YAAY;IACpB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC;AAMD;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,YAAY,CAAC,CAKvB;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAyBzE"}
|
package/dist/config.js
CHANGED
|
@@ -13,6 +13,18 @@ export function defineConfig(config) {
|
|
|
13
13
|
const CONFIG_NAME = "openworkflow.config";
|
|
14
14
|
const CONFIG_EXTENSIONS = ["ts", "mts", "cts", "js", "mjs", "cjs"];
|
|
15
15
|
const jiti = createJiti(import.meta.url);
|
|
16
|
+
/**
|
|
17
|
+
* Load OpenWorkflow config from an explicit path.
|
|
18
|
+
* @param configPath - Explicit config file path
|
|
19
|
+
* @param startDir - Optional base directory for resolving relative paths
|
|
20
|
+
* @returns The loaded configuration and metadata
|
|
21
|
+
*/
|
|
22
|
+
export async function loadConfigFromPath(configPath, startDir) {
|
|
23
|
+
const filePath = path.resolve(startDir ?? process.cwd(), configPath);
|
|
24
|
+
return existsSync(filePath)
|
|
25
|
+
? importConfigFile(filePath)
|
|
26
|
+
: getEmptyLoadedConfig();
|
|
27
|
+
}
|
|
16
28
|
/**
|
|
17
29
|
* Load the OpenWorkflow config at openworkflow.config.{ts,mts,cts,js,mjs,cjs}.
|
|
18
30
|
* Searches up the directory tree from the starting directory to find the
|
|
@@ -30,19 +42,7 @@ export async function loadConfig(startDir) {
|
|
|
30
42
|
const fileName = `${CONFIG_NAME}.${ext}`;
|
|
31
43
|
const filePath = path.join(currentDir, fileName);
|
|
32
44
|
if (existsSync(filePath)) {
|
|
33
|
-
|
|
34
|
-
const fileUrl = pathToFileURL(filePath).href;
|
|
35
|
-
const config = await jiti.import(fileUrl, {
|
|
36
|
-
default: true,
|
|
37
|
-
});
|
|
38
|
-
return {
|
|
39
|
-
config,
|
|
40
|
-
configFile: filePath,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
throw new Error(`Failed to load config file ${filePath}: ${String(error)}`);
|
|
45
|
-
}
|
|
45
|
+
return await importConfigFile(filePath);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
const parentDir = path.dirname(currentDir);
|
|
@@ -52,6 +52,33 @@ export async function loadConfig(startDir) {
|
|
|
52
52
|
}
|
|
53
53
|
currentDir = parentDir;
|
|
54
54
|
}
|
|
55
|
+
return getEmptyLoadedConfig();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Import a config file and wrap load errors with a stable message.
|
|
59
|
+
* @param filePath - Absolute config file path.
|
|
60
|
+
* @returns Loaded config metadata.
|
|
61
|
+
*/
|
|
62
|
+
async function importConfigFile(filePath) {
|
|
63
|
+
try {
|
|
64
|
+
const fileUrl = pathToFileURL(filePath).href;
|
|
65
|
+
const config = await jiti.import(fileUrl, {
|
|
66
|
+
default: true,
|
|
67
|
+
});
|
|
68
|
+
return {
|
|
69
|
+
config,
|
|
70
|
+
configFile: filePath,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
throw new Error(`Failed to load config file ${filePath}: ${String(error)}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Return an empty config result when no config file is found.
|
|
79
|
+
* @returns Empty config metadata.
|
|
80
|
+
*/
|
|
81
|
+
function getEmptyLoadedConfig() {
|
|
55
82
|
return {
|
|
56
83
|
// not great, but meant to match the c12 api since that is what was used in
|
|
57
84
|
// the initial implementation of loadConfig
|
package/dist/templates.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export declare const POSTGRES_CLIENT = "import { BackendPostgres } from \"openwo
|
|
|
3
3
|
export declare const POSTGRES_PROD_SQLITE_DEV_CLIENT = "import { BackendPostgres } from \"openworkflow/postgres\";\nimport { BackendSqlite } from \"openworkflow/sqlite\";\nimport { OpenWorkflow } from \"openworkflow\";\n\nexport const backend =\n process.env[\"NODE_ENV\"] === \"production\"\n ? await BackendPostgres.connect(process.env[\"OPENWORKFLOW_POSTGRES_URL\"])\n : BackendSqlite.connect(\"openworkflow/backend.db\");\nexport const ow = new OpenWorkflow({ backend });\n";
|
|
4
4
|
export declare const CONFIG = "import { backend } from \"./openworkflow/client.js\";\nimport { defineConfig } from \"@openworkflow/cli\";\n\nexport default defineConfig({\n backend,\n dirs: \"./openworkflow\",\n ignorePatterns: [\"**/*.run.*\"],\n});\n";
|
|
5
5
|
export declare const HELLO_WORLD_WORKFLOW = "import { defineWorkflow } from \"openworkflow\";\n\n/**\n * Example workflow that greets the world.\n *\n * This workflow is auto-discovered by the CLI worker.\n * To trigger it, use ow.runWorkflow() from your app:\n * ```ts\n * import { ow } from \"./openworkflow/client.js\";\n * import { helloWorld } from \"./openworkflow/hello-world.js\";\n * const handle = await ow.runWorkflow(helloWorld.spec, {});\n * const result = await handle.result();\n * ```\n */\nexport const helloWorld = defineWorkflow(\n { name: \"hello-world\" },\n async ({ step }) => {\n const greeting = await step.run({ name: \"greet\" }, () => {\n return \"Hello, World!\";\n });\n\n await step.sleep(\"wait-a-bit\", \"1s\");\n\n return { greeting };\n },\n);\n";
|
|
6
|
-
export declare const HELLO_WORLD_RUNNER = "import { ow } from \"./client.js\";\nimport { helloWorld } from \"./hello-world.js\";\n\n// Run this file:\n// JS: `node openworkflow/hello-world.run.js`\n// TS: `npx tsx openworkflow/hello-world.run.ts`\n//\n// This file is a temporary dev helper generated by\n// `npx @openworkflow/cli init` so you can quickly run the example workflow.\n//\n// Copy the code anywhere in your app (e.g., an API route or a script) and\n// modify it to run your workflows.\n//\n// You can delete this file once you're done with it.\n\nconsole.log(\"Running hello-world workflow...\");\nconst handle = await ow.runWorkflow(helloWorld.spec, {});\n\nconsole.log(\"Waiting for result...\");\nconst result = await handle.result(); // for very short workflows only\n\nconsole.log(`Workflow result: ${JSON.stringify(result, null, 2)}`);\n";
|
|
6
|
+
export declare const HELLO_WORLD_RUNNER = "import { backend, ow } from \"./client.js\";\nimport { helloWorld } from \"./hello-world.js\";\n\n// Run this file:\n// JS: `node openworkflow/hello-world.run.js`\n// TS: `npx tsx openworkflow/hello-world.run.ts`\n//\n// This file is a temporary dev helper generated by\n// `npx @openworkflow/cli init` so you can quickly run the example workflow.\n//\n// Copy the code anywhere in your app (e.g., an API route or a script) and\n// modify it to run your workflows.\n//\n// You can delete this file once you're done with it.\n\nconsole.log(\"Running hello-world workflow...\");\nconst handle = await ow.runWorkflow(helloWorld.spec, {});\n\nconsole.log(\"Waiting for result...\");\nconst result = await handle.result(); // for very short workflows only\n\nconsole.log(`Workflow result: ${JSON.stringify(result, null, 2)}`);\n\n// Stop backend. Only needed if this is a standalone script that you want to\n// exit after running the workflow.\nawait backend.stop();\n";
|
|
7
7
|
//# sourceMappingURL=templates.d.ts.map
|
package/dist/templates.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../templates.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,6OAKzB,CAAC;AAEF,eAAO,MAAM,eAAe,+QAO3B,CAAC;AAEF,eAAO,MAAM,+BAA+B,ibAS3C,CAAC;AAEF,eAAO,MAAM,MAAM,qOAQlB,CAAC;AAEF,eAAO,MAAM,oBAAoB,wvBA0BhC,CAAC;AAEF,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../templates.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,6OAKzB,CAAC;AAEF,eAAO,MAAM,eAAe,+QAO3B,CAAC;AAEF,eAAO,MAAM,+BAA+B,ibAS3C,CAAC;AAEF,eAAO,MAAM,MAAM,qOAQlB,CAAC;AAEF,eAAO,MAAM,oBAAoB,wvBA0BhC,CAAC;AAEF,eAAO,MAAM,kBAAkB,w8BA0B9B,CAAC"}
|
package/dist/templates.js
CHANGED
|
@@ -58,7 +58,7 @@ export const helloWorld = defineWorkflow(
|
|
|
58
58
|
},
|
|
59
59
|
);
|
|
60
60
|
`;
|
|
61
|
-
export const HELLO_WORLD_RUNNER = `import { ow } from "./client.js";
|
|
61
|
+
export const HELLO_WORLD_RUNNER = `import { backend, ow } from "./client.js";
|
|
62
62
|
import { helloWorld } from "./hello-world.js";
|
|
63
63
|
|
|
64
64
|
// Run this file:
|
|
@@ -80,4 +80,8 @@ console.log("Waiting for result...");
|
|
|
80
80
|
const result = await handle.result(); // for very short workflows only
|
|
81
81
|
|
|
82
82
|
console.log(\`Workflow result: \${JSON.stringify(result, null, 2)}\`);
|
|
83
|
+
|
|
84
|
+
// Stop backend. Only needed if this is a standalone script that you want to
|
|
85
|
+
// exit after running the workflow.
|
|
86
|
+
await backend.stop();
|
|
83
87
|
`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openworkflow/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -22,22 +22,23 @@
|
|
|
22
22
|
"!*.tsbuildinfo"
|
|
23
23
|
],
|
|
24
24
|
"scripts": {
|
|
25
|
-
"build": "tsc",
|
|
25
|
+
"build": "npm run clean && tsc",
|
|
26
|
+
"clean": "rm -rf dist",
|
|
26
27
|
"prepublishOnly": "npm run build"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
29
|
-
"@clack/prompts": "^1.0.
|
|
30
|
+
"@clack/prompts": "^1.0.1",
|
|
30
31
|
"commander": "^14.0.3",
|
|
31
32
|
"consola": "^3.4.2",
|
|
32
|
-
"dotenv": "^17.
|
|
33
|
+
"dotenv": "^17.3.1",
|
|
33
34
|
"jiti": "^2.6.1",
|
|
34
|
-
"nypm": "^0.6.
|
|
35
|
+
"nypm": "^0.6.5"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"openworkflow": "*",
|
|
38
39
|
"vitest": "^4.0.18"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
|
-
"openworkflow": "^0.6.0"
|
|
42
|
+
"openworkflow": "^0.6.0 || ^0.7.0 || ^0.8.0"
|
|
42
43
|
}
|
|
43
44
|
}
|