@jordond/kit 0.0.0-stage → 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/bin/kit +39 -0
- package/dist/_verb-espppzez.js +115 -0
- package/dist/android-g73naxgg.js +31 -0
- package/dist/build-88hxf0kc.js +42 -0
- package/dist/check-7mndz8g8.js +54 -0
- package/dist/check-ngc4kzmj.js +33 -0
- package/dist/cleanup-hrcvxmh2.js +18 -0
- package/dist/cli/builtins.d.ts +13 -0
- package/dist/cli/command.d.ts +86 -0
- package/dist/cli/discover.d.ts +10 -0
- package/dist/cli/main.d.ts +1 -0
- package/dist/cli/plugin.d.ts +7 -0
- package/dist/cli/usage.d.ts +3 -0
- package/dist/cli-07t28k94.js +30 -0
- package/dist/cli-12dww95e.js +195 -0
- package/dist/cli-5d61x8vg.js +675 -0
- package/dist/cli-5wasc5mr.js +76 -0
- package/dist/cli-6dxp4v3m.js +73 -0
- package/dist/cli-7wvrehng.js +23 -0
- package/dist/cli-bam7dqfd.js +33 -0
- package/dist/cli-fqfan92n.js +135 -0
- package/dist/cli-fqxtcj42.js +75 -0
- package/dist/cli-h974q2wr.js +2019 -0
- package/dist/cli-m53122z6.js +221 -0
- package/dist/cli-qhs8ww91.js +51 -0
- package/dist/cli-qq1ktr8q.js +234 -0
- package/dist/cli-rds33bnp.js +101 -0
- package/dist/cli-re3ntm60.js +48 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +35 -0
- package/dist/cloudflare-n5c46k6x.js +43 -0
- package/dist/command-gazq4bmt.js +19 -0
- package/dist/commands/_verb.d.ts +15 -0
- package/dist/commands/build.d.ts +11 -0
- package/dist/commands/check.d.ts +8 -0
- package/dist/commands/config.d.ts +2 -0
- package/dist/commands/db/create.d.ts +7 -0
- package/dist/commands/db/exec.d.ts +16 -0
- package/dist/commands/db/list.d.ts +11 -0
- package/dist/commands/db/migrate.d.ts +11 -0
- package/dist/commands/deploy.d.ts +13 -0
- package/dist/commands/deps.d.ts +72 -0
- package/dist/commands/dev.d.ts +8 -0
- package/dist/commands/doctor.d.ts +56 -0
- package/dist/commands/env/check.d.ts +7 -0
- package/dist/commands/env/init.d.ts +2 -0
- package/dist/commands/env/push.d.ts +12 -0
- package/dist/commands/env/sync.d.ts +2 -0
- package/dist/commands/format.d.ts +11 -0
- package/dist/commands/gradle.d.ts +2 -0
- package/dist/commands/init.d.ts +53 -0
- package/dist/commands/lint.d.ts +12 -0
- package/dist/commands/release/android.d.ts +13 -0
- package/dist/commands/release/ios.d.ts +13 -0
- package/dist/commands/test.d.ts +2 -0
- package/dist/commands/typecheck.d.ts +2 -0
- package/dist/commands/wrangler.d.ts +4 -0
- package/dist/commands/xcode.d.ts +8 -0
- package/dist/config/load.d.ts +6 -0
- package/dist/config/schema.d.ts +135 -0
- package/dist/config-ey5yrrfn.js +22 -0
- package/dist/create-7s8h3dja.js +38 -0
- package/dist/deploy-8mg1zhpb.js +102 -0
- package/dist/deps-97dq4mg8.js +334 -0
- package/dist/dev-yc9xmntj.js +62 -0
- package/dist/doctor-0wzmfyyh.js +324 -0
- package/dist/errors-1fjbr7ee.js +10 -0
- package/dist/exec-1k3sqwxz.js +53 -0
- package/dist/format-mnqfak22.js +39 -0
- package/dist/git-52v5rk51.js +80 -0
- package/dist/gradle-gtkf3geq.js +39 -0
- package/dist/index-cx34x4np.js +874 -0
- package/dist/index-erv82p4z.js +1528 -0
- package/dist/index-jqfz6hfy.js +2659 -0
- package/dist/index-mm4ht8yh.js +9 -0
- package/dist/index-s3ehw02w.js +1610 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +50 -0
- package/dist/init-0402av4m.js +78 -0
- package/dist/init-dk5sym9w.js +76 -0
- package/dist/init-qr7y55ea.js +185 -0
- package/dist/ios-msg4bk15.js +31 -0
- package/dist/lib/cleanup.d.ts +21 -0
- package/dist/lib/cloudflare.d.ts +96 -0
- package/dist/lib/env/init.d.ts +22 -0
- package/dist/lib/env/load.d.ts +12 -0
- package/dist/lib/env/push.d.ts +54 -0
- package/dist/lib/env/render.d.ts +49 -0
- package/dist/lib/env/schema.d.ts +49 -0
- package/dist/lib/errors.d.ts +14 -0
- package/dist/lib/git.d.ts +36 -0
- package/dist/lib/log.d.ts +11 -0
- package/dist/lib/pm.d.ts +8 -0
- package/dist/lib/proc.d.ts +73 -0
- package/dist/lib/prompt.d.ts +32 -0
- package/dist/lib/secrets.d.ts +32 -0
- package/dist/lib/steps.d.ts +38 -0
- package/dist/lib/targets.d.ts +46 -0
- package/dist/lib/toml.d.ts +15 -0
- package/dist/lint-280dpn4y.js +39 -0
- package/dist/list-jdc3dqk0.js +34 -0
- package/dist/load-5qzs1c6b.js +137 -0
- package/dist/log-hhspqwjw.js +11 -0
- package/dist/main-ywtsjxev.js +2052 -0
- package/dist/migrate-emk758k1.js +35 -0
- package/dist/picocolors-0dxagz5d.js +6 -0
- package/dist/pm-5q5vz6w3.js +14 -0
- package/dist/proc-jv4bcyyx.js +33 -0
- package/dist/prompt-v510j04z.js +93 -0
- package/dist/push-4z70h3d8.js +117 -0
- package/dist/push-xzqw218t.js +117 -0
- package/dist/render-488tjnsq.js +22 -0
- package/dist/sync-wc4jpmkj.js +53 -0
- package/dist/targets-hbwxv97d.js +22 -0
- package/dist/test-198w46m4.js +26 -0
- package/dist/toml-zbhtxjh1.js +1062 -0
- package/dist/typecheck-e86e6yg1.js +24 -0
- package/dist/wrangler-0ctx1p3w.js +66 -0
- package/dist/xcode-g44qh2rc.js +60 -0
- package/fastlane/Fastfile +413 -0
- package/fastlane/Gemfile +21 -0
- package/fastlane/Gemfile.lock +275 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.jar +0 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.jar.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.jar.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.jar.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.jar.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.module +64 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.module.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.module.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.module.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.module.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.pom +12 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.pom.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.pom.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.pom.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/0.1.0/kit-plugins-0.1.0.pom.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/maven-metadata.xml +13 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/maven-metadata.xml.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/maven-metadata.xml.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/maven-metadata.xml.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-plugins/maven-metadata.xml.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.jar +0 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.jar.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.jar.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.jar.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.jar.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.module +64 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.module.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.module.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.module.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.module.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.pom +12 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.pom.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.pom.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.pom.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/0.1.0/kit-settings-0.1.0.pom.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/maven-metadata.xml +13 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/maven-metadata.xml.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/maven-metadata.xml.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/maven-metadata.xml.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/kit-settings/maven-metadata.xml.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/0.1.0/io.github.jordond.kit.release.gradle.plugin-0.1.0.pom +15 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/0.1.0/io.github.jordond.kit.release.gradle.plugin-0.1.0.pom.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/0.1.0/io.github.jordond.kit.release.gradle.plugin-0.1.0.pom.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/0.1.0/io.github.jordond.kit.release.gradle.plugin-0.1.0.pom.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/0.1.0/io.github.jordond.kit.release.gradle.plugin-0.1.0.pom.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/maven-metadata.xml +13 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/maven-metadata.xml.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/maven-metadata.xml.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/maven-metadata.xml.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/release/io.github.jordond.kit.release.gradle.plugin/maven-metadata.xml.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/0.1.0/io.github.jordond.kit.settings.gradle.plugin-0.1.0.pom +15 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/0.1.0/io.github.jordond.kit.settings.gradle.plugin-0.1.0.pom.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/0.1.0/io.github.jordond.kit.settings.gradle.plugin-0.1.0.pom.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/0.1.0/io.github.jordond.kit.settings.gradle.plugin-0.1.0.pom.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/0.1.0/io.github.jordond.kit.settings.gradle.plugin-0.1.0.pom.sha512 +1 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/maven-metadata.xml +13 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/maven-metadata.xml.md5 +1 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/maven-metadata.xml.sha1 +1 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/maven-metadata.xml.sha256 +1 -0
- package/gradle/maven/io/github/jordond/kit/settings/io.github.jordond.kit.settings.gradle.plugin/maven-metadata.xml.sha512 +1 -0
- package/package.json +58 -4
- package/templates/lefthook.yml +6 -0
- package/templates/mise.toml +6 -0
- package/README.md +0 -3
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { KitConfig } from '../../config/schema';
|
|
2
|
+
import type { EnvSchema, EnvValues } from './schema';
|
|
3
|
+
/**
|
|
4
|
+
* Outputs rendered from `.env` (ported from WhaleSay `_lib/env-master.ts` and brewd `lib/env.ts`).
|
|
5
|
+
*
|
|
6
|
+
* `env.outputs[path] = { pick?, rename? }`:
|
|
7
|
+
* - `pick`: source keys written under their own name.
|
|
8
|
+
* - `rename`: `{ OUTPUT_NAME: 'SOURCE_KEY' }`, e.g. admin binds INTERNAL_ADMIN_SECRET as X_INTERNAL_SECRET.
|
|
9
|
+
* - neither: every schema key.
|
|
10
|
+
* Lines follow pick order, then rename order. Files are `.dev.vars` format, written atomically at 0600.
|
|
11
|
+
* A blank value renders as a commented `# KEY=` so the file documents the key and dev servers still boot.
|
|
12
|
+
*/
|
|
13
|
+
export declare const GENERATED_BANNER = "# Generated by `kit env sync` from .env. Edit .env and re-run; do not edit by hand.\n";
|
|
14
|
+
export interface OutputLine {
|
|
15
|
+
/** Name in the output file. */
|
|
16
|
+
name: string;
|
|
17
|
+
/** Key in `.env`. */
|
|
18
|
+
source: string;
|
|
19
|
+
}
|
|
20
|
+
export interface Output {
|
|
21
|
+
/** Repo-relative path from config. */
|
|
22
|
+
path: string;
|
|
23
|
+
lines: OutputLine[];
|
|
24
|
+
}
|
|
25
|
+
export declare function outputs(config: KitConfig, schema: EnvSchema): Output[];
|
|
26
|
+
/** Render an output. Pure. */
|
|
27
|
+
export declare function render(output: Output, values: EnvValues): string;
|
|
28
|
+
/** Parse a rendered (or any dotenv) file into name → value; `# KEY=` placeholders read as ''. */
|
|
29
|
+
export declare function parseDotenv(text: string): Record<string, string>;
|
|
30
|
+
export interface KeyDiff {
|
|
31
|
+
added: string[];
|
|
32
|
+
updated: string[];
|
|
33
|
+
removed: string[];
|
|
34
|
+
}
|
|
35
|
+
/** Which names differ between two files. Names only; values never leave this function. */
|
|
36
|
+
export declare function diffKeys(prev: string | null, next: string): KeyDiff;
|
|
37
|
+
export interface WriteResult extends KeyDiff {
|
|
38
|
+
path: string;
|
|
39
|
+
changed: boolean;
|
|
40
|
+
}
|
|
41
|
+
/** Write via a temp file and rename, so a reader never sees half a file. */
|
|
42
|
+
export declare function writeAtomic(file: string, contents: string): void;
|
|
43
|
+
/** Render and write every output; unchanged files are left alone (mode healed to 0600). */
|
|
44
|
+
export declare function writeOutputs(root: string, list: Output[], values: EnvValues, dryRun?: boolean): WriteResult[];
|
|
45
|
+
export interface Drift extends KeyDiff {
|
|
46
|
+
path: string;
|
|
47
|
+
reason: 'missing' | 'stale';
|
|
48
|
+
}
|
|
49
|
+
export declare function checkOutputs(root: string, list: Output[], values: EnvValues): Drift[];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { KitConfig } from '../../config/schema';
|
|
2
|
+
/**
|
|
3
|
+
* The env schema (PLAN §11): `env.schema` in kit.config.ts points at a module whose default export
|
|
4
|
+
* (or `schema` export) is a zod object, one key per `.env` variable.
|
|
5
|
+
*
|
|
6
|
+
* Per-key metadata is read from zod `.meta()`:
|
|
7
|
+
*
|
|
8
|
+
* export default z.object({
|
|
9
|
+
* INTERNAL_API_SECRET: z.string().min(32).meta({ description: 'CLI → edge auth' }),
|
|
10
|
+
* PUBLIC_BASE_URL: z.url().meta({ secret: false, description: 'Public edge URL' }),
|
|
11
|
+
* CORS_ALLOWED_ORIGINS: z.string().default('').meta({ secret: false }),
|
|
12
|
+
* })
|
|
13
|
+
*
|
|
14
|
+
* - `secret` defaults to true: unmarked keys are treated as secret (masked prompts, redacted).
|
|
15
|
+
* Mark plain values with `secret: false`.
|
|
16
|
+
* - `description` (or zod `.describe()`) is shown in `kit env init` prompts.
|
|
17
|
+
* - Required = the schema rejects `undefined` (no `.optional()` or `.default()`).
|
|
18
|
+
*
|
|
19
|
+
* The schema module imports the repo's own zod, so it is inspected structurally, never with
|
|
20
|
+
* `instanceof`. Values are never printed; validation messages are redacted.
|
|
21
|
+
*/
|
|
22
|
+
export interface EnvKey {
|
|
23
|
+
name: string;
|
|
24
|
+
secret: boolean;
|
|
25
|
+
required: boolean;
|
|
26
|
+
description?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface EnvIssue {
|
|
29
|
+
key: string;
|
|
30
|
+
message: string;
|
|
31
|
+
}
|
|
32
|
+
export type EnvValues = Readonly<Record<string, string | undefined>>;
|
|
33
|
+
export interface EnvSchema {
|
|
34
|
+
/** Keys in declaration order. */
|
|
35
|
+
keys: EnvKey[];
|
|
36
|
+
validate(values: EnvValues): {
|
|
37
|
+
values: Record<string, string>;
|
|
38
|
+
issues: EnvIssue[];
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export declare function describeSchema(schema: unknown): EnvSchema;
|
|
42
|
+
/** A schema with no rules: every key referenced by env config, optional and secret. */
|
|
43
|
+
export declare function implicitSchema(config: KitConfig): EnvSchema;
|
|
44
|
+
/** Source keys named anywhere in `env`: output picks and renames, worker and GitHub secrets. */
|
|
45
|
+
export declare function referencedKeys(config: KitConfig): string[];
|
|
46
|
+
/** Load `env.schema`, or the implicit schema when none is set. */
|
|
47
|
+
export declare function loadEnvSchema(root: string, config: KitConfig): Promise<EnvSchema>;
|
|
48
|
+
/** `Invalid .env` with one line per key; messages are already redacted. */
|
|
49
|
+
export declare function formatIssues(issues: EnvIssue[]): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const ExitCode: {
|
|
2
|
+
readonly ok: 0;
|
|
3
|
+
readonly failed: 1;
|
|
4
|
+
readonly usage: 2;
|
|
5
|
+
readonly config: 3;
|
|
6
|
+
readonly precondition: 4;
|
|
7
|
+
readonly interrupted: 130;
|
|
8
|
+
};
|
|
9
|
+
export type ExitCode = (typeof ExitCode)[keyof typeof ExitCode];
|
|
10
|
+
export declare class KitError extends Error {
|
|
11
|
+
readonly hint?: string | undefined;
|
|
12
|
+
readonly exitCode: ExitCode;
|
|
13
|
+
constructor(message: string, hint?: string | undefined, exitCode?: ExitCode);
|
|
14
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Files staged for commit (added, copied, modified, renamed), repo-relative. */
|
|
2
|
+
export declare function stagedFiles(cwd?: string): Promise<string[]>;
|
|
3
|
+
/** Uncommitted changes (tracked or untracked), as `git status --porcelain` lines. */
|
|
4
|
+
export declare function dirtyFiles(cwd?: string): Promise<string[]>;
|
|
5
|
+
export declare function isClean(cwd?: string): Promise<boolean>;
|
|
6
|
+
/** Branch name, or 'HEAD' when detached. */
|
|
7
|
+
export declare function currentBranch(cwd?: string): Promise<string>;
|
|
8
|
+
/**
|
|
9
|
+
* Nearest tag reachable from `ref` matching the glob `match` (`ios/v*`), or undefined when none
|
|
10
|
+
* does. `exact` asks for the tag name only (`--abbrev=0`), without the `-N-gSHA` suffix.
|
|
11
|
+
*/
|
|
12
|
+
export declare function describe(match: string, opts?: {
|
|
13
|
+
cwd?: string;
|
|
14
|
+
ref?: string;
|
|
15
|
+
exact?: boolean;
|
|
16
|
+
}): Promise<string | undefined>;
|
|
17
|
+
export interface Commit {
|
|
18
|
+
sha: string;
|
|
19
|
+
subject: string;
|
|
20
|
+
}
|
|
21
|
+
/** Commits after `since` up to HEAD (all of history when undefined), newest first, optionally limited to paths. */
|
|
22
|
+
export declare function logSince(since: string | undefined, opts?: {
|
|
23
|
+
cwd?: string;
|
|
24
|
+
paths?: string[];
|
|
25
|
+
}): Promise<Commit[]>;
|
|
26
|
+
/** Create a tag at HEAD (or `ref`); annotated when `message` is given. */
|
|
27
|
+
export declare function tag(name: string, opts?: {
|
|
28
|
+
cwd?: string;
|
|
29
|
+
message?: string;
|
|
30
|
+
ref?: string;
|
|
31
|
+
}): Promise<void>;
|
|
32
|
+
/** Push refs (branches or tags) to `remote`. */
|
|
33
|
+
export declare function push(refs: string[], opts?: {
|
|
34
|
+
cwd?: string;
|
|
35
|
+
remote?: string;
|
|
36
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const log: {
|
|
2
|
+
info: (msg: string) => boolean;
|
|
3
|
+
step: (msg: string) => boolean;
|
|
4
|
+
success: (msg: string) => boolean;
|
|
5
|
+
warn: (msg: string) => boolean;
|
|
6
|
+
error: (msg: string, hint?: string) => void;
|
|
7
|
+
dim: (msg: string) => boolean;
|
|
8
|
+
};
|
|
9
|
+
export type Logger = typeof log;
|
|
10
|
+
/** Write exactly one JSON document to stdout. */
|
|
11
|
+
export declare function emitJson(value: unknown): void;
|
package/dist/lib/pm.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type PackageManager = 'bun' | 'pnpm' | 'yarn' | 'npm';
|
|
2
|
+
/** Package manager for `dir`: the nearest lockfile walking up to `root`. Defaults to bun. */
|
|
3
|
+
export declare function detectPackageManager(dir: string, root: string): PackageManager;
|
|
4
|
+
export declare const runScript: (pm: PackageManager, script: string) => string[];
|
|
5
|
+
/** Run a binary from node_modules (`bun x`, `pnpm exec`, …). */
|
|
6
|
+
export declare function pmExec(pm: PackageManager, bin: string, ...args: string[]): string[];
|
|
7
|
+
/** Scripts in `<dir>/package.json`, or undefined when there is none. */
|
|
8
|
+
export declare function packageScripts(dir: string): Record<string, string> | undefined;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one spawn wrapper (ported from brewd `lib/proc.ts`).
|
|
3
|
+
*
|
|
4
|
+
* Children always get an explicit env: `process.env` (which already holds the root `.env`) plus
|
|
5
|
+
* anything registered with `addChildEnv`, e.g. the pinned CLOUDFLARE_ACCOUNT_ID. Bun.spawn would
|
|
6
|
+
* otherwise snapshot the env kit started with.
|
|
7
|
+
*/
|
|
8
|
+
export type Env = Readonly<Record<string, string | undefined>>;
|
|
9
|
+
export interface RunOptions {
|
|
10
|
+
cwd?: string;
|
|
11
|
+
env?: Env;
|
|
12
|
+
}
|
|
13
|
+
/** Add variables every later child gets. */
|
|
14
|
+
export declare function addChildEnv(vars: Env): void;
|
|
15
|
+
export declare function childEnv(env?: Env): Record<string, string | undefined>;
|
|
16
|
+
/** Inherit all stdio, as if run directly. For passthroughs (`kit gradle …`). */
|
|
17
|
+
export declare function run(cmd: readonly string[], opts?: RunOptions): Promise<number>;
|
|
18
|
+
/**
|
|
19
|
+
* Like `run`, but the child's stdout goes to kit's stderr. For `--json` runs that still stream a
|
|
20
|
+
* child's progress: stdout stays free for the one document.
|
|
21
|
+
*/
|
|
22
|
+
export declare function runToStderr(cmd: readonly string[], opts?: RunOptions): Promise<number>;
|
|
23
|
+
/** Like `run`, but throws on a non-zero exit. */
|
|
24
|
+
export declare function runOrThrow(cmd: readonly string[], opts?: RunOptions): Promise<void>;
|
|
25
|
+
/** Capture stdout and stderr into one string; print nothing. For steps whose output is noise until they fail. */
|
|
26
|
+
export declare function runQuiet(cmd: readonly string[], opts?: RunOptions): Promise<{
|
|
27
|
+
code: number;
|
|
28
|
+
output: string;
|
|
29
|
+
}>;
|
|
30
|
+
/** Capture stdout and stderr separately; optional `input` goes to stdin (e.g. a secret value). */
|
|
31
|
+
export declare function runPiped(cmd: readonly string[], opts?: RunOptions & {
|
|
32
|
+
input?: string;
|
|
33
|
+
}): Promise<{
|
|
34
|
+
code: number;
|
|
35
|
+
stdout: string;
|
|
36
|
+
stderr: string;
|
|
37
|
+
}>;
|
|
38
|
+
/** Capture stdout for post-processing; stderr passes through. */
|
|
39
|
+
export declare function runCapture(cmd: readonly string[], opts?: RunOptions & {
|
|
40
|
+
stdin?: 'inherit' | 'ignore';
|
|
41
|
+
}): Promise<{
|
|
42
|
+
code: number;
|
|
43
|
+
stdout: string;
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Stream stdout and stderr line by line to `onLine`, and keep the whole output.
|
|
47
|
+
* Used by steps: the tree shows the tail, failures print everything.
|
|
48
|
+
*/
|
|
49
|
+
export declare function runLines(cmd: readonly string[], opts?: RunOptions & {
|
|
50
|
+
onLine?: (line: string) => void;
|
|
51
|
+
mute?: RegExp;
|
|
52
|
+
}): Promise<{
|
|
53
|
+
code: number;
|
|
54
|
+
output: string;
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* For dev servers the user stops with Ctrl-C. The terminal already signalled the child; a Ctrl-C
|
|
58
|
+
* here is the user asking to stop, not a failure, so it returns 0. Restores the tty after.
|
|
59
|
+
*/
|
|
60
|
+
export declare function runInteractive(cmd: readonly string[], opts?: RunOptions): Promise<number>;
|
|
61
|
+
/**
|
|
62
|
+
* A child killed mid-flight can leave the terminal in raw mode with the cursor hidden and kitty
|
|
63
|
+
* key encoding pushed; the next prompt then echoes escape replies.
|
|
64
|
+
*/
|
|
65
|
+
export declare function restoreTty(): void;
|
|
66
|
+
export declare class ProcError extends Error {
|
|
67
|
+
readonly cmd: readonly string[];
|
|
68
|
+
readonly code: number;
|
|
69
|
+
readonly output?: string | undefined;
|
|
70
|
+
constructor(cmd: readonly string[], code: number, output?: string | undefined);
|
|
71
|
+
}
|
|
72
|
+
/** `sh -c` for a config command string, with extra args passed as "$@". */
|
|
73
|
+
export declare function shell(command: string, extra?: readonly string[]): string[];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Flags } from '../cli/command';
|
|
2
|
+
/**
|
|
3
|
+
* clack prompts on stderr, TTY and CI aware (brewd `lib/prompt.ts`, ported).
|
|
4
|
+
* Without a terminal kit never prompts: confirmations error with a `--yes` hint, input prompts
|
|
5
|
+
* error naming what to set instead. Collect answers before starting a steps tree, never during.
|
|
6
|
+
*/
|
|
7
|
+
type PromptFlags = Pick<Flags, 'interactive' | 'yes'>;
|
|
8
|
+
/** Yes/no. `--yes` answers yes (unless `force` is set, for prod). */
|
|
9
|
+
export declare function confirm(flags: PromptFlags, message: string, opts?: {
|
|
10
|
+
initial?: boolean;
|
|
11
|
+
force?: boolean;
|
|
12
|
+
}): Promise<boolean>;
|
|
13
|
+
export declare function text(flags: PromptFlags, message: string, opts?: {
|
|
14
|
+
initial?: string;
|
|
15
|
+
placeholder?: string;
|
|
16
|
+
hint?: string;
|
|
17
|
+
validate?: (v: string) => string | undefined;
|
|
18
|
+
}): Promise<string>;
|
|
19
|
+
/** Masked input for secrets. The value is never echoed. */
|
|
20
|
+
export declare function password(flags: PromptFlags, message: string, opts?: {
|
|
21
|
+
hint?: string;
|
|
22
|
+
validate?: (v: string) => string | undefined;
|
|
23
|
+
}): Promise<string>;
|
|
24
|
+
export declare function select<T extends string>(flags: PromptFlags, message: string, options: {
|
|
25
|
+
value: T;
|
|
26
|
+
label?: string;
|
|
27
|
+
hint?: string;
|
|
28
|
+
}[], opts?: {
|
|
29
|
+
initial?: T;
|
|
30
|
+
hint?: string;
|
|
31
|
+
}): Promise<T>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Env } from './proc';
|
|
2
|
+
/**
|
|
3
|
+
* Secret material for one kit run.
|
|
4
|
+
*
|
|
5
|
+
* - `secretFile` / `decodeSecretFile` write 0600 files under a per-run 0700 temp dir. The dir is
|
|
6
|
+
* removed by `onCleanup` (normal exit and Ctrl-C) with a sync `exit` backstop.
|
|
7
|
+
* - `registerSecret` adds a value to the redaction registry; `redact(s)` replaces every registered
|
|
8
|
+
* value in `s` with `***`. Run any text that may echo values (child stderr, validation messages)
|
|
9
|
+
* through it before printing.
|
|
10
|
+
* - `pipeSecret` feeds a value to a child on stdin, so it never lands in argv or shell history.
|
|
11
|
+
*/
|
|
12
|
+
export declare const MASK = "***";
|
|
13
|
+
export declare function registerSecret(value: string | undefined): void;
|
|
14
|
+
export declare function redact(s: string): string;
|
|
15
|
+
/** Write `contents` to a 0600 file in the run's temp dir and return its path. */
|
|
16
|
+
export declare function secretFile(name: string, contents: string | Uint8Array): string;
|
|
17
|
+
/** Decode base64 (`APPLE_ASC_KEY_P8_BASE64`, a keystore) into a 0600 temp file. */
|
|
18
|
+
export declare function decodeSecretFile(name: string, base64: string): string;
|
|
19
|
+
/** The run's temp dir if one was created. Test seam. */
|
|
20
|
+
export declare const secretDir: () => string | undefined;
|
|
21
|
+
/** Remove the temp dir and forget registered values. Test seam. */
|
|
22
|
+
export declare function resetSecrets(): void;
|
|
23
|
+
export interface PipeResult {
|
|
24
|
+
code: number;
|
|
25
|
+
/** stderr, plus stdout on failure (wrangler reports auth errors there). Redacted. */
|
|
26
|
+
output: string;
|
|
27
|
+
}
|
|
28
|
+
/** Run `cmd` with `input` on stdin. Output is captured and redacted, never streamed. */
|
|
29
|
+
export declare function pipeSecret(cmd: readonly string[], input: string, opts?: {
|
|
30
|
+
cwd?: string;
|
|
31
|
+
env?: Env;
|
|
32
|
+
}): Promise<PipeResult>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Flags } from '../cli/command';
|
|
2
|
+
import { type RunOptions } from './proc';
|
|
3
|
+
/**
|
|
4
|
+
* Steps render as a listr2 tree on stderr (brewd `runSteps`, ported). Every step runs even after
|
|
5
|
+
* a failure, so one pass surfaces every problem; `bail` stops at the first.
|
|
6
|
+
*
|
|
7
|
+
* Output modes:
|
|
8
|
+
* - TTY: the running step shows a rolling tail; a failed step's full output prints after the tree.
|
|
9
|
+
* - not a TTY (CI) or --verbose: child output streams as it comes.
|
|
10
|
+
* - --quiet: only failures' output and the summary. --json: nothing on stderr.
|
|
11
|
+
*/
|
|
12
|
+
export interface Step {
|
|
13
|
+
title: string;
|
|
14
|
+
task: (update: (line: string) => void) => Promise<void> | void;
|
|
15
|
+
}
|
|
16
|
+
export interface StepGroup {
|
|
17
|
+
title: string;
|
|
18
|
+
steps: Step[];
|
|
19
|
+
}
|
|
20
|
+
export interface StepResult {
|
|
21
|
+
group?: string;
|
|
22
|
+
title: string;
|
|
23
|
+
ok: boolean;
|
|
24
|
+
ms: number;
|
|
25
|
+
error?: string;
|
|
26
|
+
output?: string;
|
|
27
|
+
}
|
|
28
|
+
export type StepFlags = Pick<Flags, 'json' | 'quiet' | 'verbose' | 'ci'>;
|
|
29
|
+
/** A step that runs one command. Its output feeds the tree and, on failure, the report. */
|
|
30
|
+
export declare function commandStep(title: string, cmd: readonly string[], opts?: RunOptions & {
|
|
31
|
+
mute?: RegExp;
|
|
32
|
+
}): Step;
|
|
33
|
+
/** Run steps (or groups of steps). Never throws for a failed step; read the results. */
|
|
34
|
+
export declare function runSteps(items: (Step | StepGroup)[], flags: StepFlags, opts?: {
|
|
35
|
+
bail?: boolean;
|
|
36
|
+
}): Promise<StepResult[]>;
|
|
37
|
+
/** One-line outcome on stderr. Returns the exit code (0, 1, or 130 when interrupted). */
|
|
38
|
+
export declare function summarize(verb: string, results: StepResult[], startedAt: number, hint?: string): number;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { KitConfig, TargetConfig, Verb } from '../config/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Targets and kinds (PLAN §6.4). A kind maps verbs to default commands; any verb on any target can
|
|
4
|
+
* be overridden in config with a command string, a list, or `false`. Repo-wide steps live under
|
|
5
|
+
* `workspace`. This module only plans; running is `steps.ts`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const WORKSPACE = "workspace";
|
|
8
|
+
export interface PlannedCommand {
|
|
9
|
+
title: string;
|
|
10
|
+
cmd: string[];
|
|
11
|
+
cwd: string;
|
|
12
|
+
env?: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
export interface PlannedGroup {
|
|
15
|
+
/** Target name, or `workspace`. */
|
|
16
|
+
title: string;
|
|
17
|
+
commands: PlannedCommand[];
|
|
18
|
+
}
|
|
19
|
+
export interface PlanOptions {
|
|
20
|
+
/** Target names from argv; empty means all. `workspace` may be named. */
|
|
21
|
+
targets?: string[];
|
|
22
|
+
/** Appended to every command (`kit test api -- --watch`). */
|
|
23
|
+
extra?: string[];
|
|
24
|
+
/** `--env` for dev and deploy. */
|
|
25
|
+
env?: string;
|
|
26
|
+
/** Staged files (repo-relative). Workspace commands get them appended; targets without one are skipped. */
|
|
27
|
+
staged?: string[];
|
|
28
|
+
/** Gradle targets build the signed release artifact instead. */
|
|
29
|
+
release?: 'aab' | 'apk';
|
|
30
|
+
}
|
|
31
|
+
export interface Selection {
|
|
32
|
+
targets: [string, TargetConfig][];
|
|
33
|
+
workspace: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** Validate target names against config. Unknown names are a usage error with a suggestion. */
|
|
36
|
+
export declare function selectTargets(config: KitConfig, names?: string[]): Selection;
|
|
37
|
+
/** A Gradle task name (`spotlessCheck`, `:shared:test`) rather than a shell command. */
|
|
38
|
+
export declare const isGradleTask: (s: string) => boolean;
|
|
39
|
+
/** Commands for one target and verb. `undefined` = the target doesn't support the verb. */
|
|
40
|
+
export declare function targetCommands(root: string, config: KitConfig, name: string, verb: Verb, opts?: PlanOptions): PlannedCommand[] | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Plan a run of `verbs` (one, or `check` = lint + typecheck) over the selected targets.
|
|
43
|
+
* Groups: workspace first (prepare, then each verb), then each target in config order.
|
|
44
|
+
*/
|
|
45
|
+
export declare function planVerbs(root: string, config: KitConfig, verbs: Verb[], opts?: PlanOptions): PlannedGroup[];
|
|
46
|
+
export declare function suggest(token: string, candidates: string[]): string | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TOML read via smol-toml, and a surgical write that edits one line in place so comments, key
|
|
3
|
+
* order and quoting survive (brewd's version bump did this with a regex per key; this is the
|
|
4
|
+
* general form). Only single-line scalar values can be written.
|
|
5
|
+
*/
|
|
6
|
+
export type TomlScalar = string | number | boolean;
|
|
7
|
+
export declare function parseToml(text: string): Record<string, unknown>;
|
|
8
|
+
export declare function readToml(path: string): Record<string, unknown>;
|
|
9
|
+
/** `table` is a dotted table name (`versions`, `a.b`); '' is the root table. */
|
|
10
|
+
export declare function getTomlValue(text: string, table: string, key: string): unknown;
|
|
11
|
+
/**
|
|
12
|
+
* Set `key` in `[table]` to `value`, changing only that value's characters. A string keeps the
|
|
13
|
+
* existing quote style. Throws when the key isn't there or its value spans lines.
|
|
14
|
+
*/
|
|
15
|
+
export declare function setTomlValue(text: string, table: string, key: string, value: TomlScalar): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
defineCommand
|
|
4
|
+
} from "./cli-6dxp4v3m.js";
|
|
5
|
+
import"./cli-07t28k94.js";
|
|
6
|
+
import"./cli-5wasc5mr.js";
|
|
7
|
+
import"./cli-7wvrehng.js";
|
|
8
|
+
import {
|
|
9
|
+
__require
|
|
10
|
+
} from "./cli-re3ntm60.js";
|
|
11
|
+
|
|
12
|
+
// src/commands/lint.ts
|
|
13
|
+
var lint_default = defineCommand({
|
|
14
|
+
description: "Lint every target",
|
|
15
|
+
group: "Quality",
|
|
16
|
+
args: {
|
|
17
|
+
fix: { type: "boolean", short: "f", description: "Apply fixes (runs each target's format command)" },
|
|
18
|
+
staged: {
|
|
19
|
+
type: "boolean",
|
|
20
|
+
description: "Only targets with staged files; workspace commands get the files"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
examples: `kit lint
|
|
24
|
+
kit lint api web
|
|
25
|
+
kit lint --staged --fix`,
|
|
26
|
+
async run(ctx) {
|
|
27
|
+
const { runVerb } = await import("./_verb-espppzez.js");
|
|
28
|
+
const staged = ctx.args.staged ? await (await import("./git-52v5rk51.js")).stagedFiles(ctx.root) : undefined;
|
|
29
|
+
await runVerb(ctx, {
|
|
30
|
+
name: ctx.args.fix ? "lint --fix" : "lint",
|
|
31
|
+
verbs: ctx.args.fix ? ["format"] : ["lint"],
|
|
32
|
+
plan: { staged },
|
|
33
|
+
hint: ctx.args.fix ? undefined : "Run `kit lint --fix` to fix what the tools can"
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
export {
|
|
38
|
+
lint_default as default
|
|
39
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
dbArgs,
|
|
4
|
+
remoteArg
|
|
5
|
+
} from "./cli-m53122z6.js";
|
|
6
|
+
import"./cli-bam7dqfd.js";
|
|
7
|
+
import"./cli-qhs8ww91.js";
|
|
8
|
+
import"./cli-fqfan92n.js";
|
|
9
|
+
import"./cli-fqxtcj42.js";
|
|
10
|
+
import {
|
|
11
|
+
defineCommand
|
|
12
|
+
} from "./cli-6dxp4v3m.js";
|
|
13
|
+
import"./cli-07t28k94.js";
|
|
14
|
+
import"./cli-5wasc5mr.js";
|
|
15
|
+
import"./cli-7wvrehng.js";
|
|
16
|
+
import {
|
|
17
|
+
__require
|
|
18
|
+
} from "./cli-re3ntm60.js";
|
|
19
|
+
|
|
20
|
+
// src/commands/db/list.ts
|
|
21
|
+
var list_default = defineCommand({
|
|
22
|
+
description: "List applied and pending D1 migrations",
|
|
23
|
+
group: "Infra",
|
|
24
|
+
args: { ...dbArgs, ...remoteArg },
|
|
25
|
+
examples: `kit db list
|
|
26
|
+
kit db list --remote --db analytics`,
|
|
27
|
+
async run(ctx) {
|
|
28
|
+
const { runD1 } = await import("./cloudflare-n5c46k6x.js");
|
|
29
|
+
await runD1(ctx, { kind: "list", remote: !!ctx.args.remote }, { mutates: false });
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
export {
|
|
33
|
+
list_default as default
|
|
34
|
+
};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
redact,
|
|
4
|
+
registerSecret
|
|
5
|
+
} from "./cli-bam7dqfd.js";
|
|
6
|
+
import"./cli-fqfan92n.js";
|
|
7
|
+
import"./cli-fqxtcj42.js";
|
|
8
|
+
import {
|
|
9
|
+
ExitCode,
|
|
10
|
+
KitError
|
|
11
|
+
} from "./cli-7wvrehng.js";
|
|
12
|
+
import"./cli-re3ntm60.js";
|
|
13
|
+
|
|
14
|
+
// src/lib/env/schema.ts
|
|
15
|
+
import { existsSync } from "fs";
|
|
16
|
+
import { resolve } from "path";
|
|
17
|
+
import { pathToFileURL } from "url";
|
|
18
|
+
var isZodObject = (v) => typeof v === "object" && v !== null && typeof v.safeParse === "function" && typeof v.shape === "object";
|
|
19
|
+
function fieldMeta(field) {
|
|
20
|
+
const out = {};
|
|
21
|
+
let cur = field;
|
|
22
|
+
for (let depth = 0;cur && depth < 8; depth++) {
|
|
23
|
+
const m = cur.meta?.() ?? {};
|
|
24
|
+
if (out.secret === undefined && m.secret !== undefined)
|
|
25
|
+
out.secret = m.secret;
|
|
26
|
+
if (out.description === undefined)
|
|
27
|
+
out.description = m.description ?? cur.description;
|
|
28
|
+
cur = cur._zod?.def?.innerType;
|
|
29
|
+
}
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
function describeSchema(schema) {
|
|
33
|
+
if (!isZodObject(schema))
|
|
34
|
+
throw new KitError("env schema must export a zod object", undefined, ExitCode.config);
|
|
35
|
+
const keys = Object.entries(schema.shape).map(([name, field]) => {
|
|
36
|
+
const meta = fieldMeta(field);
|
|
37
|
+
return {
|
|
38
|
+
name,
|
|
39
|
+
secret: meta.secret !== false,
|
|
40
|
+
required: !field.safeParse(undefined).success,
|
|
41
|
+
...typeof meta.description === "string" ? { description: meta.description } : {}
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
keys,
|
|
46
|
+
validate(values) {
|
|
47
|
+
const input = {};
|
|
48
|
+
for (const k of keys) {
|
|
49
|
+
const v = values[k.name];
|
|
50
|
+
if (v !== undefined && v !== "")
|
|
51
|
+
input[k.name] = v;
|
|
52
|
+
if (k.secret)
|
|
53
|
+
registerSecret(v);
|
|
54
|
+
}
|
|
55
|
+
const result = schema.safeParse(input);
|
|
56
|
+
const merged = {};
|
|
57
|
+
for (const [k, v] of Object.entries(values))
|
|
58
|
+
if (typeof v === "string")
|
|
59
|
+
merged[k] = v;
|
|
60
|
+
if (!result.success) {
|
|
61
|
+
const issues = (result.error?.issues ?? []).map((i) => ({
|
|
62
|
+
key: i.path.length ? String(i.path[0]) : "(root)",
|
|
63
|
+
message: redact(i.message)
|
|
64
|
+
}));
|
|
65
|
+
return { values: merged, issues };
|
|
66
|
+
}
|
|
67
|
+
for (const [k, v] of Object.entries(result.data ?? {})) {
|
|
68
|
+
if (v !== undefined && v !== null)
|
|
69
|
+
merged[k] = String(v);
|
|
70
|
+
}
|
|
71
|
+
return { values: merged, issues: [] };
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function implicitSchema(config) {
|
|
76
|
+
const names = [...new Set(referencedKeys(config))];
|
|
77
|
+
const keys = names.map((name) => ({ name, secret: true, required: false }));
|
|
78
|
+
return {
|
|
79
|
+
keys,
|
|
80
|
+
validate(values) {
|
|
81
|
+
const merged = {};
|
|
82
|
+
for (const [k, v] of Object.entries(values))
|
|
83
|
+
if (typeof v === "string")
|
|
84
|
+
merged[k] = v;
|
|
85
|
+
for (const k of names)
|
|
86
|
+
registerSecret(values[k]);
|
|
87
|
+
return { values: merged, issues: [] };
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function referencedKeys(config) {
|
|
92
|
+
const env = config.env ?? {};
|
|
93
|
+
return [
|
|
94
|
+
...Object.values(env.outputs ?? {}).flatMap((o) => [...o.pick ?? [], ...Object.values(o.rename ?? {})]),
|
|
95
|
+
...Object.values(env.workerSecrets ?? {}).flat(),
|
|
96
|
+
...env.githubSecrets ?? []
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
async function loadEnvSchema(root, config) {
|
|
100
|
+
const path = config.env?.schema;
|
|
101
|
+
if (!path)
|
|
102
|
+
return implicitSchema(config);
|
|
103
|
+
const file = resolve(root, path);
|
|
104
|
+
if (!existsSync(file)) {
|
|
105
|
+
throw new KitError(`env.schema not found: ${path}`, "Fix env.schema in kit.config.ts", ExitCode.config);
|
|
106
|
+
}
|
|
107
|
+
const mod = await import(pathToFileURL(file).href);
|
|
108
|
+
const schema = mod.default ?? mod.schema;
|
|
109
|
+
if (!isZodObject(schema)) {
|
|
110
|
+
throw new KitError(`${path} must export a zod object (default export or \`schema\`)`, "export default z.object({ \u2026 })", ExitCode.config);
|
|
111
|
+
}
|
|
112
|
+
return describeSchema(schema);
|
|
113
|
+
}
|
|
114
|
+
function formatIssues(issues) {
|
|
115
|
+
return `Invalid .env:
|
|
116
|
+
${issues.map((i) => ` ${i.key}: ${i.message}`).join(`
|
|
117
|
+
`)}`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/lib/env/load.ts
|
|
121
|
+
async function loadEnv(root, config, raw = process.env) {
|
|
122
|
+
if (!config.env) {
|
|
123
|
+
throw new KitError("No env section in kit.config.ts", "Add env: { schema, outputs, \u2026 }", ExitCode.config);
|
|
124
|
+
}
|
|
125
|
+
const schema = await loadEnvSchema(root, config);
|
|
126
|
+
const { values, issues } = schema.validate(raw);
|
|
127
|
+
return { schema, values, issues };
|
|
128
|
+
}
|
|
129
|
+
function assertValid(state) {
|
|
130
|
+
if (state.issues.length) {
|
|
131
|
+
throw new KitError(formatIssues(state.issues), "Fix .env, or run `kit env init`", ExitCode.config);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
loadEnv,
|
|
136
|
+
assertValid
|
|
137
|
+
};
|