fix(cli): improve project metadata loading and normalize CLI error handling

This commit is contained in:
2026-05-09 12:34:58 +00:00
parent c7c1bbb460
commit adb13b027d
13 changed files with 3328 additions and 5222 deletions
+1 -1
View File
@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@git.zone/tspm',
version: '5.10.4',
version: '5.10.5',
description: 'a no fuzz process manager'
}
+4 -4
View File
@@ -1,7 +1,7 @@
import * as plugins from '../../plugins.js';
import * as paths from '../../../paths.js';
import { tspmIpcClient } from '../../../client/tspm.ipcclient.js';
import { Logger } from '../../../shared/common/utils.errorhandler.js';
import { handleError, Logger } from '../../../shared/common/utils.errorhandler.js';
import type { CliArguments } from '../../types.js';
import { formatMemory } from '../../helpers/memory.js';
@@ -76,7 +76,7 @@ export function registerDaemonCommand(smartcli: plugins.smartcli.Smartcli) {
// Disconnect from the daemon after starting
await tspmIpcClient.disconnect();
} catch (error) {
console.error('Error starting daemon:', error.message);
console.error('Error starting daemon:', handleError(error).message);
process.exit(1);
}
break;
@@ -139,7 +139,7 @@ export function registerDaemonCommand(smartcli: plugins.smartcli.Smartcli) {
// Disconnect from the daemon after stopping
await tspmIpcClient.disconnect();
} catch (error) {
console.error('Error stopping daemon:', error.message);
console.error('Error stopping daemon:', handleError(error).message);
process.exit(1);
}
break;
@@ -169,7 +169,7 @@ export function registerDaemonCommand(smartcli: plugins.smartcli.Smartcli) {
// Disconnect from daemon after getting status
await tspmIpcClient.disconnect();
} catch (error) {
console.error('Error getting daemon status:', error.message);
console.error('Error getting daemon status:', handleError(error).message);
process.exit(1);
}
break;
+1 -1
View File
@@ -8,10 +8,10 @@ import { formatMemory } from '../helpers/memory.js';
export function registerDefaultCommand(smartcli: plugins.smartcli.Smartcli) {
const cliLogger = new Logger('CLI');
const tspmProjectinfo = new plugins.projectinfo.ProjectInfo(paths.packageDir);
smartcli.standardCommand().subscribe({
next: async (argvArg: CliArguments) => {
const tspmProjectinfo = await plugins.projectinfo.ProjectInfo.create(paths.packageDir);
console.log(
`TSPM - TypeScript Process Manager v${tspmProjectinfo.npm.version}`,
);
+5 -4
View File
@@ -1,6 +1,6 @@
import * as plugins from '../../plugins.js';
import { TspmServiceManager } from '../../../client/tspm.servicemanager.js';
import { Logger } from '../../../shared/common/utils.errorhandler.js';
import { handleError, Logger } from '../../../shared/common/utils.errorhandler.js';
import type { CliArguments } from '../../types.js';
export function registerDisableCommand(smartcli: plugins.smartcli.Smartcli) {
@@ -18,10 +18,11 @@ export function registerDisableCommand(smartcli: plugins.smartcli.Smartcli) {
console.log(' The daemon will no longer start on system boot');
console.log(' Use "tspm enable" to re-enable the service');
} catch (error) {
console.error('Error disabling service:', error.message);
const errorMessage = handleError(error).message;
console.error('Error disabling service:', errorMessage);
if (
error.message.includes('permission') ||
error.message.includes('denied')
errorMessage.includes('permission') ||
errorMessage.includes('denied')
) {
console.log('\nNote: You may need to run this command with sudo');
}
+5 -4
View File
@@ -1,6 +1,6 @@
import * as plugins from '../../plugins.js';
import { TspmServiceManager } from '../../../client/tspm.servicemanager.js';
import { Logger } from '../../../shared/common/utils.errorhandler.js';
import { handleError, Logger } from '../../../shared/common/utils.errorhandler.js';
import type { CliArguments } from '../../types.js';
export function registerEnableCommand(smartcli: plugins.smartcli.Smartcli) {
@@ -18,10 +18,11 @@ export function registerEnableCommand(smartcli: plugins.smartcli.Smartcli) {
console.log(' The daemon will now start automatically on system boot');
console.log(' Use "tspm disable" to remove the service');
} catch (error) {
console.error('Error enabling service:', error.message);
const errorMessage = handleError(error).message;
console.error('Error enabling service:', errorMessage);
if (
error.message.includes('permission') ||
error.message.includes('denied')
errorMessage.includes('permission') ||
errorMessage.includes('denied')
) {
console.log('\nNote: You may need to run this command with sudo');
}
+4 -4
View File
@@ -14,7 +14,7 @@ export async function interactiveEditProcess(processId: number): Promise<void> {
message: 'Process name:',
default: config.name,
validate: (input: string) => {
return input && input.trim() !== '';
return input.trim() !== '';
}
},
{
@@ -23,7 +23,7 @@ export async function interactiveEditProcess(processId: number): Promise<void> {
message: 'Command to execute:',
default: config.command,
validate: (input: string) => {
return input && input.trim() !== '';
return input.trim() !== '';
}
},
{
@@ -32,7 +32,7 @@ export async function interactiveEditProcess(processId: number): Promise<void> {
message: 'Working directory:',
default: config.projectDir,
validate: (input: string) => {
return input && input.trim() !== '';
return input.trim() !== '';
}
},
{
@@ -161,4 +161,4 @@ export async function interactiveEditProcess(processId: number): Promise<void> {
if (updates.autorestart !== undefined) console.log(` Auto-restart: ${updates.autorestart}`);
if (updates.watch !== undefined) console.log(` Watch: ${updates.watch ? 'enabled' : 'disabled'}`);
if (updateEnv) console.log(' Environment variables: updated');
}
}
+1 -1
View File
@@ -33,7 +33,7 @@ export type { CliArguments } from './types.js';
*/
export const run = async (): Promise<void> => {
const cliLogger = new Logger('CLI');
const tspmProjectinfo = new plugins.projectinfo.ProjectInfo(paths.packageDir);
const tspmProjectinfo = await plugins.projectinfo.ProjectInfo.create(paths.packageDir);
// Check if debug mode is enabled
const debugMode = process.env.TSPM_DEBUG === 'true';
+17 -15
View File
@@ -3,6 +3,7 @@ import * as paths from '../paths.js';
import { toProcessId } from '../shared/protocol/id.js';
import type { ProcessId } from '../shared/protocol/id.js';
import { ProcessManager } from './processmanager.js';
import { handleError } from '../shared/common/utils.errorhandler.js';
import type {
IpcMethodMap,
RequestForMethod,
@@ -17,7 +18,7 @@ import { LogPersistence } from './logpersistence.js';
*/
export class TspmDaemon {
private tspmInstance: ProcessManager;
private ipcServer: plugins.smartipc.IpcServer;
private ipcServer!: plugins.smartipc.IpcServer;
private startTime: number;
private isShuttingDown: boolean = false;
private socketPath: string;
@@ -30,13 +31,7 @@ export class TspmDaemon {
this.socketPath = plugins.path.join(paths.tspmDir, 'tspm.sock');
this.daemonPidFile = plugins.path.join(paths.tspmDir, 'daemon.pid');
this.startTime = Date.now();
// Determine daemon version from package metadata
try {
const proj = new plugins.projectinfo.ProjectInfo(paths.packageDir);
this.version = proj.npm.version || 'unknown';
} catch {
this.version = 'unknown';
}
this.version = 'unknown';
}
/**
@@ -45,6 +40,13 @@ export class TspmDaemon {
public async start(): Promise<void> {
console.log('Starting TSPM daemon...');
try {
const proj = await plugins.projectinfo.ProjectInfo.create(paths.packageDir);
this.version = proj.npm.version || 'unknown';
} catch {
this.version = 'unknown';
}
// Ensure the TSPM directory exists
const fs = await import('fs/promises');
await fs.mkdir(paths.tspmDir, { recursive: true });
@@ -150,7 +152,7 @@ export class TspmDaemon {
status: processInfo?.status || 'stopped',
};
} catch (error) {
throw new Error(`Failed to start process: ${error.message}`);
throw new Error(`Failed to start process: ${handleError(error).message}`);
}
},
);
@@ -194,7 +196,7 @@ export class TspmDaemon {
status: processInfo?.status || 'stopped',
};
} catch (error) {
throw new Error(`Failed to start process: ${error.message}`);
throw new Error(`Failed to start process: ${handleError(error).message}`);
}
},
);
@@ -211,7 +213,7 @@ export class TspmDaemon {
message: `Process ${id} stopped successfully`,
};
} catch (error) {
throw new Error(`Failed to stop process: ${error.message}`);
throw new Error(`Failed to stop process: ${handleError(error).message}`);
}
},
);
@@ -230,7 +232,7 @@ export class TspmDaemon {
status: processInfo?.status || 'stopped',
};
} catch (error) {
throw new Error(`Failed to restart process: ${error.message}`);
throw new Error(`Failed to restart process: ${handleError(error).message}`);
}
},
);
@@ -248,7 +250,7 @@ export class TspmDaemon {
message: `Process ${id} deleted successfully`,
};
} catch (error) {
throw new Error(`Failed to delete process: ${error.message}`);
throw new Error(`Failed to delete process: ${handleError(error).message}`);
}
},
);
@@ -262,7 +264,7 @@ export class TspmDaemon {
const config = this.tspmInstance.processConfigs.get(id)!;
return { id, config };
} catch (error) {
throw new Error(`Failed to add process: ${error.message}`);
throw new Error(`Failed to add process: ${handleError(error).message}`);
}
},
);
@@ -275,7 +277,7 @@ export class TspmDaemon {
const updated = await this.tspmInstance.update(id, request.updates as any);
return { id, config: updated };
} catch (error) {
throw new Error(`Failed to update process: ${error.message}`);
throw new Error(`Failed to update process: ${handleError(error).message}`);
}
},
);