BREAKING CHANGE(tswatch): refactor tswatch to a config-driven design (load config from npmextra.json) and add interactive init wizard; change TsWatch public API and enhance Watcher behavior

This commit is contained in:
2026-01-24 11:29:55 +00:00
parent 5a702055f4
commit 9fb3f6a872
20 changed files with 3686 additions and 4431 deletions

View File

@@ -3,42 +3,48 @@ 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 behaviour will assume gitzone setup
tswatchCli.standardCommand().subscribe((argvArg) => {
tswatchCli.triggerCommand('npm', {});
/**
* 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();
}
}
});
tswatchCli.addCommand('element').subscribe(async (argvArg) => {
logger.log('info', `running watch task for a gitzone element project`);
const tsWatch = new TsWatch('element');
await tsWatch.start();
});
tswatchCli.addCommand('npm').subscribe(async (argvArg) => {
logger.log('info', `running watch task for a gitzone element project`);
const tsWatch = new TsWatch('node');
await tsWatch.start();
});
tswatchCli.addCommand('service').subscribe(async (argvArg) => {
logger.log('info', `running test task`);
const tsWatch = new TsWatch('service');
await tsWatch.start();
});
tswatchCli.addCommand('test').subscribe(async (argvArg) => {
logger.log('info', `running test task`);
const tsWatch = new TsWatch('test');
await tsWatch.start();
});
tswatchCli.addCommand('website').subscribe(async (argvArg) => {
logger.log('info', `running watch task for a gitzone website project`);
const tsWatch = new TsWatch('website');
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 () => {