tsbuild/ts/tsbuild.cli.ts

65 lines
2.1 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 shared is always transpiled first
const indexShared = tsFolders.indexOf('ts_shared');
if (indexShared > -1) {
tsFolders.splice(indexShared, 1);
tsFolders.unshift('ts_shared');
}
// lets make sure interfaces are always transpiled first
const indexInterfaces = tsFolders.indexOf('ts_interfaces');
if (indexInterfaces > -1) {
tsFolders.splice(indexInterfaces, 1);
tsFolders.unshift('ts_interfaces');
}
const compilationCommandObject: { [key: string]: string } = {};
console.log(`compiling in this order:`);
console.log(tsFolders);
for (const tsFolder of tsFolders) {
compilationCommandObject[`./${tsFolder}/**/*.ts`] = `./dist_${tsFolder}`;
}
await tsbuild.compileGlobStringObject(compilationCommandObject, {}, process.cwd(), argvArg);
});
tsbuildCli.startParse();
};