feat: publish command (#105)

Co-authored-by: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com>
Co-authored-by: jacob <jacoobes@sern.dev>
This commit is contained in:
Evo
2023-08-09 22:06:50 +05:30
committed by GitHub
parent 2348e3e9ab
commit 827ffb7ad9
25 changed files with 6476 additions and 6054 deletions

View File

@@ -15,19 +15,12 @@ const extraFolder = fileURLToPath(extraURL);
* @param location - The location of the file to be created.
* @param no_ext - If true, the file will be created without an extension.
*/
export async function create(
name: string,
lang: string,
location: string,
no_ext: boolean
) {
const file = `${name}.${lang}.sern`;
export async function create(name: string, lang: string, location: string, no_ext: boolean) {
const file = `${name}.${lang}.sern`;
const target = no_ext
? `${location}/${name}`
: `${location}/${name}.${lang}`;
const target = no_ext ? `${location}/${name}` : `${location}/${name}.${lang}`;
return createFile(file, target);
return createFile(file, target);
}
/**
@@ -36,11 +29,11 @@ export async function create(
* @param target - The location of the file to be created.
*/
async function createFile(template: string, target: string) {
const location = `${extraFolder}${template}`;
const location = `${extraFolder}${template}`;
const file = await readFile(location, 'utf8');
const file = await readFile(location, 'utf8');
await writeFileRecursive(target, file);
await writeFileRecursive(target, file);
}
/**
@@ -50,10 +43,10 @@ async function createFile(template: string, target: string) {
* @returns A promise that resolves to the result of the writeFile function.
*/
async function writeFileRecursive(target: string, data: string) {
const resolvedTarget = resolve(target);
const dir = dirname(resolvedTarget);
const resolvedTarget = resolve(target);
const dir = dirname(resolvedTarget);
await mkdir(dir, { recursive: true });
await mkdir(dir, { recursive: true });
return writeFile(resolvedTarget, data);
return writeFile(resolvedTarget, data);
}