53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import * as plugins from './tswatch.plugins.js';
|
|
import * as paths from './tswatch.paths.js';
|
|
import { logger } from './tswatch.logging.js';
|
|
|
|
import { TsWatch } from './tswatch.classes.tswatch.js';
|
|
import { ConfigHandler } from './tswatch.classes.confighandler.js';
|
|
import { runInit } from './tswatch.init.js';
|
|
|
|
const tswatchCli = new plugins.smartcli.Smartcli();
|
|
|
|
/**
|
|
* Standard command (no args) - run with config or launch wizard
|
|
*/
|
|
tswatchCli.standardCommand().subscribe(async (argvArg) => {
|
|
const configHandler = new ConfigHandler();
|
|
|
|
if (configHandler.hasConfig()) {
|
|
// Config exists - run with it
|
|
const tsWatch = TsWatch.fromConfig();
|
|
if (tsWatch) {
|
|
logger.log('info', 'Starting tswatch with configuration from npmextra.json');
|
|
await tsWatch.start();
|
|
} else {
|
|
logger.log('error', 'Failed to load configuration');
|
|
process.exit(1);
|
|
}
|
|
} else {
|
|
// No config - launch wizard
|
|
logger.log('info', 'No tswatch configuration found in npmextra.json');
|
|
const config = await runInit();
|
|
if (config) {
|
|
// Run with the newly created config
|
|
const tsWatch = new TsWatch(config);
|
|
await tsWatch.start();
|
|
}
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Init command - force run wizard (overwrite existing config)
|
|
*/
|
|
tswatchCli.addCommand('init').subscribe(async (argvArg) => {
|
|
logger.log('info', 'Running tswatch configuration wizard');
|
|
const config = await runInit();
|
|
if (config) {
|
|
logger.log('ok', 'Configuration created successfully');
|
|
}
|
|
});
|
|
|
|
export const runCli = async () => {
|
|
tswatchCli.startParse();
|
|
};
|