1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.DtsCreator = void 0;
|
7 | const node_process_1 = __importDefault(require("node:process"));
|
8 | const node_path_1 = __importDefault(require("node:path"));
|
9 | const node_os_1 = __importDefault(require("node:os"));
|
10 | const file_system_loader_1 = __importDefault(require("./file-system-loader"));
|
11 | const dts_content_1 = require("./dts-content");
|
12 | class DtsCreator {
|
13 | constructor(options) {
|
14 | if (!options)
|
15 | options = {};
|
16 | this.rootDir = options.rootDir || node_process_1.default.cwd();
|
17 | this.searchDir = options.searchDir || '';
|
18 | this.outDir = options.outDir || this.searchDir;
|
19 | this.loader = new file_system_loader_1.default(this.rootDir, options.loaderPlugins);
|
20 | this.inputDirectory = node_path_1.default.join(this.rootDir, this.searchDir);
|
21 | this.camelCase = options.camelCase;
|
22 | this.namedExports = !!options.namedExports;
|
23 | this.allowArbitraryExtensions = !!options.allowArbitraryExtensions;
|
24 | this.dropExtension = !!options.dropExtension;
|
25 | this.EOL = options.EOL || node_os_1.default.EOL;
|
26 | }
|
27 | async create(filePath, initialContents, clearCache = false, isDelete = false) {
|
28 | let rInputPath;
|
29 | if (node_path_1.default.isAbsolute(filePath)) {
|
30 | rInputPath = node_path_1.default.relative(this.inputDirectory, filePath);
|
31 | }
|
32 | else {
|
33 | rInputPath = node_path_1.default.relative(this.inputDirectory, node_path_1.default.join(node_process_1.default.cwd(), filePath));
|
34 | }
|
35 | if (clearCache) {
|
36 | this.loader.tokensByFile = {};
|
37 | }
|
38 | let keys = [];
|
39 | if (!isDelete) {
|
40 | const res = await this.loader.fetch(filePath, '/', undefined, initialContents);
|
41 | if (!res)
|
42 | throw res;
|
43 | keys = Object.keys(res);
|
44 | }
|
45 | const content = new dts_content_1.DtsContent({
|
46 | dropExtension: this.dropExtension,
|
47 | rootDir: this.rootDir,
|
48 | searchDir: this.searchDir,
|
49 | outDir: this.outDir,
|
50 | rInputPath,
|
51 | rawTokenList: keys,
|
52 | namedExports: this.namedExports,
|
53 | allowArbitraryExtensions: this.allowArbitraryExtensions,
|
54 | camelCase: this.camelCase,
|
55 | EOL: this.EOL,
|
56 | });
|
57 | return content;
|
58 | }
|
59 | }
|
60 | exports.DtsCreator = DtsCreator;
|
61 |
|
\ | No newline at end of file |