inferative 0.0.0 → 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.
@@ -0,0 +1,120 @@
1
+ import { ArgsDef, CommandDef } from "citty";
2
+ //#region src/registry/registry-access.d.ts
3
+ /** The result of one spawned command, captured rather than inherited. */
4
+ interface ProcessRunResult {
5
+ /** The process exit code; a process that never exited counts as `1`. */
6
+ readonly exitCode: number;
7
+ /** Captured standard output. */
8
+ readonly stdout: string;
9
+ /** Captured standard error. */
10
+ readonly stderr: string;
11
+ /** Whether the program could not be started because it is not installed. */
12
+ readonly commandMissing?: boolean;
13
+ }
14
+ /** Spawns a command and resolves its captured result. A test injects one so no real `npm` runs. */
15
+ type ProcessRunner = (command: string, commandArguments: readonly string[], workingDirectory: string, environment: Readonly<Record<string, string | undefined>>) => Promise<ProcessRunResult>;
16
+ /** The verdict {@link RegistryAccess.probe} reaches. */
17
+ declare const RegistryAccessStatus: {
18
+ /** Both scopes reach GitHub Packages and the registry answered for each probe package. */
19
+ readonly Ok: "ok";
20
+ /** A scope does not point at GitHub Packages. */
21
+ readonly ScopeNotRouted: "scope-not-routed";
22
+ /** The registry refused the request for lacking, or holding invalid, credentials. */
23
+ readonly Unauthorized: "unauthorized";
24
+ /** npm cannot be started: Node.js is installed without it, or not at all. */
25
+ readonly NpmNotFound: "npm-not-found";
26
+ /** The registry could not be reached (DNS, network, timeout or an unknown failure). */
27
+ readonly Unreachable: "unreachable";
28
+ /** The registry authorized the request, but the probe package is not there. */
29
+ readonly NotFound: "not-found";
30
+ };
31
+ /** One of {@link RegistryAccessStatus}. */
32
+ type RegistryAccessStatusValue = (typeof RegistryAccessStatus)[keyof typeof RegistryAccessStatus];
33
+ /** What {@link RegistryAccess.probe} reports. */
34
+ interface RegistryAccessReport {
35
+ /** The verdict. */
36
+ readonly status: RegistryAccessStatusValue;
37
+ /** The scope the verdict is about: the first one that is not routed or not readable. Absent for `Ok`. */
38
+ readonly scope?: string;
39
+ /** The raw output behind the verdict, for a diagnosis. */
40
+ readonly detail?: string;
41
+ }
42
+ //#endregion
43
+ //#region src/init/dependency-installer.d.ts
44
+ /**
45
+ * Installs the dependencies of a project folder, and throws when the install fails. A test injects one so no real
46
+ * package manager runs.
47
+ */
48
+ type InstallRunner = (directory: string) => Promise<void>;
49
+ //#endregion
50
+ //#region src/init/starter-source.d.ts
51
+ /** Downloads one giget source into an empty folder. A test injects one so nothing touches the network. */
52
+ type StarterDownload = (source: string, directory: string) => Promise<void>;
53
+ //#endregion
54
+ //#region src/init/project-initializer.d.ts
55
+ /** Reads whether the scopes of a folder reach GitHub Packages. A test injects one so no real `npm` runs. */
56
+ type RegistryProbe = (directory: string) => Promise<RegistryAccessReport>;
57
+ /** The injectable parts of {@link ProjectInitializer}. */
58
+ interface InitDependencies {
59
+ /** Downloads a giget source. Giget by default. */
60
+ readonly download?: StarterDownload;
61
+ /** Probes the registry. {@link RegistryAccess} by default. */
62
+ readonly probeRegistry?: RegistryProbe;
63
+ /** Runs the `npm` calls of the default registry probe. Spawns npm by default. */
64
+ readonly runNpm?: ProcessRunner;
65
+ /** Runs the install. Spawns pnpm by default. */
66
+ readonly runInstall?: InstallRunner;
67
+ }
68
+ //#endregion
69
+ //#region src/init/init-command.d.ts
70
+ /** What one `init` invocation was asked to do. */
71
+ interface InitArguments {
72
+ /** The folder to create. The current folder when absent. */
73
+ readonly directory?: string;
74
+ /** The starter folder name. */
75
+ readonly starter?: string;
76
+ /** One giget source to use alone. */
77
+ readonly source?: string;
78
+ /** A local starters folder to copy from. */
79
+ readonly local?: string;
80
+ /** The folder that a named `directory` is created in. */
81
+ readonly cwd?: string;
82
+ /** Whether to install the dependencies. `false` for `--no-install`. */
83
+ readonly install?: boolean;
84
+ }
85
+ /** The parts of an `init` run that a test replaces. */
86
+ interface InitOptions {
87
+ /** The working directory. The process's own by default. */
88
+ readonly cwd?: string;
89
+ /** The version of the command line. The package's own by default. */
90
+ readonly version?: string;
91
+ /** The download, the registry probe and the install. */
92
+ readonly dependencies?: InitDependencies;
93
+ /** Writes a line to the output. */
94
+ readonly print?: (line: string) => void;
95
+ /** Writes a line to the error output. */
96
+ readonly fail?: (line: string) => void;
97
+ }
98
+ /** The `init` command. */
99
+ export declare class InitCommand {
100
+ /** The name it is registered under. */
101
+ static readonly name: string;
102
+ /** The exit code of a run that made a usable project. */
103
+ static readonly okExitCode: number;
104
+ /** The exit code of a run that failed, including a failed install. */
105
+ static readonly failureExitCode: number;
106
+ /** The command definition. */
107
+ static definition(): CommandDef;
108
+ /** The argument definition, which `create-inferative` shares. */
109
+ static args(): ArgsDef;
110
+ /**
111
+ * Creates one project and answers the exit code.
112
+ *
113
+ * @param args - What the invocation was asked to do.
114
+ * @param options - The working directory, the version and the replaceable parts. A test supplies them.
115
+ * @returns {@link okExitCode} when the project is usable, otherwise {@link failureExitCode}.
116
+ */
117
+ static execute(args: InitArguments, options?: InitOptions): Promise<number>;
118
+ }
119
+ //#endregion
120
+ export type { InitArguments, InitOptions };
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import { t as InitCommand } from "./init-command-C2q2dkCV.mjs";
2
+ export { InitCommand };