UNPKG

@jqassistant/ts-lce

Version:

Tool to extract language concepts from a TypeScript codebase and export them to a JSON file.

54 lines (53 loc) 1.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LCEProject = void 0; const typescript_1 = require("typescript"); /** * Represents a TypeScript project along with all concepts contained within it. */ class LCEProject { projectInfo; concepts; constructor(projectInfo, concepts) { this.projectInfo = projectInfo; this.concepts = concepts; } toJSON() { const jsonConcepts = new Map(); this.concepts.forEach((value, key) => { jsonConcepts.set(key, value.map(i => i.toJSON())); }); return { rootPath: this.projectInfo.rootPath, configPath: this.projectInfo.configPath, subProjectPaths: this.projectInfo.subProjectPaths, sourceFilePaths: this.projectInfo.sourceFilePaths, tsConfig: this.tsConfigToJSON(), concepts: Object.fromEntries(jsonConcepts) }; } /** * converts the natively resolved tsconfig object to a human-readable JSON object with enum values replaced with their respective names */ tsConfigToJSON() { const options = this.projectInfo.tsConfig.options; const result = structuredClone(options); if (options.module) { result.module = typescript_1.ModuleKind[options.module]; } if (options.moduleResolution) { result.moduleResolution = typescript_1.ModuleResolutionKind[options.moduleResolution]; } if (options.moduleDetection) { result.moduleDetection = typescript_1.ModuleDetectionKind[options.moduleDetection]; } if (options.newLine) { result.newLine = typescript_1.NewLineKind[options.newLine]; } if (options.target) { result.target = typescript_1.ScriptTarget[options.target]; } return result; } } exports.LCEProject = LCEProject;