@kradle/cli 0.0.16 → 0.1.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.
- package/README.md +62 -65
- package/dist/commands/agent/list.d.ts +4 -0
- package/dist/commands/agent/list.js +6 -4
- package/dist/commands/challenge/build.d.ts +9 -1
- package/dist/commands/challenge/build.js +40 -12
- package/dist/commands/challenge/create.d.ts +5 -1
- package/dist/commands/challenge/create.js +17 -18
- package/dist/commands/challenge/delete.d.ts +4 -1
- package/dist/commands/challenge/delete.js +5 -5
- package/dist/commands/challenge/list.d.ts +5 -0
- package/dist/commands/challenge/list.js +9 -10
- package/dist/commands/challenge/run.d.ts +8 -1
- package/dist/commands/challenge/run.js +13 -8
- package/dist/commands/challenge/watch.d.ts +4 -1
- package/dist/commands/challenge/watch.js +8 -8
- package/dist/commands/{evaluation → experiment}/create.d.ts +4 -0
- package/dist/commands/{evaluation → experiment}/create.js +22 -21
- package/dist/commands/{evaluation → experiment}/list.js +17 -19
- package/dist/commands/{evaluation → experiment}/run.d.ts +4 -1
- package/dist/commands/experiment/run.js +61 -0
- package/dist/commands/init.js +2 -2
- package/dist/lib/api-client.d.ts +29 -10
- package/dist/lib/api-client.js +81 -37
- package/dist/lib/arguments.d.ts +3 -2
- package/dist/lib/arguments.js +5 -3
- package/dist/lib/challenge.d.ts +13 -18
- package/dist/lib/challenge.js +60 -61
- package/dist/lib/experiment/experimenter.d.ts +87 -0
- package/dist/lib/{evaluation/evaluator.js → experiment/experimenter.js} +74 -72
- package/dist/lib/{evaluation → experiment}/index.d.ts +1 -1
- package/dist/lib/{evaluation → experiment}/index.js +1 -1
- package/dist/lib/{evaluation → experiment}/runner.js +2 -1
- package/dist/lib/{evaluation → experiment}/tui.d.ts +1 -1
- package/dist/lib/{evaluation → experiment}/tui.js +3 -3
- package/dist/lib/{evaluation → experiment}/types.d.ts +6 -4
- package/dist/lib/{evaluation → experiment}/types.js +4 -3
- package/dist/lib/flags.d.ts +47 -0
- package/dist/lib/flags.js +63 -0
- package/dist/lib/schemas.d.ts +32 -0
- package/dist/lib/schemas.js +8 -0
- package/dist/lib/utils.d.ts +9 -10
- package/dist/lib/utils.js +12 -12
- package/oclif.manifest.json +342 -64
- package/package.json +5 -6
- package/static/challenge.ts +12 -13
- package/static/experiment_template.ts +114 -0
- package/static/project_template/dev.env +5 -5
- package/static/project_template/prod.env +4 -4
- package/static/project_template/tsconfig.json +1 -1
- package/dist/commands/challenge/multi-upload.d.ts +0 -6
- package/dist/commands/challenge/multi-upload.js +0 -80
- package/dist/commands/evaluation/run.js +0 -61
- package/dist/lib/config.d.ts +0 -12
- package/dist/lib/config.js +0 -49
- package/dist/lib/evaluation/evaluator.d.ts +0 -88
- package/static/evaluation_template.ts +0 -69
- /package/dist/commands/{evaluation → experiment}/list.d.ts +0 -0
- /package/dist/lib/{evaluation → experiment}/runner.d.ts +0 -0
|
@@ -39,7 +39,7 @@ const RenderRunLine = ({ state, total, isSelected, padding, }) => {
|
|
|
39
39
|
const summaryText = summary.length > maxSummaryLength ? summary.slice(0, maxSummaryLength - 1) + "…" : summary;
|
|
40
40
|
return (_jsxs(Text, { inverse: isSelected, children: [_jsx(Text, { color: color, children: icon }), " ", indexLabel, " ", _jsx(Text, { color: color, children: statusLabel }), elapsedLabel ? (_jsxs(_Fragment, { children: [" ", _jsx(Text, { dimColor: true, children: elapsedLabel })] })) : null, " ", _jsx(Text, { dimColor: true, children: summaryText })] }));
|
|
41
41
|
};
|
|
42
|
-
const
|
|
42
|
+
const ExperimentUI = ({ experimentName, states, statusCounts, onQuit, onOpenRun }) => {
|
|
43
43
|
const [selectedIndex, setSelectedIndex] = useState(0);
|
|
44
44
|
const [scrollOffset, setScrollOffset] = useState(0);
|
|
45
45
|
const [tick, setTick] = useState(0); // force elapsed-time updates
|
|
@@ -89,7 +89,7 @@ const EvaluationUI = ({ evaluationName, states, statusCounts, onQuit, onOpenRun
|
|
|
89
89
|
const rangeEnd = Math.min(scrollOffset + rowsAvailable, states.length);
|
|
90
90
|
const horizontalRule = "─".repeat(Math.min(process.stdout.columns || 80, 80));
|
|
91
91
|
const padding = states.length.toString().length;
|
|
92
|
-
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: `
|
|
92
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: `Experiment: ${experimentName}` }), _jsx(Text, { dimColor: true, children: horizontalRule }), _jsx(Text, { dimColor: true, children: "q:quit \u2191/\u2193/j/k:select o:open in browser" }), _jsx(Text, { children: " " }), _jsxs(Box, { flexDirection: "column", children: [visibleRuns.map((state, index) => (_jsx(RenderRunLine, { state: state, total: states.length, isSelected: scrollOffset + index === selectedIndex, padding: padding }, state.index))), visibleRuns.length < rowsAvailable
|
|
93
93
|
? Array.from({ length: rowsAvailable - visibleRuns.length }).map((_, index) => (_jsx(Text, { children: " " }, `empty-${index}`)))
|
|
94
94
|
: null] }), showScroll ? _jsx(Text, { dimColor: true, children: `[${rangeStart}-${rangeEnd} of ${states.length}]` }) : _jsx(Text, { children: " " }), _jsx(Text, { dimColor: true, children: horizontalRule }), _jsxs(Text, { children: [_jsx(Text, { children: "Completed: " }), _jsx(Text, { color: "green", children: statusCounts.completed }), _jsx(Text, { children: ` | Active: ` }), _jsx(Text, { color: "yellow", children: statusCounts.active }), _jsx(Text, { children: ` | Queued: ` }), _jsx(Text, { dimColor: true, children: statusCounts.queued }), statusCounts.errors > 0 ? (_jsxs(_Fragment, { children: [_jsx(Text, { children: ` | Errors: ` }), _jsx(Text, { color: "red", children: statusCounts.errors })] })) : null] })] }));
|
|
95
95
|
};
|
|
@@ -125,6 +125,6 @@ export class TUI {
|
|
|
125
125
|
this.app.rerender(this.renderApp());
|
|
126
126
|
}
|
|
127
127
|
renderApp() {
|
|
128
|
-
return (_jsx(
|
|
128
|
+
return (_jsx(ExperimentUI, { experimentName: this.options.experimentName, states: this.states, statusCounts: this.statusCounts, onQuit: this.options.onQuit, onOpenRun: this.options.onOpenRun }));
|
|
129
129
|
}
|
|
130
130
|
}
|
|
@@ -10,6 +10,7 @@ export declare const RunConfigSchema: z.ZodObject<{
|
|
|
10
10
|
agent: z.ZodString;
|
|
11
11
|
role: z.ZodOptional<z.ZodString>;
|
|
12
12
|
}, z.core.$strip>>;
|
|
13
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
13
14
|
}, z.core.$strip>;
|
|
14
15
|
export type RunConfig = z.infer<typeof RunConfigSchema>;
|
|
15
16
|
export declare const ManifestSchema: z.ZodObject<{
|
|
@@ -19,6 +20,7 @@ export declare const ManifestSchema: z.ZodObject<{
|
|
|
19
20
|
agent: z.ZodString;
|
|
20
21
|
role: z.ZodOptional<z.ZodString>;
|
|
21
22
|
}, z.core.$strip>>;
|
|
23
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
22
24
|
}, z.core.$strip>>;
|
|
23
25
|
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
24
26
|
}, z.core.$strip>;
|
|
@@ -113,11 +115,11 @@ export declare const RunLogsResponseSchema: z.ZodObject<{
|
|
|
113
115
|
logs: z.ZodArray<z.ZodUnknown>;
|
|
114
116
|
}, z.core.$strip>;
|
|
115
117
|
export type RunLogsResponse = z.infer<typeof RunLogsResponseSchema>;
|
|
116
|
-
export declare const
|
|
117
|
-
|
|
118
|
+
export declare const ExperimentMetadataSchema: z.ZodObject<{
|
|
119
|
+
currentVersion: z.ZodNumber;
|
|
118
120
|
}, z.core.$strip>;
|
|
119
|
-
export type
|
|
120
|
-
export interface
|
|
121
|
+
export type ExperimentMetadata = z.infer<typeof ExperimentMetadataSchema>;
|
|
122
|
+
export interface ExperimentOptions {
|
|
121
123
|
new: boolean;
|
|
122
124
|
maxConcurrent: number;
|
|
123
125
|
openMetabase?: boolean;
|
|
@@ -8,6 +8,7 @@ export const ParticipantSchema = z.object({
|
|
|
8
8
|
export const RunConfigSchema = z.object({
|
|
9
9
|
challenge_slug: z.string(),
|
|
10
10
|
participants: z.array(ParticipantSchema),
|
|
11
|
+
tags: z.array(z.string()).optional(),
|
|
11
12
|
});
|
|
12
13
|
// Manifest returned by config.ts main()
|
|
13
14
|
export const ManifestSchema = z.object({
|
|
@@ -66,9 +67,9 @@ export const RunStatusResponseSchema = z.object({
|
|
|
66
67
|
export const RunLogsResponseSchema = z.object({
|
|
67
68
|
logs: z.array(z.unknown()),
|
|
68
69
|
});
|
|
69
|
-
//
|
|
70
|
-
export const
|
|
71
|
-
|
|
70
|
+
// Experiment metadata stored in .experiment.json
|
|
71
|
+
export const ExperimentMetadataSchema = z.object({
|
|
72
|
+
currentVersion: z.number(),
|
|
72
73
|
});
|
|
73
74
|
// Icons and colors for TUI
|
|
74
75
|
export const STATUS_ICONS = {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* All available config flags that can be used by commands.
|
|
3
|
+
* Each flag has an `env` property that allows it to be set via environment variable.
|
|
4
|
+
*/
|
|
5
|
+
export declare const ALL_CONFIG_FLAGS: {
|
|
6
|
+
readonly "api-url": import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
readonly "web-url": import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
readonly "studio-api-url": import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
readonly "studio-url": import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
readonly "api-key": import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
readonly "challenges-path": import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Type representing all config flag keys.
|
|
15
|
+
*/
|
|
16
|
+
export type ConfigFlagKey = keyof typeof ALL_CONFIG_FLAGS;
|
|
17
|
+
/**
|
|
18
|
+
* Type representing the parsed values of all config flags.
|
|
19
|
+
*/
|
|
20
|
+
export type AllConfigFlagValues = {
|
|
21
|
+
[K in ConfigFlagKey]: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Returns a subset of config flags for use in a command's static flags definition.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // In a command file:
|
|
28
|
+
* static override flags = {
|
|
29
|
+
* ...getConfigFlags("api-key", "web-api-url", "studio-api-url"),
|
|
30
|
+
* // other command-specific flags
|
|
31
|
+
* };
|
|
32
|
+
*
|
|
33
|
+
* @param keys - The config flag keys to include.
|
|
34
|
+
* @returns An object containing only the specified flags
|
|
35
|
+
*/
|
|
36
|
+
export declare function getConfigFlags<K extends ConfigFlagKey>(...keys: K[]): Pick<typeof ALL_CONFIG_FLAGS, K>;
|
|
37
|
+
/**
|
|
38
|
+
* Helper type to extract the parsed flag values for a subset of config flags.
|
|
39
|
+
* Use this to type the flags object after parsing.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* type MyFlags = ConfigFlagValues<"api-key" | "web-api-url">;
|
|
43
|
+
* // Results in: { "api-key": string; "web-api-url": string }
|
|
44
|
+
*/
|
|
45
|
+
export type ConfigFlagValues<K extends ConfigFlagKey> = {
|
|
46
|
+
[P in K]: AllConfigFlagValues[P];
|
|
47
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Flags } from "@oclif/core";
|
|
2
|
+
import { untildify } from "./utils.js";
|
|
3
|
+
/**
|
|
4
|
+
* All available config flags that can be used by commands.
|
|
5
|
+
* Each flag has an `env` property that allows it to be set via environment variable.
|
|
6
|
+
*/
|
|
7
|
+
export const ALL_CONFIG_FLAGS = {
|
|
8
|
+
"api-url": Flags.string({
|
|
9
|
+
description: "Kradle Web API URL",
|
|
10
|
+
env: "KRADLE_API_URL",
|
|
11
|
+
required: true,
|
|
12
|
+
default: "https://api.kradle.ai/v0",
|
|
13
|
+
}),
|
|
14
|
+
"web-url": Flags.string({
|
|
15
|
+
description: "Kradle Web URL, used to display the run URL",
|
|
16
|
+
env: "KRADLE_WEB_URL",
|
|
17
|
+
required: true,
|
|
18
|
+
default: "https://kradle.ai",
|
|
19
|
+
}),
|
|
20
|
+
"studio-api-url": Flags.string({
|
|
21
|
+
description: "Kradle Studio API URL, used to communicate with the Studio API",
|
|
22
|
+
env: "KRADLE_STUDIO_API_URL",
|
|
23
|
+
required: true,
|
|
24
|
+
default: "http://localhost:2999/api/v0",
|
|
25
|
+
}),
|
|
26
|
+
"studio-url": Flags.string({
|
|
27
|
+
description: "Kradle Studio URL, used to display the run URL in Studio",
|
|
28
|
+
env: "KRADLE_STUDIO_URL",
|
|
29
|
+
required: true,
|
|
30
|
+
default: "kradle://open",
|
|
31
|
+
}),
|
|
32
|
+
"api-key": Flags.string({
|
|
33
|
+
description: "Kradle API key",
|
|
34
|
+
env: "KRADLE_API_KEY",
|
|
35
|
+
required: true,
|
|
36
|
+
}),
|
|
37
|
+
"challenges-path": Flags.string({
|
|
38
|
+
description: "Absolute path to the challenges directory",
|
|
39
|
+
env: "KRADLE_CHALLENGES_PATH",
|
|
40
|
+
default: "~/Documents/kradle-studio/challenges",
|
|
41
|
+
parse: async (input) => untildify(input),
|
|
42
|
+
}),
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Returns a subset of config flags for use in a command's static flags definition.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* // In a command file:
|
|
49
|
+
* static override flags = {
|
|
50
|
+
* ...getConfigFlags("api-key", "web-api-url", "studio-api-url"),
|
|
51
|
+
* // other command-specific flags
|
|
52
|
+
* };
|
|
53
|
+
*
|
|
54
|
+
* @param keys - The config flag keys to include.
|
|
55
|
+
* @returns An object containing only the specified flags
|
|
56
|
+
*/
|
|
57
|
+
export function getConfigFlags(...keys) {
|
|
58
|
+
const result = {};
|
|
59
|
+
for (const key of keys) {
|
|
60
|
+
result[key] = ALL_CONFIG_FLAGS[key];
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
package/dist/lib/schemas.d.ts
CHANGED
|
@@ -40,6 +40,37 @@ export declare const ChallengeSchema: z.ZodObject<{
|
|
|
40
40
|
updateTime: z.ZodOptional<z.ZodString>;
|
|
41
41
|
creator: z.ZodOptional<z.ZodString>;
|
|
42
42
|
}, z.core.$strip>;
|
|
43
|
+
export declare const ChallengeConfigSchema: z.ZodObject<{
|
|
44
|
+
name: z.ZodString;
|
|
45
|
+
description: z.ZodOptional<z.ZodString>;
|
|
46
|
+
domain: z.ZodString;
|
|
47
|
+
world: z.ZodString;
|
|
48
|
+
challengeConfig: z.ZodObject<{
|
|
49
|
+
cheat: z.ZodBoolean;
|
|
50
|
+
datapack: z.ZodBoolean;
|
|
51
|
+
gameMode: z.ZodEnum<{
|
|
52
|
+
survival: "survival";
|
|
53
|
+
creative: "creative";
|
|
54
|
+
adventure: "adventure";
|
|
55
|
+
spectator: "spectator";
|
|
56
|
+
}>;
|
|
57
|
+
}, z.core.$strip>;
|
|
58
|
+
task: z.ZodOptional<z.ZodString>;
|
|
59
|
+
roles: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
60
|
+
description: z.ZodOptional<z.ZodString>;
|
|
61
|
+
specificTask: z.ZodOptional<z.ZodString>;
|
|
62
|
+
minParticipants: z.ZodOptional<z.ZodNumber>;
|
|
63
|
+
maxParticipants: z.ZodOptional<z.ZodNumber>;
|
|
64
|
+
}, z.core.$strip>>;
|
|
65
|
+
objective: z.ZodObject<{
|
|
66
|
+
fieldName: z.ZodString;
|
|
67
|
+
direction: z.ZodEnum<{
|
|
68
|
+
maximize: "maximize";
|
|
69
|
+
minimize: "minimize";
|
|
70
|
+
}>;
|
|
71
|
+
}, z.core.$strip>;
|
|
72
|
+
endStates: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
73
|
+
}, z.core.$strip>;
|
|
43
74
|
export declare const ChallengesResponseSchema: z.ZodObject<{
|
|
44
75
|
challenges: z.ZodArray<z.ZodObject<{
|
|
45
76
|
id: z.ZodOptional<z.ZodString>;
|
|
@@ -135,6 +166,7 @@ export declare const AgentsResponseSchema: z.ZodObject<{
|
|
|
135
166
|
nextPageToken: z.ZodOptional<z.ZodString>;
|
|
136
167
|
}, z.core.$strip>;
|
|
137
168
|
export type ChallengeSchemaType = z.infer<typeof ChallengeSchema>;
|
|
169
|
+
export type ChallengeConfigSchemaType = z.infer<typeof ChallengeConfigSchema>;
|
|
138
170
|
export type ChallengesResponseType = z.infer<typeof ChallengesResponseSchema>;
|
|
139
171
|
export type HumanSchemaType = z.infer<typeof HumanSchema>;
|
|
140
172
|
export type RunResponseType = z.infer<typeof RunResponseSchema>;
|
package/dist/lib/schemas.js
CHANGED
|
@@ -28,6 +28,14 @@ export const ChallengeSchema = z.object({
|
|
|
28
28
|
updateTime: z.string().optional(),
|
|
29
29
|
creator: z.string().optional(),
|
|
30
30
|
});
|
|
31
|
+
export const ChallengeConfigSchema = ChallengeSchema.omit({
|
|
32
|
+
slug: true,
|
|
33
|
+
id: true,
|
|
34
|
+
visibility: true,
|
|
35
|
+
creationTime: true,
|
|
36
|
+
updateTime: true,
|
|
37
|
+
creator: true,
|
|
38
|
+
});
|
|
31
39
|
export const ChallengesResponseSchema = z.object({
|
|
32
40
|
challenges: z.array(ChallengeSchema),
|
|
33
41
|
nextPageToken: z.string().optional(),
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Dirent } from "node:fs";
|
|
2
|
-
import type { Config } from "./config.js";
|
|
3
2
|
export declare function loadTemplateRun(): Promise<Record<string, unknown>>;
|
|
4
3
|
/**
|
|
5
4
|
* Resolve tildes in a path to the home directory
|
|
@@ -33,34 +32,34 @@ export declare function getStaticResourcePath(name: string): string;
|
|
|
33
32
|
*/
|
|
34
33
|
export declare function readDirSorted(dir: string): Promise<Dirent[]>;
|
|
35
34
|
/**
|
|
36
|
-
* Runs a NodeJS module. The module is executed in the current working directory, and the environment is set to the given
|
|
35
|
+
* Runs a NodeJS module. The module is executed in the current working directory, and the environment is set to the given env.
|
|
37
36
|
* stdout & stdout are piped to the parent process.
|
|
38
37
|
*
|
|
39
38
|
* Returns a promise that resolves when the module completes.
|
|
40
39
|
*
|
|
41
40
|
* @param file The file to execute.
|
|
42
|
-
* @param
|
|
41
|
+
* @param env The environment variables to set.
|
|
43
42
|
* @param options The options to use.
|
|
44
43
|
* @param options.silent Whether to suppress stdout.
|
|
45
44
|
* @returns A promise that resolves when the command completes.
|
|
46
45
|
*/
|
|
47
|
-
export declare function runNodeModule(file: string,
|
|
46
|
+
export declare function runNodeModule(file: string, env: Record<string, string>, options?: {
|
|
48
47
|
silent?: boolean;
|
|
49
48
|
}): Promise<undefined>;
|
|
50
49
|
/**
|
|
51
50
|
* Execute a TypeScript file using NodeJS's built-in TS support.
|
|
52
51
|
*
|
|
53
52
|
* @param filePath The path to the TypeScript file.
|
|
54
|
-
* @param
|
|
53
|
+
* @param env The environment variables to set.
|
|
55
54
|
* @param options The options to use.
|
|
56
55
|
* @param options.silent Whether to suppress stdout.
|
|
57
56
|
* @returns The result of the execution.
|
|
58
57
|
*/
|
|
59
|
-
export declare function executeTypescriptFile(filePath: string,
|
|
58
|
+
export declare function executeTypescriptFile(filePath: string, env: Record<string, string>, options?: {
|
|
60
59
|
silent?: boolean;
|
|
61
60
|
}): Promise<unknown>;
|
|
62
61
|
/**
|
|
63
|
-
* Executes an arbitrary command. The command is spawned in the current working directory, and the environment is set to the given
|
|
62
|
+
* Executes an arbitrary command. The command is spawned in the current working directory, and the environment is set to the given env.
|
|
64
63
|
*
|
|
65
64
|
* stdout will be returned as a string.
|
|
66
65
|
* if stderr is not empty, an error will be thrown.
|
|
@@ -76,17 +75,17 @@ export declare function executeCommand(command: string, args: string[], options?
|
|
|
76
75
|
cwd?: string;
|
|
77
76
|
}): Promise<string>;
|
|
78
77
|
/**
|
|
79
|
-
* Executes an arbitrary NodeJS command. The command is spawned in the current working directory, and the environment is set to the given
|
|
78
|
+
* Executes an arbitrary NodeJS command. The command is spawned in the current working directory, and the environment is set to the given env.
|
|
80
79
|
* It will use the process.execPath of the current process to find the NodeJS executable.
|
|
81
80
|
*
|
|
82
81
|
* stdout will be returned as a string.
|
|
83
82
|
* if stderr is not empty, an error will be thrown.
|
|
84
83
|
*
|
|
85
84
|
* @param args The arguments to pass to the command.
|
|
86
|
-
* @param
|
|
85
|
+
* @param env The environment variables to set.
|
|
87
86
|
* @returns A promise that resolves with the stdout of the command.
|
|
88
87
|
*/
|
|
89
|
-
export declare function executeNodeCommand(args: string[],
|
|
88
|
+
export declare function executeNodeCommand(args: string[], env: Record<string, string>): Promise<string>;
|
|
90
89
|
/**
|
|
91
90
|
* Open a URL in the default browser.
|
|
92
91
|
* This is fire-and-forget, so we don't wait for it to complete.
|
package/dist/lib/utils.js
CHANGED
|
@@ -75,22 +75,22 @@ export async function readDirSorted(dir) {
|
|
|
75
75
|
return files.sort((a, b) => a.name.localeCompare(b.name));
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
|
-
* Runs a NodeJS module. The module is executed in the current working directory, and the environment is set to the given
|
|
78
|
+
* Runs a NodeJS module. The module is executed in the current working directory, and the environment is set to the given env.
|
|
79
79
|
* stdout & stdout are piped to the parent process.
|
|
80
80
|
*
|
|
81
81
|
* Returns a promise that resolves when the module completes.
|
|
82
82
|
*
|
|
83
83
|
* @param file The file to execute.
|
|
84
|
-
* @param
|
|
84
|
+
* @param env The environment variables to set.
|
|
85
85
|
* @param options The options to use.
|
|
86
86
|
* @param options.silent Whether to suppress stdout.
|
|
87
87
|
* @returns A promise that resolves when the command completes.
|
|
88
88
|
*/
|
|
89
|
-
export function runNodeModule(file,
|
|
89
|
+
export function runNodeModule(file, env, options = {}) {
|
|
90
90
|
return new Promise((resolve, reject) => {
|
|
91
91
|
const child = fork(file, {
|
|
92
92
|
cwd: path.resolve(process.cwd()),
|
|
93
|
-
env: { ...process.env, ...
|
|
93
|
+
env: { ...process.env, ...env },
|
|
94
94
|
silent: options.silent,
|
|
95
95
|
});
|
|
96
96
|
child.on("close", (code) => {
|
|
@@ -108,16 +108,16 @@ export function runNodeModule(file, config, options = {}) {
|
|
|
108
108
|
* Execute a TypeScript file using NodeJS's built-in TS support.
|
|
109
109
|
*
|
|
110
110
|
* @param filePath The path to the TypeScript file.
|
|
111
|
-
* @param
|
|
111
|
+
* @param env The environment variables to set.
|
|
112
112
|
* @param options The options to use.
|
|
113
113
|
* @param options.silent Whether to suppress stdout.
|
|
114
114
|
* @returns The result of the execution.
|
|
115
115
|
*/
|
|
116
|
-
export async function executeTypescriptFile(filePath,
|
|
117
|
-
return await runNodeModule(filePath,
|
|
116
|
+
export async function executeTypescriptFile(filePath, env, options = {}) {
|
|
117
|
+
return await runNodeModule(filePath, env, options);
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
|
-
* Executes an arbitrary command. The command is spawned in the current working directory, and the environment is set to the given
|
|
120
|
+
* Executes an arbitrary command. The command is spawned in the current working directory, and the environment is set to the given env.
|
|
121
121
|
*
|
|
122
122
|
* stdout will be returned as a string.
|
|
123
123
|
* if stderr is not empty, an error will be thrown.
|
|
@@ -155,18 +155,18 @@ export async function executeCommand(command, args, options) {
|
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
157
|
/**
|
|
158
|
-
* Executes an arbitrary NodeJS command. The command is spawned in the current working directory, and the environment is set to the given
|
|
158
|
+
* Executes an arbitrary NodeJS command. The command is spawned in the current working directory, and the environment is set to the given env.
|
|
159
159
|
* It will use the process.execPath of the current process to find the NodeJS executable.
|
|
160
160
|
*
|
|
161
161
|
* stdout will be returned as a string.
|
|
162
162
|
* if stderr is not empty, an error will be thrown.
|
|
163
163
|
*
|
|
164
164
|
* @param args The arguments to pass to the command.
|
|
165
|
-
* @param
|
|
165
|
+
* @param env The environment variables to set.
|
|
166
166
|
* @returns A promise that resolves with the stdout of the command.
|
|
167
167
|
*/
|
|
168
|
-
export async function executeNodeCommand(args,
|
|
169
|
-
return executeCommand(process.execPath, args, { env
|
|
168
|
+
export async function executeNodeCommand(args, env) {
|
|
169
|
+
return executeCommand(process.execPath, args, { env });
|
|
170
170
|
}
|
|
171
171
|
/**
|
|
172
172
|
* Open a URL in the default browser.
|