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[],
|
2018-12-05 22:29:01 +00:00
|
|
|
compilerOptionsArg: CompilerOptions = {},
|
2019-08-26 14:28:03 +00:00
|
|
|
argvArg?: any
|
2018-07-25 18:56:42 +00:00
|
|
|
): Promise<any[]> => {
|
2018-12-05 22:29:01 +00:00
|
|
|
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 = {},
|
2018-12-05 22:29:01 +00:00
|
|
|
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[] = [];
|
2018-12-05 22:29:01 +00:00
|
|
|
for (const keyArg in globStringObjectArg) {
|
2019-08-26 14:28:03 +00:00
|
|
|
if (globStringObjectArg[keyArg]) {
|
2018-12-05 22:29:01 +00:00
|
|
|
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(
|
2018-12-05 22:29:01 +00:00
|
|
|
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(
|
2018-12-05 22:29:01 +00:00
|
|
|
globStringObjectArg[keyArg],
|
|
|
|
cwdArg
|
2022-05-25 21:43:44 +00:00
|
|
|
) as string;
|
2018-12-05 22:29:01 +00:00
|
|
|
tsOptionsArg = {
|
|
|
|
...tsOptionsArg,
|
2022-03-18 13:32:35 +00:00
|
|
|
outDir: destDir,
|
2018-12-05 22:29:01 +00:00
|
|
|
};
|
|
|
|
compiledFiles = compiledFiles.concat(
|
|
|
|
compiledFiles,
|
|
|
|
await compileFileArray(absoluteFilePathArray, tsOptionsArg, argvArg)
|
|
|
|
);
|
|
|
|
}
|
2018-07-25 18:56:42 +00:00
|
|
|
}
|
|
|
|
return compiledFiles;
|
|
|
|
};
|