tsbuild/ts/tsbuild.exports.ts

60 lines
1.8 KiB
TypeScript
Raw Permalink Normal View History

2024-05-10 13:55:25 +00:00
import * as plugins from './plugins.js';
2022-03-12 18:42:49 +00:00
import type { CompilerOptions, ScriptTarget, ModuleKind } from 'typescript';
2022-03-12 18:05:46 +00:00
import { compiler, mergeCompilerOptions } from './tsbuild.classes.compiler.js';
2018-07-25 18:56:42 +00:00
2022-03-18 13:32:35 +00:00
export type { CompilerOptions, ScriptTarget, ModuleKind };
2022-03-12 18:42:49 +00:00
2022-03-12 18:05:46 +00:00
export * from './tsbuild.classes.compiler.js';
2018-07-25 18:56:42 +00:00
/**
* compile am array of absolute file paths
*/
export let compileFileArray = (
fileStringArrayArg: string[],
compilerOptionsArg: CompilerOptions = {},
2019-08-26 14:28:03 +00:00
argvArg?: any
2018-07-25 18:56:42 +00:00
): Promise<any[]> => {
return compiler(fileStringArrayArg, mergeCompilerOptions(compilerOptionsArg, argvArg), argvArg);
2018-07-25 18:56:42 +00:00
};
/**
* compile advanced glob configurations
* @param globStringArrayArg a array of glob strings
* {
* './some/origin/folder/**\/*.ts': './some/destination/folder'
* }
*/
export let compileGlobStringObject = async (
globStringObjectArg: any,
tsOptionsArg: CompilerOptions = {},
cwdArg: string = process.cwd(),
2019-08-26 14:28:03 +00:00
argvArg?: any
2018-07-25 18:56:42 +00:00
) => {
2024-05-10 13:55:25 +00:00
let compiledFiles: plugins.smartfile.SmartFile[] = [];
for (const keyArg in globStringObjectArg) {
2019-08-26 14:28:03 +00:00
if (globStringObjectArg[keyArg]) {
console.log(
`TypeScript assignment: transpile from ${keyArg} to ${globStringObjectArg[keyArg]}`
);
const fileTreeArray = await plugins.smartfile.fs.listFileTree(cwdArg, keyArg);
2020-08-10 22:10:20 +00:00
const absoluteFilePathArray: string[] = plugins.smartpath.transform.toAbsolute(
fileTreeArray,
cwdArg
2022-05-25 21:43:44 +00:00
) as string[];
2020-08-10 22:10:20 +00:00
const destDir: string = plugins.smartpath.transform.toAbsolute(
globStringObjectArg[keyArg],
cwdArg
2022-05-25 21:43:44 +00:00
) as string;
tsOptionsArg = {
...tsOptionsArg,
2022-03-18 13:32:35 +00:00
outDir: destDir,
};
compiledFiles = compiledFiles.concat(
compiledFiles,
await compileFileArray(absoluteFilePathArray, tsOptionsArg, argvArg)
);
}
2018-07-25 18:56:42 +00:00
}
return compiledFiles;
};