@devbie/fewbie-cli 0.1.0-stage.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/dist/commands/add.d.ts +8 -0
- package/dist/commands/add.js +97 -0
- package/dist/commands/add.js.map +1 -0
- package/dist/commands/gen-api-templates.d.ts +11 -0
- package/dist/commands/gen-api-templates.js +100 -0
- package/dist/commands/gen-api-templates.js.map +1 -0
- package/dist/commands/gen-api.d.ts +8 -0
- package/dist/commands/gen-api.js +105 -0
- package/dist/commands/gen-api.js.map +1 -0
- package/dist/commands/init.d.ts +13 -0
- package/dist/commands/init.js +82 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +76 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/errors.d.ts +3 -0
- package/dist/lib/errors.js +11 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/exec-interactive.d.ts +1 -0
- package/dist/lib/exec-interactive.js +17 -0
- package/dist/lib/exec-interactive.js.map +1 -0
- package/dist/lib/exec.d.ts +7 -0
- package/dist/lib/exec.js +30 -0
- package/dist/lib/exec.js.map +1 -0
- package/dist/registry/api-client/item.json +18 -0
- package/dist/registry/auth/item.json +18 -0
- package/dist/registry/build.d.ts +1 -0
- package/dist/registry/build.js +55 -0
- package/dist/registry/build.js.map +1 -0
- package/dist/registry/login-form/item.json +17 -0
- package/dist/registry/store.d.ts +12 -0
- package/dist/registry/store.js +106 -0
- package/dist/registry/store.js.map +1 -0
- package/dist/registry/theme/item.json +23 -0
- package/dist/registry/types.d.ts +30 -0
- package/dist/registry/types.js +3 -0
- package/dist/registry/types.js.map +1 -0
- package/package.json +35 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runAdd = runAdd;
|
|
7
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const colorette_1 = require("colorette");
|
|
10
|
+
const errors_1 = require("../lib/errors");
|
|
11
|
+
const exec_interactive_1 = require("../lib/exec-interactive");
|
|
12
|
+
const store_1 = require("../registry/store");
|
|
13
|
+
async function assertProjectRoot(projectRoot) {
|
|
14
|
+
await promises_1.default.access(node_path_1.default.join(projectRoot, "package.json")).catch(() => {
|
|
15
|
+
throw new errors_1.CliError(`No package.json found in ${projectRoot}. Run 'fewbie add' inside a Next.js project.`);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function packageNameOf(spec) {
|
|
19
|
+
if (spec.startsWith("@")) {
|
|
20
|
+
const at = spec.indexOf("@", 1);
|
|
21
|
+
return at === -1 ? spec : spec.slice(0, at);
|
|
22
|
+
}
|
|
23
|
+
return spec.split("@")[0];
|
|
24
|
+
}
|
|
25
|
+
async function missingPackages(projectRoot, specs) {
|
|
26
|
+
const pkg = JSON.parse(await promises_1.default.readFile(node_path_1.default.join(projectRoot, "package.json"), "utf8"));
|
|
27
|
+
const declared = new Set([
|
|
28
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
29
|
+
...Object.keys(pkg.devDependencies ?? {}),
|
|
30
|
+
]);
|
|
31
|
+
return specs.filter((spec) => !declared.has(packageNameOf(spec)));
|
|
32
|
+
}
|
|
33
|
+
async function writeItemFiles(item, projectRoot, force) {
|
|
34
|
+
const written = [];
|
|
35
|
+
const conflicts = [];
|
|
36
|
+
for (const file of item.files) {
|
|
37
|
+
const target = node_path_1.default.join(projectRoot, file.target);
|
|
38
|
+
const exists = await promises_1.default
|
|
39
|
+
.access(target)
|
|
40
|
+
.then(() => true)
|
|
41
|
+
.catch(() => false);
|
|
42
|
+
if (exists && !force) {
|
|
43
|
+
conflicts.push(file.target);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
await promises_1.default.mkdir(node_path_1.default.dirname(target), { recursive: true });
|
|
47
|
+
const content = file.content ?? (await promises_1.default.readFile(file.source, "utf8"));
|
|
48
|
+
await promises_1.default.writeFile(target, content);
|
|
49
|
+
written.push(file.target);
|
|
50
|
+
}
|
|
51
|
+
if (conflicts.length > 0) {
|
|
52
|
+
throw new errors_1.CliError(`The following files already exist (re-run with --force to overwrite):\n ${conflicts.join("\n ")}`);
|
|
53
|
+
}
|
|
54
|
+
return written;
|
|
55
|
+
}
|
|
56
|
+
async function runAdd(options) {
|
|
57
|
+
const projectRoot = node_path_1.default.resolve(options.cwd ?? process.cwd());
|
|
58
|
+
await assertProjectRoot(projectRoot);
|
|
59
|
+
const requested = [...options.names];
|
|
60
|
+
if (options.withLoginForm && !requested.includes("login-form")) {
|
|
61
|
+
requested.push("login-form");
|
|
62
|
+
}
|
|
63
|
+
const registryRoot = await (0, store_1.resolveRegistryRoot)();
|
|
64
|
+
const items = await (0, store_1.resolveInstallSet)(registryRoot, requested);
|
|
65
|
+
console.info((0, colorette_1.cyan)(`Installing ${items.map((i) => i.manifest.name).join(", ")} into ${projectRoot}...`));
|
|
66
|
+
const allWritten = [];
|
|
67
|
+
for (const item of items) {
|
|
68
|
+
const written = await writeItemFiles(item, projectRoot, options.force === true);
|
|
69
|
+
allWritten.push(...written);
|
|
70
|
+
console.info(` ${(0, colorette_1.green)("✓")} ${item.manifest.name}`);
|
|
71
|
+
}
|
|
72
|
+
const specs = [
|
|
73
|
+
...new Set(items.flatMap((i) => i.manifest.dependencies ?? [])),
|
|
74
|
+
];
|
|
75
|
+
const missing = await missingPackages(projectRoot, specs);
|
|
76
|
+
if (missing.length > 0) {
|
|
77
|
+
if (options.skipInstall) {
|
|
78
|
+
console.info((0, colorette_1.yellow)(`\nSkipped npm install. Add manually: npm install ${missing.join(" ")}`));
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
console.info(`\nInstalling dependencies: ${missing.join(", ")}`);
|
|
82
|
+
await (0, exec_interactive_1.execInteractive)("npm", ["install", ...missing], projectRoot);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
for (const file of allWritten) {
|
|
86
|
+
console.info(` ${(0, colorette_1.green)("added")} ${file}`);
|
|
87
|
+
}
|
|
88
|
+
const hints = items
|
|
89
|
+
.map((i) => i.manifest.postInstall)
|
|
90
|
+
.filter((hint) => Boolean(hint));
|
|
91
|
+
if (hints.length > 0) {
|
|
92
|
+
console.info(`\n${(0, colorette_1.bold)("Next steps")}:`);
|
|
93
|
+
for (const hint of hints)
|
|
94
|
+
console.info(` - ${hint}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=add.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add.js","sourceRoot":"","sources":["../../src/commands/add.ts"],"names":[],"mappings":";;;;;AAiGA,wBA2DC;AA5JD,gEAAkC;AAClC,0DAA6B;AAC7B,yCAAsD;AAEtD,0CAAyC;AACzC,8DAA0D;AAC1D,6CAI2B;AAqB3B,KAAK,UAAU,iBAAiB,CAAC,WAAmB;IAClD,MAAM,kBAAE,CAAC,MAAM,CAAC,mBAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;QACjE,MAAM,IAAI,iBAAQ,CAChB,4BAA4B,WAAW,8CAA8C,CACtF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAGD,SAAS,aAAa,CAAC,IAAY;IACjC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QAChC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC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,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,OAAO,CAAC,IAAI,CAAC,KAAK,IAAA,iBAAK,EAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,KAAK,GAAG,KAAK;SAChB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC;SAClC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,KAAK,IAAA,gBAAI,EAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QACzC,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,OAAO,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IACxD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const GENERATOR_PACKAGE_NAME = "open-api-typescript-request-generator";
|
|
2
|
+
export declare const GENERATOR_PACKAGE_SPEC = "open-api-typescript-request-generator@^0.0.7-alpha.0";
|
|
3
|
+
export declare const GENERATOR_BIN_RELATIVE = "node_modules/open-api-typescript-request-generator/bin/apits";
|
|
4
|
+
export declare const CONFIG_PROJECT_PATH = "apits.config.ts";
|
|
5
|
+
export declare const API_CLIENT_PROJECT_PATH = "src/lib/api-client.ts";
|
|
6
|
+
export declare const ADAPTER_PROJECT_PATH = "src/api/request.ts";
|
|
7
|
+
export declare const DEFAULT_OUTPUT_DIR = "src/api/_gen";
|
|
8
|
+
export declare const DEFAULT_GENERATED_NAME = "api";
|
|
9
|
+
export declare const PUBLIC_BASE_URL_ENV = "NEXT_PUBLIC_BASE_URL";
|
|
10
|
+
export declare function renderApitsConfig(input: string): string;
|
|
11
|
+
export declare const ADAPTER_CONTENT = "/**\n * Adapter between generated API code and the fewbie api client.\n *\n * Scaffolded by `fewbie gen api` and never overwritten afterwards \u2014 edit it\n * freely (for example to unwrap a { code, data } response envelope).\n */\nimport type { AxiosRequestConfig } from \"axios\";\n\nimport { apiClient } from \"@/lib/api-client\";\n\ntype GeneratedMethod = <Req, Res>(\n url: string,\n config?: AxiosRequestConfig,\n) => Promise<Res>;\n\n// The generator puts POST/PUT/PATCH payloads on config.data; the fewbie\n// apiClient takes the body as a separate positional argument.\nfunction withBodyData(\n call: (\n url: string,\n data?: unknown,\n config?: AxiosRequestConfig,\n ) => Promise<unknown>,\n): GeneratedMethod {\n return (url, config) => {\n const { data, ...rest } = config ?? {};\n return call(url, data, rest) as Promise<never>;\n };\n}\n\n// HEAD/OPTIONS carry no response body; return the full AxiosResponse so\n// status and headers remain observable.\nfunction responseOnly(\n call: (url: string, config?: AxiosRequestConfig) => Promise<unknown>,\n): GeneratedMethod {\n return (url, config) => call(url, config) as Promise<never>;\n}\n\nexport interface GeneratedRequest {\n get: GeneratedMethod;\n post: GeneratedMethod;\n put: GeneratedMethod;\n patch: GeneratedMethod;\n delete: GeneratedMethod;\n head: GeneratedMethod;\n options: GeneratedMethod;\n}\n\nexport const request: GeneratedRequest = {\n get: (url, config) => apiClient.get(url, config) as Promise<never>,\n delete: (url, config) => apiClient.delete(url, config) as Promise<never>,\n head: responseOnly((url, config) => apiClient.head(url, config)),\n options: responseOnly((url, config) => apiClient.options(url, config)),\n post: withBodyData((url, data, config) => apiClient.post(url, data, config)),\n put: withBodyData((url, data, config) => apiClient.put(url, data, config)),\n patch: withBodyData((url, data, config) =>\n apiClient.patch(url, data, config),\n ),\n};\n";
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ADAPTER_CONTENT = exports.PUBLIC_BASE_URL_ENV = exports.DEFAULT_GENERATED_NAME = exports.DEFAULT_OUTPUT_DIR = exports.ADAPTER_PROJECT_PATH = exports.API_CLIENT_PROJECT_PATH = exports.CONFIG_PROJECT_PATH = exports.GENERATOR_BIN_RELATIVE = exports.GENERATOR_PACKAGE_SPEC = exports.GENERATOR_PACKAGE_NAME = void 0;
|
|
4
|
+
exports.renderApitsConfig = renderApitsConfig;
|
|
5
|
+
exports.GENERATOR_PACKAGE_NAME = "open-api-typescript-request-generator";
|
|
6
|
+
exports.GENERATOR_PACKAGE_SPEC = "open-api-typescript-request-generator@^0.0.7-alpha.0";
|
|
7
|
+
exports.GENERATOR_BIN_RELATIVE = "node_modules/open-api-typescript-request-generator/bin/apits";
|
|
8
|
+
exports.CONFIG_PROJECT_PATH = "apits.config.ts";
|
|
9
|
+
exports.API_CLIENT_PROJECT_PATH = "src/lib/api-client.ts";
|
|
10
|
+
exports.ADAPTER_PROJECT_PATH = "src/api/request.ts";
|
|
11
|
+
exports.DEFAULT_OUTPUT_DIR = "src/api/_gen";
|
|
12
|
+
exports.DEFAULT_GENERATED_NAME = "api";
|
|
13
|
+
exports.PUBLIC_BASE_URL_ENV = "NEXT_PUBLIC_BASE_URL";
|
|
14
|
+
function escapeSingleQuoted(value) {
|
|
15
|
+
return value.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
16
|
+
}
|
|
17
|
+
function renderApitsConfig(input) {
|
|
18
|
+
const safeInput = escapeSingleQuoted(input);
|
|
19
|
+
return `import { defineConfig } from '${exports.GENERATOR_PACKAGE_NAME}';
|
|
20
|
+
|
|
21
|
+
// Scaffolded by \`fewbie gen api\`. The generator owns this file afterwards:
|
|
22
|
+
// add more OpenAPI sources here and select one with \`fewbie gen api -n <name>\`.
|
|
23
|
+
export default defineConfig([
|
|
24
|
+
{
|
|
25
|
+
// OpenAPI document source: an http(s) URL or a local JSON/YAML file.
|
|
26
|
+
// API_JSON lets you point at a local snapshot for one-off generation.
|
|
27
|
+
input: process.env.API_JSON || '${safeInput}',
|
|
28
|
+
output: '${exports.DEFAULT_OUTPUT_DIR}',
|
|
29
|
+
name: '${exports.DEFAULT_GENERATED_NAME}',
|
|
30
|
+
// Emit baseURL as runtime code reading the public env var (browser code
|
|
31
|
+
// can only read NEXT_PUBLIC_* variables).
|
|
32
|
+
baseURL: '[code]:process.env.${exports.PUBLIC_BASE_URL_ENV}',
|
|
33
|
+
// Generate against the fewbie api-client adapter; providing this import
|
|
34
|
+
// also suppresses the generator's own request.ts scaffold.
|
|
35
|
+
clientImportTemplate: () => "import { request } from '../request'",
|
|
36
|
+
},
|
|
37
|
+
]);
|
|
38
|
+
`;
|
|
39
|
+
}
|
|
40
|
+
exports.ADAPTER_CONTENT = `/**
|
|
41
|
+
* Adapter between generated API code and the fewbie api client.
|
|
42
|
+
*
|
|
43
|
+
* Scaffolded by \`fewbie gen api\` and never overwritten afterwards — edit it
|
|
44
|
+
* freely (for example to unwrap a { code, data } response envelope).
|
|
45
|
+
*/
|
|
46
|
+
import type { AxiosRequestConfig } from "axios";
|
|
47
|
+
|
|
48
|
+
import { apiClient } from "@/lib/api-client";
|
|
49
|
+
|
|
50
|
+
type GeneratedMethod = <Req, Res>(
|
|
51
|
+
url: string,
|
|
52
|
+
config?: AxiosRequestConfig,
|
|
53
|
+
) => Promise<Res>;
|
|
54
|
+
|
|
55
|
+
// The generator puts POST/PUT/PATCH payloads on config.data; the fewbie
|
|
56
|
+
// apiClient takes the body as a separate positional argument.
|
|
57
|
+
function withBodyData(
|
|
58
|
+
call: (
|
|
59
|
+
url: string,
|
|
60
|
+
data?: unknown,
|
|
61
|
+
config?: AxiosRequestConfig,
|
|
62
|
+
) => Promise<unknown>,
|
|
63
|
+
): GeneratedMethod {
|
|
64
|
+
return (url, config) => {
|
|
65
|
+
const { data, ...rest } = config ?? {};
|
|
66
|
+
return call(url, data, rest) as Promise<never>;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// HEAD/OPTIONS carry no response body; return the full AxiosResponse so
|
|
71
|
+
// status and headers remain observable.
|
|
72
|
+
function responseOnly(
|
|
73
|
+
call: (url: string, config?: AxiosRequestConfig) => Promise<unknown>,
|
|
74
|
+
): GeneratedMethod {
|
|
75
|
+
return (url, config) => call(url, config) as Promise<never>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface GeneratedRequest {
|
|
79
|
+
get: GeneratedMethod;
|
|
80
|
+
post: GeneratedMethod;
|
|
81
|
+
put: GeneratedMethod;
|
|
82
|
+
patch: GeneratedMethod;
|
|
83
|
+
delete: GeneratedMethod;
|
|
84
|
+
head: GeneratedMethod;
|
|
85
|
+
options: GeneratedMethod;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export const request: GeneratedRequest = {
|
|
89
|
+
get: (url, config) => apiClient.get(url, config) as Promise<never>,
|
|
90
|
+
delete: (url, config) => apiClient.delete(url, config) as Promise<never>,
|
|
91
|
+
head: responseOnly((url, config) => apiClient.head(url, config)),
|
|
92
|
+
options: responseOnly((url, config) => apiClient.options(url, config)),
|
|
93
|
+
post: withBodyData((url, data, config) => apiClient.post(url, data, config)),
|
|
94
|
+
put: withBodyData((url, data, config) => apiClient.put(url, data, config)),
|
|
95
|
+
patch: withBodyData((url, data, config) =>
|
|
96
|
+
apiClient.patch(url, data, config),
|
|
97
|
+
),
|
|
98
|
+
};
|
|
99
|
+
`;
|
|
100
|
+
//# sourceMappingURL=gen-api-templates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gen-api-templates.js","sourceRoot":"","sources":["../../src/commands/gen-api-templates.ts"],"names":[],"mappings":";;;AA6BA,8CAsBC;AAzCY,QAAA,sBAAsB,GAAG,uCAAuC,CAAC;AACjE,QAAA,sBAAsB,GACjC,sDAAsD,CAAC;AAC5C,QAAA,sBAAsB,GACjC,8DAA8D,CAAC;AAEpD,QAAA,mBAAmB,GAAG,iBAAiB,CAAC;AACxC,QAAA,uBAAuB,GAAG,uBAAuB,CAAC;AAClD,QAAA,oBAAoB,GAAG,oBAAoB,CAAC;AAC5C,QAAA,kBAAkB,GAAG,cAAc,CAAC;AACpC,QAAA,sBAAsB,GAAG,KAAK,CAAC;AAC/B,QAAA,mBAAmB,GAAG,sBAAsB,CAAC;AAG1D,SAAS,kBAAkB,CAAC,KAAa;IACvC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC3D,CAAC;AAGD,SAAgB,iBAAiB,CAAC,KAAa;IAC7C,MAAM,SAAS,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAC5C,OAAO,iCAAiC,8BAAsB;;;;;;;;sCAQ1B,SAAS;eAChC,0BAAkB;aACpB,8BAAsB;;;mCAGA,2BAAmB;;;;;;CAMrD,CAAC;AACF,CAAC;AAQY,QAAA,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2D9B,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runGenApi = runGenApi;
|
|
7
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const node_child_process_1 = require("node:child_process");
|
|
10
|
+
const colorette_1 = require("colorette");
|
|
11
|
+
const errors_1 = require("../lib/errors");
|
|
12
|
+
const exec_interactive_1 = require("../lib/exec-interactive");
|
|
13
|
+
const gen_api_templates_1 = require("./gen-api-templates");
|
|
14
|
+
async function exists(target) {
|
|
15
|
+
return promises_1.default
|
|
16
|
+
.access(target)
|
|
17
|
+
.then(() => true)
|
|
18
|
+
.catch(() => false);
|
|
19
|
+
}
|
|
20
|
+
async function readPackageJson(projectRoot) {
|
|
21
|
+
return JSON.parse(await promises_1.default.readFile(node_path_1.default.join(projectRoot, "package.json"), "utf8"));
|
|
22
|
+
}
|
|
23
|
+
function runGenerator(projectRoot, args) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const child = (0, node_child_process_1.spawn)(process.execPath, args, {
|
|
26
|
+
cwd: projectRoot,
|
|
27
|
+
stdio: "inherit",
|
|
28
|
+
});
|
|
29
|
+
child.on("error", reject);
|
|
30
|
+
child.on("close", (code) => {
|
|
31
|
+
if (code === 0)
|
|
32
|
+
resolve();
|
|
33
|
+
else
|
|
34
|
+
reject(new Error(`apits exited with code ${code}`));
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async function runGenApi(options) {
|
|
39
|
+
const projectRoot = node_path_1.default.resolve(options.cwd ?? process.cwd());
|
|
40
|
+
if (!(await exists(node_path_1.default.join(projectRoot, "package.json")))) {
|
|
41
|
+
throw new errors_1.CliError(`No package.json found in ${projectRoot}. Run 'fewbie gen api' inside a fewbie project.`);
|
|
42
|
+
}
|
|
43
|
+
if (!(await exists(node_path_1.default.join(projectRoot, gen_api_templates_1.API_CLIENT_PROJECT_PATH)))) {
|
|
44
|
+
throw new errors_1.CliError(`'fewbie gen api' requires the api-client item. Run 'fewbie add api-client' first.`);
|
|
45
|
+
}
|
|
46
|
+
const configPath = node_path_1.default.join(projectRoot, gen_api_templates_1.CONFIG_PROJECT_PATH);
|
|
47
|
+
const hasConfig = await exists(configPath);
|
|
48
|
+
if (!hasConfig) {
|
|
49
|
+
if (!options.input) {
|
|
50
|
+
throw new errors_1.CliError(`No OpenAPI input and no ${gen_api_templates_1.CONFIG_PROJECT_PATH} found.\n` +
|
|
51
|
+
` First run: fewbie gen api <openapi-url-or-json-file>\n` +
|
|
52
|
+
` Afterwards: edit ${gen_api_templates_1.CONFIG_PROJECT_PATH} to manage sources.`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else if (options.input) {
|
|
56
|
+
throw new errors_1.CliError(`${gen_api_templates_1.CONFIG_PROJECT_PATH} already exists. Update its \`input\` directly (or pass -n <name> to select a source) instead of passing a positional input.`);
|
|
57
|
+
}
|
|
58
|
+
const adapterPath = node_path_1.default.join(projectRoot, gen_api_templates_1.ADAPTER_PROJECT_PATH);
|
|
59
|
+
if (!(await exists(adapterPath))) {
|
|
60
|
+
await promises_1.default.mkdir(node_path_1.default.dirname(adapterPath), { recursive: true });
|
|
61
|
+
await promises_1.default.writeFile(adapterPath, gen_api_templates_1.ADAPTER_CONTENT);
|
|
62
|
+
console.info(` ${(0, colorette_1.green)("added")} ${gen_api_templates_1.ADAPTER_PROJECT_PATH}`);
|
|
63
|
+
}
|
|
64
|
+
if (!hasConfig) {
|
|
65
|
+
await promises_1.default.writeFile(configPath, (0, gen_api_templates_1.renderApitsConfig)(options.input));
|
|
66
|
+
console.info(` ${(0, colorette_1.green)("added")} ${gen_api_templates_1.CONFIG_PROJECT_PATH}`);
|
|
67
|
+
}
|
|
68
|
+
const pkg = await readPackageJson(projectRoot);
|
|
69
|
+
const declared = new Set([
|
|
70
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
71
|
+
...Object.keys(pkg.devDependencies ?? {}),
|
|
72
|
+
]);
|
|
73
|
+
if (!declared.has(gen_api_templates_1.GENERATOR_PACKAGE_NAME)) {
|
|
74
|
+
if (options.skipInstall) {
|
|
75
|
+
throw new errors_1.CliError(`Generator not installed. Run: npm install -D ${gen_api_templates_1.GENERATOR_PACKAGE_SPEC}`);
|
|
76
|
+
}
|
|
77
|
+
console.info(`\nInstalling dev dependency: ${gen_api_templates_1.GENERATOR_PACKAGE_SPEC}`);
|
|
78
|
+
await (0, exec_interactive_1.execInteractive)("npm", ["install", "-D", gen_api_templates_1.GENERATOR_PACKAGE_SPEC], projectRoot);
|
|
79
|
+
}
|
|
80
|
+
const binPath = node_path_1.default.join(projectRoot, gen_api_templates_1.GENERATOR_BIN_RELATIVE);
|
|
81
|
+
if (!(await exists(binPath))) {
|
|
82
|
+
throw new errors_1.CliError(`Generator binary not found at ${gen_api_templates_1.GENERATOR_BIN_RELATIVE}. Run 'npm install' and retry.`);
|
|
83
|
+
}
|
|
84
|
+
const genArgs = [binPath, "gen"];
|
|
85
|
+
if (options.name)
|
|
86
|
+
genArgs.push("-n", options.name);
|
|
87
|
+
if (options.watch)
|
|
88
|
+
genArgs.push("--watch");
|
|
89
|
+
const expectedOutput = node_path_1.default.join(projectRoot, gen_api_templates_1.DEFAULT_OUTPUT_DIR, `${options.name ?? gen_api_templates_1.DEFAULT_GENERATED_NAME}.ts`);
|
|
90
|
+
const beforeStat = await promises_1.default.stat(expectedOutput).catch(() => null);
|
|
91
|
+
console.info((0, colorette_1.cyan)(`\nGenerating API code (${gen_api_templates_1.DEFAULT_OUTPUT_DIR})...`));
|
|
92
|
+
await runGenerator(projectRoot, genArgs);
|
|
93
|
+
if (!options.watch) {
|
|
94
|
+
const afterStat = await promises_1.default.stat(expectedOutput).catch(() => null);
|
|
95
|
+
const refreshed = afterStat !== null &&
|
|
96
|
+
(beforeStat === null || afterStat.mtimeMs > beforeStat.mtimeMs);
|
|
97
|
+
if (!refreshed) {
|
|
98
|
+
throw new errors_1.CliError(`Code generation failed: ${gen_api_templates_1.DEFAULT_OUTPUT_DIR}/${options.name ?? gen_api_templates_1.DEFAULT_GENERATED_NAME}.ts was not produced or updated. See the generator output above.`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
console.info(`\n${(0, colorette_1.bold)("Next steps")}:`);
|
|
102
|
+
console.info(` - Set ${(0, colorette_1.yellow)(gen_api_templates_1.PUBLIC_BASE_URL_ENV)} in .env.local (generated requests read it at runtime).`);
|
|
103
|
+
console.info(` - Import generated functions from ${gen_api_templates_1.DEFAULT_OUTPUT_DIR}/api.ts (re-run after schema changes, or use --watch).`);
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=gen-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gen-api.js","s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AC,GAAG,CAAC,CAAC;IACzC,OAAO,CAAC,IAAI,CACV,WAAW,IAAA,kBAAM,EAAC,uCAAmB,CAAC,yDAAyD,CAChG,CAAC;IACF,OAAO,CAAC,IAAI,CACV,uCAAuC,sCAAkB,wDAAwD,CAClH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface InitOptions {
|
|
2
|
+
name: string;
|
|
3
|
+
templatePath?: string;
|
|
4
|
+
templateRef?: string;
|
|
5
|
+
cwd?: string;
|
|
6
|
+
gitInit?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface ResolvedTemplate {
|
|
9
|
+
root: string;
|
|
10
|
+
source: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function resolveTemplate(options: Pick<InitOptions, "templatePath" | "templateRef">): Promise<ResolvedTemplate>;
|
|
13
|
+
export declare function runInit(options: InitOptions): Promise<void>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveTemplate = resolveTemplate;
|
|
7
|
+
exports.runInit = runInit;
|
|
8
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
9
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
const colorette_1 = require("colorette");
|
|
12
|
+
const errors_1 = require("../lib/errors");
|
|
13
|
+
const exec_1 = require("../lib/exec");
|
|
14
|
+
const TEMPLATE_REPOSITORY_URL = "https://github.com/worldzhy/fewbie.git";
|
|
15
|
+
const TEMPLATE_SUBDIR = "templates/basic";
|
|
16
|
+
const TEMPLATE_PATH_ENV = "FEWBIE_TEMPLATE_PATH";
|
|
17
|
+
const PACKAGE_NAME_RE = /^(?:@[a-z0-9][a-z0-9-._]*\/)?[a-z0-9][a-z0-9-._]*$/;
|
|
18
|
+
const COPY_IGNORE = new Set([
|
|
19
|
+
"node_modules",
|
|
20
|
+
".next",
|
|
21
|
+
"dist",
|
|
22
|
+
".git",
|
|
23
|
+
".env",
|
|
24
|
+
]);
|
|
25
|
+
async function resolveTemplate(options) {
|
|
26
|
+
const explicit = options.templatePath ?? process.env[TEMPLATE_PATH_ENV];
|
|
27
|
+
if (explicit) {
|
|
28
|
+
const root = node_path_1.default.resolve(explicit);
|
|
29
|
+
await promises_1.default.access(node_path_1.default.join(root, "package.json"));
|
|
30
|
+
return { root, source: root };
|
|
31
|
+
}
|
|
32
|
+
const localDev = node_path_1.default.resolve(__dirname, "..", "..", "..", "..", TEMPLATE_SUBDIR);
|
|
33
|
+
if (await promises_1.default
|
|
34
|
+
.access(node_path_1.default.join(localDev, "package.json"))
|
|
35
|
+
.then(() => true)
|
|
36
|
+
.catch(() => false)) {
|
|
37
|
+
return { root: localDev, source: `monorepo checkout (${localDev})` };
|
|
38
|
+
}
|
|
39
|
+
const ref = options.templateRef;
|
|
40
|
+
const temp = await promises_1.default.mkdtemp(node_path_1.default.join(node_os_1.default.tmpdir(), "fewbie-template-"));
|
|
41
|
+
const cloneArgs = ["clone", "--quiet"];
|
|
42
|
+
if (!ref)
|
|
43
|
+
cloneArgs.push("--depth", "1");
|
|
44
|
+
if (ref)
|
|
45
|
+
cloneArgs.push("--branch", ref);
|
|
46
|
+
cloneArgs.push(TEMPLATE_REPOSITORY_URL, temp);
|
|
47
|
+
await (0, exec_1.execCapture)("git", cloneArgs);
|
|
48
|
+
return {
|
|
49
|
+
root: node_path_1.default.join(temp, TEMPLATE_SUBDIR),
|
|
50
|
+
source: `${TEMPLATE_REPOSITORY_URL}#${ref ?? "HEAD"}`,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async function copyTemplate(from, to) {
|
|
54
|
+
await promises_1.default.cp(from, to, {
|
|
55
|
+
recursive: true,
|
|
56
|
+
filter: (src) => !COPY_IGNORE.has(node_path_1.default.basename(src)) || src === from,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async function runInit(options) {
|
|
60
|
+
const { name } = options;
|
|
61
|
+
if (!PACKAGE_NAME_RE.test(name) || name.length > 214) {
|
|
62
|
+
throw new errors_1.CliError(`Invalid project name '${name}'. Use a lowercase npm package name, e.g. my-project or @scope/my-project.`);
|
|
63
|
+
}
|
|
64
|
+
const targetDir = node_path_1.default.resolve(options.cwd ?? process.cwd(), name);
|
|
65
|
+
const existing = await promises_1.default.readdir(targetDir).catch(() => null);
|
|
66
|
+
if (existing && existing.length > 0) {
|
|
67
|
+
throw new errors_1.CliError(`Target directory ${targetDir} is not empty.`);
|
|
68
|
+
}
|
|
69
|
+
console.info((0, colorette_1.cyan)(`Creating project '${name}' from the basic template...`));
|
|
70
|
+
const templateRoot = (await resolveTemplate(options)).root;
|
|
71
|
+
await copyTemplate(templateRoot, targetDir);
|
|
72
|
+
const packageJsonPath = node_path_1.default.join(targetDir, "package.json");
|
|
73
|
+
const packageJson = JSON.parse(await promises_1.default.readFile(packageJsonPath, "utf8"));
|
|
74
|
+
packageJson.name = name;
|
|
75
|
+
await promises_1.default.writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`);
|
|
76
|
+
if (options.gitInit !== false) {
|
|
77
|
+
await (0, exec_1.execCapture)("git", ["init", "--quiet"], { cwd: targetDir });
|
|
78
|
+
}
|
|
79
|
+
console.info((0, colorette_1.green)((0, colorette_1.bold)("\n✓ Project created.\n")));
|
|
80
|
+
console.info(`Next steps:\n cd ${name}\n npm install\n npm run dev\n`);
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":";;;;;AA0CA,0CAuCC;AASD,0BAwCC;AAlID,gEAAkC;AAClC,sDAAyB;AACzB,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C,wBAAwB,CAAC,CAAC,CAAC,CAAC;IACpD,OAAO,CAAC,IAAI,CACV,qBAAqB,IAAI,kCAAkC,CAC5D,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.VERSION = void 0;
|
|
5
|
+
const commander_1 = require("commander");
|
|
6
|
+
const colorette_1 = require("colorette");
|
|
7
|
+
const init_1 = require("./commands/init");
|
|
8
|
+
const add_1 = require("./commands/add");
|
|
9
|
+
const gen_api_1 = require("./commands/gen-api");
|
|
10
|
+
exports.VERSION = require("../package.json")
|
|
11
|
+
.version;
|
|
12
|
+
const program = new commander_1.Command();
|
|
13
|
+
program
|
|
14
|
+
.name("fewbie")
|
|
15
|
+
.description("Fewbie frontend framework CLI: scaffold Next.js projects and install business components from the fewbie registry")
|
|
16
|
+
.version(exports.VERSION)
|
|
17
|
+
.option("-C, --cwd <dir>", "project root directory", process.cwd())
|
|
18
|
+
.action(() => {
|
|
19
|
+
program.outputHelp();
|
|
20
|
+
console.log(`\n${(0, colorette_1.bold)("@devbie/fewbie-cli")} ${exports.VERSION}`);
|
|
21
|
+
});
|
|
22
|
+
program
|
|
23
|
+
.command("init <project-name>")
|
|
24
|
+
.description("create a new project from the fewbie basic template")
|
|
25
|
+
.option("--template-path <dir>", "use a local template directory instead of cloning the fewbie repository")
|
|
26
|
+
.option("--template-ref <ref>", "git ref of the fewbie repository to clone the template from")
|
|
27
|
+
.option("--no-git-init", "skip 'git init' in the new project", undefined)
|
|
28
|
+
.action(async function (projectName) {
|
|
29
|
+
const flags = this.optsWithGlobals();
|
|
30
|
+
await (0, init_1.runInit)({
|
|
31
|
+
name: projectName,
|
|
32
|
+
cwd: flags.cwd ?? process.cwd(),
|
|
33
|
+
templatePath: flags.templatePath,
|
|
34
|
+
templateRef: flags.templateRef,
|
|
35
|
+
gitInit: flags.gitInit,
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
program
|
|
39
|
+
.command("add <names...>")
|
|
40
|
+
.description("add one or more components or logic utils from the fewbie registry")
|
|
41
|
+
.option("-f, --force", "overwrite files that already exist", false)
|
|
42
|
+
.option("--skip-install", "do not run npm install for missing dependencies", false)
|
|
43
|
+
.option("--with-login-form", "also install the login-form block (e.g. `fewbie add auth --with-login-form`)", false)
|
|
44
|
+
.action(async function (names) {
|
|
45
|
+
const flags = this.optsWithGlobals();
|
|
46
|
+
await (0, add_1.runAdd)({
|
|
47
|
+
names,
|
|
48
|
+
cwd: flags.cwd ?? process.cwd(),
|
|
49
|
+
force: Boolean(flags.force),
|
|
50
|
+
skipInstall: Boolean(flags.skipInstall),
|
|
51
|
+
withLoginForm: Boolean(flags.withLoginForm),
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
const gen = program.command("gen").description("code generation");
|
|
55
|
+
gen
|
|
56
|
+
.command("api [input]")
|
|
57
|
+
.description("generate typed API request code from an OpenAPI document (URL or local JSON/YAML); the first run scaffolds apits.config.ts")
|
|
58
|
+
.option("-n, --name <name>", "only generate the config source with this name")
|
|
59
|
+
.option("-w, --watch", "watch a local OpenAPI document and regenerate on change", false)
|
|
60
|
+
.option("--skip-install", "do not install the generator dev dependency", false)
|
|
61
|
+
.action(async function (input) {
|
|
62
|
+
const flags = this.optsWithGlobals();
|
|
63
|
+
await (0, gen_api_1.runGenApi)({
|
|
64
|
+
input,
|
|
65
|
+
name: flags.name,
|
|
66
|
+
watch: Boolean(flags.watch),
|
|
67
|
+
skipInstall: Boolean(flags.skipInstall),
|
|
68
|
+
cwd: flags.cwd ?? process.cwd(),
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
program.parseAsync(process.argv).catch((error) => {
|
|
72
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
73
|
+
console.error(`${(0, colorette_1.red)("error")} ${message}`);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
});
|
|
76
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AACA,yCAAoC;AACpC,yCAAsC;AAEtC,0CAA0C;AAC1C,wCAAwC;AACxC,gDAA+C;AAIlC,QAAA,OAAO,GAAI,OAAO,CAAC,iBAAiB,CAAyB;KACvE,OAAO,CAAC;AAEX,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,QAAQ,CAAC;KACd,WAAW,CACV,mHAAmH,CACpH;KACA,OAAO,CAAC,eAAO,CAAC;KAChB,MAAM,CAAC,iBAAiB,EAAE,wBAAwB,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;KAIlE,MAAM,CAAC,GAAG,EAAE;IACX,OAAO,CAAC,UAAU,EAAE,CAAC;IACrB,OAAO,CAAC,GAAG,CAAC,KAAK,IAAA,gBAAI,EAAC,oBAAoB,CAAC,IAAI,eAAO,EAAE,CAAC,CAAC;AAC5D,CAAC,CAAC,CAAC;AAIL,OAAO;KACJ,OAAO,CAAC,qBAAqB,CAAC;KAC9B,WAAW,CAAC,qDAAqD,CAAC;KAClE,MAAM,CACL,uBAAuB,EACvB,yEAAyE,CAC1E;KACA,MAAM,CACL,sBAAsB,EACtB,6DAA6D,CAC9D;KACA,MAAM,CAAC,eAAe,EAAE,oCAAoC,EAAE,SAAS,CAAC;KACxE,MAAM,CAAC,KAAK,WAA0B,WAAmB;IACxD,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;IACrC,MAAM,IAAA,cAAO,EAAC;QACZ,IAAI,EAAE,WAAW;QACjB,GAAG,EAAG,KAAK,CAAC,GAAc,IAAI,OAAO,CAAC,GAAG,EAAE;QAC3C,YAAY,EAAE,KAAK,CAAC,YAAkC;QACtD,WAAW,EAAE,KAAK,C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0B;QACtC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;QAC3B,WAAW,EAAE,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC;QACvC,GAAG,EAAG,KAAK,CAAC,GAAc,IAAI,OAAO,CAAC,GAAG,EAAE;KAC5C,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAKL,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IACxD,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,OAAO,CAAC,KAAK,CAAC,GAAG,IAAA,eAAG,EAAC,OAAO,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC;IAC5C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CliError = void 0;
|
|
4
|
+
class CliError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "CliError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.CliError = CliError;
|
|
11
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":";;;AACA,MAAa,QAAS,SAAQ,KAAK;IACjC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AALD,4BAKC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function execInteractive(command: string, args: string[], cwd: string): Promise<void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execInteractive = execInteractive;
|
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
|
5
|
+
async function execInteractive(command, args, cwd) {
|
|
6
|
+
await new Promise((resolve, reject) => {
|
|
7
|
+
const child = (0, node_child_process_1.spawn)(command, args, { cwd, stdio: "inherit" });
|
|
8
|
+
child.on("error", reject);
|
|
9
|
+
child.on("close", (code) => {
|
|
10
|
+
if (code === 0)
|
|
11
|
+
resolve();
|
|
12
|
+
else
|
|
13
|
+
reject(new Error(`\`${command} ${args.join(" ")}\` exited with code ${code}`));
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=exec-interactive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec-interactive.js","sourceRoot":"","sources":["../../src/lib/exec-interactive.ts"],"names":[],"mappings":";;AAGA,0CAaC;AAhBD,2DAA2C;AAGpC,KAAK,UAAU,eAAe,CACnC,OAAe,EACf,IAAc,EACd,GAAW;IAEX,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC1C,MAAM,KAAK,GAAG,IAAA,0BAAK,EAAC,OAAO,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QAC9D,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC1B,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YACzB,IAAI,IAAI,KAAK,CAAC;gBAAE,OAAO,EAAE,CAAC;;gBACrB,MAAM,CAAC,IAAI,KAAK,CAAC,KAAK,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,uBAAuB,IAAI,EAAE,CAAC,CAAC,CAAC;QACtF,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/lib/exec.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execCapture = execCapture;
|
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
|
5
|
+
async function execCapture(command, args, options = {}) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const child = (0, node_child_process_1.spawn)(command, args, {
|
|
8
|
+
cwd: options.cwd,
|
|
9
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
10
|
+
});
|
|
11
|
+
let stdout = "";
|
|
12
|
+
let stderr = "";
|
|
13
|
+
child.stdout.on("data", (chunk) => {
|
|
14
|
+
stdout += chunk;
|
|
15
|
+
});
|
|
16
|
+
child.stderr.on("data", (chunk) => {
|
|
17
|
+
stderr += chunk;
|
|
18
|
+
});
|
|
19
|
+
child.on("error", reject);
|
|
20
|
+
child.on("close", (code) => {
|
|
21
|
+
if (code === 0) {
|
|
22
|
+
resolve({ stdout, stderr });
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
reject(new Error(`\`${command} ${args.join(" ")}\` exited with code ${code}${stderr.trim() ? `\n${stderr.trim()}` : ""}`));
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=exec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../../src/lib/exec.ts"],"names":[],"mappings":";;AASA,kCA+BC;AAxCD,2DAA2C;AASpC,KAAK,UAAU,WAAW,CAC/B,OAAe,EACf,IAAc,EACd,UAA4B,EAAE;IAE9B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,KAAK,GAAG,IAAA,0BAAK,EAAC,OAAO,EAAE,IAAI,EAAE;YACjC,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC;SAClC,CAAC,CAAC;QACH,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;YACxC,MAAM,IAAI,KAAK,CAAC;QAClB,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;YACxC,MAAM,IAAI,KAAK,CAAC;QAClB,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC1B,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YACzB,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;gBACf,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;YAC9B,CAAC;iBAAM,CAAC;gBACN,MAAM,CACJ,IAAI,KAAK,CACP,KAAK,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,uBAAuB,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CACxG,CACF,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/r/registry-item.json",
|
|
3
|
+
"name": "api-client",
|
|
4
|
+
"type": "registry:lib",
|
|
5
|
+
"title": "API client",
|
|
6
|
+
"description": "Axios instance with bearer-token auth, httpOnly refresh-cookie rotation, single-flight 401 retry and proactive token refresh.",
|
|
7
|
+
"dependencies": [
|
|
8
|
+
"axios@^1.20.0"
|
|
9
|
+
],
|
|
10
|
+
"postInstall": "Adjust BASE_URL / storage keys / REFRESH_PATH in src/lib/api-client.ts to match your backend contract.",
|
|
11
|
+
"files": [
|
|
12
|
+
{
|
|
13
|
+
"path": "src/lib/api-client.ts",
|
|
14
|
+
"content": "import axios, {\n type AxiosRequestConfig,\n type AxiosResponse,\n type InternalAxiosRequestConfig,\n} from \"axios\";\n\n// ---------------------------------------------------------------------------\n// Project-specific configuration — edit these for your backend contract.\n// ---------------------------------------------------------------------------\n\n/** Base URL of the API; same-origin by default. */\nconst BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL ?? \"\";\n\n/** localStorage key of the short-lived access token. */\nconst ACCESS_TOKEN_KEY = \"access-token\";\n\n/** localStorage key of the access-token expiry epoch in milliseconds. */\nconst ACCESS_TOKEN_EXPIRES_AT_KEY = \"access-token-expires-at\";\n\n/** Endpoint that exchanges the httpOnly refresh cookie for a new access token. */\nconst REFRESH_PATH = \"/auth/refresh-access-token\";\n\n/** Paths that must never trigger a silent refresh (would recurse). */\nconst AUTH_PATH_PATTERN = /^\\/auth\\//;\n\n/** Refresh this early so business requests never carry an expired token. */\nconst PROACTIVE_REFRESH_LEAD_MS = 60_000;\n\n/** How often the proactive scheduler checks expiry. */\nconst PROACTIVE_REFRESH_CHECK_INTERVAL_MS = 30_000;\n\n/**\n * Pause before retrying a failed refresh. When another tab rotates the\n * refresh cookie, its Set-Cookie reaches this tab a moment later; the retry\n * then carries the renewed cookie.\n */\nconst REFRESH_RETRY_DELAY_MS = 1_500;\n\n// ---------------------------------------------------------------------------\n// Token storage\n// ---------------------------------------------------------------------------\n\nexport function getAccessToken(): string {\n if (typeof window === \"undefined\") return \"\";\n return window.localStorage.getItem(ACCESS_TOKEN_KEY) ?? \"\";\n}\n\n/** Persist token + expiry after login or refresh. */\nexport function setSession(token: string, expiresInSeconds?: number): void {\n if (typeof window === \"undefined\") return;\n window.localStorage.setItem(ACCESS_TOKEN_KEY, token);\n if (typeof expiresInSeconds === \"number\" && expiresInSeconds > 0) {\n window.localStorage.setItem(\n ACCESS_TOKEN_EXPIRES_AT_KEY,\n String(Date.now() + expiresInSeconds * 1000),\n );\n }\n}\n\n/** Remove all locally stored session data. */\nexport function clearSession(): void {\n if (typeof window === \"undefined\") return;\n window.localStorage.removeItem(ACCESS_TOKEN_KEY);\n window.localStorage.removeItem(ACCESS_TOKEN_EXPIRES_AT_KEY);\n}\n\n/** Normalized error so callers never depend on the axios error shape. */\nexport class ApiError extends Error {\n readonly status: number;\n readonly data: unknown;\n\n constructor(message: string, status: number, data: unknown) {\n super(message);\n this.name = \"ApiError\";\n this.status = status;\n this.data = data;\n }\n}\n\n/**\n * Hook invoked when the refresh cookie is missing/expired. Wire it to your\n * router (e.g. redirect to the login page); the client itself stays\n * router-agnostic.\n */\nlet sessionExpiredHandler: (() => void) | null = null;\nexport function onSessionExpired(handler: () => void): void {\n sessionExpiredHandler = handler;\n}\n\n// ---------------------------------------------------------------------------\n// Refresh-token rotation\n// ---------------------------------------------------------------------------\n\nfunction isUnauthorized(error: unknown): boolean {\n return axios.isAxiosError(error) && error.response?.status === 401;\n}\n\n/** One refresh round-trip; persists the renewed token and its expiry. */\nasync function requestRefreshOnce(): Promise<string | null> {\n const response = await axios.get(`${BASE_URL}${REFRESH_PATH}`, {\n withCredentials: true,\n });\n // Default envelope: { token, tokenExpiresInSeconds }.\n const data = response.data as {\n token?: string;\n tokenExpiresInSeconds?: number;\n };\n if (!data?.token) return null;\n setSession(data.token, data.tokenExpiresInSeconds);\n return data.token;\n}\n\n// Shared in-flight refresh. The backend rotates the refresh cookie on every\n// call, so concurrent 401s must await the same request instead of issuing\n// parallel refreshes that invalidate each other's cookie.\nlet refreshPromise: Promise<string | null> | null = null;\n\n/** Exchange the httpOnly refresh cookie for a new access token (single-flight). */\nfunction refreshAccessToken(): Promise<string | null> {\n if (refreshPromise) return refreshPromise;\n\n refreshPromise = (async () => {\n try {\n return await requestRefreshOnce();\n } catch (firstError) {\n if (!isUnauthorized(firstError)) return null;\n // Possible cross-tab cookie rotation: retry once after a short pause.\n await new Promise((resolve) =>\n setTimeout(resolve, REFRESH_RETRY_DELAY_MS),\n );\n try {\n return await requestRefreshOnce();\n } catch {\n return null;\n }\n } finally {\n refreshPromise = null;\n }\n })();\n\n return refreshPromise;\n}\n\n// ---------------------------------------------------------------------------\n// Proactive refresh scheduler (module-level singleton)\n// ---------------------------------------------------------------------------\n\nlet schedulerTimer: ReturnType<typeof setInterval> | null = null;\n\n/**\n * Start the scheduler that renews the token shortly before expiry. Call once\n * on the client (e.g. in the authenticated layout). Reactive 401 refresh\n * stays as a fallback for laptop sleep / scheduler drift.\n */\nexport function initProactiveTokenRefresh(): void {\n if (typeof window === \"undefined\" || schedulerTimer) return;\n\n const refreshIfDue = (): void => {\n const token = getAccessToken();\n const expiresAt = Number(\n window.localStorage.getItem(ACCESS_TOKEN_EXPIRES_AT_KEY) ?? 0,\n );\n if (\n token &&\n expiresAt &&\n Date.now() >= expiresAt - PROACTIVE_REFRESH_LEAD_MS\n ) {\n void refreshAccessToken();\n }\n };\n\n // Run immediately (tabs reopened after sleep) and then on an interval.\n refreshIfDue();\n schedulerTimer = setInterval(\n refreshIfDue,\n PROACTIVE_REFRESH_CHECK_INTERVAL_MS,\n );\n}\n\n// ---------------------------------------------------------------------------\n// Axios instance\n// ---------------------------------------------------------------------------\n\nexport const api = axios.create({\n baseURL: BASE_URL,\n withCredentials: true,\n});\n\napi.interceptors.request.use((config) => {\n const token = getAccessToken();\n // Within the interceptor chain headers is always an AxiosHeaders instance.\n if (token) {\n config.headers.set(\"Authorization\", `Bearer ${token}`);\n }\n return config;\n});\n\napi.interceptors.response.use(\n (response) => response,\n async (error) => {\n const original = error?.config as\n | (InternalAxiosRequestConfig & { _retriedAfterRefresh?: boolean })\n | undefined;\n const url: string = original?.url ?? \"\";\n const canSilentlyRefresh =\n typeof window !== \"undefined\" &&\n !original?._retriedAfterRefresh &&\n !AUTH_PATH_PATTERN.test(url);\n\n if (isUnauthorized(error) && original && canSilentlyRefresh) {\n original._retriedAfterRefresh = true;\n const renewed = await refreshAccessToken();\n if (renewed) {\n original.headers.set(\"Authorization\", `Bearer ${renewed}`);\n return api(original);\n }\n // Refresh cookie missing or expired: the session is over.\n clearSession();\n sessionExpiredHandler?.();\n }\n\n if (axios.isAxiosError(error)) {\n const data = error.response?.data as { message?: string } | undefined;\n throw new ApiError(\n data?.message ?? error.message,\n error.response?.status ?? 0,\n data,\n );\n }\n throw error;\n },\n);\n\n// ---------------------------------------------------------------------------\n// Typed convenience methods — return the response body directly.\n// ---------------------------------------------------------------------------\n\nexport const apiClient = {\n get<T>(url: string, config?: AxiosRequestConfig): Promise<T> {\n return api.get<unknown, AxiosResponse<T>>(url, config).then((r) => r.data);\n },\n post<T>(\n url: string,\n data?: unknown,\n config?: AxiosRequestConfig,\n ): Promise<T> {\n return api\n .post<unknown, AxiosResponse<T>>(url, data, config)\n .then((r) => r.data);\n },\n put<T>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<T> {\n return api\n .put<unknown, AxiosResponse<T>>(url, data, config)\n .then((r) => r.data);\n },\n patch<T>(\n url: string,\n data?: unknown,\n config?: AxiosRequestConfig,\n ): Promise<T> {\n return api\n .patch<unknown, AxiosResponse<T>>(url, data, config)\n .then((r) => r.data);\n },\n delete<T>(url: string, config?: AxiosRequestConfig): Promise<T> {\n return api\n .delete<unknown, AxiosResponse<T>>(url, config)\n .then((r) => r.data);\n },\n // HEAD/OPTIONS responses carry no body; resolve to the full AxiosResponse\n // so callers can still inspect status and headers.\n head<T>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> {\n return api.head<unknown, AxiosResponse<T>>(url, config);\n },\n options<T>(\n url: string,\n config?: AxiosRequestConfig,\n ): Promise<AxiosResponse<T>> {\n return api.options<unknown, AxiosResponse<T>>(url, config);\n },\n};\n",
|
|
15
|
+
"type": "registry:lib"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/r/registry-item.json",
|
|
3
|
+
"name": "auth",
|
|
4
|
+
"type": "registry:lib",
|
|
5
|
+
"title": "Auth utilities",
|
|
6
|
+
"description": "login/logout helpers, session-expired redirect binding and proactive-refresh bootstrap built on the api-client.",
|
|
7
|
+
"registryDependencies": [
|
|
8
|
+
"api-client"
|
|
9
|
+
],
|
|
10
|
+
"postInstall": "Adjust LOGIN_PATH/LOGOUT_PATH and the login response fields in src/lib/auth.ts; call initAuth() once in your authenticated client layout.",
|
|
11
|
+
"files": [
|
|
12
|
+
{
|
|
13
|
+
"path": "src/lib/auth.ts",
|
|
14
|
+
"content": "\"use client\";\n\nimport {\n apiClient,\n clearSession,\n getAccessToken,\n initProactiveTokenRefresh,\n onSessionExpired,\n setSession,\n} from \"@/lib/api-client\";\n\n// ---------------------------------------------------------------------------\n// Project-specific configuration — edit these for your backend contract.\n// ---------------------------------------------------------------------------\n\n/** Login endpoint; accepts the credentials object and returns a session. */\nconst LOGIN_PATH = \"/auth/login\";\n\n/** Logout endpoint (called best-effort; local session is cleared regardless). */\nconst LOGOUT_PATH = \"/auth/logout\";\n\n/** Where to redirect when the session expires or login is required. */\nconst DEFAULT_LOGIN_PATH = \"/login\";\n\n/** Login response envelope (adjust fields to match your backend). */\ninterface LoginResult {\n token: string;\n tokenExpiresInSeconds?: number;\n}\n\nexport interface LoginCredentials {\n account: string;\n password: string;\n}\n\nlet initialized = false;\n\n/**\n * Wire auth behaviour to the router and start proactive token refresh.\n * Call once on the client, e.g. in the authenticated layout's useEffect.\n */\nexport function initAuth(options?: { loginPath?: string }): void {\n if (initialized || typeof window === \"undefined\") return;\n initialized = true;\n\n const loginPath = options?.loginPath ?? DEFAULT_LOGIN_PATH;\n\n // Avoid bouncing on the login page itself.\n onSessionExpired(() => {\n if (window.location.pathname !== loginPath) {\n const redirect = encodeURIComponent(\n window.location.pathname + window.location.search,\n );\n window.location.replace(`${loginPath}?redirect=${redirect}`);\n }\n });\n\n initProactiveTokenRefresh();\n}\n\n/** Log in, persist the session, and return the raw result for callers. */\nexport async function login(\n credentials: LoginCredentials,\n): Promise<LoginResult> {\n const result = await apiClient.post<LoginResult>(LOGIN_PATH, credentials);\n setSession(result.token, result.tokenExpiresInSeconds);\n return result;\n}\n\n/** Log out; always clears the local session even if the API call fails. */\nexport async function logout(): Promise<void> {\n try {\n await apiClient.post(LOGOUT_PATH);\n } finally {\n clearSession();\n }\n}\n\nexport function isAuthenticated(): boolean {\n return Boolean(getAccessToken());\n}\n",
|
|
15
|
+
"type": "registry:lib"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function buildRegistry(sourceRoot: string, outputRoot: string): Promise<string[]>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.buildRegistry = buildRegistry;
|
|
7
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const SHADCN_ITEM_SCHEMA = "https://ui.shadcn.com/r/registry-item.json";
|
|
10
|
+
async function buildRegistry(sourceRoot, outputRoot) {
|
|
11
|
+
const entries = await promises_1.default.readdir(sourceRoot, { withFileTypes: true });
|
|
12
|
+
const built = [];
|
|
13
|
+
for (const entry of entries) {
|
|
14
|
+
if (!entry.isDirectory())
|
|
15
|
+
continue;
|
|
16
|
+
const itemDir = node_path_1.default.join(sourceRoot, entry.name);
|
|
17
|
+
const manifestPath = node_path_1.default.join(itemDir, "item.json");
|
|
18
|
+
const manifestExists = await promises_1.default
|
|
19
|
+
.access(manifestPath)
|
|
20
|
+
.then(() => true)
|
|
21
|
+
.catch(() => false);
|
|
22
|
+
if (!manifestExists)
|
|
23
|
+
continue;
|
|
24
|
+
const manifest = JSON.parse(await promises_1.default.readFile(manifestPath, "utf8"));
|
|
25
|
+
if (manifest.name !== entry.name) {
|
|
26
|
+
throw new Error(`Registry folder '${entry.name}' does not match item name '${manifest.name}'.`);
|
|
27
|
+
}
|
|
28
|
+
const files = await Promise.all(manifest.files.map(async (relative) => ({
|
|
29
|
+
path: relative,
|
|
30
|
+
content: await promises_1.default.readFile(node_path_1.default.join(itemDir, relative), "utf8"),
|
|
31
|
+
type: manifest.type,
|
|
32
|
+
})));
|
|
33
|
+
const builtItem = {
|
|
34
|
+
$schema: SHADCN_ITEM_SCHEMA,
|
|
35
|
+
name: manifest.name,
|
|
36
|
+
type: manifest.type,
|
|
37
|
+
title: manifest.title,
|
|
38
|
+
...(manifest.description ? { description: manifest.description } : {}),
|
|
39
|
+
...(manifest.dependencies?.length
|
|
40
|
+
? { dependencies: manifest.dependencies }
|
|
41
|
+
: {}),
|
|
42
|
+
...(manifest.registryDependencies?.length
|
|
43
|
+
? { registryDependencies: manifest.registryDependencies }
|
|
44
|
+
: {}),
|
|
45
|
+
...(manifest.postInstall ? { postInstall: manifest.postInstall } : {}),
|
|
46
|
+
files,
|
|
47
|
+
};
|
|
48
|
+
const outDir = node_path_1.default.join(outputRoot, entry.name);
|
|
49
|
+
await promises_1.default.mkdir(outDir, { recursive: true });
|
|
50
|
+
await promises_1.default.writeFile(node_path_1.default.join(outDir, "item.json"), `${JSON.stringify(builtItem, null, 2)}\n`);
|
|
51
|
+
built.push(entry.name);
|
|
52
|
+
}
|
|
53
|
+
return built;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/registry/build.ts"],"names":[],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,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAC1C,CAAC;QACF,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/r/registry-item.json",
|
|
3
|
+
"name": "login-form",
|
|
4
|
+
"type": "registry:block",
|
|
5
|
+
"title": "Login form",
|
|
6
|
+
"description": "Account/password login card built on shadcn ui primitives; submits through the auth util and honors the ?redirect= query parameter.",
|
|
7
|
+
"registryDependencies": [
|
|
8
|
+
"auth"
|
|
9
|
+
],
|
|
10
|
+
"files": [
|
|
11
|
+
{
|
|
12
|
+
"path": "src/components/login-form.tsx",
|
|
13
|
+
"content": "\"use client\";\n\nimport { Suspense, useState, type FormEvent } from \"react\";\nimport { useRouter, useSearchParams } from \"next/navigation\";\nimport { Loader2 } from \"lucide-react\";\n\nimport { login } from \"@/lib/auth\";\nimport { Button } from \"@/components/ui/button\";\nimport { Input } from \"@/components/ui/input\";\nimport { Label } from \"@/components/ui/label\";\nimport {\n Card,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from \"@/components/ui/card\";\n\nfunction LoginFormFields() {\n const router = useRouter();\n const searchParams = useSearchParams();\n const [account, setAccount] = useState(\"\");\n const [password, setPassword] = useState(\"\");\n const [error, setError] = useState<string | null>(null);\n const [submitting, setSubmitting] = useState(false);\n\n async function handleSubmit(event: FormEvent<HTMLFormElement>) {\n event.preventDefault();\n setError(null);\n setSubmitting(true);\n try {\n await login({ account, password });\n // Honor ?redirect=/path when present, otherwise go home.\n router.replace(searchParams.get(\"redirect\") ?? \"/\");\n } catch (err) {\n setError(err instanceof Error ? err.message : \"Login failed\");\n } finally {\n setSubmitting(false);\n }\n }\n\n return (\n <Card className=\"w-full max-w-sm\">\n <CardHeader>\n <CardTitle className=\"text-xl\">Sign in</CardTitle>\n <CardDescription>\n Use your account and password to continue.\n </CardDescription>\n </CardHeader>\n <CardContent>\n <form\n onSubmit={handleSubmit}\n className=\"flex flex-col gap-4\"\n noValidate\n >\n <div className=\"flex flex-col gap-2\">\n <Label htmlFor=\"account\">Account</Label>\n <Input\n id=\"account\"\n name=\"account\"\n autoComplete=\"username\"\n placeholder=\"you@example.com\"\n value={account}\n onChange={(event) => setAccount(event.target.value)}\n required\n />\n </div>\n\n <div className=\"flex flex-col gap-2\">\n <Label htmlFor=\"password\">Password</Label>\n <Input\n id=\"password\"\n name=\"password\"\n type=\"password\"\n autoComplete=\"current-password\"\n value={password}\n onChange={(event) => setPassword(event.target.value)}\n required\n />\n </div>\n\n {error ? <p className=\"text-sm text-destructive\">{error}</p> : null}\n\n <Button type=\"submit\" disabled={submitting} className=\"w-full\">\n {submitting ? (\n <Loader2 className=\"size-4 animate-spin\" />\n ) : (\n \"Sign in\"\n )}\n </Button>\n </form>\n </CardContent>\n </Card>\n );\n}\n\n// useSearchParams requires a Suspense boundary; provide one so the block can\n// be dropped into any page directly.\nexport function LoginForm() {\n return (\n <div className=\"flex min-h-svh items-center justify-center p-4\">\n <Suspense fallback={null}>\n <LoginFormFields />\n </Suspense>\n </div>\n );\n}\n",
|
|
14
|
+
"type": "registry:block"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RegistryManifest } from "./types";
|
|
2
|
+
export interface LoadedItem {
|
|
3
|
+
manifest: RegistryManifest;
|
|
4
|
+
files: Array<{
|
|
5
|
+
target: string;
|
|
6
|
+
source?: string;
|
|
7
|
+
content?: string;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
export declare function resolveRegistryRoot(): Promise<string>;
|
|
11
|
+
export declare function loadItem(root: string, name: string): Promise<LoadedItem>;
|
|
12
|
+
export declare function resolveInstallSet(root: string, names: string[]): Promise<LoadedItem[]>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveRegistryRoot = resolveRegistryRoot;
|
|
7
|
+
exports.loadItem = loadItem;
|
|
8
|
+
exports.resolveInstallSet = resolveInstallSet;
|
|
9
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
const errors_1 = require("../lib/errors");
|
|
12
|
+
async function isRegistryRoot(candidate) {
|
|
13
|
+
let entries;
|
|
14
|
+
try {
|
|
15
|
+
entries = await promises_1.default.readdir(candidate, { withFileTypes: true });
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
for (const entry of entries) {
|
|
21
|
+
if (!entry.isDirectory())
|
|
22
|
+
continue;
|
|
23
|
+
const hasItem = await promises_1.default
|
|
24
|
+
.access(node_path_1.default.join(candidate, entry.name, "item.json"))
|
|
25
|
+
.then(() => true)
|
|
26
|
+
.catch(() => false);
|
|
27
|
+
if (hasItem)
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
async function resolveRegistryRoot() {
|
|
33
|
+
const candidates = [
|
|
34
|
+
node_path_1.default.resolve(__dirname, "..", "registry"),
|
|
35
|
+
node_path_1.default.resolve(__dirname, "..", "..", "registry"),
|
|
36
|
+
];
|
|
37
|
+
for (const candidate of candidates) {
|
|
38
|
+
if (await isRegistryRoot(candidate)) {
|
|
39
|
+
return candidate;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
throw new errors_1.CliError("Registry not found (expected dist/registry or registry/).");
|
|
43
|
+
}
|
|
44
|
+
async function readItemFile(root, name) {
|
|
45
|
+
const raw = await promises_1.default.readFile(node_path_1.default.join(root, name, "item.json"), "utf8");
|
|
46
|
+
return JSON.parse(raw);
|
|
47
|
+
}
|
|
48
|
+
function isBuilt(item) {
|
|
49
|
+
return (Array.isArray(item.files) &&
|
|
50
|
+
item.files.length > 0 &&
|
|
51
|
+
typeof item.files[0] === "object");
|
|
52
|
+
}
|
|
53
|
+
async function loadItem(root, name) {
|
|
54
|
+
const item = await readItemFile(root, name);
|
|
55
|
+
if (isBuilt(item)) {
|
|
56
|
+
return {
|
|
57
|
+
manifest: {
|
|
58
|
+
name: item.name,
|
|
59
|
+
type: item.type,
|
|
60
|
+
title: item.title,
|
|
61
|
+
description: item.description,
|
|
62
|
+
dependencies: item.dependencies,
|
|
63
|
+
registryDependencies: item.registryDependencies,
|
|
64
|
+
postInstall: item.postInstall,
|
|
65
|
+
files: item.files.map((f) => f.path),
|
|
66
|
+
},
|
|
67
|
+
files: item.files.map((f) => ({
|
|
68
|
+
target: f.path,
|
|
69
|
+
content: f.content,
|
|
70
|
+
})),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const manifest = item;
|
|
74
|
+
const files = manifest.files.map((relative) => ({
|
|
75
|
+
target: relative,
|
|
76
|
+
source: node_path_1.default.join(root, name, relative),
|
|
77
|
+
}));
|
|
78
|
+
return { manifest, files };
|
|
79
|
+
}
|
|
80
|
+
async function resolveInstallSet(root, names) {
|
|
81
|
+
const ordered = [];
|
|
82
|
+
const seen = new Set();
|
|
83
|
+
const visiting = new Set();
|
|
84
|
+
async function visit(name) {
|
|
85
|
+
if (seen.has(name))
|
|
86
|
+
return;
|
|
87
|
+
if (visiting.has(name)) {
|
|
88
|
+
throw new errors_1.CliError(`Circular registry dependency involving '${name}'.`);
|
|
89
|
+
}
|
|
90
|
+
visiting.add(name);
|
|
91
|
+
const loaded = await loadItem(root, name).catch(() => {
|
|
92
|
+
throw new errors_1.CliError(`Registry item '${name}' not found. Run 'fewbie add' with a valid item name.`);
|
|
93
|
+
});
|
|
94
|
+
for (const dep of loaded.manifest.registryDependencies ?? []) {
|
|
95
|
+
await visit(dep);
|
|
96
|
+
}
|
|
97
|
+
visiting.delete(name);
|
|
98
|
+
seen.add(name);
|
|
99
|
+
ordered.push(loaded);
|
|
100
|
+
}
|
|
101
|
+
for (const name of names) {
|
|
102
|
+
await visit(name);
|
|
103
|
+
}
|
|
104
|
+
return ordered;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/registry/store.ts"],"names":[],"mappings":";;;;;AA2CA,kDAaC;AAqBD,4BA+BC;AAMD,8CA+BC;AAjJD,gEAAkC;AAClC,0DAA6B;AAE7B,0CAAyC;AAgBzC,KAAK,UAAU,cAAc,CAAC,SAAiB;IAC7C,IAAI,OAAmC,CAAC;IACxC,IAAI,CAAC;QACH,OAAO,GAAG,MAAM,kBAAE,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IACjE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;IACD,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE;YAAE,SAAS;QACnC,MAAM,OAAO,GAAG,MAAM,kBAAE;aACrB,MAAM,CAAC,mBAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;aACrD,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;aAChB,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;QACtB,IAAI,OAAO;YAAE,OAAO,IAAI,CAAC;IAC3B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAQM,KAAK,UAAU,mBAAmB;IACvC,MAAM,UAAU,GAAG;QACjB,mBAAI,CAAC,OAAO,CAAC,SAAS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I,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;YACnD,MAAM,IAAI,iBAAQ,CAChB,kBAAkB,IAAI,uDAAuD,CAC9E,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,oBAAoB,IAAI,EAAE,EAAE,CAAC;YAC7D,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;QACD,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/r/registry-item.json",
|
|
3
|
+
"name": "theme",
|
|
4
|
+
"type": "registry:component",
|
|
5
|
+
"title": "Theme provider & toggle",
|
|
6
|
+
"description": "next-themes ThemeProvider wrapper and a light/dark toggle button. The CSS-variable token system itself ships with the shadcn-initialized template (Tailwind v4).",
|
|
7
|
+
"dependencies": [
|
|
8
|
+
"next-themes@^0.4.6"
|
|
9
|
+
],
|
|
10
|
+
"postInstall": "Wrap your root layout <body> with <ThemeProvider> (see src/components/theme-provider.tsx).",
|
|
11
|
+
"files": [
|
|
12
|
+
{
|
|
13
|
+
"path": "src/components/theme-provider.tsx",
|
|
14
|
+
"content": "\"use client\";\n\nimport type { ComponentProps } from \"react\";\nimport { ThemeProvider as NextThemesProvider } from \"next-themes\";\n\nexport function ThemeProvider({\n children,\n ...props\n}: ComponentProps<typeof NextThemesProvider>) {\n return <NextThemesProvider {...props}>{children}</NextThemesProvider>;\n}\n",
|
|
15
|
+
"type": "registry:component"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "src/components/theme-toggle.tsx",
|
|
19
|
+
"content": "\"use client\";\n\nimport { Moon, Sun } from \"lucide-react\";\nimport { useTheme } from \"next-themes\";\n\nimport { Button } from \"@/components/ui/button\";\n\nexport function ThemeToggle() {\n const { resolvedTheme, setTheme } = useTheme();\n\n return (\n <Button\n variant=\"outline\"\n size=\"icon\"\n aria-label=\"Toggle theme\"\n onClick={() => setTheme(resolvedTheme === \"dark\" ? \"light\" : \"dark\")}\n >\n <Sun className=\"size-5 scale-100 rotate-0 transition-all dark:scale-0 dark:-rotate-90\" />\n <Moon className=\"absolute size-5 scale-0 rotate-90 transition-all dark:scale-100 dark:rotate-0\" />\n </Button>\n );\n}\n",
|
|
20
|
+
"type": "registry:component"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type RegistryItemType = "registry:lib" | "registry:component" | "registry:block";
|
|
2
|
+
export interface RegistryFileRef {
|
|
3
|
+
path: string;
|
|
4
|
+
}
|
|
5
|
+
export interface RegistryFileEntry {
|
|
6
|
+
path: string;
|
|
7
|
+
content: string;
|
|
8
|
+
type: RegistryItemType;
|
|
9
|
+
}
|
|
10
|
+
export interface RegistryManifest {
|
|
11
|
+
name: string;
|
|
12
|
+
type: RegistryItemType;
|
|
13
|
+
title: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
dependencies?: string[];
|
|
16
|
+
registryDependencies?: string[];
|
|
17
|
+
files: string[];
|
|
18
|
+
postInstall?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface BuiltRegistryItem {
|
|
21
|
+
$schema: string;
|
|
22
|
+
name: string;
|
|
23
|
+
type: RegistryItemType;
|
|
24
|
+
title: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
dependencies?: string[];
|
|
27
|
+
registryDependencies?: string[];
|
|
28
|
+
files: RegistryFileEntry[];
|
|
29
|
+
postInstall?: string;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/registry/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@devbie/fewbie-cli",
|
|
3
|
+
"version": "0.1.0-stage.0",
|
|
4
|
+
"description": "fewbie frontend framework CLI",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "worldzhy",
|
|
7
|
+
"bin": {
|
|
8
|
+
"fewbie": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -p tsconfig.json && node --import tsx scripts/build-registry.ts && chmod +x dist/index.js",
|
|
18
|
+
"clean": "rimraf dist",
|
|
19
|
+
"test": "node --import tsx --test test/*.test.ts",
|
|
20
|
+
"prepublishOnly": "npm run build"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"colorette": "^2.0.20",
|
|
24
|
+
"commander": "^12.1.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^22.0.0",
|
|
28
|
+
"rimraf": "^6.1.3",
|
|
29
|
+
"tsx": "^4.19.0",
|
|
30
|
+
"typescript": "^5.9.3"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=20"
|
|
34
|
+
}
|
|
35
|
+
}
|