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";
import { collectionTemplate } from "./templates/collection";
import { generateCollections } from "./generate-collections";
const target_locreq = _locreq(process.cwd());
export async function addCollection(): Promise<void> {
const collection_name = await question(
'What\'s the name of the collection class (e.g. "SecretDocuments", must start with a capital letter): ',
(s: string) => s.length > 3 && s[0].toUpperCase() == s[0]
);
const url = await question(
"Enter the url-friendly name for the collection (e.g. secret-documents): ",
(s: string) => !s.includes("/") && !s.includes(" ")
);
const file_path = target_locreq.resolve(`src/back/collections/${url}.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
Wed, May 7, 19:38 (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
625887
Default Alt Text
add-collection.ts (1 KB)

Event Timeline