nx-factory-cli 2.1.3 → 2.1.5
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/dist/commands/add-app.d.ts +10 -0
- package/dist/commands/add-app.d.ts.map +1 -0
- package/dist/commands/add-app.js +392 -0
- package/dist/commands/add-app.js.map +1 -0
- package/dist/commands/add-auth.d.ts +8 -0
- package/dist/commands/add-auth.d.ts.map +1 -0
- package/dist/commands/add-auth.js +182 -0
- package/dist/commands/add-auth.js.map +1 -0
- package/dist/commands/add-component.d.ts +2 -0
- package/dist/commands/add-component.d.ts.map +1 -0
- package/dist/commands/add-component.js +116 -0
- package/dist/commands/add-component.js.map +1 -0
- package/dist/commands/add-lib.d.ts +9 -0
- package/dist/commands/add-lib.d.ts.map +1 -0
- package/dist/commands/add-lib.js +190 -0
- package/dist/commands/add-lib.js.map +1 -0
- package/dist/commands/add-storybook.d.ts +6 -0
- package/dist/commands/add-storybook.d.ts.map +1 -0
- package/dist/commands/add-storybook.js +181 -0
- package/dist/commands/add-storybook.js.map +1 -0
- package/dist/commands/doctor.d.ts +2 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +235 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/init.d.ts +9 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +527 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/list.d.ts +2 -0
- package/dist/commands/list.d.ts.map +1 -0
- package/dist/commands/list.js +130 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/publish.d.ts +8 -0
- package/dist/commands/publish.d.ts.map +1 -0
- package/dist/commands/publish.js +179 -0
- package/dist/commands/publish.js.map +1 -0
- package/dist/commands/remove-component.d.ts +5 -0
- package/dist/commands/remove-component.d.ts.map +1 -0
- package/dist/commands/remove-component.js +172 -0
- package/dist/commands/remove-component.js.map +1 -0
- package/dist/commands/update.d.ts +5 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +126 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/config.d.ts +14 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +35 -0
- package/dist/config.js.map +1 -0
- package/dist/exec.d.ts +25 -0
- package/dist/exec.d.ts.map +1 -0
- package/dist/exec.js +80 -0
- package/dist/exec.js.map +1 -0
- package/dist/files.d.ts +7 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +23 -0
- package/dist/files.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +93 -42127
- package/dist/index.js.map +1 -0
- package/dist/resolve-root.d.ts +22 -0
- package/dist/resolve-root.d.ts.map +1 -0
- package/dist/resolve-root.js +65 -0
- package/dist/resolve-root.js.map +1 -0
- package/dist/setups/auth/base.d.ts +11 -0
- package/dist/setups/auth/base.d.ts.map +1 -0
- package/dist/setups/auth/base.js +91 -0
- package/dist/setups/auth/base.js.map +1 -0
- package/dist/setups/auth/index.d.ts +6 -0
- package/dist/setups/auth/index.d.ts.map +1 -0
- package/dist/setups/auth/index.js +5 -0
- package/dist/setups/auth/index.js.map +1 -0
- package/dist/setups/auth/systems/better-auth.d.ts +3 -0
- package/dist/setups/auth/systems/better-auth.d.ts.map +1 -0
- package/dist/setups/auth/systems/better-auth.js +357 -0
- package/dist/setups/auth/systems/better-auth.js.map +1 -0
- package/dist/setups/auth/systems/clerk.d.ts +3 -0
- package/dist/setups/auth/systems/clerk.d.ts.map +1 -0
- package/dist/setups/auth/systems/clerk.js +259 -0
- package/dist/setups/auth/systems/clerk.js.map +1 -0
- package/dist/setups/auth/systems/workos.d.ts +3 -0
- package/dist/setups/auth/systems/workos.d.ts.map +1 -0
- package/dist/setups/auth/systems/workos.js +273 -0
- package/dist/setups/auth/systems/workos.js.map +1 -0
- package/dist/setups/auth/types.d.ts +39 -0
- package/dist/setups/auth/types.d.ts.map +1 -0
- package/dist/setups/auth/types.js +2 -0
- package/dist/setups/auth/types.js.map +1 -0
- package/dist/ui.d.ts +44 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +149 -0
- package/dist/ui.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAiB,oBAAoB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAe,uBAAuB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAS,6BAA6B,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAe,sBAAsB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAiB,oBAAoB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAe,sBAAsB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAe,uBAAuB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAS,6BAA6B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAc,uBAAuB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAc,wBAAwB,CAAC;AAEhE,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,WAAW,EAAE,CAAC;AAEd,OAAO;KACJ,IAAI,CAAC,YAAY,CAAC;KAClB,WAAW,CAAC,uEAAuE,CAAC;KACpF,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO;KACJ,OAAO,CAAC,MAAM,CAAC;KACf,WAAW,CAAC,uDAAuD,CAAC;KACpE,MAAM,CAAC,gBAAgB,EAAe,gBAAgB,CAAC;KACvD,MAAM,CAAC,6BAA6B,EAAE,qCAA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MAAM,CAAC,WAAW,EAAkB,mCAAmC,CAAC;KACxE,MAAM,CAAC,WAAW,EAAkB,wDAAwD,CAAC;KAC7F,MAAM,CAAC,cAAc,CAAC,CAAC;AAE1B,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves the monorepo root from any working directory.
|
|
3
|
+
*
|
|
4
|
+
* Strategy (in order):
|
|
5
|
+
* 1. Walk up from process.cwd() looking for nx-factory.config.json
|
|
6
|
+
* 2. Walk up looking for nx.json (an Nx workspace marker)
|
|
7
|
+
* 3. Walk up looking for a package.json that has a "workspaces" field
|
|
8
|
+
* 4. Fall back to process.cwd() with a warning
|
|
9
|
+
*
|
|
10
|
+
* Returns the absolute path to the monorepo root.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveMonorepoRoot(): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Asserts we can find a monorepo root and returns it.
|
|
15
|
+
* Throws a structured error if we can only fall back to cwd and cwd doesn't
|
|
16
|
+
* look like a monorepo root (no package.json at all).
|
|
17
|
+
*/
|
|
18
|
+
export declare function requireMonorepoRoot(): Promise<string>;
|
|
19
|
+
export declare class MonorepoRootNotFoundError extends Error {
|
|
20
|
+
constructor(cwd: string);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=resolve-root.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-root.d.ts","sourceRoot":"","sources":["../src/resolve-root.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,CA6B3D;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,CAM3D;AAED,qBAAa,yBAA0B,SAAQ,KAAK;gBACtC,GAAG,EAAE,MAAM;CAOxB"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { pathExists } from "./files.js";
|
|
3
|
+
import { findConfig } from "./config.js";
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the monorepo root from any working directory.
|
|
6
|
+
*
|
|
7
|
+
* Strategy (in order):
|
|
8
|
+
* 1. Walk up from process.cwd() looking for nx-factory.config.json
|
|
9
|
+
* 2. Walk up looking for nx.json (an Nx workspace marker)
|
|
10
|
+
* 3. Walk up looking for a package.json that has a "workspaces" field
|
|
11
|
+
* 4. Fall back to process.cwd() with a warning
|
|
12
|
+
*
|
|
13
|
+
* Returns the absolute path to the monorepo root.
|
|
14
|
+
*/
|
|
15
|
+
export async function resolveMonorepoRoot() {
|
|
16
|
+
// Strategy 1: nx-factory.config.json
|
|
17
|
+
const configFile = await findConfig();
|
|
18
|
+
if (configFile) {
|
|
19
|
+
return path.dirname(configFile);
|
|
20
|
+
}
|
|
21
|
+
// Strategy 2 & 3: walk up from cwd
|
|
22
|
+
let dir = process.cwd();
|
|
23
|
+
for (let i = 0; i < 8; i++) {
|
|
24
|
+
if (await pathExists(path.join(dir, "nx.json"))) {
|
|
25
|
+
return dir;
|
|
26
|
+
}
|
|
27
|
+
if (await pathExists(path.join(dir, "package.json"))) {
|
|
28
|
+
const { default: fs } = await import("fs-extra");
|
|
29
|
+
try {
|
|
30
|
+
const pkg = await fs.readJson(path.join(dir, "package.json"));
|
|
31
|
+
if (pkg.workspaces)
|
|
32
|
+
return dir;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// malformed package.json — keep walking
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const parent = path.dirname(dir);
|
|
39
|
+
if (parent === dir)
|
|
40
|
+
break;
|
|
41
|
+
dir = parent;
|
|
42
|
+
}
|
|
43
|
+
// Fallback: use cwd (will work if user IS at the root)
|
|
44
|
+
return process.cwd();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Asserts we can find a monorepo root and returns it.
|
|
48
|
+
* Throws a structured error if we can only fall back to cwd and cwd doesn't
|
|
49
|
+
* look like a monorepo root (no package.json at all).
|
|
50
|
+
*/
|
|
51
|
+
export async function requireMonorepoRoot() {
|
|
52
|
+
const root = await resolveMonorepoRoot();
|
|
53
|
+
if (!(await pathExists(path.join(root, "package.json")))) {
|
|
54
|
+
throw new MonorepoRootNotFoundError(process.cwd());
|
|
55
|
+
}
|
|
56
|
+
return root;
|
|
57
|
+
}
|
|
58
|
+
export class MonorepoRootNotFoundError extends Error {
|
|
59
|
+
constructor(cwd) {
|
|
60
|
+
super(`Could not find a monorepo root from: ${cwd}\n` +
|
|
61
|
+
`Make sure you are inside an nx-factory workspace, or run 'nx-factory init' first.`);
|
|
62
|
+
this.name = "MonorepoRootNotFoundError";
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=resolve-root.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-root.js","sourceRoot":"","sources":["../src/resolve-root.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAmB,UAAU,EAAE,MAAM,aAAa,CAAC;AAE1D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACvC,qCAAqC;IACrC,MAAM,UAAU,GAAG,MAAM,UAAU,EAAE,CAAC;IACtC,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IAED,mCAAmC;IACnC,IAAI,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IACxB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,IAAI,MAAM,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,EAAE,CAA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
|
|
|
1
|
+
import type { AuthPackageScaffolder } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Writes the boilerplate every auth package needs:
|
|
4
|
+
* packages/auth/package.json
|
|
5
|
+
* packages/auth/tsconfig.json
|
|
6
|
+
* packages/auth/tsup.config.ts
|
|
7
|
+
*
|
|
8
|
+
* The caller (provider scaffolder) writes the src/ files on top of this.
|
|
9
|
+
*/
|
|
10
|
+
export declare function writeAuthPackageBase(pkgDir: string, scaffolder: AuthPackageScaffolder, pm: string): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/setups/auth/base.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAM,MAAM,EAClB,UAAU,EAAE,qBAAqB,EACjC,EAAE,EAAU,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAqFf"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { writeJson, writeFile } from "../../files.js";
|
|
3
|
+
/**
|
|
4
|
+
* Writes the boilerplate every auth package needs:
|
|
5
|
+
* packages/auth/package.json
|
|
6
|
+
* packages/auth/tsconfig.json
|
|
7
|
+
* packages/auth/tsup.config.ts
|
|
8
|
+
*
|
|
9
|
+
* The caller (provider scaffolder) writes the src/ files on top of this.
|
|
10
|
+
*/
|
|
11
|
+
export async function writeAuthPackageBase(pkgDir, scaffolder, pm) {
|
|
12
|
+
// ── package.json ────────────────────────────────────────────────────────────
|
|
13
|
+
await writeJson(path.join(pkgDir, "package.json"), {
|
|
14
|
+
name: "@workspace/auth",
|
|
15
|
+
version: "0.0.1",
|
|
16
|
+
private: true,
|
|
17
|
+
type: "module",
|
|
18
|
+
exports: {
|
|
19
|
+
".": {
|
|
20
|
+
import: "./dist/index.js",
|
|
21
|
+
types: "./dist/index.d.ts",
|
|
22
|
+
},
|
|
23
|
+
// Named sub-paths so apps can do: import { ... } from "@workspace/auth/server"
|
|
24
|
+
"./server": {
|
|
25
|
+
import: "./dist/server.js",
|
|
26
|
+
types: "./dist/server.d.ts",
|
|
27
|
+
},
|
|
28
|
+
"./client": {
|
|
29
|
+
import: "./dist/client.js",
|
|
30
|
+
types: "./dist/client.d.ts",
|
|
31
|
+
},
|
|
32
|
+
"./middleware": {
|
|
33
|
+
import: "./dist/middleware.js",
|
|
34
|
+
types: "./dist/middleware.d.ts",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
main: "./dist/index.js",
|
|
38
|
+
types: "./dist/index.d.ts",
|
|
39
|
+
scripts: {
|
|
40
|
+
build: "tsup",
|
|
41
|
+
"build:watch": "tsup --watch",
|
|
42
|
+
typecheck: "tsc --noEmit",
|
|
43
|
+
},
|
|
44
|
+
dependencies: scaffolder.dependencies,
|
|
45
|
+
devDependencies: {
|
|
46
|
+
...scaffolder.devDependencies,
|
|
47
|
+
tsup: "^8.3.0",
|
|
48
|
+
typescript: "^5.6.0",
|
|
49
|
+
},
|
|
50
|
+
peerDependencies: scaffolder.peerDependencies,
|
|
51
|
+
});
|
|
52
|
+
// ── tsconfig.json ───────────────────────────────────────────────────────────
|
|
53
|
+
await writeJson(path.join(pkgDir, "tsconfig.json"), {
|
|
54
|
+
extends: "../../tsconfig.base.json",
|
|
55
|
+
compilerOptions: {
|
|
56
|
+
target: "ES2022",
|
|
57
|
+
module: "ESNext",
|
|
58
|
+
moduleResolution: "bundler",
|
|
59
|
+
jsx: "react-jsx",
|
|
60
|
+
strict: true,
|
|
61
|
+
declaration: true,
|
|
62
|
+
declarationMap: true,
|
|
63
|
+
sourceMap: true,
|
|
64
|
+
esModuleInterop: true,
|
|
65
|
+
skipLibCheck: true,
|
|
66
|
+
outDir: "dist",
|
|
67
|
+
rootDir: "src",
|
|
68
|
+
},
|
|
69
|
+
include: ["src"],
|
|
70
|
+
exclude: ["node_modules", "dist"],
|
|
71
|
+
});
|
|
72
|
+
// ── tsup.config.ts ──────────────────────────────────────────────────────────
|
|
73
|
+
await writeFile(path.join(pkgDir, "tsup.config.ts"), `import { defineConfig } from "tsup";
|
|
74
|
+
|
|
75
|
+
export default defineConfig({
|
|
76
|
+
entry: {
|
|
77
|
+
index: "src/index.ts",
|
|
78
|
+
server: "src/server.ts",
|
|
79
|
+
client: "src/client.ts",
|
|
80
|
+
middleware: "src/middleware.ts",
|
|
81
|
+
},
|
|
82
|
+
format: ["esm"],
|
|
83
|
+
dts: true,
|
|
84
|
+
sourcemap: true,
|
|
85
|
+
clean: true,
|
|
86
|
+
treeshake: true,
|
|
87
|
+
external: ["react", "react-dom"],
|
|
88
|
+
});
|
|
89
|
+
`);
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/setups/auth/base.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGtD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,MAAkB,EAClB,UAAiC,EACjC,EAAkB;IAGlB,+EAA+E;IAC/E,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE;QACjD,IAAI,EAAK,iBAAiB;QAC1B,OAAO,EAAE,OAAO;QAChB,OAAO,EAAE,IAAI;QACb,IAAI,EAAK,QAAQ;QACjB,OAAO,EAAE;YACP,GAAG,EAAE;gBACH,MAAM,EAAE,iBAAiB;gBACzB,KAAK,EAAG,mBAAmB;aAC5B;YACD,gFAAgF;YAChF,UAAU,EAAE;gBACV,MAAM,EAAE,kBAAkB;gBAC1B,KAAK,EAAG,oB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6 @@
|
|
|
1
|
+
export { clerkScaffolder } from "./systems/clerk";
|
|
2
|
+
export { betterAuthScaffolder } from "./systems/better-auth";
|
|
3
|
+
export { workosScaffolder } from "./systems/workos";
|
|
4
|
+
export { writeAuthPackageBase } from "./base";
|
|
5
|
+
export type { AuthProvider, AuthPackageOptions, AuthPackageScaffolder } from "./types";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/setups/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAW,iBAAiB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAU,kBAAkB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAC9C,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/setups/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAW,iBAAiB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAU,kBAAkB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"better-auth.d.ts","sourceRoot":"","sources":["../../../../src/setups/auth/systems/better-auth.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAsB,MAAM,aAAa,CAAC;AAE7E,eAAO,MAAM,oBAAoB,EAAE,qBAiYlC,CAAC"}
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { writeFile, ensureDir } from "../../../files";
|
|
3
|
+
export const betterAuthScaffolder = {
|
|
4
|
+
label: "Better Auth",
|
|
5
|
+
dependencies: {
|
|
6
|
+
"better-auth": "latest",
|
|
7
|
+
},
|
|
8
|
+
devDependencies: {
|
|
9
|
+
"@types/react": "^19.0.0",
|
|
10
|
+
},
|
|
11
|
+
peerDependencies: {
|
|
12
|
+
react: "^18 || ^19",
|
|
13
|
+
"react-dom": "^18 || ^19",
|
|
14
|
+
},
|
|
15
|
+
async scaffold(pkgDir, _opts) {
|
|
16
|
+
await ensureDir(path.join(pkgDir, "src"));
|
|
17
|
+
// ── src/index.ts ──────────────────────────────────────────────────────────
|
|
18
|
+
await writeFile(path.join(pkgDir, "src/index.ts"), `/**
|
|
19
|
+
* @workspace/auth — Better Auth v1.2+
|
|
20
|
+
*
|
|
21
|
+
* Prefer sub-path imports for tree-shaking:
|
|
22
|
+
* import { auth } from "@workspace/auth/server"
|
|
23
|
+
* import { authClient } from "@workspace/auth/client"
|
|
24
|
+
* import { authMiddleware } from "@workspace/auth/middleware"
|
|
25
|
+
*/
|
|
26
|
+
export * from "./server.js";
|
|
27
|
+
export * from "./client.js";
|
|
28
|
+
`);
|
|
29
|
+
// ── src/server.ts ─────────────────────────────────────────────────────────
|
|
30
|
+
// better-auth v1.2: betterAuth() config, database adapters, plugins
|
|
31
|
+
await writeFile(path.join(pkgDir, "src/server.ts"), `/**
|
|
32
|
+
* Better Auth @latest — server instance.
|
|
33
|
+
*
|
|
34
|
+
* This file is the single source of truth for your auth configuration.
|
|
35
|
+
* Import \`auth\` in API routes, server components, and middleware.
|
|
36
|
+
*
|
|
37
|
+
* @example Next.js App Router (Server Component)
|
|
38
|
+
* import { auth } from "@workspace/auth/server";
|
|
39
|
+
* import { headers } from "next/headers";
|
|
40
|
+
*
|
|
41
|
+
* const session = await auth.api.getSession({ headers: await headers() });
|
|
42
|
+
*
|
|
43
|
+
* @example Next.js Route Handler
|
|
44
|
+
* import { auth } from "@workspace/auth/server";
|
|
45
|
+
* import { toNextJsHandler } from "better-auth/next-js";
|
|
46
|
+
* export const { GET, POST } = toNextJsHandler(auth.handler);
|
|
47
|
+
*
|
|
48
|
+
* @example Remix loader
|
|
49
|
+
* import { auth } from "@workspace/auth/server";
|
|
50
|
+
* const session = await auth.api.getSession({ headers: request.headers });
|
|
51
|
+
*/
|
|
52
|
+
import { betterAuth } from "better-auth";
|
|
53
|
+
|
|
54
|
+
export const auth = betterAuth({
|
|
55
|
+
/**
|
|
56
|
+
* Database adapter.
|
|
57
|
+
*
|
|
58
|
+
* Default: in-memory (development only — data is lost on restart).
|
|
59
|
+
* For production, pick one:
|
|
60
|
+
*
|
|
61
|
+
* PostgreSQL:
|
|
62
|
+
* import { pg } from "better-auth/adapters/pg";
|
|
63
|
+
* database: pg({ connectionString: process.env.DATABASE_URL! }),
|
|
64
|
+
*
|
|
65
|
+
* MySQL:
|
|
66
|
+
* import { mysql } from "better-auth/adapters/mysql";
|
|
67
|
+
* database: mysql({ uri: process.env.DATABASE_URL! }),
|
|
68
|
+
*
|
|
69
|
+
* SQLite (local dev):
|
|
70
|
+
* import { sqlite } from "better-auth/adapters/sqlite";
|
|
71
|
+
* import Database from "better-sqlite3";
|
|
72
|
+
* database: sqlite(new Database("./dev.db")),
|
|
73
|
+
*
|
|
74
|
+
* Prisma:
|
|
75
|
+
* import { prismaAdapter } from "better-auth/adapters/prisma";
|
|
76
|
+
* import { prisma } from "@workspace/db";
|
|
77
|
+
* database: prismaAdapter(prisma, { provider: "postgresql" }),
|
|
78
|
+
*
|
|
79
|
+
* Drizzle:
|
|
80
|
+
* import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
|
81
|
+
* import { db } from "@workspace/db";
|
|
82
|
+
* database: drizzleAdapter(db, { provider: "pg" }),
|
|
83
|
+
*/
|
|
84
|
+
database: undefined as never, // Replace with your adapter
|
|
85
|
+
|
|
86
|
+
emailAndPassword: {
|
|
87
|
+
enabled: true,
|
|
88
|
+
// requireEmailVerification: true,
|
|
89
|
+
// sendResetPassword: async ({ user, url }) => { ... },
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
session: {
|
|
93
|
+
cookieCache: {
|
|
94
|
+
enabled: true,
|
|
95
|
+
maxAge: 60 * 5, // 5 minutes
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
// Social providers (uncomment as needed):
|
|
100
|
+
// socialProviders: {
|
|
101
|
+
// github: {
|
|
102
|
+
// clientId: process.env.GITHUB_CLIENT_ID!,
|
|
103
|
+
// clientSecret: process.env.GITHUB_CLIENT_SECRET!,
|
|
104
|
+
// },
|
|
105
|
+
// google: {
|
|
106
|
+
// clientId: process.env.GOOGLE_CLIENT_ID!,
|
|
107
|
+
// clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
|
|
108
|
+
// },
|
|
109
|
+
// },
|
|
110
|
+
|
|
111
|
+
// Plugins (uncomment to enable):
|
|
112
|
+
// plugins: [
|
|
113
|
+
// twoFactor(), // import { twoFactor } from "better-auth/plugins";
|
|
114
|
+
// organization(), // import { organization } from "better-auth/plugins";
|
|
115
|
+
// admin(), // import { admin } from "better-auth/plugins";
|
|
116
|
+
// passkey(), // import { passkey } from "better-auth/plugins";
|
|
117
|
+
// ],
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
/** Inferred Session type from your auth config */
|
|
121
|
+
export type Session = typeof auth.$Infer.Session;
|
|
122
|
+
/** Inferred User type from your auth config */
|
|
123
|
+
export type User = typeof auth.$Infer.Session.user;
|
|
124
|
+
`);
|
|
125
|
+
// ── src/client.ts ─────────────────────────────────────────────────────────
|
|
126
|
+
// better-auth v1.2: createAuthClient from "better-auth/react"
|
|
127
|
+
await writeFile(path.join(pkgDir, "src/client.ts"), `/**
|
|
128
|
+
* Better Auth v1.2+ — browser client.
|
|
129
|
+
*
|
|
130
|
+
* Works in React Client Components, Vite SPAs, and Expo.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* import { signIn, signOut, useSession } from "@workspace/auth/client";
|
|
134
|
+
*
|
|
135
|
+
* // React hook
|
|
136
|
+
* const { data: session, isPending } = useSession();
|
|
137
|
+
*
|
|
138
|
+
* // Sign in with email
|
|
139
|
+
* const { data, error } = await signIn.email({ email, password });
|
|
140
|
+
*
|
|
141
|
+
* // Sign in with OAuth
|
|
142
|
+
* await signIn.social({ provider: "github" });
|
|
143
|
+
*
|
|
144
|
+
* // Sign out
|
|
145
|
+
* await signOut();
|
|
146
|
+
*/
|
|
147
|
+
"use client";
|
|
148
|
+
|
|
149
|
+
import { createAuthClient } from "better-auth/react";
|
|
150
|
+
|
|
151
|
+
export const authClient = createAuthClient({
|
|
152
|
+
/**
|
|
153
|
+
* The base URL of your app's auth API.
|
|
154
|
+
* Each app in the monorepo exposes /api/auth, so override per-app
|
|
155
|
+
* via NEXT_PUBLIC_APP_URL (or VITE_APP_URL for Vite apps).
|
|
156
|
+
*/
|
|
157
|
+
baseURL:
|
|
158
|
+
process.env.NEXT_PUBLIC_APP_URL ??
|
|
159
|
+
(typeof window !== "undefined" ? window.location.origin : "http://localhost:3000"),
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
export const {
|
|
163
|
+
signIn,
|
|
164
|
+
signOut,
|
|
165
|
+
signUp,
|
|
166
|
+
useSession,
|
|
167
|
+
useActiveSessions,
|
|
168
|
+
getSession,
|
|
169
|
+
updateUser,
|
|
170
|
+
deleteUser,
|
|
171
|
+
linkSocial,
|
|
172
|
+
unlinkAccount,
|
|
173
|
+
listSessions,
|
|
174
|
+
revokeSession,
|
|
175
|
+
revokeSessions,
|
|
176
|
+
changeEmail,
|
|
177
|
+
changePassword,
|
|
178
|
+
resetPassword,
|
|
179
|
+
forgetPassword,
|
|
180
|
+
verifyEmail,
|
|
181
|
+
sendVerificationEmail,
|
|
182
|
+
} = authClient;
|
|
183
|
+
`);
|
|
184
|
+
// ── src/middleware.ts ─────────────────────────────────────────────────────
|
|
185
|
+
// better-auth v1.2: auth.api.getSession pattern (no separate middleware pkg)
|
|
186
|
+
await writeFile(path.join(pkgDir, "src/middleware.ts"), `/**
|
|
187
|
+
* Better Auth v1.2+ — Next.js middleware.
|
|
188
|
+
*
|
|
189
|
+
* Quick start — copy into apps/<your-app>/middleware.ts:
|
|
190
|
+
*
|
|
191
|
+
* export { authMiddleware as default, middlewareConfig as config }
|
|
192
|
+
* from "@workspace/auth/middleware";
|
|
193
|
+
*
|
|
194
|
+
* Custom public paths:
|
|
195
|
+
*
|
|
196
|
+
* import { buildMiddleware } from "@workspace/auth/middleware";
|
|
197
|
+
* export default buildMiddleware({ publicPaths: ["/", "/about(.*)"] });
|
|
198
|
+
* export { middlewareConfig as config } from "@workspace/auth/middleware";
|
|
199
|
+
*/
|
|
200
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
201
|
+
import { auth } from "./server.js";
|
|
202
|
+
|
|
203
|
+
const DEFAULT_PUBLIC_PATHS = [
|
|
204
|
+
"/",
|
|
205
|
+
"/sign-in",
|
|
206
|
+
"/sign-up",
|
|
207
|
+
"/api/auth", // Better Auth's own handler
|
|
208
|
+
"/api/webhooks", // Webhook endpoints
|
|
209
|
+
];
|
|
210
|
+
|
|
211
|
+
export const middlewareConfig = {
|
|
212
|
+
matcher: [
|
|
213
|
+
"/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)",
|
|
214
|
+
"/(api|trpc)(.*)",
|
|
215
|
+
],
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/** Default middleware — protects everything except the paths above */
|
|
219
|
+
export const authMiddleware = buildMiddleware();
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Build a middleware with configurable public paths.
|
|
223
|
+
*
|
|
224
|
+
* @param publicPaths - Paths that do NOT require authentication (prefix match)
|
|
225
|
+
* @param redirectTo - Where to redirect unauthenticated users (default: /sign-in)
|
|
226
|
+
*/
|
|
227
|
+
export function buildMiddleware({
|
|
228
|
+
publicPaths = DEFAULT_PUBLIC_PATHS,
|
|
229
|
+
redirectTo = "/sign-in",
|
|
230
|
+
}: {
|
|
231
|
+
publicPaths?: string[];
|
|
232
|
+
redirectTo?: string;
|
|
233
|
+
} = {}) {
|
|
234
|
+
return async function middleware(request: NextRequest): Promise<NextResponse> {
|
|
235
|
+
const { pathname } = request.nextUrl;
|
|
236
|
+
const isPublic = publicPaths.some((p) => pathname.startsWith(p));
|
|
237
|
+
|
|
238
|
+
if (!isPublic) {
|
|
239
|
+
// better-auth v1.2: auth.api.getSession({ headers })
|
|
240
|
+
const session = await auth.api.getSession({
|
|
241
|
+
headers: request.headers,
|
|
242
|
+
});
|
|
243
|
+
if (!session) {
|
|
244
|
+
const signInUrl = new URL(redirectTo, request.url);
|
|
245
|
+
signInUrl.searchParams.set("callbackUrl", pathname);
|
|
246
|
+
return NextResponse.redirect(signInUrl);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return NextResponse.next();
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
`);
|
|
254
|
+
// ── src/next-route-handler.ts — template for the catch-all API route ─────
|
|
255
|
+
await writeFile(path.join(pkgDir, "src/next-route-handler.ts"), `/**
|
|
256
|
+
* Template: apps/<your-app>/src/app/api/auth/[...all]/route.ts
|
|
257
|
+
*
|
|
258
|
+
* Copy this pattern into your app's API route directory.
|
|
259
|
+
* Do NOT import this file directly — it must live under app/api/auth/[...all]/.
|
|
260
|
+
*
|
|
261
|
+
* better-auth v1.2: auth.handler is the standard way to expose the API.
|
|
262
|
+
*/
|
|
263
|
+
import { auth } from "@workspace/auth/server";
|
|
264
|
+
import { toNextJsHandler } from "better-auth/next-js";
|
|
265
|
+
|
|
266
|
+
// This creates GET and POST handlers that Next.js will pick up automatically.
|
|
267
|
+
export const { GET, POST } = toNextJsHandler(auth.handler);
|
|
268
|
+
`);
|
|
269
|
+
// ── .env.example ─────────────────────────────────────────────────────────
|
|
270
|
+
await writeFile(path.join(pkgDir, ".env.example"), `# ─── Better Auth v1.2+ ────────────────────────────────────────────────────────
|
|
271
|
+
# Secret used to sign session tokens — generate with: openssl rand -base64 32
|
|
272
|
+
BETTER_AUTH_SECRET=REPLACE_WITH_RANDOM_32_CHAR_SECRET
|
|
273
|
+
|
|
274
|
+
# The canonical URL of your app (used for cookie domain & CORS)
|
|
275
|
+
BETTER_AUTH_URL=http://localhost:3000
|
|
276
|
+
NEXT_PUBLIC_APP_URL=http://localhost:3000
|
|
277
|
+
|
|
278
|
+
# ─── Database ─────────────────────────────────────────────────────────────────
|
|
279
|
+
# Uncomment the adapter you're using (see packages/auth/src/server.ts)
|
|
280
|
+
# DATABASE_URL=postgresql://user:pass@localhost:5432/mydb
|
|
281
|
+
|
|
282
|
+
# ─── OAuth providers (optional) ───────────────────────────────────────────────
|
|
283
|
+
# GITHUB_CLIENT_ID=
|
|
284
|
+
# GITHUB_CLIENT_SECRET=
|
|
285
|
+
# GOOGLE_CLIENT_ID=
|
|
286
|
+
# GOOGLE_CLIENT_SECRET=
|
|
287
|
+
`);
|
|
288
|
+
// ── README.md ─────────────────────────────────────────────────────────────
|
|
289
|
+
await writeFile(path.join(pkgDir, "README.md"), `# @workspace/auth — Better Auth v1.2+
|
|
290
|
+
|
|
291
|
+
Shared authentication powered by [Better Auth](https://www.better-auth.com) — open-source, self-hosted, database-agnostic.
|
|
292
|
+
|
|
293
|
+
## Setup
|
|
294
|
+
|
|
295
|
+
### 1. Choose a database adapter
|
|
296
|
+
Edit \`packages/auth/src/server.ts\` and uncomment the adapter for your database (PostgreSQL, MySQL, SQLite, Prisma, Drizzle).
|
|
297
|
+
|
|
298
|
+
### 2. Copy env vars to your app
|
|
299
|
+
\`\`\`bash
|
|
300
|
+
cp packages/auth/.env.example apps/<your-app>/.env.local
|
|
301
|
+
# Fill in BETTER_AUTH_SECRET (openssl rand -base64 32) and DATABASE_URL
|
|
302
|
+
\`\`\`
|
|
303
|
+
|
|
304
|
+
### 3. Add the dependency
|
|
305
|
+
\`\`\`json
|
|
306
|
+
{ "dependencies": { "@workspace/auth": "workspace:*" } }
|
|
307
|
+
\`\`\`
|
|
308
|
+
|
|
309
|
+
### 4. Add the API route (Next.js)
|
|
310
|
+
\`\`\`ts
|
|
311
|
+
// apps/<your-app>/src/app/api/auth/[...all]/route.ts
|
|
312
|
+
import { auth } from "@workspace/auth/server";
|
|
313
|
+
import { toNextJsHandler } from "better-auth/next-js";
|
|
314
|
+
export const { GET, POST } = toNextJsHandler(auth.handler);
|
|
315
|
+
\`\`\`
|
|
316
|
+
|
|
317
|
+
### 5. Add middleware
|
|
318
|
+
\`\`\`ts
|
|
319
|
+
// apps/<your-app>/middleware.ts
|
|
320
|
+
export { authMiddleware as default, middlewareConfig as config }
|
|
321
|
+
from "@workspace/auth/middleware";
|
|
322
|
+
\`\`\`
|
|
323
|
+
|
|
324
|
+
### 6. Run migrations
|
|
325
|
+
\`\`\`bash
|
|
326
|
+
npx better-auth migrate
|
|
327
|
+
# or: npx better-auth generate (for Drizzle/Prisma — creates migration files)
|
|
328
|
+
\`\`\`
|
|
329
|
+
|
|
330
|
+
## Usage
|
|
331
|
+
|
|
332
|
+
\`\`\`tsx
|
|
333
|
+
// Server component
|
|
334
|
+
import { auth } from "@workspace/auth/server";
|
|
335
|
+
import { headers } from "next/headers";
|
|
336
|
+
const session = await auth.api.getSession({ headers: await headers() });
|
|
337
|
+
|
|
338
|
+
// Client component
|
|
339
|
+
"use client";
|
|
340
|
+
import { useSession, signIn, signOut } from "@workspace/auth/client";
|
|
341
|
+
const { data: session, isPending } = useSession();
|
|
342
|
+
await signIn.email({ email, password });
|
|
343
|
+
await signIn.social({ provider: "github" });
|
|
344
|
+
await signOut();
|
|
345
|
+
\`\`\`
|
|
346
|
+
|
|
347
|
+
## API
|
|
348
|
+
|
|
349
|
+
| Sub-path | Key exports |
|
|
350
|
+
|---|---|
|
|
351
|
+
| \`@workspace/auth/server\` | \`auth\`, \`Session\` type, \`User\` type |
|
|
352
|
+
| \`@workspace/auth/client\` | \`authClient\`, \`signIn\`, \`signOut\`, \`signUp\`, \`useSession\` |
|
|
353
|
+
| \`@workspace/auth/middleware\` | \`authMiddleware\`, \`buildMiddleware()\`, \`middlewareConfig\` |
|
|
354
|
+
`);
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
//# sourceMappingURL=better-auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"better-auth.js","sourceRoot":"","sources":["../../../../src/setups/auth/systems/better-auth.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGtD,MAAM,CAAC,MAAM,oBAAoB,GAA0B;IACzD,KAAK,EAAE,aAAa;IAEpB,YAAY,EAAE;QACZ,aAAa,EAAE,QAAQ;KACxB;IAED,eAAe,EAAE;QACf,cAAc,EAAE,SAAS;KAC1B;IAED,gBAAgB,EAAE;QAChB,KAAK,EAAQ,YAAY;QACzB,WAAW,EAAE,YAAY;KAC1B;IAED,KAAK,CAAC,QAAQ,CAAC,MAAc,EAAE,KAAyB;QACtD,MAAM,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QAE1C,6EAA6E;QAC7E,MAAM,SAAS,CACb,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,cAAc,CAAC,EACjC;;;;;;;;;;CAUL,CACI,CAAC;QAEF,6EAA6E;QAC7E,oEAAoE;QACpE,MAAM,SAAS,CACb,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC,EAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6FL,CACI,CAAC;QAEF,6EAA6E;QAC7E,8DAA8D;QA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