add 添加初始化依赖安装

This commit is contained in:
2025-11-25 00:44:05 +08:00
parent 283fa5c603
commit fdb3a1f4d1
3 changed files with 45 additions and 4 deletions

View File

@@ -0,0 +1,36 @@
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 });
} else {
syncSpawn('npm', params, { cwd: appPath, stdio: 'inherit', env: process.env });
}
};

View File

@@ -4,7 +4,7 @@ import { checkFileExists, AssistantConfig, AssistantConfigData, parseHomeArg, pa
import { chalk } from '@/module/chalk.ts'; import { chalk } from '@/module/chalk.ts';
import { HttpsPem } from '@/module/assistant/https/sign.ts'; import { HttpsPem } from '@/module/assistant/https/sign.ts';
import { Query } from '@kevisual/query/query'; import { Query } from '@kevisual/query/query';
import { installDeps } from '@/module/npm-install.ts'
export { parseHomeArg, parseHelpArg }; export { parseHomeArg, parseHelpArg };
export type AssistantInitOptions = { export type AssistantInitOptions = {
path?: string; path?: string;
@@ -114,8 +114,8 @@ export class AssistantInit extends AssistantConfig {
"description": "assistant-app package pnpm, node pkgs projects", "description": "assistant-app package pnpm, node pkgs projects",
"type": "module", "type": "module",
"scripts": { "scripts": {
"start": "pm2 start apps/code-center/dist/app.mjs --name code-center", "start": "pm2 start apps/root/code-center/app.mjs --name root/code-center",
"proxy": "pm2 start apps/page-proxy/dist/app.mjs --name page-proxy" "proxy": "pm2 start apps/root/page-proxy/app.mjs --name root/page-proxy"
}, },
"keywords": [], "keywords": [],
"author": "", "author": "",
@@ -123,6 +123,7 @@ export class AssistantInit extends AssistantConfig {
"dependencies": { "dependencies": {
"@kevisual/router": "latest", "@kevisual/router": "latest",
"@kevisual/use-config": "latest", "@kevisual/use-config": "latest",
"@kevisual/query": "latest",
"ioredis": "latest", "ioredis": "latest",
"minio": "latest", "minio": "latest",
"pg": "latest", "pg": "latest",
@@ -143,7 +144,10 @@ export class AssistantInit extends AssistantConfig {
} }
`, `,
); );
console.log(chalk.green('助手 package.json 文件创建成功')); console.log(chalk.green('助手 package.json 文件创建成功, 正在安装依赖...'));
installDeps({ appPath: path.dirname(packagePath), isProduction: true }).then(() => {
console.log(chalk.green('助手依赖安装完成'));
});
} }
return { return {
create, create,

View File

@@ -13,6 +13,7 @@
"dependencies": { "dependencies": {
"@kevisual/router": "latest", "@kevisual/router": "latest",
"@kevisual/use-config": "latest", "@kevisual/use-config": "latest",
"@kevisual/query": "latest",
"ioredis": "latest", "ioredis": "latest",
"minio": "latest", "minio": "latest",
"pg": "latest", "pg": "latest",