@sealcode/sealgen 0.11.0 → 0.11.2
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/@types/add-jdd-component.d.ts +1 -0
- package/@types/generate-components.d.ts +1 -0
- package/@types/templates/jdd-component.d.ts +1 -0
- package/@types/templates/templates.d.ts +2 -0
- package/lib/add-jdd-component.js +34 -0
- package/lib/build.js +6 -1
- package/lib/cli.js +4 -0
- package/lib/generate-components.js +63 -0
- package/lib/templates/jdd-component.js +43 -0
- package/lib/templates/templates.js +2 -0
- package/package.json +4 -1
- package/src/add-jdd-component.ts +43 -0
- package/src/build.ts +6 -1
- package/src/cli.ts +4 -0
- package/src/generate-components.ts +46 -0
- package/src/templates/jdd-component.ts +41 -0
- package/src/templates/templates.ts +2 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function addJDDComponent(): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function generateComponents(): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function jddComponentTemplate(component_name: string): string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { formTemplate } from "./form";
|
|
2
|
+
import { jddComponentTemplate } from "./jdd-component";
|
|
2
3
|
import { LongRunningProcessTemplate } from "./long-running-process";
|
|
3
4
|
import { multiformTemplate } from "./multiform";
|
|
4
5
|
import { pageTemplate } from "./page";
|
|
@@ -14,4 +15,5 @@ export declare const Templates: {
|
|
|
14
15
|
post: typeof postTemplate;
|
|
15
16
|
sreact: typeof statefulPageTemplate;
|
|
16
17
|
lpr: typeof LongRunningProcessTemplate;
|
|
18
|
+
jdd: typeof jddComponentTemplate;
|
|
17
19
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
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.addJDDComponent = void 0;
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const locreq_1 = __importDefault(require("locreq"));
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
const question_1 = require("./utils/question");
|
|
11
|
+
const target_locreq = (0, locreq_1.default)(process.cwd());
|
|
12
|
+
const jdd_component_1 = require("./templates/jdd-component");
|
|
13
|
+
const generate_components_1 = require("./generate-components");
|
|
14
|
+
const js_convert_case_1 = require("js-convert-case");
|
|
15
|
+
async function addJDDComponent() {
|
|
16
|
+
const component_name = await (0, question_1.question)("What's the name of the component? > ", (s) => s.length > 3);
|
|
17
|
+
const file_path = target_locreq.resolve(`src/back/jdd-components/${(0, js_convert_case_1.toKebabCase)(component_name)}/${(0, js_convert_case_1.toKebabCase)(component_name)}.jdd.tsx`);
|
|
18
|
+
if ((0, fs_1.existsSync)(file_path)) {
|
|
19
|
+
// eslint-disable-next-line no-console
|
|
20
|
+
console.error(`ERROR: File ${file_path} already exists.`);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
await fs_1.promises.mkdir((0, path_1.resolve)(file_path, "../"), { recursive: true });
|
|
24
|
+
await fs_1.promises.writeFile(file_path, (0, jdd_component_1.jddComponentTemplate)(component_name));
|
|
25
|
+
const css_file_path = target_locreq.resolve(`src/back/jdd-components/${(0, js_convert_case_1.toKebabCase)(component_name)}/${(0, js_convert_case_1.toKebabCase)(component_name)}.scss`);
|
|
26
|
+
await fs_1.promises.writeFile(css_file_path, `.${(0, js_convert_case_1.toKebabCase)(component_name)} {
|
|
27
|
+
}`);
|
|
28
|
+
// eslint-disable-next-line no-console
|
|
29
|
+
console.log(`Created ${file_path}`);
|
|
30
|
+
console.log(`Created ${css_file_path}`);
|
|
31
|
+
await (0, generate_components_1.generateComponents)();
|
|
32
|
+
}
|
|
33
|
+
exports.addJDDComponent = addJDDComponent;
|
|
34
|
+
//# sourceMappingURL=add-jdd-component.js.map
|
package/lib/build.js
CHANGED
|
@@ -37,6 +37,7 @@ const find_scss_includes_1 = require("./find-scss-includes");
|
|
|
37
37
|
const sleep_1 = require("./utils/sleep");
|
|
38
38
|
const generate_collections_1 = require("./generate-collections");
|
|
39
39
|
const generate_routes_1 = require("./generate-routes");
|
|
40
|
+
const generate_components_1 = require("./generate-components");
|
|
40
41
|
const generate_names = (function* generate_names() {
|
|
41
42
|
const base_name = "____unique_import_";
|
|
42
43
|
let count = 0;
|
|
@@ -46,7 +47,11 @@ const generate_names = (function* generate_names() {
|
|
|
46
47
|
}
|
|
47
48
|
})();
|
|
48
49
|
async function build_ts() {
|
|
49
|
-
await Promise.all([
|
|
50
|
+
await Promise.all([
|
|
51
|
+
(0, generate_collections_1.generateCollections)(),
|
|
52
|
+
(0, generate_routes_1.generateRoutes)(),
|
|
53
|
+
(0, generate_components_1.generateComponents)(),
|
|
54
|
+
]);
|
|
50
55
|
const entryPoints = (await (0, tiny_glob_1.default)("./src/back/**/*.{ts,tsx}")).filter((path) => !path.includes(".#"));
|
|
51
56
|
try {
|
|
52
57
|
await (0, esbuild_1.build)({
|
package/lib/cli.js
CHANGED
|
@@ -2,16 +2,19 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const add_collection_1 = require("./add-collection");
|
|
5
|
+
const add_jdd_component_1 = require("./add-jdd-component");
|
|
5
6
|
const add_route_1 = require("./add-route");
|
|
6
7
|
const build_1 = require("./build");
|
|
7
8
|
const find_scss_includes_1 = require("./find-scss-includes");
|
|
8
9
|
const generate_collections_1 = require("./generate-collections");
|
|
10
|
+
const generate_components_1 = require("./generate-components");
|
|
9
11
|
const generate_routes_1 = require("./generate-routes");
|
|
10
12
|
const make_env_1 = require("./make-env");
|
|
11
13
|
const actions = {
|
|
12
14
|
"add-collection": add_collection_1.addCollection,
|
|
13
15
|
"add-route": add_route_1.addRoute,
|
|
14
16
|
"generate-collections": generate_collections_1.generateCollections,
|
|
17
|
+
"generate-components": generate_components_1.generateComponents,
|
|
15
18
|
"generate-routes": generate_routes_1.generateRoutes,
|
|
16
19
|
"generate-scss-includes": find_scss_includes_1.generateScssIncludes,
|
|
17
20
|
build: build_1.buildProject,
|
|
@@ -22,6 +25,7 @@ const actions = {
|
|
|
22
25
|
.join(", ")}`);
|
|
23
26
|
},
|
|
24
27
|
"make-env": make_env_1.makeEnv,
|
|
28
|
+
"add-component": add_jdd_component_1.addJDDComponent
|
|
25
29
|
};
|
|
26
30
|
void (async function () {
|
|
27
31
|
const action = process.argv.at(2);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.generateComponents = void 0;
|
|
30
|
+
const locreq_1 = __importDefault(require("locreq"));
|
|
31
|
+
const prettier = __importStar(require("prettier"));
|
|
32
|
+
const fs_1 = require("fs");
|
|
33
|
+
const prettier_1 = require("./utils/prettier");
|
|
34
|
+
const recursive_readdir_1 = __importDefault(require("recursive-readdir"));
|
|
35
|
+
const path_1 = __importDefault(require("path"));
|
|
36
|
+
const js_convert_case_1 = require("js-convert-case");
|
|
37
|
+
const target_locreq = (0, locreq_1.default)(process.cwd());
|
|
38
|
+
async function generateComponents() {
|
|
39
|
+
const components_dir = target_locreq.resolve("src/back/jdd-components");
|
|
40
|
+
const component_names = (await (0, recursive_readdir_1.default)(components_dir)).filter((c) => c.endsWith(".jdd.tsx"));
|
|
41
|
+
const component_data = component_names
|
|
42
|
+
.map((p) => "./" +
|
|
43
|
+
path_1.default.relative(components_dir, p).replace(/\.[tj]sx?$/, ".js"))
|
|
44
|
+
.map((relative_path) => {
|
|
45
|
+
const name = relative_path.match(/\/([^\/]+).jdd/)?.[1];
|
|
46
|
+
return { name, relative_path };
|
|
47
|
+
});
|
|
48
|
+
const content = `// DO NOT EDIT! This file is generated automaticaly with 'npm run generate-components'
|
|
49
|
+
import { Registry } from "@sealcode/jdd";
|
|
50
|
+
|
|
51
|
+
export const registry = new Registry();
|
|
52
|
+
${component_data
|
|
53
|
+
.map((c) => `
|
|
54
|
+
import { ${(0, js_convert_case_1.toPascalCase)(c.name)} } from "${c.relative_path}";
|
|
55
|
+
registry.add("${(0, js_convert_case_1.toKebabCase)(c.name)}", ${(0, js_convert_case_1.toPascalCase)(c.name)});`)
|
|
56
|
+
.join("\n")}`;
|
|
57
|
+
const target = "src/back/jdd-components/components.ts";
|
|
58
|
+
await fs_1.promises.writeFile(target_locreq.resolve(target), prettier.format(content, await (0, prettier_1.getPrettierConfig)()));
|
|
59
|
+
// eslint-disable-next-line no-console
|
|
60
|
+
console.log(`Successfuly generated new ${target} file`);
|
|
61
|
+
}
|
|
62
|
+
exports.generateComponents = generateComponents;
|
|
63
|
+
//# sourceMappingURL=generate-components.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jddComponentTemplate = void 0;
|
|
4
|
+
const js_convert_case_1 = require("js-convert-case");
|
|
5
|
+
function jddComponentTemplate(component_name) {
|
|
6
|
+
return `import { FlatTemplatable, TempstreamJSX } from "tempstream";
|
|
7
|
+
import {
|
|
8
|
+
Component,
|
|
9
|
+
ComponentArguments,
|
|
10
|
+
ExtractStructuredComponentArgumentsValues,
|
|
11
|
+
JDDContext,
|
|
12
|
+
} from "@sealcode/jdd";
|
|
13
|
+
|
|
14
|
+
const component_arguments = {
|
|
15
|
+
title: new ComponentArguments.ShortText(),
|
|
16
|
+
content: new ComponentArguments.Markdown(),
|
|
17
|
+
} as const;
|
|
18
|
+
|
|
19
|
+
export class ${(0, js_convert_case_1.toPascalCase)(component_name)} extends Component<typeof component_arguments> {
|
|
20
|
+
getArguments() {
|
|
21
|
+
return component_arguments;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
toHTML(
|
|
25
|
+
{
|
|
26
|
+
title,
|
|
27
|
+
content,
|
|
28
|
+
}: ExtractStructuredComponentArgumentsValues<typeof component_arguments>,
|
|
29
|
+
{ render_markdown }: JDDContext
|
|
30
|
+
): FlatTemplatable {
|
|
31
|
+
return (
|
|
32
|
+
<div class="${(0, js_convert_case_1.toKebabCase)(component_name)}">
|
|
33
|
+
<h2>{title} • ${(0, js_convert_case_1.toPascalCase)(component_name)} </h2>
|
|
34
|
+
<div>{render_markdown(content)}</div>
|
|
35
|
+
</div>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
`;
|
|
41
|
+
}
|
|
42
|
+
exports.jddComponentTemplate = jddComponentTemplate;
|
|
43
|
+
//# sourceMappingURL=jdd-component.js.map
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Templates = void 0;
|
|
4
4
|
const form_1 = require("./form");
|
|
5
|
+
const jdd_component_1 = require("./jdd-component");
|
|
5
6
|
const list_1 = require("./list");
|
|
6
7
|
const long_running_process_1 = require("./long-running-process");
|
|
7
8
|
const multiform_1 = require("./multiform");
|
|
@@ -18,5 +19,6 @@ exports.Templates = {
|
|
|
18
19
|
post: post_1.postTemplate,
|
|
19
20
|
sreact: stateful_page_1.statefulPageTemplate,
|
|
20
21
|
lpr: long_running_process_1.LongRunningProcessTemplate,
|
|
22
|
+
jdd: jdd_component_1.jddComponentTemplate,
|
|
21
23
|
};
|
|
22
24
|
//# sourceMappingURL=templates.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sealcode/sealgen",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"description": "Module to automate adding routes and collections to a sealious application",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"@types/node": "^18.11.4",
|
|
27
27
|
"@types/prettier": "^2.7.0",
|
|
28
28
|
"@types/prompts": "^2.0.14",
|
|
29
|
+
"@types/recursive-readdir": "^2.2.4",
|
|
29
30
|
"@typescript-eslint/eslint-plugin": "^4.29.3",
|
|
30
31
|
"@typescript-eslint/parser": "^4.29.3",
|
|
31
32
|
"eslint": "^7.32.0",
|
|
@@ -50,11 +51,13 @@
|
|
|
50
51
|
"deepmerge": "^4.3.1",
|
|
51
52
|
"esbuild": "^0.15.5",
|
|
52
53
|
"esbuild-sass-plugin": "^2.3.1",
|
|
54
|
+
"js-convert-case": "^4.2.0",
|
|
53
55
|
"koa": "^2.13.0",
|
|
54
56
|
"locreq": "^2.0.2",
|
|
55
57
|
"merge": "^2.1.1",
|
|
56
58
|
"prettier": "^2.7.1",
|
|
57
59
|
"prompts": "^2.4.2",
|
|
60
|
+
"recursive-readdir": "^2.2.3",
|
|
58
61
|
"tempstream": "^0.3.0",
|
|
59
62
|
"tiny-glob": "^0.2.9",
|
|
60
63
|
"yargs": "^17.6.2"
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { resolve } from "path";
|
|
2
|
+
import _locreq from "locreq";
|
|
3
|
+
import { promises as fs, existsSync } from "fs";
|
|
4
|
+
import { question } from "./utils/question";
|
|
5
|
+
const target_locreq = _locreq(process.cwd());
|
|
6
|
+
import { jddComponentTemplate } from "./templates/jdd-component";
|
|
7
|
+
import { generateComponents } from "./generate-components";
|
|
8
|
+
import { toKebabCase } from "js-convert-case";
|
|
9
|
+
|
|
10
|
+
export async function addJDDComponent(): Promise<void> {
|
|
11
|
+
const component_name = await question(
|
|
12
|
+
"What's the name of the component? > ",
|
|
13
|
+
(s: string) => s.length > 3
|
|
14
|
+
);
|
|
15
|
+
const file_path = target_locreq.resolve(
|
|
16
|
+
`src/back/jdd-components/${toKebabCase(component_name)}/${toKebabCase(
|
|
17
|
+
component_name
|
|
18
|
+
)}.jdd.tsx`
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
if (existsSync(file_path)) {
|
|
22
|
+
// eslint-disable-next-line no-console
|
|
23
|
+
console.error(`ERROR: File ${file_path} already exists.`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
await fs.mkdir(resolve(file_path, "../"), { recursive: true });
|
|
27
|
+
await fs.writeFile(file_path, jddComponentTemplate(component_name));
|
|
28
|
+
|
|
29
|
+
const css_file_path = target_locreq.resolve(
|
|
30
|
+
`src/back/jdd-components/${toKebabCase(component_name)}/${toKebabCase(
|
|
31
|
+
component_name
|
|
32
|
+
)}.scss`
|
|
33
|
+
);
|
|
34
|
+
await fs.writeFile(
|
|
35
|
+
css_file_path,
|
|
36
|
+
`.${toKebabCase(component_name)} {
|
|
37
|
+
}`
|
|
38
|
+
);
|
|
39
|
+
// eslint-disable-next-line no-console
|
|
40
|
+
console.log(`Created ${file_path}`);
|
|
41
|
+
console.log(`Created ${css_file_path}`);
|
|
42
|
+
await generateComponents();
|
|
43
|
+
}
|
package/src/build.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { generateScssIncludes } from "./find-scss-includes";
|
|
|
8
8
|
import { sleep } from "./utils/sleep";
|
|
9
9
|
import { generateCollections } from "./generate-collections";
|
|
10
10
|
import { generateRoutes } from "./generate-routes";
|
|
11
|
+
import { generateComponents } from "./generate-components";
|
|
11
12
|
|
|
12
13
|
const generate_names = (function* generate_names() {
|
|
13
14
|
const base_name = "____unique_import_";
|
|
@@ -19,7 +20,11 @@ const generate_names = (function* generate_names() {
|
|
|
19
20
|
})();
|
|
20
21
|
|
|
21
22
|
async function build_ts() {
|
|
22
|
-
await Promise.all([
|
|
23
|
+
await Promise.all([
|
|
24
|
+
generateCollections(),
|
|
25
|
+
generateRoutes(),
|
|
26
|
+
generateComponents(),
|
|
27
|
+
]);
|
|
23
28
|
const entryPoints = (await glob("./src/back/**/*.{ts,tsx}")).filter(
|
|
24
29
|
(path) => !path.includes(".#")
|
|
25
30
|
);
|
package/src/cli.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { addCollection } from "./add-collection";
|
|
3
|
+
import { addJDDComponent } from "./add-jdd-component";
|
|
3
4
|
import { addRoute } from "./add-route";
|
|
4
5
|
import { buildProject } from "./build";
|
|
5
6
|
import { generateScssIncludes } from "./find-scss-includes";
|
|
6
7
|
import { generateCollections } from "./generate-collections";
|
|
8
|
+
import { generateComponents } from "./generate-components";
|
|
7
9
|
import { generateRoutes } from "./generate-routes";
|
|
8
10
|
import { makeEnv } from "./make-env";
|
|
9
11
|
|
|
@@ -14,6 +16,7 @@ const actions: Record<
|
|
|
14
16
|
"add-collection": addCollection,
|
|
15
17
|
"add-route": addRoute,
|
|
16
18
|
"generate-collections": generateCollections,
|
|
19
|
+
"generate-components": generateComponents,
|
|
17
20
|
"generate-routes": generateRoutes,
|
|
18
21
|
"generate-scss-includes": generateScssIncludes,
|
|
19
22
|
build: buildProject,
|
|
@@ -26,6 +29,7 @@ const actions: Record<
|
|
|
26
29
|
);
|
|
27
30
|
},
|
|
28
31
|
"make-env": makeEnv,
|
|
32
|
+
"add-component": addJDDComponent
|
|
29
33
|
};
|
|
30
34
|
|
|
31
35
|
void (async function () {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import _locreq from "locreq";
|
|
2
|
+
import * as prettier from "prettier";
|
|
3
|
+
import { promises as fs } from "fs";
|
|
4
|
+
import { assertType, predicates } from "@sealcode/ts-predicates";
|
|
5
|
+
import { getPrettierConfig } from "./utils/prettier";
|
|
6
|
+
import recursive from "recursive-readdir";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
9
|
+
|
|
10
|
+
const target_locreq = _locreq(process.cwd());
|
|
11
|
+
|
|
12
|
+
export async function generateComponents(): Promise<void> {
|
|
13
|
+
const components_dir = target_locreq.resolve("src/back/jdd-components");
|
|
14
|
+
const component_names = (await recursive(components_dir)).filter((c) =>
|
|
15
|
+
c.endsWith(".jdd.tsx")
|
|
16
|
+
);
|
|
17
|
+
const component_data = component_names
|
|
18
|
+
.map(
|
|
19
|
+
(p) =>
|
|
20
|
+
"./" +
|
|
21
|
+
path.relative(components_dir, p).replace(/\.[tj]sx?$/, ".js")
|
|
22
|
+
)
|
|
23
|
+
.map((relative_path) => {
|
|
24
|
+
const name = relative_path.match(/\/([^\/]+).jdd/)?.[1];
|
|
25
|
+
return { name, relative_path };
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const content = `// DO NOT EDIT! This file is generated automaticaly with 'npm run generate-components'
|
|
29
|
+
import { Registry } from "@sealcode/jdd";
|
|
30
|
+
|
|
31
|
+
export const registry = new Registry();
|
|
32
|
+
${component_data
|
|
33
|
+
.map(
|
|
34
|
+
(c) => `
|
|
35
|
+
import { ${toPascalCase(c.name)} } from "${c.relative_path}";
|
|
36
|
+
registry.add("${toKebabCase(c.name)}", ${toPascalCase(c.name)});`
|
|
37
|
+
)
|
|
38
|
+
.join("\n")}`;
|
|
39
|
+
const target = "src/back/jdd-components/components.ts";
|
|
40
|
+
await fs.writeFile(
|
|
41
|
+
target_locreq.resolve(target),
|
|
42
|
+
prettier.format(content, await getPrettierConfig())
|
|
43
|
+
);
|
|
44
|
+
// eslint-disable-next-line no-console
|
|
45
|
+
console.log(`Successfuly generated new ${target} file`);
|
|
46
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
2
|
+
|
|
3
|
+
export function jddComponentTemplate(component_name: string) {
|
|
4
|
+
return `import { FlatTemplatable, TempstreamJSX } from "tempstream";
|
|
5
|
+
import {
|
|
6
|
+
Component,
|
|
7
|
+
ComponentArguments,
|
|
8
|
+
ExtractStructuredComponentArgumentsValues,
|
|
9
|
+
JDDContext,
|
|
10
|
+
} from "@sealcode/jdd";
|
|
11
|
+
|
|
12
|
+
const component_arguments = {
|
|
13
|
+
title: new ComponentArguments.ShortText(),
|
|
14
|
+
content: new ComponentArguments.Markdown(),
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
export class ${toPascalCase(
|
|
18
|
+
component_name
|
|
19
|
+
)} extends Component<typeof component_arguments> {
|
|
20
|
+
getArguments() {
|
|
21
|
+
return component_arguments;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
toHTML(
|
|
25
|
+
{
|
|
26
|
+
title,
|
|
27
|
+
content,
|
|
28
|
+
}: ExtractStructuredComponentArgumentsValues<typeof component_arguments>,
|
|
29
|
+
{ render_markdown }: JDDContext
|
|
30
|
+
): FlatTemplatable {
|
|
31
|
+
return (
|
|
32
|
+
<div class="${toKebabCase(component_name)}">
|
|
33
|
+
<h2>{title} • ${toPascalCase(component_name)} </h2>
|
|
34
|
+
<div>{render_markdown(content)}</div>
|
|
35
|
+
</div>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
`;
|
|
41
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { formTemplate } from "./form";
|
|
2
|
+
import { jddComponentTemplate } from "./jdd-component";
|
|
2
3
|
import { listTemplate } from "./list";
|
|
3
4
|
import { LongRunningProcessTemplate } from "./long-running-process";
|
|
4
5
|
import { multiformTemplate } from "./multiform";
|
|
@@ -16,4 +17,5 @@ export const Templates = {
|
|
|
16
17
|
post: postTemplate,
|
|
17
18
|
sreact: statefulPageTemplate,
|
|
18
19
|
lpr: LongRunningProcessTemplate,
|
|
20
|
+
jdd: jddComponentTemplate,
|
|
19
21
|
};
|