tsbuild/ts/tsbuild.cli.ts
2024-05-14 01:20:49 +02:00

68 lines
2.3 KiB
TypeScript

import * as plugins from './plugins.js';
import * as paths from './paths.js';
import * as tsbuild from './tsbuild.exports.js';
export const runCli = async () => {
const tsbuildCli = new plugins.smartcli.Smartcli();
/**
* the standard task compiles anything in ts/ directory to dist directory
*/
tsbuildCli.standardCommand().subscribe(async (argvArg) => {
tsbuild.compileGlobStringObject(
{
'./ts/**/*.ts': './dist_ts',
},
{},
process.cwd(),
argvArg
);
});
/**
* the custom command compiles any customDir to dist_customDir
*/
tsbuildCli.addCommand('custom').subscribe(async (argvArg) => {
const listedDirectories = argvArg._;
listedDirectories.shift(); // removes the first element that is "custom"
const compilationCommandObject: { [key: string]: string } = {};
for (const directory of listedDirectories) {
compilationCommandObject[`./${directory}/**/*.ts`] = `./dist_${directory}`;
}
await tsbuild.compileGlobStringObject(compilationCommandObject, {}, process.cwd(), argvArg);
});
/**
* the custom command compiles any customDir to dist_customDir
*/
tsbuildCli.addCommand('tsfolders').subscribe(async (argvArg) => {
const tsFolders = await plugins.smartfile.fs.listFolders(paths.cwd, /^ts/);
// lets make sure interfaces are always transpiled first
const index = tsFolders.indexOf('ts_interfaces');
if (index > -1) {
tsFolders.splice(index, 1);
tsFolders.unshift('ts_interfaces');
}
const compilationCommandObject: { [key: string]: string } = {};
for (const tsFolder of tsFolders) {
compilationCommandObject[`./${tsFolder}/**/*.ts`] = `./dist_${tsFolder}`;
}
await tsbuild.compileGlobStringObject(compilationCommandObject, {}, process.cwd(), argvArg);
});
/**
* the custom command compiles any customDir to dist_customDir
*/
tsbuildCli.addCommand('interfaces').subscribe(async (argvArg) => {
const tsFolders = ['ts_interfaces'];
const compilationCommandObject: { [key: string]: string } = {};
for (const tsFolder of tsFolders) {
compilationCommandObject[`./${tsFolder}/**/*.ts`] = `./dist_${tsFolder}`;
}
await tsbuild.compileGlobStringObject(compilationCommandObject, {}, process.cwd(), argvArg);
});
tsbuildCli.startParse();
};