tsdoc/ts/cli.ts
2024-06-22 13:20:55 +02:00

50 lines
1.6 KiB
TypeScript

import * as plugins from './plugins.js';
import * as paths from './paths.js';
import { logger } from './logging.js';
import { TypeDoc } from './classes.typedoc.js';
import { AiDoc } from './classes.aidoc.js';
export const run = async () => {
const tsdocCli = new plugins.smartcli.Smartcli();
tsdocCli.standardCommand().subscribe(async (argvArg) => {
logger.log('warn', `Auto detecting environment!`);
switch (true) {
case await TypeDoc.isTypeDocDir(paths.cwd):
logger.log('ok', `Detected TypeDoc compliant directory at ${paths.cwd}`);
tsdocCli.triggerCommand('typedoc', argvArg);
break;
default:
logger.log('error', `Cannot determine docs format at ${paths.cwd}`);
}
});
tsdocCli.addCommand('typedoc').subscribe(async (argvArg) => {
const typeDocInstance = new TypeDoc(paths.cwd);
await typeDocInstance.compile({
publicSubdir: argvArg.publicSubdir,
});
});
tsdocCli.addCommand('aidoc').subscribe(async (argvArg) => {
logger.log('info', `Generating new readme...`);
logger.log('info', `This may take some time...`);
const aidocInstance = new AiDoc();
await aidocInstance.start();
aidocInstance.buildReadme(paths.cwd);
logger.log('info', `Generating new keywords...`);
logger.log('info', `This may take some time...`);
aidocInstance.buildDescription(paths.cwd);
});
tsdocCli.addCommand('test').subscribe((argvArg) => {
tsdocCli.triggerCommand('typedoc', argvArg);
process.on('exit', async () => {
await plugins.smartfile.fs.remove(paths.publicDir);
});
});
tsdocCli.startParse();
};