fix(config): switch configuration loading and saving from npmextra.json to smartconfig.json
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@git.zone/tswatch',
|
||||
version: '3.3.0',
|
||||
version: '3.3.1',
|
||||
description: 'A development tool for automatically watching and re-compiling TypeScript projects upon detecting file changes, enhancing developer workflows.'
|
||||
}
|
||||
|
||||
@@ -119,28 +119,28 @@ const presets: Record<string, interfaces.ITswatchConfig> = {
|
||||
* Handles loading and managing tswatch configuration
|
||||
*/
|
||||
export class ConfigHandler {
|
||||
private npmextra: plugins.npmextra.Npmextra;
|
||||
private smartconfig: plugins.smartconfig.Smartconfig;
|
||||
private cwd: string;
|
||||
|
||||
constructor(cwdArg?: string) {
|
||||
this.cwd = cwdArg || paths.cwd;
|
||||
this.npmextra = new plugins.npmextra.Npmextra(this.cwd);
|
||||
this.smartconfig = new plugins.smartconfig.Smartconfig(this.cwd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a tswatch configuration exists
|
||||
*/
|
||||
public hasConfig(): boolean {
|
||||
const config = this.npmextra.dataFor<interfaces.ITswatchConfig>(CONFIG_KEY, null);
|
||||
const config = this.smartconfig.dataFor<interfaces.ITswatchConfig>(CONFIG_KEY, null);
|
||||
return config !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load configuration from npmextra.json
|
||||
* Load configuration from smartconfig.json
|
||||
* If a preset is specified, merge preset defaults with user overrides
|
||||
*/
|
||||
public loadConfig(): interfaces.ITswatchConfig | null {
|
||||
const config = this.npmextra.dataFor<interfaces.ITswatchConfig>(CONFIG_KEY, null);
|
||||
const config = this.smartconfig.dataFor<interfaces.ITswatchConfig>(CONFIG_KEY, null);
|
||||
|
||||
if (!config) {
|
||||
return null;
|
||||
@@ -177,7 +177,7 @@ export class ConfigHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the config key for npmextra.json
|
||||
* Get the config key for smartconfig.json
|
||||
*/
|
||||
public getConfigKey(): string {
|
||||
return CONFIG_KEY;
|
||||
|
||||
@@ -9,7 +9,7 @@ import { logger } from './tswatch.logging.js';
|
||||
/**
|
||||
* TsWatch - Config-driven file watcher
|
||||
*
|
||||
* Reads configuration from npmextra.json under the key '@git.zone/tswatch'
|
||||
* Reads configuration from smartconfig.json under the key '@git.zone/tswatch'
|
||||
* and sets up watchers, bundles, and dev server accordingly.
|
||||
*/
|
||||
export class TsWatch {
|
||||
@@ -27,7 +27,7 @@ export class TsWatch {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create TsWatch from npmextra.json configuration
|
||||
* Create TsWatch from smartconfig.json configuration
|
||||
*/
|
||||
public static fromConfig(cwdArg?: string): TsWatch | null {
|
||||
const configHandler = new ConfigHandler(cwdArg);
|
||||
|
||||
@@ -18,7 +18,7 @@ tswatchCli.standardCommand().subscribe(async (argvArg) => {
|
||||
// Config exists - run with it
|
||||
const tsWatch = TsWatch.fromConfig();
|
||||
if (tsWatch) {
|
||||
logger.log('info', 'Starting tswatch with configuration from npmextra.json');
|
||||
logger.log('info', 'Starting tswatch with configuration from smartconfig.json');
|
||||
await tsWatch.start();
|
||||
} else {
|
||||
logger.log('error', 'Failed to load configuration');
|
||||
@@ -26,7 +26,7 @@ tswatchCli.standardCommand().subscribe(async (argvArg) => {
|
||||
}
|
||||
} else {
|
||||
// No config - launch wizard
|
||||
logger.log('info', 'No tswatch configuration found in npmextra.json');
|
||||
logger.log('info', 'No tswatch configuration found in smartconfig.json');
|
||||
const config = await runInit();
|
||||
if (config) {
|
||||
// Run with the newly created config
|
||||
|
||||
@@ -56,10 +56,10 @@ export class TswatchInit {
|
||||
config = { ...preset, preset: template as interfaces.ITswatchConfig['preset'] };
|
||||
}
|
||||
|
||||
// Save to npmextra.json
|
||||
// Save to smartconfig.json
|
||||
await this.saveConfig(config);
|
||||
|
||||
console.log('\nConfiguration saved to npmextra.json');
|
||||
console.log('\nConfiguration saved to smartconfig.json');
|
||||
console.log('Run "tswatch" to start watching.\n');
|
||||
|
||||
return config;
|
||||
@@ -166,16 +166,16 @@ export class TswatchInit {
|
||||
}
|
||||
|
||||
/**
|
||||
* Save configuration to npmextra.json
|
||||
* Save configuration to smartconfig.json
|
||||
*/
|
||||
private async saveConfig(config: interfaces.ITswatchConfig): Promise<void> {
|
||||
const npmextraPath = plugins.path.join(paths.cwd, 'npmextra.json');
|
||||
const smartconfigPath = plugins.path.join(paths.cwd, 'smartconfig.json');
|
||||
|
||||
// Read existing npmextra.json if it exists
|
||||
// Read existing smartconfig.json if it exists
|
||||
let existingConfig: Record<string, any> = {};
|
||||
try {
|
||||
const smartfsInstance = new plugins.smartfs.SmartFs(new plugins.smartfs.SmartFsProviderNode());
|
||||
const content = await smartfsInstance.file(npmextraPath).encoding('utf8').read() as string;
|
||||
const content = await smartfsInstance.file(smartconfigPath).encoding('utf8').read() as string;
|
||||
existingConfig = JSON.parse(content);
|
||||
} catch {
|
||||
// File doesn't exist or is invalid, start fresh
|
||||
@@ -186,7 +186,7 @@ export class TswatchInit {
|
||||
|
||||
// Write back
|
||||
const smartfsInstance = new plugins.smartfs.SmartFs(new plugins.smartfs.SmartFsProviderNode());
|
||||
await smartfsInstance.file(npmextraPath).encoding('utf8').write(JSON.stringify(existingConfig, null, 2));
|
||||
await smartfsInstance.file(smartconfigPath).encoding('utf8').write(JSON.stringify(existingConfig, null, 2));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ export { typedserver };
|
||||
|
||||
// @push.rocks scope
|
||||
import * as lik from '@push.rocks/lik';
|
||||
import * as npmextra from '@push.rocks/npmextra';
|
||||
import * as smartconfig from '@push.rocks/smartconfig';
|
||||
import * as smartcli from '@push.rocks/smartcli';
|
||||
import * as smartdelay from '@push.rocks/smartdelay';
|
||||
import * as smartexit from '@push.rocks/smartexit';
|
||||
@@ -26,7 +26,7 @@ import * as smartwatch from '@push.rocks/smartwatch';
|
||||
|
||||
export {
|
||||
lik,
|
||||
npmextra,
|
||||
smartconfig,
|
||||
smartcli,
|
||||
smartdelay,
|
||||
smartexit,
|
||||
|
||||
Reference in New Issue
Block a user