@verikit/cli 0.2.2 → 0.25.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.
Files changed (48) hide show
  1. package/bin/verikit.js +4 -0
  2. package/dist/cli.d.ts +10 -0
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/cli.js +97 -0
  5. package/dist/field-spec.d.ts +17 -0
  6. package/dist/field-spec.d.ts.map +1 -0
  7. package/dist/field-spec.js +64 -0
  8. package/dist/imports.d.ts +14 -0
  9. package/dist/imports.d.ts.map +1 -0
  10. package/dist/imports.js +12 -0
  11. package/dist/index.d.ts +3 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +7 -52
  14. package/dist/load-resources.d.ts +38 -0
  15. package/dist/load-resources.d.ts.map +1 -0
  16. package/dist/load-resources.js +71 -0
  17. package/dist/names.d.ts +21 -0
  18. package/dist/names.d.ts.map +1 -0
  19. package/dist/names.js +73 -0
  20. package/dist/project.d.ts +41 -0
  21. package/dist/project.d.ts.map +1 -0
  22. package/dist/project.js +196 -0
  23. package/dist/render-registry.d.ts +20 -0
  24. package/dist/render-registry.d.ts.map +1 -0
  25. package/dist/render-registry.js +86 -0
  26. package/dist/render-resource.d.ts +26 -0
  27. package/dist/render-resource.d.ts.map +1 -0
  28. package/dist/render-resource.js +141 -0
  29. package/dist/render-schema.d.ts +13 -0
  30. package/dist/render-schema.d.ts.map +1 -0
  31. package/dist/render-schema.js +172 -0
  32. package/dist/wire-actions.d.ts +18 -0
  33. package/dist/wire-actions.d.ts.map +1 -0
  34. package/dist/wire-actions.js +32 -0
  35. package/package.json +30 -32
  36. package/README.md +0 -73
  37. package/dist/commands/init.js +0 -235
  38. package/dist/detect/database.js +0 -7
  39. package/dist/detect/framework.js +0 -25
  40. package/dist/detect/package-manager.js +0 -41
  41. package/dist/detect/project.js +0 -22
  42. package/dist/generators/route.js +0 -22
  43. package/dist/generators/server.js +0 -38
  44. package/dist/generators/theme.js +0 -25
  45. package/dist/install/capabilities.js +0 -45
  46. package/dist/install/dependencies.js +0 -21
  47. package/dist/utils/banner.js +0 -6
  48. package/dist/utils/fs.js +0 -29
