Page MenuHomeSealhub

generate-components.ts
No OneTemporary

generate-components.ts

import _locreq from "locreq";
import * as prettier from "prettier";
import { promises as fs } from "fs";
import { assertType, predicates } from "@sealcode/ts-predicates";
import { getPrettierConfig } from "./utils/prettier";
import recursive from "recursive-readdir";
import path from "path";
import { toKebabCase, toPascalCase } from "js-convert-case";
const target_locreq = _locreq(process.cwd());
export async function generateComponents(): Promise<void> {
const components_dir = target_locreq.resolve("src/back/jdd-components");
const component_names = (await recursive(components_dir)).filter((c) =>
c.endsWith(".jdd.tsx")
);
const component_data = component_names
.map(
(p) =>
"./" +
path.relative(components_dir, p).replace(/\.[tj]sx?$/, ".js")
)
.map((relative_path) => {
const name = relative_path.match(/\/([^\/]+).jdd/)?.[1];
return { name, relative_path };
});
const content = `// DO NOT EDIT! This file is generated automaticaly with 'npm run generate-components'
import { Registry } from "@sealcode/jdd";
export const registry = new Registry();
${component_data
.map(
(c) => `
import { ${toPascalCase(c.name)} } from "${c.relative_path}";
registry.add("${toKebabCase(c.name)}", ${toPascalCase(c.name)});`
)
.join("\n")}`;
const target = "src/back/jdd-components/components.ts";
await fs.writeFile(
target_locreq.resolve(target),
prettier.format(content, await getPrettierConfig())
);
// eslint-disable-next-line no-console
console.log(`Successfuly generated new ${target} file`);
}

File Metadata

Mime Type
text/x-java
Expires
Fri, Jan 24, 15:16 (20 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
601282
Default Alt Text
generate-components.ts (1 KB)

Event Timeline