Page MenuHomeSealhub

add-jdd-component.ts
No OneTemporary

add-jdd-component.ts

import { resolve } from "path";
import _locreq from "locreq";
import { promises as fs, existsSync } from "fs";
import { question } from "./utils/question.js";
const target_locreq = _locreq(process.cwd());
import { jddComponentTemplate } from "./templates/jdd-component.js";
import { generateComponents } from "./generate-components.js";
import { toKebabCase } from "js-convert-case";
export async function addJDDComponent(): Promise<void> {
const component_name = await question(
"What's the name of the component? > ",
(s: string) => s.length > 3
);
const file_path = target_locreq.resolve(
`src/back/jdd-components/${toKebabCase(component_name)}/${toKebabCase(
component_name
)}.jdd.tsx`
);
if (existsSync(file_path)) {
// eslint-disable-next-line no-console
console.error(`ERROR: File ${file_path} already exists.`);
return;
}
await fs.mkdir(resolve(file_path, "../"), { recursive: true });
await fs.writeFile(file_path, jddComponentTemplate(component_name));
const css_file_path = target_locreq.resolve(
`src/back/jdd-components/${toKebabCase(component_name)}/${toKebabCase(
component_name
)}.css`
);
await fs.writeFile(
css_file_path,
`.${toKebabCase(component_name)} {
}`
);
// eslint-disable-next-line no-console
console.log(`Created ${file_path}`);
console.log(`Created ${css_file_path}`);
await generateComponents();
}

File Metadata

Mime Type
text/x-java
Expires
Tue, Dec 24, 14:02 (21 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
557152
Default Alt Text
add-jdd-component.ts (1 KB)

Event Timeline