Skip to content

Commit

Permalink
add mechanism for changing source of types
Browse files Browse the repository at this point in the history
  • Loading branch information
SignpostMarv committed Jun 30, 2024
1 parent d9b84b6 commit f9da0b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/DocsTsGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class DocsTsGenerator {
private readonly cache_path: string | undefined;
private readonly docs_path: string | DocsData;
public readonly ajv:Ajv;
readonly types_from_module: string|undefined;

static readonly PERF_EARLY_RETURN = 'Early Return of Docs.json';
static readonly PERF_FAILURE = 'Failure to load Docs.json';
Expand All @@ -106,14 +107,17 @@ export class DocsTsGenerator {
docs_path,
// optional cache folder path for cacheable resources
cache_path = undefined,
types_from_module = undefined,
}: {
ajv: Ajv,
docs_path: string | DocsData;
cache_path?: string;
types_from_module?: string,
}) {
this.ajv = ajv;
this.docs_path = docs_path;
this.cache_path = cache_path;
this.types_from_module = types_from_module;
}

async definition(
Expand Down
17 changes: 13 additions & 4 deletions lib/TypeDefinitionWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,21 @@ export class TypeDefinitionWriter
}
}

let code = await format_code(
node_strings
.join('\n\n')
);

if (this.docs.types_from_module) {
code = code.replace(
/} from '(?:\.\.\/)+(classes|common|utils)\//g,
`} from '${this.docs.types_from_module}/$1`
);
}

await writeFile(
file_name,
await format_code(
node_strings
.join('\n\n')
)
code
);
}
performance.measure(
Expand Down

0 comments on commit f9da0b6

Please sign in to comment.