feat: add basic type checking

This commit is contained in:
EvolutionX
2022-06-22 11:58:30 +05:30
parent e86e3a7e67
commit eb85a7a8f2
10 changed files with 85 additions and 15 deletions

View File

@@ -7,6 +7,15 @@ const templates = new URL('./templates/', root);
const extraURL = new URL('./extra/', templates);
const extraFolder = fileURLToPath(extraURL);
/**
* It creates a file with the name `name.lang.sern` in the `location` directory
* @param {string} name - The name of the file.
* @param {string} lang - The language you want to use.
* @param {string} location - The location of the file to be created.
* @param {boolean} no_ext - If true, the file will be created without an extension.
* @returns File
*/
export async function create(name, lang, location, no_ext) {
const file = `${name}.${lang}.sern`;
@@ -17,6 +26,11 @@ export async function create(name, lang, location, no_ext) {
return createFile(file, target);
}
/**
* It reads a file from a template folder, and writes it to a target folder
* @param {string} template - The name of the file to be created.
* @param {string} target - The location of the file to be created.
*/
async function createFile(template, target) {
const location = `${extraFolder}${template}`;
@@ -25,6 +39,12 @@ async function createFile(template, target) {
await writeFileRecursive(target, file);
}
/**
* It creates a directory recursively, then writes a file to it
* @param {string} target - The path to the file you want to write to.
* @param {string} data - The data to write to the file.
* @returns A promise that resolves to the result of the writeFile function.
*/
async function writeFileRecursive(target, data) {
const resolvedTarget = resolve(target);
const dir = dirname(resolvedTarget);