UNPKG

kt-extendscript-builder

Version:

Vite based builder for transpile TypeScript to ExtendScript

56 lines (55 loc) 2.04 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TsconfigLoader = void 0; const path_1 = __importDefault(require("path")); const fs_1 = __importDefault(require("fs")); const tsconfigTemplates_1 = require("./tsconfigTemplates"); // Ajusta la ruta a tus templates class TsconfigLoader { constructor() { } load(options) { let tsconfig; let tsconfigPath = 'tsconfig.json'; if (options.test && options['tsconfig-test-path']) { tsconfigPath = options['tsconfig-test-path']; } else if (options.tsconfig) { tsconfigPath = options['tsconfig']; } if (options['tsconfig-template']) { tsconfig = this.loadFromTemplate(options.test); } else { tsconfig = this.loadFromFile(tsconfigPath); } if (options.input) { tsconfig.compilerOptions.rootDir = path_1.default.dirname(options.input); } if (options.output) { tsconfig.compilerOptions.outDir = path_1.default.dirname(options.output); } return tsconfig; } loadFromTemplate(test = false) { if (test) { return tsconfigTemplates_1.tsconfigTestsES3; } return tsconfigTemplates_1.tsconfigES3; } loadFromFile(configPath) { const absolutePath = path_1.default.resolve(process.cwd(), configPath); if (!fs_1.default.existsSync(absolutePath)) { throw new Error(`El archivo tsconfig en ${absolutePath} no existe`); } const fileContent = fs_1.default.readFileSync(absolutePath, 'utf-8'); try { return JSON.parse(fileContent); } catch (error) { throw new Error(`Error al parsear el archivo tsconfig en ${absolutePath}: ${error.message}`); } } } exports.TsconfigLoader = TsconfigLoader;