mirror of
https://github.com/sern-handler/cli
synced 2026-06-28 02:32:20 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user