UNPKG

yamlresume

Version:
10 lines 4.46 kB
#!/usr/bin/env node import {Command}from'commander';import A from'node:child_process';import l from'node:fs';import b from'node:path';import a,{consola}from'consola';import I from'which';import N from'yaml';import {YAMLResumeError,joinNonEmptyString,toCodeBlock,LOCALE_LANGUAGE_OPTIONS,getLocaleLanguageOptionDetail,TEMPLATE_OPTIONS,getTemplateOptionDetail,getResumeRenderer}from'@yamlresume/core';import {fileURLToPath}from'node:url';import {markdownTable}from'markdown-table';var y={version:"0.4.2"};function x(e){let t=b.extname(e);if(e.endsWith(".yaml")||e.endsWith(".yml")||e.endsWith(".json"))return e.replace(/\.yaml|\.yml|\.json$/,".tex");throw new YAMLResumeError("INVALID_EXTNAME",{extname:t})}function L(e){try{return !!I.sync(e)}catch{return false}}function D(){if(L("xelatex"))return "xelatex";if(L("tectonic"))return "tectonic";throw new YAMLResumeError("LATEX_NOT_FOUND",{})}function M(e){let t=D(),r=x(e);switch(t){case "xelatex":return `xelatex -halt-on-error ${r}`;case "tectonic":return `tectonic ${r}`}}function k(e){let t=x(e),r;try{r=l.readFileSync(e,"utf8");}catch{throw new YAMLResumeError("FILE_READ_ERROR",{path:e})}let o;try{o=N.parse(r);}catch(i){throw new YAMLResumeError("INVALID_YAML",{error:i.message})}let R=getResumeRenderer(o).render();try{l.writeFileSync(t,R);}catch{throw new YAMLResumeError("FILE_WRITE_ERROR",{path:t})}}function S(e,t={pdf:true}){if(k(e),!t.pdf){consola.success("Generated resume TeX file successfully.");return}let r=M(e);consola.start(`Generating resume PDF file with command: \`${r}\`...`);try{let o=A.execSync(r,{encoding:"utf8"});consola.success("Generated resume PDF file successfully."),consola.debug(joinNonEmptyString(["stdout: ",toCodeBlock(o)]));}catch(o){throw consola.debug(joinNonEmptyString(["stdout: ",toCodeBlock(o.stdout)])),consola.debug(joinNonEmptyString(["stderr: ",toCodeBlock(o.stderr)])),new YAMLResumeError("LATEX_COMPILE_ERROR",{error:o.message})}}function u(){return new Command().name("build").description("build a resume to LaTeX and PDF").argument("<source>","the source resume file").option("--no-pdf","only generate TeX file without PDF").action(async(e,t)=>{try{S(e,t);}catch(r){consola.error(r.message),process.exit(r.errno);}})}function Y(e){if(l.existsSync(e))throw new YAMLResumeError("FILE_CONFLICT",{path:e});let t=b.join(b.dirname(fileURLToPath(import.meta.url)),import.meta.url.includes("dist")?"../resources/resume.yml":"../../resources/resume.yml"),r;try{r=l.readFileSync(t,"utf8");}catch(o){throw a.debug(joinNonEmptyString(["Error reading template: ",toCodeBlock(o.stack)])),new YAMLResumeError("FILE_READ_ERROR",{path:t})}try{l.writeFileSync(e,r),a.success(`Created ${e} successfully.`);}catch(o){throw a.debug(joinNonEmptyString(["Error creating resume: ",toCodeBlock(o.stack)])),new YAMLResumeError("FILE_WRITE_ERROR",{path:e})}}function _(){return new Command().name("new").description("create a new resume").argument("[filename]","output filename","resume.yml").action(e=>{try{Y(e);}catch(t){a.error(t.message),process.exit(t.errno);}})}function $(){return markdownTable([["layout.locale.language","Language Name"],...LOCALE_LANGUAGE_OPTIONS.map(e=>[e,getLocaleLanguageOptionDetail(e).name])])}function f(){let e=new Command().name("languages").description("i18n and l10n support");return e.command("list").description("list all supported languages").action(()=>{a.log($());}),e}function K(){return markdownTable([["layout.template","Template Name","Description"],...TEMPLATE_OPTIONS.map(e=>{let t=getTemplateOptionDetail(e);return [e,t.name,t.description]})])}function g(){let e=new Command().name("templates").description("manage resume templates");return e.command("list").description("list all supported templates").action(()=>{a.log(K());}),e}function h(e){a.level=e?4:3;}var m=new Command,ee=` __ __ _ __ __ _ ____ \\ \\ / // \\ | \\/ | | | _ \\ ___ ___ _ _ ___ ___ ___ \\ V // _ \\ | |\\/| | | | |_) / _ \\/ __| | | / _ \\/ _ \\ / _ \\ | |/ ___ \\| | | | |___| _ < __/\\__ \\ |_| | | | | | | __/ |_/_/ \\_\\_| |_|_____|_| \\_\\___||___/\\____|_| |_| |_|\\___| `;m.name("yamlresume").description(["YAMLResume \u2014 Resume as Code in YAML",ee].join(` `)).version(y.version).option("-v, --verbose","verbose output").hook("preAction",e=>{h(e.opts().verbose);});m.addCommand(_());m.addCommand(u());m.addCommand(f());m.addCommand(g());m.parse();//# sourceMappingURL=cli.js.map //# sourceMappingURL=cli.js.map