UNPKG

@ewwmy/cv-builder

Version:

💻 A CLI utility to generate a well-formatted CV in PDF format 📕 based on JSON CV data and a Handlebars template

138 lines (137 loc) • 6.46 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ArgumentsService = void 0; const inversify_1 = require("inversify"); const yargs_1 = __importDefault(require("yargs")); const dependency_types_1 = require("../types/dependency.types"); const helpers_1 = require("yargs/helpers"); const app_config_service_1 = require("../config/app-config.service"); let ArgumentsService = class ArgumentsService { constructor(config) { this.config = config; } // getting command line arguments getCommandLineOptions() { return __awaiter(this, void 0, void 0, function* () { const userConfig = this.config.getUserConfig(); return (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)) .options({ locales: { alias: 'l', describe: 'Locales to build', default: userConfig.LOCALES, type: 'array', }, templates: { alias: 't', describe: 'Templates to build', default: userConfig.TEMPLATES, type: 'array', }, input: { alias: 'i', describe: 'Path to the input JSON CV file', default: userConfig.INPUT_CV_FILE_PATH, type: 'string', }, output: { alias: 'o', describe: 'Path to the output folder', default: userConfig.OUTPUT_DIR, type: 'string', }, watch: { alias: 'w', describe: 'Watch for changes in CV data and templates to provide live preview', requiresArg: false, default: false, type: 'boolean', }, 'templates-dir': { alias: 'd', describe: 'Path to the templates folder', default: userConfig.TEMPLATES_DIR, type: 'string', }, 'images-base-dir': { describe: 'Base path for the images that are supposed to be used in a template', default: userConfig.BASE_IMAGES_DIR, type: 'string', }, 'icons-base-dir': { describe: 'Base path for the icons that are supposed to be used in a template', default: userConfig.BASE_ICONS_DIR, type: 'string', }, margins: { alias: 'm', describe: 'Margins of the output PDF [top]:[right]:[bottom]:[left]. Examples: --margins=2cm:0cm:1cm:1cm | --margins=:1cm::1cm | --margins=0px:24px:0px:24px', default: '0cm:0cm:0cm:0cm', usage: '2cm:1cm:1cm:0cm', type: 'string', }, restore: { alias: 'r', describe: 'Restore sample data, preserving existing files !!! CAUTION: If the `--force` option given, existing configuration, CV file `cv-example.json`, template `default.hbs`, image `example-user-photo.jpg` WILL BE OVERWRITTEN !!!', requiresArg: false, default: false, type: 'boolean', }, force: { describe: 'See `--restore`', requiresArg: false, default: false, type: 'boolean', }, }) .locale('en') .wrap(120).argv; }); } // function to parse and set margins as an object for puppeteer marginsToPuppeteer(input) { let result = {}; if (!(typeof input === 'string')) return result; const items = input.split(':'); if (items.length !== 4) return result; const labels = ['top', 'right', 'bottom', 'left']; items.forEach((item, key) => { const pattern = /^\d+(\.\d+)?(px|pt|cm|mm|in)?$/; if (pattern.test(item)) result[labels[key]] = item; }); return result; } }; exports.ArgumentsService = ArgumentsService; exports.ArgumentsService = ArgumentsService = __decorate([ (0, inversify_1.injectable)(), __param(0, (0, inversify_1.inject)(dependency_types_1.DependencyTypes.Config)), __metadata("design:paramtypes", [app_config_service_1.AppConfigService]) ], ArgumentsService);