@fireproof/core-cli 0.23.1

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.
@@ -0,0 +1,160 @@
1
+ /* eslint-disable no-console */
2
+ import { array, command, flag, multioption, option, string } from "cmd-ts";
3
+ import fs from "fs-extra";
4
+ import { glob } from "zx";
5
+ import { SuperThis } from "@fireproof/core-types-base";
6
+
7
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
8
+ export function setDependenciesCmd(sthis: SuperThis) {
9
+ const cmd = command({
10
+ name: "fireproof set dependencies",
11
+ description: "helps to set dependencies in package.json files",
12
+ version: "1.0.0",
13
+ args: {
14
+ packageJsons: multioption({
15
+ long: "packageJsons",
16
+ short: "p",
17
+ type: array(string),
18
+ defaultValue: () => ["**/package.json"],
19
+ defaultValueIsSerializable: true,
20
+ description: "List of package.json files to patch, defaults to ['**/package.json'].",
21
+ }),
22
+ depName: option({
23
+ long: "depName",
24
+ short: "n",
25
+ type: string,
26
+ description: "The dependency name to set in package.json files.",
27
+ }),
28
+ depVersion: option({
29
+ long: "depVersion",
30
+ short: "v",
31
+ type: string,
32
+ defaultValue: () => "",
33
+ description: "The version of the dependency to set in package.json files.",
34
+ }),
35
+ devDependency: flag({
36
+ long: "devDependency",
37
+ short: "D",
38
+ description: "If set, the dependency will be added to devDependencies instead of dependencies.",
39
+ }),
40
+ peerDependency: flag({
41
+ long: "peerDependency",
42
+ short: "P",
43
+ description: "If set, the dependency will be added to peerDependencies instead of dependencies.",
44
+ }),
45
+ },
46
+ handler: async (args) => {
47
+ const packagesJsonFiles = await glob(args.packageJsons, {
48
+ gitignore: true, // Respect .gitignore
49
+ dot: false, // Don't include hidden files
50
+ ignore: [
51
+ // Additional ignores
52
+ "node_modules/**",
53
+ "**/node_modules/**",
54
+ "dist/**",
55
+ "build/**",
56
+ ".next/**",
57
+ "coverage/**",
58
+ ],
59
+ onlyFiles: true, // Only return files, not directories
60
+ absolute: false, // Return relative paths
61
+ caseSensitiveMatch: false,
62
+ });
63
+ console.log(`Found ${packagesJsonFiles.length} package.json files to patch.`);
64
+ for (const packageJsonPath of packagesJsonFiles) {
65
+ const packageJson = await fs.readJSON(packageJsonPath);
66
+ let ref: Record<string, string>;
67
+ if (args.devDependency) {
68
+ ref = packageJson.devDependencies || {};
69
+ packageJson.devDependencies = ref;
70
+ console.log(`Setting devDependency ${args.depName} to "${args.depVersion}" in ${packageJsonPath}`);
71
+ } else if (args.peerDependency) {
72
+ ref = packageJson.peerDependencies || {};
73
+ packageJson.peerDependencies = ref;
74
+ console.log(`Setting peerDependency ${args.depName} to "${args.depVersion}" in ${packageJsonPath}`);
75
+ } else {
76
+ ref = packageJson.dependencies || {};
77
+ packageJson.dependencies = ref;
78
+ console.log(`Setting dependency ${args.depName} to "${args.depVersion}" in ${packageJsonPath}`);
79
+ }
80
+ if (!args.depVersion) {
81
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
82
+ delete ref[args.depName];
83
+ } else {
84
+ ref[args.depName] = args.depVersion;
85
+ }
86
+ await fs.writeJSONSync(packageJsonPath, packageJson, { spaces: 2 });
87
+ }
88
+ },
89
+ });
90
+ return cmd;
91
+ }
92
+
93
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
94
+ export function setScriptsCmd(sthis: SuperThis) {
95
+ const cmd = command({
96
+ name: "fireproof build cli",
97
+ description: "helps to build fp",
98
+ version: "1.0.0",
99
+ args: {
100
+ packageJsons: multioption({
101
+ long: "packageJsons",
102
+ short: "p",
103
+ type: array(string),
104
+ defaultValue: () => ["**/package.json"],
105
+ defaultValueIsSerializable: true,
106
+ description: "List of package.json files to patch, defaults to ['**/package.json'].",
107
+ }),
108
+ scriptName: option({
109
+ long: "scriptName",
110
+ short: "s",
111
+ type: string,
112
+ description: "The script name to set in package.json files.",
113
+ }),
114
+ scriptAction: option({
115
+ long: "scriptAction",
116
+ short: "a",
117
+ type: string,
118
+ defaultValue: () => "",
119
+ description: "The script action to set in package.json files.",
120
+ }),
121
+ scriptDelete: flag({
122
+ long: "scriptDelete",
123
+ short: "d",
124
+ description: "If set, the script will be deleted instead of set.",
125
+ }),
126
+ },
127
+ handler: async (args) => {
128
+ const packagesJsonFiles = await glob(args.packageJsons, {
129
+ gitignore: true, // Respect .gitignore
130
+ dot: false, // Don't include hidden files
131
+ ignore: [
132
+ // Additional ignores
133
+ "node_modules/**",
134
+ "**/node_modules/**",
135
+ "dist/**",
136
+ "build/**",
137
+ ".next/**",
138
+ "coverage/**",
139
+ ],
140
+ onlyFiles: true, // Only return files, not directories
141
+ absolute: false, // Return relative paths
142
+ caseSensitiveMatch: false,
143
+ });
144
+ console.log(`Found ${packagesJsonFiles.length} package.json files to patch.`);
145
+ for (const packageJsonPath of packagesJsonFiles) {
146
+ const packageJson = await fs.readJSON(packageJsonPath);
147
+ if (args.scriptDelete || !args.scriptAction) {
148
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
149
+ delete packageJson.scripts[args.scriptName];
150
+ console.log(`Deleting script ${args.scriptName} from ${packageJsonPath}`);
151
+ } else {
152
+ packageJson.scripts[args.scriptName] = args.scriptAction;
153
+ console.log(`Setting script ${args.scriptName} to "${args.scriptAction}" in ${packageJsonPath}`);
154
+ }
155
+ await fs.writeJSONSync(packageJsonPath, packageJson, { spaces: 2 });
156
+ }
157
+ },
158
+ });
159
+ return cmd;
160
+ }
package/tsc-cmd.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { SuperThis } from "@fireproof/core-types-base";
2
+ export declare function handleTsc(args: string[], sthis: SuperThis): Promise<void>;
3
+ export declare function tscCmd(sthis: SuperThis): Partial<import("cmd-ts/dist/cjs/argparser.js").Register> & {
4
+ parse(context: import("cmd-ts/dist/cjs/argparser.js").ParseContext): Promise<import("cmd-ts/dist/cjs/argparser.js").ParsingResult<{
5
+ help: boolean;
6
+ }>>;
7
+ } & import("cmd-ts/dist/cjs/helpdoc.js").PrintHelp & import("cmd-ts/dist/cjs/helpdoc.js").ProvidesHelp & import("cmd-ts/dist/cjs/helpdoc.js").Named & Partial<import("cmd-ts/dist/cjs/helpdoc.js").Versioned> & import("cmd-ts/dist/cjs/argparser.js").Register & import("cmd-ts/dist/cjs/runner.js").Handling<{
8
+ help: boolean;
9
+ }, Promise<void>> & {
10
+ run(context: import("cmd-ts/dist/cjs/argparser.js").ParseContext): Promise<import("cmd-ts/dist/cjs/argparser.js").ParsingResult<Promise<void>>>;
11
+ } & Partial<import("cmd-ts/dist/cjs/helpdoc.js").Versioned & import("cmd-ts/dist/cjs/helpdoc.js").Descriptive & import("cmd-ts/dist/cjs/helpdoc.js").Aliased>;
package/tsc-cmd.js ADDED
@@ -0,0 +1,33 @@
1
+ import { command, flag } from "cmd-ts";
2
+ import { findUp } from "find-up";
3
+ import { $ } from "zx";
4
+ export async function handleTsc(args, sthis) {
5
+ const top = await findUp("tsconfig.dist.json");
6
+ if (!top) {
7
+ throw new Error("Could not find tsconfig.dist.json in the project root.");
8
+ }
9
+ const tsc = sthis.env.get("FP_TSC") ?? "tsc";
10
+ const cmd = [tsc, ...args];
11
+ $.verbose = false;
12
+ const p = $({ stdio: ["inherit", "inherit", "inherit"] }) `${cmd}`;
13
+ await p;
14
+ }
15
+ export function tscCmd(sthis) {
16
+ const cmd = command({
17
+ name: "fireproof tsc",
18
+ description: "tsc evolution tsgo",
19
+ args: {
20
+ help: flag({
21
+ long: "help",
22
+ short: "h",
23
+ defaultValue: () => false,
24
+ description: "Show help.",
25
+ }),
26
+ },
27
+ handler: async (args) => {
28
+ handleTsc(args, sthis);
29
+ },
30
+ });
31
+ return cmd;
32
+ }
33
+ //# sourceMappingURL=tsc-cmd.js.map
package/tsc-cmd.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tsc-cmd.js","sourceRoot":"","sources":["tsc-cmd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,S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findUp } from "find-up";
4
+ import { $ } from "zx";
5
+
6
+ export async function handleTsc(args: string[], sthis: SuperThis) {
7
+ const top = await findUp("tsconfig.dist.json");
8
+ if (!top) {
9
+ throw new Error("Could not find tsconfig.dist.json in the project root.");
10
+ }
11
+ const tsc = sthis.env.get("FP_TSC") ?? "tsc";
12
+ // const rargs = process.argv.slice(2);
13
+ const cmd = [tsc, ...args];
14
+ // console.log("args[", cmd, "]");
15
+
16
+ $.verbose = false;
17
+ const p = $({ stdio: ["inherit", "inherit", "inherit"] })`${cmd}`;
18
+ await p;
19
+ // $.verbose = true;
20
+ // await $`${cmd}`
21
+ }
22
+
23
+ export function tscCmd(sthis: SuperThis) {
24
+ const cmd = command({
25
+ name: "fireproof tsc",
26
+ description: "tsc evolution tsgo",
27
+ args: {
28
+ help: flag({
29
+ long: "help",
30
+ short: "h",
31
+ defaultValue: () => false,
32
+ description: "Show help.",
33
+ }),
34
+ },
35
+
36
+ handler: async (args) => {
37
+ handleTsc(args as unknown as string[], sthis);
38
+ },
39
+ });
40
+ return cmd;
41
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": [
3
+ "/home/runner/work/fireproof/fireproof/tsconfig.dist.json"
4
+ ],
5
+ "compilerOptions": {
6
+ "noEmit": false,
7
+ "outDir": "./"
8
+ },
9
+ "include": [
10
+ "**/*"
11
+ ],
12
+ "exclude": [
13
+ "node_modules",
14
+ "dist",
15
+ ".git",
16
+ ".vscode"
17
+ ]
18
+ }
package/write-env.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { SuperThis } from "@fireproof/core-types-base";
2
+ export declare function writeEnvFile(sthis: SuperThis, envFname: string, outFname: string | undefined, env: string, vals: Record<string, string>, doNotOverwrite: boolean, json: boolean): Promise<string>;
3
+ export declare function writeEnvCmd(sthis: SuperThis): Partial<import("cmd-ts/dist/cjs/argparser.js").Register> & {
4
+ parse(context: import("cmd-ts/dist/cjs/argparser.js").ParseContext): Promise<import("cmd-ts/dist/cjs/argparser.js").ParsingResult<{
5
+ wranglerToml: string;
6
+ env: string;
7
+ doNotOverwrite: boolean;
8
+ excludeSecrets: boolean;
9
+ fromEnv: string[];
10
+ out: string | undefined;
11
+ json: boolean;
12
+ }>>;
13
+ } & import("cmd-ts/dist/cjs/helpdoc.js").PrintHelp & import("cmd-ts/dist/cjs/helpdoc.js").ProvidesHelp & import("cmd-ts/dist/cjs/helpdoc.js").Named & Partial<import("cmd-ts/dist/cjs/helpdoc.js").Versioned> & import("cmd-ts/dist/cjs/argparser.js").Register & import("cmd-ts/dist/cjs/runner.js").Handling<{
14
+ wranglerToml: string;
15
+ env: string;
16
+ doNotOverwrite: boolean;
17
+ excludeSecrets: boolean;
18
+ fromEnv: string[];
19
+ out: string | undefined;
20
+ json: boolean;
21
+ }, Promise<void>> & {
22
+ run(context: import("cmd-ts/dist/cjs/argparser.js").ParseContext): Promise<import("cmd-ts/dist/cjs/argparser.js").ParsingResult<Promise<void>>>;
23
+ } & Partial<import("cmd-ts/dist/cjs/helpdoc.js").Versioned & import("cmd-ts/dist/cjs/helpdoc.js").Descriptive & import("cmd-ts/dist/cjs/helpdoc.js").Aliased>;
package/write-env.js ADDED
@@ -0,0 +1,103 @@
1
+ import { command, option, string, flag, optional, array, multioption } from "cmd-ts";
2
+ import * as rt from "@fireproof/core-runtime";
3
+ import { param } from "@adviser/cement";
4
+ import fs from "fs/promises";
5
+ export async function writeEnvFile(sthis, envFname, outFname, env, vals, doNotOverwrite, json) {
6
+ if (outFname === "-") {
7
+ outFname = "/dev/stdout";
8
+ }
9
+ const fname = outFname ?? sthis.pathOps.join(sthis.pathOps.dirname(envFname), `.dev.vars.${env}`);
10
+ if (doNotOverwrite &&
11
+ (await fs
12
+ .stat(fname)
13
+ .then(() => true)
14
+ .catch(() => false))) {
15
+ return fname;
16
+ }
17
+ let render;
18
+ if (json) {
19
+ render = JSON.stringify(vals, null, 2);
20
+ }
21
+ else {
22
+ render = Object.entries(vals)
23
+ .map(([k, v]) => `${k}=${v}`)
24
+ .join("\n");
25
+ }
26
+ await fs.writeFile(outFname ?? fname, render);
27
+ return fname;
28
+ }
29
+ export function writeEnvCmd(sthis) {
30
+ return command({
31
+ name: "cli-write-env",
32
+ description: "write env file",
33
+ version: "1.0.0",
34
+ args: {
35
+ wranglerToml: option({
36
+ long: "wranglerToml",
37
+ type: string,
38
+ defaultValue: () => "./wrangler.toml",
39
+ defaultValueIsSerializable: true,
40
+ }),
41
+ env: option({
42
+ long: "env",
43
+ type: string,
44
+ defaultValue: () => "test",
45
+ defaultValueIsSerializable: true,
46
+ }),
47
+ doNotOverwrite: flag({
48
+ long: "doNotOverwrite",
49
+ }),
50
+ excludeSecrets: flag({
51
+ long: "excludeSecrets",
52
+ }),
53
+ fromEnv: multioption({
54
+ long: "fromEnv",
55
+ type: array(string),
56
+ }),
57
+ out: option({
58
+ long: "out",
59
+ type: optional(string),
60
+ }),
61
+ json: flag({
62
+ long: "json",
63
+ }),
64
+ },
65
+ handler: async (args) => {
66
+ let vals = {};
67
+ if (args.fromEnv.length === 0) {
68
+ vals = {
69
+ [rt.sts.envKeyDefaults.PUBLIC]: param.REQUIRED,
70
+ STORAGE_URL: "http://127.0.0.1:9000/testbucket",
71
+ FP_STORAGE_URL: param.OPTIONAL,
72
+ };
73
+ if (!args.excludeSecrets) {
74
+ vals["ACCESS_KEY_ID"] = "minioadmin";
75
+ vals["SECRET_ACCESS_KEY"] = "minioadmin";
76
+ }
77
+ }
78
+ else {
79
+ Array.from(new Set(args.fromEnv))
80
+ .sort()
81
+ .reduce((acc, i) => {
82
+ const [k, v] = i.split("=");
83
+ if (v === undefined) {
84
+ acc[k] = param.REQUIRED;
85
+ }
86
+ else {
87
+ acc[k] = v;
88
+ }
89
+ return acc;
90
+ }, vals);
91
+ }
92
+ const rVal = sthis.env.gets(vals);
93
+ if (rVal.isErr()) {
94
+ throw rVal.Err();
95
+ }
96
+ const fname = await writeEnvFile(sthis, args.wranglerToml, args.out, args.env, rVal.Ok(), args.doNotOverwrite, args.json);
97
+ if (!["-", "stdout"].find((i) => args.out?.includes(i))) {
98
+ console.log(`Wrote: ${fname} keys: ${JSON.stringify(Object.keys(rVal.Ok()))}`);
99
+ }
100
+ },
101
+ });
102
+ }
103
+ //# sourceMappingURL=write-env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-env.js","sourceRoot":"","sources":["write-env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrF,OAAO,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAE9C,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,MAAM,aAAa,CAAC;AAE7B,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,KAAgB,EAChB,QAAgB,EAChB,QAA4B,EAC5B,GAAW,EACX,IAA4B,EAC5B,cAAuB,EACvB,IAAa;IAEb,IAAI,QAAQ,KAAK,GAAG,EAAE,CAAC;QACrB,QAAQ,GAAG,aAAa,CAAC;IAC3B,CAAC;IACD,MAAM,KAAK,GAAG,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,aAAa,GAAG,EAAE,CAAC,CAAC;IAClG,IACE,cAAc;QACd,CAAC,MAAM,EAAE;aACN,IAAI,CAAC,KAAK,CAAC;aACX,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;aAChB,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,EACtB,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,MAAc,CAAC;IACnB,IAAI,IAAI,EAAE,CAAC;QACT,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAA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,CAAC;YACnB,CAAC;YACD,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YAC1H,IAAI,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBAExD,OAAO,CAAC,GAAG,CAAC,UAAU,KAAK,WAAW,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;YAClF,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
package/write-env.ts ADDED
@@ -0,0 +1,116 @@
1
+ import { command, option, string, flag, optional, array, multioption } from "cmd-ts";
2
+ import * as rt from "@fireproof/core-runtime";
3
+ import { SuperThis } from "@fireproof/core-types-base";
4
+ import { param } from "@adviser/cement";
5
+ import fs from "fs/promises";
6
+
7
+ export async function writeEnvFile(
8
+ sthis: SuperThis,
9
+ envFname: string,
10
+ outFname: string | undefined,
11
+ env: string,
12
+ vals: Record<string, string>,
13
+ doNotOverwrite: boolean,
14
+ json: boolean,
15
+ ) {
16
+ if (outFname === "-") {
17
+ outFname = "/dev/stdout";
18
+ }
19
+ const fname = outFname ?? sthis.pathOps.join(sthis.pathOps.dirname(envFname), `.dev.vars.${env}`);
20
+ if (
21
+ doNotOverwrite &&
22
+ (await fs
23
+ .stat(fname)
24
+ .then(() => true)
25
+ .catch(() => false))
26
+ ) {
27
+ return fname;
28
+ }
29
+ let render: string;
30
+ if (json) {
31
+ render = JSON.stringify(vals, null, 2);
32
+ } else {
33
+ // console.log("Writing to", fname);
34
+ render = Object.entries(vals)
35
+ .map(([k, v]) => `${k}=${v}`)
36
+ .join("\n");
37
+ }
38
+ await fs.writeFile(outFname ?? fname, render);
39
+ return fname;
40
+ }
41
+
42
+ export function writeEnvCmd(sthis: SuperThis) {
43
+ return command({
44
+ name: "cli-write-env",
45
+ description: "write env file",
46
+ version: "1.0.0",
47
+ args: {
48
+ wranglerToml: option({
49
+ long: "wranglerToml",
50
+ type: string,
51
+ defaultValue: () => "./wrangler.toml",
52
+ defaultValueIsSerializable: true,
53
+ }),
54
+ env: option({
55
+ long: "env",
56
+ type: string,
57
+ defaultValue: () => "test",
58
+ defaultValueIsSerializable: true,
59
+ }),
60
+ doNotOverwrite: flag({
61
+ long: "doNotOverwrite",
62
+ }),
63
+ excludeSecrets: flag({
64
+ long: "excludeSecrets",
65
+ }),
66
+ fromEnv: multioption({
67
+ long: "fromEnv",
68
+ type: array(string),
69
+ }),
70
+ out: option({
71
+ long: "out",
72
+ type: optional(string),
73
+ }),
74
+ json: flag({
75
+ long: "json",
76
+ }),
77
+ },
78
+ handler: async (args) => {
79
+ let vals: Record<string, string | param> = {};
80
+ if (args.fromEnv.length === 0) {
81
+ vals = {
82
+ [rt.sts.envKeyDefaults.PUBLIC]: param.REQUIRED,
83
+ STORAGE_URL: "http://127.0.0.1:9000/testbucket",
84
+ FP_STORAGE_URL: param.OPTIONAL,
85
+ };
86
+
87
+ if (!args.excludeSecrets) {
88
+ vals["ACCESS_KEY_ID"] = "minioadmin";
89
+ vals["SECRET_ACCESS_KEY"] = "minioadmin";
90
+ }
91
+ } else {
92
+ Array.from(new Set(args.fromEnv))
93
+ .sort()
94
+ .reduce((acc, i) => {
95
+ const [k, v] = i.split("=");
96
+ if (v === undefined) {
97
+ acc[k] = param.REQUIRED;
98
+ } else {
99
+ acc[k] = v;
100
+ }
101
+ return acc;
102
+ }, vals);
103
+ }
104
+
105
+ const rVal = sthis.env.gets(vals);
106
+ if (rVal.isErr()) {
107
+ throw rVal.Err();
108
+ }
109
+ const fname = await writeEnvFile(sthis, args.wranglerToml, args.out, args.env, rVal.Ok(), args.doNotOverwrite, args.json);
110
+ if (!["-", "stdout"].find((i) => args.out?.includes(i))) {
111
+ // eslint-disable-next-line no-console
112
+ console.log(`Wrote: ${fname} keys: ${JSON.stringify(Object.keys(rVal.Ok()))}`);
113
+ }
114
+ },
115
+ });
116
+ }