75 lines
2.7 KiB
TypeScript
75 lines
2.7 KiB
TypeScript
import * as plugins from '../../plugins.js';
|
|
import { tspmIpcClient } from '../../../client/tspm.ipcclient.js';
|
|
import type { CliArguments } from '../../types.js';
|
|
import { registerIpcCommand } from '../../registration/index.js';
|
|
import { formatMemory, parseMemoryString } from '../../helpers/memory.js';
|
|
|
|
export function registerEditCommand(smartcli: plugins.smartcli.Smartcli) {
|
|
registerIpcCommand(
|
|
smartcli,
|
|
'edit',
|
|
async (argvArg: CliArguments) => {
|
|
const target = argvArg._[1];
|
|
if (!target) {
|
|
console.error('Error: Please provide a process target to edit');
|
|
console.log('Usage: tspm edit <id | id:N | name:LABEL>');
|
|
return;
|
|
}
|
|
|
|
// Resolve and load current config
|
|
const resolved = await tspmIpcClient.request('resolveTarget', { target: String(target) });
|
|
const { config } = await tspmIpcClient.request('describe', { id: resolved.id });
|
|
|
|
// Interactive editing is temporarily disabled - needs smartinteract API update
|
|
console.log('Interactive editing is temporarily disabled.');
|
|
console.log('Current configuration:');
|
|
console.log(` Name: ${config.name}`);
|
|
console.log(` Command: ${config.command}`);
|
|
console.log(` Directory: ${config.projectDir}`);
|
|
console.log(` Memory: ${formatMemory(config.memoryLimitBytes)}`);
|
|
console.log(` Auto-restart: ${config.autorestart}`);
|
|
console.log(` Watch: ${config.watch ? 'enabled' : 'disabled'}`);
|
|
|
|
// For now, just update environment variables to current
|
|
const essentialEnvVars: NodeJS.ProcessEnv = {
|
|
PATH: process.env.PATH || '',
|
|
HOME: process.env.HOME,
|
|
USER: process.env.USER,
|
|
SHELL: process.env.SHELL,
|
|
LANG: process.env.LANG,
|
|
LC_ALL: process.env.LC_ALL,
|
|
// Node.js specific
|
|
NODE_ENV: process.env.NODE_ENV,
|
|
NODE_PATH: process.env.NODE_PATH,
|
|
// npm/pnpm/yarn paths
|
|
npm_config_prefix: process.env.npm_config_prefix,
|
|
// Include any TSPM_ prefixed vars
|
|
...Object.fromEntries(
|
|
Object.entries(process.env).filter(([key]) => key.startsWith('TSPM_'))
|
|
),
|
|
};
|
|
|
|
// Remove undefined values
|
|
Object.keys(essentialEnvVars).forEach(key => {
|
|
if (essentialEnvVars[key] === undefined) {
|
|
delete essentialEnvVars[key];
|
|
}
|
|
});
|
|
|
|
// Update environment variables
|
|
const updates = {
|
|
env: { ...(config.env || {}), ...essentialEnvVars }
|
|
};
|
|
|
|
const updateResponse = await tspmIpcClient.request('update', {
|
|
id: resolved.id,
|
|
updates,
|
|
});
|
|
|
|
console.log('✓ Environment variables updated');
|
|
console.log(' Process configuration updated successfully');
|
|
},
|
|
{ actionLabel: 'edit process config' },
|
|
);
|
|
}
|