@verikit/cli 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/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Chidi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # @verikit/cli
2
+
3
+ Scaffolding CLI for [VeriKit](https://verikit.dev). It inspects your existing project, installs
4
+ the right `@verikit/*` packages for your stack, and generates the integration boilerplate so
5
+ you don't have to read the docs just to wire it up.
6
+
7
+ ## Usage
8
+
9
+ Run inside an existing project (Next.js, React, or Vue):
10
+
11
+ ```sh
12
+ npx @verikit/cli init
13
+ # or
14
+ pnpm dlx @verikit/cli init
15
+ ```
16
+
17
+ ## Commands
18
+
19
+ ### `verikit init`
20
+
21
+ Detects your package manager, UI framework, and database ORM from `package.json`, then:
22
+
23
+ - Installs the matching `@verikit/*` packages (and their peer dependencies)
24
+ - Generates `verikit/server.ts` and a starter `verikit/resources/example.ts`
25
+ - For Next.js App Router projects, generates `app/api/verikit/[...path]/route.ts`
26
+ - Adds the `@verikit/theme` import to your global stylesheet, if you opt in
27
+
28
+ It only prompts for what it can't determine on its own, and it's safe to run more than once
29
+ existing files and imports are left untouched.
30
+
31
+ Flags:
32
+
33
+ | Flag | Effect |
34
+ | ---------------- | -------------------------------------------------------------- |
35
+ | `--dry-run` | Show what would be installed and generated without changing anything |
36
+ | `--skip-install` | Generate files without installing dependencies |
37
+
38
+ ### `verikit install`
39
+
40
+ Same detection and prompts as `init`, but only installs packages no files are generated. Useful
41
+ if you're managing the integration by hand and just want the dependencies.
42
+
43
+ Flags:
44
+
45
+ | Flag | Effect |
46
+ | ----------- | -------------------------------------------------------- |
47
+ | `--dry-run` | Show what would be installed without changing anything |
48
+
49
+ ## Docs
50
+
51
+ Guides and API reference: [verikit.dev](https://verikit.dev)
52
+
53
+ ## Development
54
+
55
+ Requires Node.js 24 and pnpm.
56
+
57
+ ```sh
58
+ pnpm install
59
+ pnpm dev init # run the CLI against the current directory, via tsx
60
+ pnpm verify # typecheck, lint, build, and run tests at 100% coverage
61
+ ```
62
+
63
+ This repo includes the [VeriKit framework](https://github.com/iamceeso/verikit) as a git
64
+ submodule under `framework/`, kept as a development-time reference for the real package APIs
65
+ the CLI has no runtime dependency on it.
66
+
67
+ ## Status
68
+
69
+ Under active development. Commands and flags may change.
70
+
71
+ ## License
72
+
73
+ MIT see [LICENSE.md](LICENSE.md).
@@ -0,0 +1,235 @@
1
+ import * as clack from "@clack/prompts";
2
+ import path from "node:path";
3
+ import { detectDatabase } from "../detect/database.js";
4
+ import { detectFramework } from "../detect/framework.js";
5
+ import { detectPackageManager, } from "../detect/package-manager.js";
6
+ import { detectSrcRoot, readPackageJson } from "../detect/project.js";
7
+ import { generateServer } from "../generators/server.js";
8
+ import { generateNextRoute } from "../generators/route.js";
9
+ import { applyTheme, THEME_IMPORT } from "../generators/theme.js";
10
+ import { resolvePackages } from "../install/capabilities.js";
11
+ import { installPackages, } from "../install/dependencies.js";
12
+ import { logo } from "../utils/banner.js";
13
+ /* node:coverage disable */
14
+ // Thin passthrough to @clack/prompts' real terminal I/O exercising select/confirm here would
15
+ // block on stdin, so this whole adapter is excluded from coverage in favor of the Prompts fake
16
+ // used throughout the test suite.
17
+ export const realPrompts = {
18
+ intro: (title) => clack.intro(title),
19
+ outro: (message) => clack.outro(message),
20
+ log: {
21
+ success: (message) => clack.log.success(message),
22
+ warn: (message) => clack.log.warn(message),
23
+ error: (message) => clack.log.error(message),
24
+ step: (message) => clack.log.step(message),
25
+ },
26
+ select: (opts) => clack.select(opts),
27
+ confirm: (opts) => clack.confirm(opts),
28
+ spinner: () => clack.spinner(),
29
+ isCancel: (value) => clack.isCancel(value),
30
+ cancel: (message) => clack.cancel(message),
31
+ };
32
+ const defaultDeps = { prompts: realPrompts, installPackages };
33
+ /** Thrown to unwind out of `runInit` when the flow stops early; the CLI entrypoint maps `code` to `process.exitCode`. */
34
+ export class InitAbort extends Error {
35
+ code;
36
+ constructor(code) {
37
+ super(`init aborted with code ${code}`);
38
+ this.code = code;
39
+ this.name = "InitAbort";
40
+ }
41
+ }
42
+ const DEV_COMMAND = {
43
+ pnpm: "pnpm dev",
44
+ npm: "npm run dev",
45
+ yarn: "yarn dev",
46
+ bun: "bun dev",
47
+ };
48
+ export async function runInit(options, deps = defaultDeps) {
49
+ const { prompts, installPackages: install } = deps;
50
+ const cwd = process.cwd();
51
+ const dryRun = Boolean(options.dryRun);
52
+ prompts.intro(logo(dryRun ? "(dry run)" : undefined));
53
+ const pkg = readPackageJson(cwd);
54
+ if (!pkg) {
55
+ prompts.log.error("No package.json found here run `verikit init` inside an existing project.");
56
+ prompts.outro("Stopped.");
57
+ throw new InitAbort(1);
58
+ }
59
+ const packageManager = detectPackageManager(cwd);
60
+ const framework = detectFramework(cwd, pkg);
61
+ const database = detectDatabase(pkg);
62
+ prompts.log.success(`Detected ${packageManager}`);
63
+ if (framework.ui === "next")
64
+ prompts.log.success("Detected Next.js");
65
+ if (framework.ui === "react" || framework.ui === "next")
66
+ prompts.log.success("Detected React");
67
+ if (framework.ui === "vue")
68
+ prompts.log.success("Detected Vue");
69
+ if (framework.typescript)
70
+ prompts.log.success("Detected TypeScript");
71
+ if (database.prisma)
72
+ prompts.log.success("Detected Prisma");
73
+ if (database.drizzle)
74
+ prompts.log.success("Detected Drizzle");
75
+ let ui = framework.ui;
76
+ if (!ui) {
77
+ prompts.log.warn("Couldn't detect React or Vue.");
78
+ const choice = await prompts.select({
79
+ message: "Which UI framework are you using?",
80
+ options: [
81
+ { value: "react", label: "React" },
82
+ { value: "vue", label: "Vue" },
83
+ { value: "none", label: "None server only" },
84
+ ],
85
+ });
86
+ if (prompts.isCancel(choice))
87
+ return cancelled(prompts);
88
+ ui = choice === "none" ? null : choice;
89
+ }
90
+ let adapter;
91
+ if (database.prisma && database.drizzle) {
92
+ const choice = await prompts.select({
93
+ message: "Both Prisma and Drizzle were detected. Use as your VeriKit storage adapter?",
94
+ options: [
95
+ { value: "prisma", label: "Prisma" },
96
+ { value: "drizzle", label: "Drizzle" },
97
+ ],
98
+ });
99
+ if (prompts.isCancel(choice))
100
+ return cancelled(prompts);
101
+ adapter = choice;
102
+ }
103
+ else if (database.prisma) {
104
+ const confirmed = await prompts.confirm({
105
+ message: "Use Prisma as your VeriKit storage adapter?",
106
+ });
107
+ if (prompts.isCancel(confirmed))
108
+ return cancelled(prompts);
109
+ adapter = confirmed ? "prisma" : null;
110
+ }
111
+ else if (database.drizzle) {
112
+ const confirmed = await prompts.confirm({
113
+ message: "Use Drizzle as your VeriKit storage adapter?",
114
+ });
115
+ if (prompts.isCancel(confirmed))
116
+ return cancelled(prompts);
117
+ adapter = confirmed ? "drizzle" : null;
118
+ }
119
+ else {
120
+ const choice = await prompts.select({
121
+ message: "Use a storage adapter?",
122
+ options: [
123
+ { value: "prisma", label: "Prisma" },
124
+ { value: "drizzle", label: "Drizzle" },
125
+ { value: "none", label: "Skip for now" },
126
+ ],
127
+ });
128
+ if (prompts.isCancel(choice))
129
+ return cancelled(prompts);
130
+ adapter = choice === "none" ? null : choice;
131
+ }
132
+ let theme = false;
133
+ if (ui) {
134
+ const confirmed = await prompts.confirm({
135
+ message: "Install VeriKit's default theme?",
136
+ });
137
+ if (prompts.isCancel(confirmed))
138
+ return cancelled(prompts);
139
+ theme = confirmed;
140
+ }
141
+ const proceed = await prompts.confirm({
142
+ message: dryRun
143
+ ? "Preview this configuration?"
144
+ : options.packagesOnly
145
+ ? "Install these packages?"
146
+ : "Set up VeriKit with this configuration?",
147
+ });
148
+ if (prompts.isCancel(proceed) || !proceed)
149
+ return cancelled(prompts);
150
+ // Always non-empty: `server: true` above guarantees at least `@verikit/server` is included.
151
+ const { packages } = resolvePackages({
152
+ server: true,
153
+ ui,
154
+ theme,
155
+ adapter,
156
+ pkg,
157
+ });
158
+ if (dryRun) {
159
+ prompts.log.step(`Would install ${packages.length} package${packages.length === 1 ? "" : "s"}: ${packages.join(", ")}`);
160
+ }
161
+ else if (options.skipInstall) {
162
+ prompts.log.step(`Skipped install (--skip-install): ${packages.join(", ")}`);
163
+ }
164
+ else {
165
+ const spinner = prompts.spinner();
166
+ spinner.start(`Installing ${packages.length} package${packages.length === 1 ? "" : "s"}`);
167
+ const result = await install(packageManager, packages, cwd);
168
+ if (result.ok) {
169
+ spinner.stop("Installed dependencies");
170
+ }
171
+ else {
172
+ spinner.stop("Failed to install dependencies");
173
+ prompts.log.error(result.output.trim().slice(-2000));
174
+ prompts.log.warn(options.packagesOnly
175
+ ? "Install manually to finish setup."
176
+ : "Continuing to generate integration files install manually to finish setup.");
177
+ }
178
+ }
179
+ if (!options.packagesOnly) {
180
+ const srcRoot = detectSrcRoot(cwd);
181
+ const server = generateServer(srcRoot, adapter, dryRun);
182
+ report(prompts, server.serverOutcome, `verikit/server.ts`, relative(cwd, server.serverFile), dryRun);
183
+ report(prompts, server.exampleOutcome, `example resource`, relative(cwd, server.exampleFile), dryRun);
184
+ if (framework.ui === "next") {
185
+ if (framework.appDir) {
186
+ const route = generateNextRoute(framework.appDir, server.serverFile, dryRun);
187
+ report(prompts, route.outcome, "API route", relative(cwd, route.routeFile), dryRun);
188
+ }
189
+ else {
190
+ prompts.log.warn("Pages Router detected VeriKit CLI only wires up the App Router automatically. " +
191
+ "Mount `verikit` from `verikit/server.ts` as a catch-all route handler manually.");
192
+ }
193
+ }
194
+ if (theme) {
195
+ const result = applyTheme(cwd, dryRun);
196
+ if (result.status === "not-found") {
197
+ prompts.log.warn(`Couldn't find a global stylesheet to configure. Add this import to your app's global CSS:\n ${THEME_IMPORT}`);
198
+ }
199
+ else {
200
+ report(prompts, result.status === "inserted" ? "created" : "exists", "theme import", relative(cwd, result.file), dryRun);
201
+ }
202
+ }
203
+ }
204
+ prompts.outro(outroMessage({
205
+ dryRun,
206
+ packagesOnly: Boolean(options.packagesOnly),
207
+ packageManager,
208
+ }));
209
+ }
210
+ function outroMessage(opts) {
211
+ if (opts.dryRun) {
212
+ return opts.packagesOnly
213
+ ? `${logo()} dry run complete nothing was installed.`
214
+ : `${logo()} dry run complete nothing was installed or written.`;
215
+ }
216
+ if (opts.packagesOnly) {
217
+ return `${logo()} packages installed.`;
218
+ }
219
+ return `${logo()} is ready.\n\nRun:\n ${DEV_COMMAND[opts.packageManager]}\n\nDocs:\n verikit.dev/getting-started`;
220
+ }
221
+ function report(prompts, outcome, label, file, dryRun) {
222
+ if (outcome === "created") {
223
+ prompts.log.success(`${dryRun ? "Would create" : "Created"} ${label} (${file})`);
224
+ }
225
+ else {
226
+ prompts.log.step(`${label} already exists, skipping (${file})`);
227
+ }
228
+ }
229
+ function relative(cwd, file) {
230
+ return path.relative(cwd, file);
231
+ }
232
+ function cancelled(prompts) {
233
+ prompts.cancel("Cancelled.");
234
+ throw new InitAbort(0);
235
+ }
@@ -0,0 +1,7 @@
1
+ import { hasDependency } from "./project.js";
2
+ export function detectDatabase(pkg) {
3
+ return {
4
+ prisma: hasDependency(pkg, "@prisma/client") || hasDependency(pkg, "prisma"),
5
+ drizzle: hasDependency(pkg, "drizzle-orm"),
6
+ };
7
+ }
@@ -0,0 +1,25 @@
1
+ import { existsSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { hasDependency } from "./project.js";
4
+ /** Locates a Next.js App Router `app/` directory, preferring `src/app`. Returns its parent (the source root) or `null` if neither exists. */
5
+ function findAppRouterRoot(cwd) {
6
+ if (existsSync(path.join(cwd, "src", "app")))
7
+ return path.join(cwd, "src");
8
+ if (existsSync(path.join(cwd, "app")))
9
+ return cwd;
10
+ return null;
11
+ }
12
+ export function detectFramework(cwd, pkg) {
13
+ const typescript = hasDependency(pkg, "typescript") ||
14
+ existsSync(path.join(cwd, "tsconfig.json"));
15
+ if (hasDependency(pkg, "next")) {
16
+ return { ui: "next", appDir: findAppRouterRoot(cwd), typescript };
17
+ }
18
+ if (hasDependency(pkg, "vue")) {
19
+ return { ui: "vue", appDir: null, typescript };
20
+ }
21
+ if (hasDependency(pkg, "react")) {
22
+ return { ui: "react", appDir: null, typescript };
23
+ }
24
+ return { ui: null, appDir: null, typescript };
25
+ }
@@ -0,0 +1,41 @@
1
+ import { existsSync } from "node:fs";
2
+ import path from "node:path";
3
+ const LOCKFILES = {
4
+ "pnpm-lock.yaml": "pnpm",
5
+ "package-lock.json": "npm",
6
+ "yarn.lock": "yarn",
7
+ "bun.lockb": "bun",
8
+ "bun.lock": "bun",
9
+ };
10
+ /** Detects the package manager from lockfiles in `cwd`, falling back to the `npm_config_user_agent` env var, then npm. */
11
+ export function detectPackageManager(cwd) {
12
+ for (const [file, manager] of Object.entries(LOCKFILES)) {
13
+ if (existsSync(path.join(cwd, file)))
14
+ return manager;
15
+ }
16
+ const userAgent = process.env.npm_config_user_agent;
17
+ if (userAgent) {
18
+ if (userAgent.startsWith("pnpm"))
19
+ return "pnpm";
20
+ if (userAgent.startsWith("yarn"))
21
+ return "yarn";
22
+ if (userAgent.startsWith("bun"))
23
+ return "bun";
24
+ if (userAgent.startsWith("npm"))
25
+ return "npm";
26
+ }
27
+ return "npm";
28
+ }
29
+ /** Builds the install invocation for adding the given packages as production dependencies. */
30
+ export function installCommand(manager, packages) {
31
+ switch (manager) {
32
+ case "pnpm":
33
+ return { command: "pnpm", args: ["add", ...packages] };
34
+ case "yarn":
35
+ return { command: "yarn", args: ["add", ...packages] };
36
+ case "bun":
37
+ return { command: "bun", args: ["add", ...packages] };
38
+ case "npm":
39
+ return { command: "npm", args: ["install", ...packages] };
40
+ }
41
+ }
@@ -0,0 +1,22 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ /** Reads and parses `package.json` from `cwd`, or `null` if it doesn't exist / isn't valid JSON. */
4
+ export function readPackageJson(cwd) {
5
+ const file = path.join(cwd, "package.json");
6
+ if (!existsSync(file))
7
+ return null;
8
+ try {
9
+ return JSON.parse(readFileSync(file, "utf8"));
10
+ }
11
+ catch {
12
+ return null;
13
+ }
14
+ }
15
+ /** True if `name` appears in either `dependencies` or `devDependencies`. */
16
+ export function hasDependency(pkg, name) {
17
+ return Boolean(pkg.dependencies?.[name] ?? pkg.devDependencies?.[name]);
18
+ }
19
+ /** The directory generated source files should live under: `src/` if the project has one, else the project root. */
20
+ export function detectSrcRoot(cwd) {
21
+ return existsSync(path.join(cwd, "src")) ? path.join(cwd, "src") : cwd;
22
+ }
@@ -0,0 +1,22 @@
1
+ import path from "node:path";
2
+ import { writeFileIfAbsent } from "../utils/fs.js";
3
+ /** Generates a Next.js App Router catch-all route that forwards every method to the VeriKit request handler. */
4
+ export function generateNextRoute(appRoot, serverFile, dryRun = false) {
5
+ const routeDir = path.join(appRoot, "app", "api", "verikit", "[...path]");
6
+ const routeFile = path.join(routeDir, "route.ts");
7
+ let importPath = path
8
+ .relative(routeDir, serverFile)
9
+ .replace(/\.ts$/, "")
10
+ .split(path.sep)
11
+ .join("/");
12
+ if (!importPath.startsWith("."))
13
+ importPath = `./${importPath}`;
14
+ const source = `import { verikit } from "${importPath}";
15
+
16
+ export const GET = verikit;
17
+ export const POST = verikit;
18
+ export const PATCH = verikit;
19
+ export const DELETE = verikit;
20
+ `;
21
+ return { routeFile, outcome: writeFileIfAbsent(routeFile, source, dryRun) };
22
+ }
@@ -0,0 +1,38 @@
1
+ import path from "node:path";
2
+ import { writeFileIfAbsent } from "../utils/fs.js";
3
+ const EXAMPLE_RESOURCE = `import { boolean, defineResource, text } from "@verikit/core";
4
+
5
+ export const example = defineResource("example", {
6
+ fields: {
7
+ title: text().required(),
8
+ completed: boolean().default(false),
9
+ },
10
+ });
11
+ `;
12
+ function serverSource(adapter) {
13
+ const adapterNote = adapter === "prisma"
14
+ ? `// Wire up @verikit/prisma's createPrismaAdapter() for each resource's storage, then\n// add the resource below.\n`
15
+ : adapter === "drizzle"
16
+ ? `// Wire up @verikit/drizzle's createDrizzleAdapter() for each resource's storage, then\n// add the resource below.\n`
17
+ : `// Give each resource a storage adapter (see @verikit/prisma or @verikit/drizzle), then\n// add it below.\n`;
18
+ return `import { createServer } from "@verikit/server";
19
+
20
+ ${adapterNote}export const verikit = createServer({
21
+ resources: [
22
+ // {
23
+ // resource: example,
24
+ // adapter: /* your adapter for "example" */,
25
+ // permissions: "open",
26
+ // },
27
+ ],
28
+ });
29
+ `;
30
+ }
31
+ /** Generates `verikit/server.ts` and a starter `verikit/resources/example.ts` under `srcRoot`. Never overwrites existing files. */
32
+ export function generateServer(srcRoot, adapter, dryRun = false) {
33
+ const serverFile = path.join(srcRoot, "verikit", "server.ts");
34
+ const exampleFile = path.join(srcRoot, "verikit", "resources", "example.ts");
35
+ const serverOutcome = writeFileIfAbsent(serverFile, serverSource(adapter), dryRun);
36
+ const exampleOutcome = writeFileIfAbsent(exampleFile, EXAMPLE_RESOURCE, dryRun);
37
+ return { serverFile, serverOutcome, exampleFile, exampleOutcome };
38
+ }
@@ -0,0 +1,25 @@
1
+ import { existsSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { insertLineIfAbsent } from "../utils/fs.js";
4
+ const THEME_IMPORT = '@import "@verikit/theme/globals.css";';
5
+ const CANDIDATE_STYLESHEETS = [
6
+ "src/app/globals.css",
7
+ "app/globals.css",
8
+ "src/styles/globals.css",
9
+ "styles/globals.css",
10
+ "src/index.css",
11
+ "src/style.css",
12
+ ];
13
+ /** Finds the project's global stylesheet and inserts the VeriKit theme import if it's missing. */
14
+ export function applyTheme(cwd, dryRun = false) {
15
+ for (const candidate of CANDIDATE_STYLESHEETS) {
16
+ const file = path.join(cwd, candidate);
17
+ if (!existsSync(file))
18
+ continue;
19
+ // The existsSync check above guarantees insertLineIfAbsent can't return "not-found" here.
20
+ const status = insertLineIfAbsent(file, THEME_IMPORT, dryRun);
21
+ return { status, file };
22
+ }
23
+ return { status: "not-found" };
24
+ }
25
+ export { THEME_IMPORT };
package/dist/index.js ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import { pathToFileURL } from "node:url";
4
+ import { InitAbort, runInit } from "./commands/init.js";
5
+ /**
6
+ * Bridges a commander action to `runInit`, translating a thrown `InitAbort` into
7
+ * `process.exitCode` instead of letting it surface as an unhandled rejection.
8
+ */
9
+ export async function runInitCommand(opts, run = runInit) {
10
+ try {
11
+ await run(opts);
12
+ }
13
+ catch (err) {
14
+ if (err instanceof InitAbort) {
15
+ process.exitCode = err.code;
16
+ return;
17
+ }
18
+ throw err;
19
+ }
20
+ }
21
+ /** `run` overrides what `init`/`install` ultimately call used in tests to avoid driving a real interactive prompt. */
22
+ export function createProgram(run = runInit) {
23
+ const program = new Command();
24
+ program
25
+ .name("verikit")
26
+ .description("Scaffolding CLI for VeriKit")
27
+ .version("0.1.0");
28
+ program
29
+ .command("init")
30
+ .description("Detect your stack, install VeriKit packages, and generate the integration")
31
+ .option("--skip-install", "Generate files without installing dependencies")
32
+ .option("--dry-run", "Show what would be installed and generated without changing anything")
33
+ .action((opts) => runInitCommand(opts, run));
34
+ program
35
+ .command("install")
36
+ .description("Install VeriKit packages for your detected stack, without generating integration files")
37
+ .option("--dry-run", "Show what would be installed without changing anything")
38
+ .action((opts) => runInitCommand({ ...opts, packagesOnly: true }, run));
39
+ return program;
40
+ }
41
+ /* node:coverage disable */
42
+ const isMain = typeof process.argv[1] === "string" &&
43
+ import.meta.url === pathToFileURL(process.argv[1]).href;
44
+ if (isMain) {
45
+ void createProgram().parseAsync(process.argv);
46
+ }
47
+ /* node:coverage enable */
@@ -0,0 +1,43 @@
1
+ import { hasDependency } from "../detect/project.js";
2
+ /**
3
+ * Top-level dependencies required by each capability. Kept explicit because
4
+ * generated integrations may import packages directly, which isolated
5
+ * node_modules setups don't expose transitively.
6
+ *
7
+ * Keep in sync with the framework's @verikit/* versions.
8
+ */
9
+ const VERIKIT_VERSION = "^0.23.1";
10
+ function verikit(...names) {
11
+ return names.map((name) => `@verikit/${name}@${VERIKIT_VERSION}`);
12
+ }
13
+ /** Strips a trailing `@version` from an install spec, e.g. `"@verikit/react@^0.23.1"` -> `"@verikit/react"`. */
14
+ function bareName(spec) {
15
+ const at = spec.lastIndexOf("@");
16
+ return at > 0 ? spec.slice(0, at) : spec;
17
+ }
18
+ export function resolvePackages(selection) {
19
+ const packages = [];
20
+ const add = (...specs) => {
21
+ for (const spec of specs) {
22
+ if (!hasDependency(selection.pkg, bareName(spec)))
23
+ packages.push(spec);
24
+ }
25
+ };
26
+ if (selection.server)
27
+ add(...verikit("server"));
28
+ if (selection.ui === "react" || selection.ui === "next") {
29
+ add(...verikit("react"), "@tanstack/react-query", "@tanstack/react-form", "@tanstack/react-table", "@base-ui/react");
30
+ if (selection.theme)
31
+ add(...verikit("theme"));
32
+ }
33
+ else if (selection.ui === "vue") {
34
+ add(...verikit("vue"), "@tanstack/vue-query", "@tanstack/vue-form", "@tanstack/vue-table", "reka-ui");
35
+ if (selection.theme)
36
+ add(...verikit("theme"));
37
+ }
38
+ if (selection.adapter === "prisma")
39
+ add(...verikit("prisma"));
40
+ if (selection.adapter === "drizzle")
41
+ add(...verikit("drizzle"));
42
+ return { packages };
43
+ }
@@ -0,0 +1,21 @@
1
+ import { spawn } from "node:child_process";
2
+ import { installCommand, } from "../detect/package-manager.js";
3
+ /** Runs `command args` in `cwd`, capturing combined stdout/stderr. Never rejects. */
4
+ export function runCommand(command, args, cwd) {
5
+ return new Promise((resolve) => {
6
+ const child = spawn(command, args, {
7
+ cwd,
8
+ shell: process.platform === "win32",
9
+ });
10
+ let output = "";
11
+ child.stdout?.on("data", (chunk) => (output += chunk));
12
+ child.stderr?.on("data", (chunk) => (output += chunk));
13
+ child.on("error", (err) => resolve({ ok: false, output: String(err) }));
14
+ child.on("close", (code) => resolve({ ok: code === 0, output }));
15
+ });
16
+ }
17
+ /** Runs the package manager's add/install command for `packages` in `cwd`, capturing output. */
18
+ export function installPackages(manager, packages, cwd, run = runCommand) {
19
+ const { command, args } = installCommand(manager, packages);
20
+ return run(command, args, cwd);
21
+ }
@@ -0,0 +1,6 @@
1
+ import pc from "picocolors";
2
+ /** The colored "VeriKit" wordmark used in the CLI's intro/outro banners. */
3
+ export function logo(suffix) {
4
+ const word = pc.bold(`${pc.cyan("Veri")}${pc.magenta("Kit")}`);
5
+ return suffix ? `${word} ${pc.dim(suffix)}` : word;
6
+ }
@@ -0,0 +1,29 @@
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ /**
4
+ * Writes `contents` to `file`, creating parent directories as needed. Never overwrites an
5
+ * existing file. With `dryRun`, reports what would happen without touching the filesystem.
6
+ */
7
+ export function writeFileIfAbsent(file, contents, dryRun = false) {
8
+ if (existsSync(file))
9
+ return "exists";
10
+ if (!dryRun) {
11
+ mkdirSync(path.dirname(file), { recursive: true });
12
+ writeFileSync(file, contents, "utf8");
13
+ }
14
+ return "created";
15
+ }
16
+ /**
17
+ * Inserts `line` at the top of `file` if it isn't already present anywhere in the file. With
18
+ * `dryRun`, reports what would happen without touching the filesystem.
19
+ */
20
+ export function insertLineIfAbsent(file, line, dryRun = false) {
21
+ if (!existsSync(file))
22
+ return "not-found";
23
+ const contents = readFileSync(file, "utf8");
24
+ if (contents.includes(line))
25
+ return "already-present";
26
+ if (!dryRun)
27
+ writeFileSync(file, `${line}\n${contents}`, "utf8");
28
+ return "inserted";
29
+ }
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@verikit/cli",
3
+ "version": "0.1.0",
4
+ "description": "Scaffolding CLI for VeriKit detects your stack, installs the right packages, and wires up the integration.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Chidi E <hi@ceeso.dev>",
8
+ "bin": {
9
+ "verikit": "./dist/index.js"
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "engines": {
15
+ "node": ">=18.18"
16
+ },
17
+ "dependencies": {
18
+ "@clack/prompts": "^1.7.0",
19
+ "commander": "^15.0.0",
20
+ "picocolors": "^1.1.1"
21
+ },
22
+ "devDependencies": {
23
+ "@eslint/js": "^10.0.1",
24
+ "@types/node": "^22.10.2",
25
+ "eslint": "^10.7.0",
26
+ "eslint-config-prettier": "^10.1.8",
27
+ "globals": "^17.7.0",
28
+ "prettier": "^3.9.6",
29
+ "tsx": "^4.23.12",
30
+ "typescript": "^6.0.3",
31
+ "typescript-eslint": "^8.63.0"
32
+ },
33
+ "scripts": {
34
+ "build": "tsc -p tsconfig.json",
35
+ "dev": "tsx src/index.ts",
36
+ "typecheck": "tsc --noEmit",
37
+ "lint": "eslint .",
38
+ "format": "prettier --write .",
39
+ "format:check": "prettier --check .",
40
+ "test": "rm -rf .test-dist && tsc -p tsconfig.test.json && node --test $(find ./.test-dist/test -name '*.test.js' -type f | sort)",
41
+ "test:coverage": "rm -rf .test-dist coverage && tsc -p tsconfig.test.json && node --test --experimental-test-coverage --test-coverage-lines=100 --test-coverage-branches=100 --test-coverage-functions=100 $(find ./.test-dist/test -name '*.test.js' -type f | sort)",
42
+ "verify": "pnpm typecheck && pnpm lint && pnpm build && pnpm format:check && pnpm test:coverage"
43
+ }
44
+ }