tsbuild/ts/tsbuild.exports.ts

64 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-03-12 18:05:46 +00:00
import * as plugins from './tsbuild.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-12 18:42:49 +00:00
export type {
CompilerOptions,
ScriptTarget,
ModuleKind
}
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
) => {
2021-08-17 10:13:51 +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
);
2020-08-10 22:10:20 +00:00
const destDir: string = plugins.smartpath.transform.toAbsolute(
globStringObjectArg[keyArg],
cwdArg
);
tsOptionsArg = {
...tsOptionsArg,
outDir: destDir
};
compiledFiles = compiledFiles.concat(
compiledFiles,
await compileFileArray(absoluteFilePathArray, tsOptionsArg, argvArg)
);
}
2018-07-25 18:56:42 +00:00
}
return compiledFiles;
};