Files
cli/assistant/src/module/npm-install.ts
abearxiong 68c1976754 feat: add user info command and package management for assistant app
- Implemented a new command 'me' to view current user information in the assistant application.
- Created a common configuration file for the assistant app with package details and scripts.
- Added functionality to check and update package.json dependencies and devDependencies in the assistant app.
- Refactored storage initialization in query module to use StorageNode.
2026-02-21 03:08:39 +08:00

46 lines
1.1 KiB
TypeScript

import { spawn, spawnSync } from 'child_process';
export const checkPnpm = () => {
try {
spawnSync('pnpm', ['--version']);
return true;
} catch (e) {
return false;
}
};
type InstallDepsOptions = {
appPath: string;
isProduction?: boolean;
sync?: boolean;
};
export const installDeps = async (opts: InstallDepsOptions) => {
const { appPath } = opts;
const isProduction = opts.isProduction ?? true;
const isPnpm = checkPnpm();
const params = ['i'];
if (isProduction && isPnpm) {
params.push('--production');
} else {
params.push('--omit=dev');
}
console.log('installDeps', appPath, params);
const syncSpawn = opts.sync ? spawnSync : spawn;
if (isPnpm) {
syncSpawn('pnpm', params, { cwd: appPath, stdio: 'inherit', env: { ...process.env, CI: 'true' }, shell: true });
} else {
syncSpawn('npm', params, { cwd: appPath, stdio: 'inherit', env: process.env, shell: true });
}
};
export const execCommand = (command: string, options: { cwd?: string } = {}) => {
const { cwd } = options;
return spawnSync(command, {
stdio: 'inherit',
shell: true,
cwd: cwd,
env: process.env,
});
};