@@ -0,0 +1,18 @@
1
+ /** What happened when connecting a resource to its action declarations. */
2
+ export type WireResult = {
3
+ status: "already";
4
+ } | {
5
+ status: "wired";
6
+ source: string;
7
+ } | {
8
+ status: "manual";
9
+ reason: string;
10
+ };
11
+ /**
12
+ * Adds `import * as <namespace> from "<module>"` and
13
+ * `actions: Object.values(<namespace>)` to the `defineResource(name, {` call in
14
+ * `source`. It edits only when the call has the layout `make:resource` writes,
15
+ * and reports `manual` otherwise so the user can add the two lines.
16
+ */
17
+ export declare function wireResourceActions(source: string, resourceName: string, actionsModule: string, namespace: string): WireResult;
18
+ //# sourceMappingURL=wire-actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wire-actions.d.ts","sourceRoot":"","sources":["../src/wire-actions.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,MAAM,MAAM,UAAU,GAClB;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GACrB;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAMzC;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,GAChB,UAAU,CA+BZ"}
@@ -0,0 +1,32 @@
1
+ function escapeRegExp(text) {
2
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3
+ }
4
+ /**
5
+ * Adds `import * as <namespace> from "<module>"` and
6
+ * `actions: Object.values(<namespace>)` to the `defineResource(name, {` call in
7
+ * `source`. It edits only when the call has the layout `make:resource` writes,
8
+ * and reports `manual` otherwise so the user can add the two lines.
9
+ */
10
+ export function wireResourceActions(source, resourceName, actionsModule, namespace) {
11
+ if (source.includes(`"${actionsModule}"`)) {
12
+ return { status: "already" };
13
+ }
14
+ const call = new RegExp(`defineResource\\(\\s*["'\`]${escapeRegExp(resourceName)}["'\`]\\s*,\\s*\\{[ \\t]*\\n`).exec(source);
15
+ if (!call) {
16
+ return {
17
+ status: "manual",
18
+ reason: `couldn't find defineResource("${resourceName}", {`,
19
+ };
20
+ }
21
+ const configStart = call.index + call[0].length;
22
+ if (/^\s*actions\s*:/m.test(source.slice(configStart))) {
23
+ return { status: "manual", reason: "it already sets `actions`" };
24
+ }
25
+ const withActions = `${source.slice(0, configStart)} actions: Object.values(${namespace}),\n${source.slice(configStart)}`;
26
+ const imports = [...withActions.matchAll(/^import [^;]*;\n/gm)];
27
+ const importEnd = imports.length > 0 ? imports.at(-1).index + imports.at(-1)[0].length : 0;
28
+ return {
29
+ status: "wired",
30
+ source: `${withActions.slice(0, importEnd)}import * as ${namespace} from "${actionsModule}";\n${withActions.slice(importEnd)}`,
31
+ };
32
+ }
package/package.json CHANGED
@@ -1,48 +1,46 @@
1
1
  {
2
2
  "name": "@verikit/cli",
3
- "version": "0.2.2",
4
- "description": "Scaffolding CLI for VeriKit detects your stack, installs the right packages, and wires up the integration.",
3
+ "version": "0.25.0",
4
+ "description": "Generators for Verikit apps: make:resource, make:action, and generate:schema.",
5
+ "type": "module",
6
+ "bin": {
7
+ "verikit": "./bin/verikit.js"
8
+ },
9
+ "keywords": [
10
+ "typescript",
11
+ "resource",
12
+ "framework",
13
+ "verikit",
14
+ "cli",
15
+ "generator",
16
+ "drizzle"
17
+ ],
18
+ "author": "Chidi E <hi@ceeso.dev>",
19
+ "license": "MIT",
5
20
  "repository": {
6
21
  "type": "git",
7
- "url": "git+https://github.com/verikit-project/verikit-cli.git"
22
+ "url": "https://github.com/verikit-project/verikit",
23
+ "directory": "packages/cli"
8
24
  },
9
- "type": "module",
10
- "license": "MIT",
11
- "author": "Chidi E <hi@ceeso.dev>",
12
- "bin": {
13
- "verikit": "./dist/index.js"
25
+ "engines": {
26
+ "node": ">=24"
14
27
  },
15
28
  "files": [
29
+ "bin",
16
30
  "dist"
17
31
  ],
18
- "engines": {
19
- "node": ">=18.18"
20
- },
21
- "dependencies": {
22
- "@clack/prompts": "^1.7.0",
23
- "commander": "^15.0.0",
24
- "picocolors": "^1.1.1"
25
- },
26
32
  "devDependencies": {
27
- "@eslint/js": "^10.0.1",
28
- "@types/node": "^22.10.2",
29
- "eslint": "^10.7.0",
30
- "eslint-config-prettier": "^10.1.8",
31
- "globals": "^17.7.0",
32
- "prettier": "^3.9.6",
33
- "tsx": "^4.23.12",
33
+ "@types/node": "^26.1.1",
34
+ "drizzle-orm": "^0.45.2",
34
35
  "typescript": "^6.0.3",
35
- "typescript-eslint": "^8.63.0"
36
+ "@verikit/core": "0.25.0",
37
+ "@verikit/runtime": "0.25.0",
38
+ "@verikit/server": "0.25.0"
36
39
  },
37
40
  "scripts": {
38
- "build": "tsc -p tsconfig.json",
39
- "dev": "tsx src/index.ts",
40
- "typecheck": "tsc --noEmit",
41
- "lint": "eslint .",
42
- "format": "prettier --write .",
43
- "format:check": "prettier --check .",
41
+ "clean": "rm -rf dist tsconfig.tsbuildinfo",
42
+ "build": "pnpm clean && tsc -b",
44
43
  "test": "rm -rf .test-dist && tsc -p tsconfig.test.json && node --test $(find ./.test-dist/test -name '*.test.js' -type f | sort)",
45
- "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)",
46
- "verify": "pnpm typecheck && pnpm lint && pnpm build && pnpm format:check && pnpm test:coverage"
44
+ "test:coverage": "rm -rf .test-dist coverage && tsc -p tsconfig.test.json && node --test --experimental-test-coverage --test-coverage-include='.test-dist/src/**/*.js' --test-coverage-lines=100 --test-coverage-branches=100 --test-coverage-functions=100 $(find ./.test-dist/test -name '*.test.js' -type f | sort)"
47
45
  }
48
46
  }
package/README.md DELETED
@@ -1,73 +0,0 @@
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).
@@ -1,235 +0,0 @@
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
- }
@@ -1,7 +0,0 @@
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
- }
@@ -1,25 +0,0 @@
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") || hasDependency(pkg, "nuxt")) {
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
- }
@@ -1,41 +0,0 @@
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
- }
@@ -1,22 +0,0 @@
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
- }
@@ -1,22 +0,0 @@
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
- }
@@ -1,38 +0,0 @@
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
- }
@@ -1,25 +0,0 @@
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 };