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

142 lines (141 loc) • 7.25 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AppConfigService = void 0; const inversify_1 = require("inversify"); const dependency_types_1 = require("../types/dependency.types"); const node_path_1 = require("node:path"); const node_os_1 = require("node:os"); const file_service_1 = require("../files/file.service"); let AppConfigService = class AppConfigService { constructor(fileService) { this.fileService = fileService; this.data = { APP_GROUP_NAME: '', APP_NAME: '', EXAMPLE_CV: '', EXAMPLE_IMAGES: '', EXAMPLE_ICONS: '', EXAMPLE_TEMPLATES: '', APP_DIR: '', CONFIG_DIR: '', CONFIG_FILE_PATH: '', EXAMPLES_DIR: '', EXAMPLE_CV_FILE_PATH: '', EXAMPLE_IMAGES_DIR: '', EXAMPLE_ICONS_DIR: '', EXAMPLE_TEMPLATES_DIR: '', DEFAULT_CV_FILE_PATH: '', DEFAULT_IMAGES_DIR: '', DEFAULT_ICONS_DIR: '', DEFAULT_TEMPLATES_DIR: '', DEFAULT_OUTPUT_DIR: '', DEFAULT_USER_CONFIG: { LOCALES: [], TEMPLATES: [], INPUT_CV_FILE_PATH: '', OUTPUT_DIR: '', TEMPLATES_DIR: '', BASE_IMAGES_DIR: '', BASE_ICONS_DIR: '', }, }; this.initializeDefault(); } initializeDefault() { // initialize main app config this.data.APP_GROUP_NAME = 'ewwmy'; this.data.APP_NAME = 'cv-builder'; this.data.EXAMPLE_CV = 'cv-example.json'; this.data.EXAMPLE_IMAGES = 'images'; this.data.EXAMPLE_ICONS = 'icons'; this.data.EXAMPLE_TEMPLATES = 'templates'; this.data.APP_DIR = (0, node_path_1.resolve)((0, node_path_1.join)((0, node_os_1.homedir)(), '.config', this.data.APP_GROUP_NAME, this.data.APP_NAME)); this.data.CONFIG_DIR = (0, node_path_1.resolve)((0, node_path_1.join)(this.data.APP_DIR, 'settings')); this.data.CONFIG_FILE_PATH = (0, node_path_1.resolve)((0, node_path_1.join)(this.data.CONFIG_DIR, 'settings.json')); this.data.EXAMPLES_DIR = (0, node_path_1.resolve)((0, node_path_1.join)(__dirname, '..', '..', 'data', 'examples')); this.data.EXAMPLE_CV_FILE_PATH = (0, node_path_1.resolve)((0, node_path_1.join)(this.data.EXAMPLES_DIR, this.data.EXAMPLE_CV)); this.data.EXAMPLE_IMAGES_DIR = (0, node_path_1.resolve)((0, node_path_1.join)(this.data.EXAMPLES_DIR, this.data.EXAMPLE_IMAGES)); this.data.EXAMPLE_ICONS_DIR = (0, node_path_1.resolve)((0, node_path_1.join)(this.data.EXAMPLES_DIR, this.data.EXAMPLE_ICONS)); this.data.EXAMPLE_TEMPLATES_DIR = (0, node_path_1.resolve)((0, node_path_1.join)(this.data.EXAMPLES_DIR, this.data.EXAMPLE_TEMPLATES)); this.data.DEFAULT_CV_FILE_PATH = (0, node_path_1.resolve)((0, node_path_1.join)(this.data.APP_DIR, this.data.EXAMPLE_CV)); this.data.DEFAULT_IMAGES_DIR = (0, node_path_1.resolve)((0, node_path_1.join)(this.data.APP_DIR, this.data.EXAMPLE_IMAGES)); this.data.DEFAULT_ICONS_DIR = (0, node_path_1.resolve)((0, node_path_1.join)(this.data.APP_DIR, this.data.EXAMPLE_ICONS)); this.data.DEFAULT_TEMPLATES_DIR = (0, node_path_1.resolve)((0, node_path_1.join)(this.data.APP_DIR, this.data.EXAMPLE_TEMPLATES)); this.data.DEFAULT_OUTPUT_DIR = (0, node_path_1.resolve)((0, node_path_1.join)(this.data.APP_DIR, 'out')); this.data.DEFAULT_USER_CONFIG = { LOCALES: ['en-US', 'ru-RU'], TEMPLATES: ['example'], INPUT_CV_FILE_PATH: this.data.DEFAULT_CV_FILE_PATH, OUTPUT_DIR: this.data.DEFAULT_OUTPUT_DIR, TEMPLATES_DIR: this.data.DEFAULT_TEMPLATES_DIR, BASE_IMAGES_DIR: this.data.DEFAULT_IMAGES_DIR, BASE_ICONS_DIR: this.data.DEFAULT_ICONS_DIR, }; } get(key) { return this.data[key]; } getAll() { return this.data; } getUserConfig() { return this.data.DEFAULT_USER_CONFIG; } set(key, value) { this.data[key] = value; } update(config) { this.data = Object.assign(Object.assign({}, this.data), config); } updateUserConfig(userConfig) { this.data.DEFAULT_USER_CONFIG = Object.assign(Object.assign({}, this.data.DEFAULT_USER_CONFIG), userConfig); } restoreDefault() { this.initializeDefault(); } // function to get the configuration by the passed filename (json file) loadFromFile() { return __awaiter(this, arguments, void 0, function* (filename = this.data.CONFIG_FILE_PATH) { const data = yield this.fileService.readFileData(filename, true); let result = {}; try { result = JSON.parse(data !== null && data !== void 0 ? data : '{}'); } catch (error) { if (error instanceof Error) { error.message = `Cannot parse JSON in user config file: ${error.message}`; } throw error; } this.data.DEFAULT_USER_CONFIG = Object.assign(Object.assign({}, this.data.DEFAULT_USER_CONFIG), result); return this.data.DEFAULT_USER_CONFIG; }); } }; exports.AppConfigService = AppConfigService; exports.AppConfigService = AppConfigService = __decorate([ (0, inversify_1.injectable)(), __param(0, (0, inversify_1.inject)(dependency_types_1.DependencyTypes.File)), __metadata("design:paramtypes", [file_service_1.FileService]) ], AppConfigService);