@nubitio/eject 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/bin/nubit.mjs +32 -0
- package/dist/index.cjs +134 -0
- package/dist/index.d.cts +26 -0
- package/dist/index.d.mts +26 -0
- package/dist/index.mjs +129 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Johan Guerreros
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/bin/nubit.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Nubit eject CLI — generates explicit resource/page files from Hydra docs.
|
|
4
|
+
* Run from the monorepo root: node packages/eject/bin/nubit.mjs eject fields /api/products
|
|
5
|
+
*/
|
|
6
|
+
import process from 'node:process';
|
|
7
|
+
import { writeFileSync } from 'node:fs';
|
|
8
|
+
import { resolve, dirname } from 'node:path';
|
|
9
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
10
|
+
|
|
11
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
|
|
13
|
+
async function loadModule() {
|
|
14
|
+
const distRoot = resolve(__dirname, '../dist');
|
|
15
|
+
try {
|
|
16
|
+
return await import(pathToFileURL(resolve(distRoot, 'index.mjs')).href);
|
|
17
|
+
} catch {
|
|
18
|
+
// Dev fallback: import TypeScript sources via relative path (requires built hydra/crud)
|
|
19
|
+
return await import(pathToFileURL(resolve(__dirname, '../src/runCli.ts')).href);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const [, , command, target, ...rest] = process.argv;
|
|
24
|
+
|
|
25
|
+
function flag(name, fallback) {
|
|
26
|
+
const index = rest.indexOf(name);
|
|
27
|
+
if (index === -1) return fallback;
|
|
28
|
+
return rest[index + 1] ?? fallback;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const mod = await loadModule();
|
|
32
|
+
await mod.runCli({ command, target, rest, flag, writeFileSync, resolve });
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _nubitio_hydra = require("@nubitio/hydra");
|
|
3
|
+
//#region packages/eject/src/ejectFromDocs.ts
|
|
4
|
+
function normalizeUrl(url) {
|
|
5
|
+
const base = url.split("?")[0];
|
|
6
|
+
return base.startsWith("/") ? base.slice(1) : base;
|
|
7
|
+
}
|
|
8
|
+
async function ejectFieldsFromDocs(apiUrl, docsUrl) {
|
|
9
|
+
const response = await fetch(docsUrl);
|
|
10
|
+
if (!response.ok) throw new Error(`Failed to fetch ${docsUrl}: ${response.status} ${response.statusText}`);
|
|
11
|
+
const doc = await response.json();
|
|
12
|
+
const resourceMap = doc["@type"] === "ApiDocumentation" || doc["@type"] === "hydra:ApiDocumentation" ? (0, _nubitio_hydra.parseHydraDoc)(doc, {}) : (0, _nubitio_hydra.parseOpenApiDoc)(doc);
|
|
13
|
+
const normalizedInput = normalizeUrl(apiUrl);
|
|
14
|
+
const resourceSchema = Object.values(resourceMap).find((schema) => normalizeUrl(schema.apiUrl) === normalizedInput);
|
|
15
|
+
if (!resourceSchema) {
|
|
16
|
+
const known = Object.values(resourceMap).map((schema) => schema.apiUrl).join(", ");
|
|
17
|
+
throw new Error(`No schema found for ${apiUrl}. Known: ${known || "(none)"}`);
|
|
18
|
+
}
|
|
19
|
+
const fields = (0, _nubitio_hydra.mapHydraSchemaToFields)(resourceSchema, (className) => resourceMap[className]?.apiUrl, (className) => resourceMap[className]);
|
|
20
|
+
return {
|
|
21
|
+
apiUrl: resourceSchema.apiUrl,
|
|
22
|
+
className: resourceSchema.className,
|
|
23
|
+
fields
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region packages/eject/src/fieldToCode.ts
|
|
28
|
+
const BUILDER_BY_TYPE = {
|
|
29
|
+
text: "textField",
|
|
30
|
+
password: "passwordField",
|
|
31
|
+
textarea: "textareaField",
|
|
32
|
+
date: "dateField",
|
|
33
|
+
datetime: "datetimeField",
|
|
34
|
+
number: "numberField",
|
|
35
|
+
currency: "currencyField",
|
|
36
|
+
select: "selectField",
|
|
37
|
+
enum: "enumField",
|
|
38
|
+
entity: "entityField",
|
|
39
|
+
radio: "radioField",
|
|
40
|
+
switch: "switchField",
|
|
41
|
+
checkbox: "checkboxField",
|
|
42
|
+
file: "fileField",
|
|
43
|
+
image: "imageField",
|
|
44
|
+
tags: "tagsField",
|
|
45
|
+
html: "htmlField",
|
|
46
|
+
none: "noneField"
|
|
47
|
+
};
|
|
48
|
+
function fieldToCodeLine(field) {
|
|
49
|
+
const builder = BUILDER_BY_TYPE[field.type] ?? "textField";
|
|
50
|
+
const parts = [];
|
|
51
|
+
if (builder === "entityField" && field.url) parts.push(`${builder}('${field.url}', '${field.valueField || "_iri"}', '${field.textField || "name"}')`);
|
|
52
|
+
else if (builder === "enumField" && field.data.length > 0) {
|
|
53
|
+
const options = field.data.map((opt) => `{ value: ${JSON.stringify(opt.value)}, text: ${JSON.stringify(opt.text)} }`).join(", ");
|
|
54
|
+
parts.push(`${builder}([${options}])`);
|
|
55
|
+
} else if (builder === "fileField" || builder === "imageField") parts.push(`${builder}('${field.url ?? "/api/media"}')`);
|
|
56
|
+
else parts.push(`${builder}()`);
|
|
57
|
+
let chain = parts[0] + `.name('${field.name}').label(${JSON.stringify(field.label)})`;
|
|
58
|
+
if (field.required) chain += ".required(true)";
|
|
59
|
+
if (field.readonly) chain += ".readonly(true)";
|
|
60
|
+
if (field.precision !== void 0 && field.type === "number") chain += `.precision(${field.precision})`;
|
|
61
|
+
chain += ".build()";
|
|
62
|
+
return ` ${chain},`;
|
|
63
|
+
}
|
|
64
|
+
function renderFieldsModule(apiUrl, fields) {
|
|
65
|
+
const hintable = fields.filter((f) => !f.isIdentity);
|
|
66
|
+
const imports = new Set(["defineResource"]);
|
|
67
|
+
for (const field of hintable) {
|
|
68
|
+
const builder = BUILDER_BY_TYPE[field.type] ?? "textField";
|
|
69
|
+
imports.add(builder);
|
|
70
|
+
}
|
|
71
|
+
return `import { ${[...imports].join(", ")} } from '@nubitio/react-admin';
|
|
72
|
+
|
|
73
|
+
/** Ejected from ${apiUrl} — ${(/* @__PURE__ */ new Date()).toISOString()} */
|
|
74
|
+
export const resource = defineResource('${apiUrl}', {
|
|
75
|
+
fields: [
|
|
76
|
+
${hintable.map(fieldToCodeLine).join("\n")}
|
|
77
|
+
],
|
|
78
|
+
});
|
|
79
|
+
`;
|
|
80
|
+
}
|
|
81
|
+
function renderPageModule(componentName, apiUrl, title) {
|
|
82
|
+
return `import { SmartCrudPage, defineResource } from '@nubitio/react-admin';
|
|
83
|
+
|
|
84
|
+
const resource = defineResource('${apiUrl}', {
|
|
85
|
+
title: ${JSON.stringify(title)},
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
export function ${componentName}() {
|
|
89
|
+
return <SmartCrudPage resource={resource} />;
|
|
90
|
+
}
|
|
91
|
+
`;
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region packages/eject/src/runCli.ts
|
|
95
|
+
async function runCli(ctx) {
|
|
96
|
+
const { command, target, rest, flag, writeFileSync, resolve } = ctx;
|
|
97
|
+
if (!command || command === "--help" || command === "-h") {
|
|
98
|
+
console.log(`Usage:
|
|
99
|
+
nubit eject fields <apiUrl> [--docs http://localhost:8000/api/docs.jsonld] [--out file.ts]
|
|
100
|
+
nubit eject page <Name> <apiUrl> [--docs ...] [--out Pages/Name.tsx] [--title "Title"]
|
|
101
|
+
`);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const docsUrl = flag("--docs", "http://localhost:8000/api/docs.jsonld");
|
|
105
|
+
const outPath = flag("--out", "");
|
|
106
|
+
if (command === "eject" && target === "fields") {
|
|
107
|
+
const apiUrl = rest.find((arg) => !arg.startsWith("--") && arg !== docsUrl && arg !== outPath);
|
|
108
|
+
if (!apiUrl) throw new Error("Missing apiUrl argument");
|
|
109
|
+
const result = await ejectFieldsFromDocs(apiUrl, docsUrl);
|
|
110
|
+
const code = renderFieldsModule(result.apiUrl, result.fields);
|
|
111
|
+
if (outPath) {
|
|
112
|
+
writeFileSync(resolve(outPath), code);
|
|
113
|
+
console.log(`Wrote ${outPath} (${result.className}, ${result.fields.length} fields)`);
|
|
114
|
+
} else console.log(code);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (command === "eject" && target === "page") {
|
|
118
|
+
const [componentName, apiUrl] = rest.filter((arg) => !arg.startsWith("--") && arg !== docsUrl && arg !== outPath);
|
|
119
|
+
if (!componentName || !apiUrl) throw new Error("Usage: nubit eject page <ComponentName> <apiUrl>");
|
|
120
|
+
const code = renderPageModule(componentName, apiUrl, flag("--title", componentName.replace(/Page$/, "")));
|
|
121
|
+
if (outPath) {
|
|
122
|
+
writeFileSync(resolve(outPath), code);
|
|
123
|
+
console.log(`Wrote ${outPath}`);
|
|
124
|
+
} else console.log(code);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
throw new Error(`Unknown command: ${command} ${target ?? ""}`);
|
|
128
|
+
}
|
|
129
|
+
//#endregion
|
|
130
|
+
exports.ejectFieldsFromDocs = ejectFieldsFromDocs;
|
|
131
|
+
exports.fieldToCodeLine = fieldToCodeLine;
|
|
132
|
+
exports.renderFieldsModule = renderFieldsModule;
|
|
133
|
+
exports.renderPageModule = renderPageModule;
|
|
134
|
+
exports.runCli = runCli;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Field } from "@nubitio/crud";
|
|
2
|
+
|
|
3
|
+
//#region packages/eject/src/ejectFromDocs.d.ts
|
|
4
|
+
interface EjectFieldsResult {
|
|
5
|
+
apiUrl: string;
|
|
6
|
+
className: string;
|
|
7
|
+
fields: Field[];
|
|
8
|
+
}
|
|
9
|
+
declare function ejectFieldsFromDocs(apiUrl: string, docsUrl: string): Promise<EjectFieldsResult>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region packages/eject/src/fieldToCode.d.ts
|
|
12
|
+
declare function fieldToCodeLine(field: Field): string;
|
|
13
|
+
declare function renderFieldsModule(apiUrl: string, fields: Field[]): string;
|
|
14
|
+
declare function renderPageModule(componentName: string, apiUrl: string, title: string): string;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region packages/eject/src/runCli.d.ts
|
|
17
|
+
declare function runCli(ctx: {
|
|
18
|
+
command?: string;
|
|
19
|
+
target?: string;
|
|
20
|
+
rest: string[];
|
|
21
|
+
flag: (name: string, fallback: string) => string;
|
|
22
|
+
writeFileSync: (path: string, data: string) => void;
|
|
23
|
+
resolve: (...paths: string[]) => string;
|
|
24
|
+
}): Promise<void>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { ejectFieldsFromDocs, fieldToCodeLine, renderFieldsModule, renderPageModule, runCli };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Field } from "@nubitio/crud";
|
|
2
|
+
|
|
3
|
+
//#region packages/eject/src/ejectFromDocs.d.ts
|
|
4
|
+
interface EjectFieldsResult {
|
|
5
|
+
apiUrl: string;
|
|
6
|
+
className: string;
|
|
7
|
+
fields: Field[];
|
|
8
|
+
}
|
|
9
|
+
declare function ejectFieldsFromDocs(apiUrl: string, docsUrl: string): Promise<EjectFieldsResult>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region packages/eject/src/fieldToCode.d.ts
|
|
12
|
+
declare function fieldToCodeLine(field: Field): string;
|
|
13
|
+
declare function renderFieldsModule(apiUrl: string, fields: Field[]): string;
|
|
14
|
+
declare function renderPageModule(componentName: string, apiUrl: string, title: string): string;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region packages/eject/src/runCli.d.ts
|
|
17
|
+
declare function runCli(ctx: {
|
|
18
|
+
command?: string;
|
|
19
|
+
target?: string;
|
|
20
|
+
rest: string[];
|
|
21
|
+
flag: (name: string, fallback: string) => string;
|
|
22
|
+
writeFileSync: (path: string, data: string) => void;
|
|
23
|
+
resolve: (...paths: string[]) => string;
|
|
24
|
+
}): Promise<void>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { ejectFieldsFromDocs, fieldToCodeLine, renderFieldsModule, renderPageModule, runCli };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { mapHydraSchemaToFields, parseHydraDoc, parseOpenApiDoc } from "@nubitio/hydra";
|
|
2
|
+
//#region packages/eject/src/ejectFromDocs.ts
|
|
3
|
+
function normalizeUrl(url) {
|
|
4
|
+
const base = url.split("?")[0];
|
|
5
|
+
return base.startsWith("/") ? base.slice(1) : base;
|
|
6
|
+
}
|
|
7
|
+
async function ejectFieldsFromDocs(apiUrl, docsUrl) {
|
|
8
|
+
const response = await fetch(docsUrl);
|
|
9
|
+
if (!response.ok) throw new Error(`Failed to fetch ${docsUrl}: ${response.status} ${response.statusText}`);
|
|
10
|
+
const doc = await response.json();
|
|
11
|
+
const resourceMap = doc["@type"] === "ApiDocumentation" || doc["@type"] === "hydra:ApiDocumentation" ? parseHydraDoc(doc, {}) : parseOpenApiDoc(doc);
|
|
12
|
+
const normalizedInput = normalizeUrl(apiUrl);
|
|
13
|
+
const resourceSchema = Object.values(resourceMap).find((schema) => normalizeUrl(schema.apiUrl) === normalizedInput);
|
|
14
|
+
if (!resourceSchema) {
|
|
15
|
+
const known = Object.values(resourceMap).map((schema) => schema.apiUrl).join(", ");
|
|
16
|
+
throw new Error(`No schema found for ${apiUrl}. Known: ${known || "(none)"}`);
|
|
17
|
+
}
|
|
18
|
+
const fields = mapHydraSchemaToFields(resourceSchema, (className) => resourceMap[className]?.apiUrl, (className) => resourceMap[className]);
|
|
19
|
+
return {
|
|
20
|
+
apiUrl: resourceSchema.apiUrl,
|
|
21
|
+
className: resourceSchema.className,
|
|
22
|
+
fields
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region packages/eject/src/fieldToCode.ts
|
|
27
|
+
const BUILDER_BY_TYPE = {
|
|
28
|
+
text: "textField",
|
|
29
|
+
password: "passwordField",
|
|
30
|
+
textarea: "textareaField",
|
|
31
|
+
date: "dateField",
|
|
32
|
+
datetime: "datetimeField",
|
|
33
|
+
number: "numberField",
|
|
34
|
+
currency: "currencyField",
|
|
35
|
+
select: "selectField",
|
|
36
|
+
enum: "enumField",
|
|
37
|
+
entity: "entityField",
|
|
38
|
+
radio: "radioField",
|
|
39
|
+
switch: "switchField",
|
|
40
|
+
checkbox: "checkboxField",
|
|
41
|
+
file: "fileField",
|
|
42
|
+
image: "imageField",
|
|
43
|
+
tags: "tagsField",
|
|
44
|
+
html: "htmlField",
|
|
45
|
+
none: "noneField"
|
|
46
|
+
};
|
|
47
|
+
function fieldToCodeLine(field) {
|
|
48
|
+
const builder = BUILDER_BY_TYPE[field.type] ?? "textField";
|
|
49
|
+
const parts = [];
|
|
50
|
+
if (builder === "entityField" && field.url) parts.push(`${builder}('${field.url}', '${field.valueField || "_iri"}', '${field.textField || "name"}')`);
|
|
51
|
+
else if (builder === "enumField" && field.data.length > 0) {
|
|
52
|
+
const options = field.data.map((opt) => `{ value: ${JSON.stringify(opt.value)}, text: ${JSON.stringify(opt.text)} }`).join(", ");
|
|
53
|
+
parts.push(`${builder}([${options}])`);
|
|
54
|
+
} else if (builder === "fileField" || builder === "imageField") parts.push(`${builder}('${field.url ?? "/api/media"}')`);
|
|
55
|
+
else parts.push(`${builder}()`);
|
|
56
|
+
let chain = parts[0] + `.name('${field.name}').label(${JSON.stringify(field.label)})`;
|
|
57
|
+
if (field.required) chain += ".required(true)";
|
|
58
|
+
if (field.readonly) chain += ".readonly(true)";
|
|
59
|
+
if (field.precision !== void 0 && field.type === "number") chain += `.precision(${field.precision})`;
|
|
60
|
+
chain += ".build()";
|
|
61
|
+
return ` ${chain},`;
|
|
62
|
+
}
|
|
63
|
+
function renderFieldsModule(apiUrl, fields) {
|
|
64
|
+
const hintable = fields.filter((f) => !f.isIdentity);
|
|
65
|
+
const imports = new Set(["defineResource"]);
|
|
66
|
+
for (const field of hintable) {
|
|
67
|
+
const builder = BUILDER_BY_TYPE[field.type] ?? "textField";
|
|
68
|
+
imports.add(builder);
|
|
69
|
+
}
|
|
70
|
+
return `import { ${[...imports].join(", ")} } from '@nubitio/react-admin';
|
|
71
|
+
|
|
72
|
+
/** Ejected from ${apiUrl} — ${(/* @__PURE__ */ new Date()).toISOString()} */
|
|
73
|
+
export const resource = defineResource('${apiUrl}', {
|
|
74
|
+
fields: [
|
|
75
|
+
${hintable.map(fieldToCodeLine).join("\n")}
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
`;
|
|
79
|
+
}
|
|
80
|
+
function renderPageModule(componentName, apiUrl, title) {
|
|
81
|
+
return `import { SmartCrudPage, defineResource } from '@nubitio/react-admin';
|
|
82
|
+
|
|
83
|
+
const resource = defineResource('${apiUrl}', {
|
|
84
|
+
title: ${JSON.stringify(title)},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
export function ${componentName}() {
|
|
88
|
+
return <SmartCrudPage resource={resource} />;
|
|
89
|
+
}
|
|
90
|
+
`;
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region packages/eject/src/runCli.ts
|
|
94
|
+
async function runCli(ctx) {
|
|
95
|
+
const { command, target, rest, flag, writeFileSync, resolve } = ctx;
|
|
96
|
+
if (!command || command === "--help" || command === "-h") {
|
|
97
|
+
console.log(`Usage:
|
|
98
|
+
nubit eject fields <apiUrl> [--docs http://localhost:8000/api/docs.jsonld] [--out file.ts]
|
|
99
|
+
nubit eject page <Name> <apiUrl> [--docs ...] [--out Pages/Name.tsx] [--title "Title"]
|
|
100
|
+
`);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const docsUrl = flag("--docs", "http://localhost:8000/api/docs.jsonld");
|
|
104
|
+
const outPath = flag("--out", "");
|
|
105
|
+
if (command === "eject" && target === "fields") {
|
|
106
|
+
const apiUrl = rest.find((arg) => !arg.startsWith("--") && arg !== docsUrl && arg !== outPath);
|
|
107
|
+
if (!apiUrl) throw new Error("Missing apiUrl argument");
|
|
108
|
+
const result = await ejectFieldsFromDocs(apiUrl, docsUrl);
|
|
109
|
+
const code = renderFieldsModule(result.apiUrl, result.fields);
|
|
110
|
+
if (outPath) {
|
|
111
|
+
writeFileSync(resolve(outPath), code);
|
|
112
|
+
console.log(`Wrote ${outPath} (${result.className}, ${result.fields.length} fields)`);
|
|
113
|
+
} else console.log(code);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (command === "eject" && target === "page") {
|
|
117
|
+
const [componentName, apiUrl] = rest.filter((arg) => !arg.startsWith("--") && arg !== docsUrl && arg !== outPath);
|
|
118
|
+
if (!componentName || !apiUrl) throw new Error("Usage: nubit eject page <ComponentName> <apiUrl>");
|
|
119
|
+
const code = renderPageModule(componentName, apiUrl, flag("--title", componentName.replace(/Page$/, "")));
|
|
120
|
+
if (outPath) {
|
|
121
|
+
writeFileSync(resolve(outPath), code);
|
|
122
|
+
console.log(`Wrote ${outPath}`);
|
|
123
|
+
} else console.log(code);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
throw new Error(`Unknown command: ${command} ${target ?? ""}`);
|
|
127
|
+
}
|
|
128
|
+
//#endregion
|
|
129
|
+
export { ejectFieldsFromDocs, fieldToCodeLine, renderFieldsModule, renderPageModule, runCli };
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nubitio/eject",
|
|
3
|
+
"version": "0.6.1",
|
|
4
|
+
"description": "Eject explicit resource definitions from Hydra API docs",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"nubit",
|
|
9
|
+
"hydra",
|
|
10
|
+
"api-platform",
|
|
11
|
+
"codegen",
|
|
12
|
+
"cli"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/nubitio/nubit-react.git",
|
|
17
|
+
"directory": "packages/eject"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/nubitio/nubit-react/issues"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/nubitio/nubit-react/tree/main/packages/eject#readme",
|
|
23
|
+
"bin": {
|
|
24
|
+
"nubit": "./bin/nubit.mjs"
|
|
25
|
+
},
|
|
26
|
+
"main": "./dist/index.cjs",
|
|
27
|
+
"module": "./dist/index.mjs",
|
|
28
|
+
"types": "./dist/index.d.mts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": {
|
|
32
|
+
"import": "./dist/index.d.mts",
|
|
33
|
+
"require": "./dist/index.d.cts"
|
|
34
|
+
},
|
|
35
|
+
"import": "./dist/index.mjs",
|
|
36
|
+
"require": "./dist/index.cjs"
|
|
37
|
+
},
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"bin"
|
|
43
|
+
],
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public",
|
|
46
|
+
"provenance": true
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@nubitio/crud": "0.6.1",
|
|
50
|
+
"@nubitio/hydra": "0.6.1"
|
|
51
|
+
}
|
|
52
|
+
}
|