summaryrefslogtreecommitdiff
path: root/tools/ts_library_builder/ast_util.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tools/ts_library_builder/ast_util.ts')
-rw-r--r--tools/ts_library_builder/ast_util.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/tools/ts_library_builder/ast_util.ts b/tools/ts_library_builder/ast_util.ts
index 9bb7e8edc..58aa7fb9c 100644
--- a/tools/ts_library_builder/ast_util.ts
+++ b/tools/ts_library_builder/ast_util.ts
@@ -243,6 +243,32 @@ export function getSourceComment(
return `\n// @url ${relative(rootPath, sourceFile.getFilePath())}\n\n`;
}
+interface InlineFilesOptions {
+ basePath: string;
+ debug?: boolean;
+ inline: string[];
+ targetSourceFile: SourceFile;
+}
+
+/** Inline files into the target source file. */
+export function inlineFiles({
+ basePath,
+ debug,
+ inline,
+ targetSourceFile
+}: InlineFilesOptions) {
+ for (const filename of inline) {
+ const text = readFileSync(filename, {
+ encoding: "utf8"
+ });
+ targetSourceFile.addStatements(
+ debug
+ ? `\n// @url ${relative(basePath, filename)}\n\n${text}`
+ : `\n${text}`
+ );
+ }
+}
+
/**
* Load and write to a virtual file system all the default libs needed to
* resolve types on project.