Page MenuHomeSealhub

add-collection.ts
No OneTemporary

add-collection.ts

import { resolve } from "path";
import _locreq from "locreq";
import { promises as fs, existsSync } from "fs";
import { question } from "./utils/question.js";
import { collectionTemplate } from "./templates/collection.js";
import { generateCollections } from "./generate-collections.js";
import { toKebabCase, toPascalCase } from "js-convert-case";
const target_locreq = _locreq(process.cwd());
export async function addCollection(): Promise<void> {
const collection_name = toPascalCase(
await question(
"What's the name of the collection class: ",
(s: string) => s.length > 3
)
);
const file_path = target_locreq.resolve(
`src/back/collections/${toKebabCase(collection_name)}.ts`
);
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, collectionTemplate(collection_name));
// eslint-disable-next-line no-console
console.log(`${file_path} created`);
await generateCollections();
}

File Metadata

Mime Type
text/x-java
Expires
Sat, Jun 7, 23:21 (1 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
624863
Default Alt Text
add-collection.ts (1 KB)

Event Timeline