add 添加初始化依赖安装
This commit is contained in:
36
assistant/src/module/npm-install.ts
Normal file
36
assistant/src/module/npm-install.ts
Normal 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 });
|
||||
}
|
||||
};
|
||||
@@ -4,7 +4,7 @@ import { checkFileExists, AssistantConfig, AssistantConfigData, parseHomeArg, pa
|
||||
import { chalk } from '@/module/chalk.ts';
|
||||
import { HttpsPem } from '@/module/assistant/https/sign.ts';
|
||||
import { Query } from '@kevisual/query/query';
|
||||
|
||||
import { installDeps } from '@/module/npm-install.ts'
|
||||
export { parseHomeArg, parseHelpArg };
|
||||
export type AssistantInitOptions = {
|
||||
path?: string;
|
||||
@@ -114,8 +114,8 @@ export class AssistantInit extends AssistantConfig {
|
||||
"description": "assistant-app package pnpm, node pkgs projects",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "pm2 start apps/code-center/dist/app.mjs --name code-center",
|
||||
"proxy": "pm2 start apps/page-proxy/dist/app.mjs --name page-proxy"
|
||||
"start": "pm2 start apps/root/code-center/app.mjs --name root/code-center",
|
||||
"proxy": "pm2 start apps/root/page-proxy/app.mjs --name root/page-proxy"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
@@ -123,6 +123,7 @@ export class AssistantInit extends AssistantConfig {
|
||||
"dependencies": {
|
||||
"@kevisual/router": "latest",
|
||||
"@kevisual/use-config": "latest",
|
||||
"@kevisual/query": "latest",
|
||||
"ioredis": "latest",
|
||||
"minio": "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 {
|
||||
create,
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"dependencies": {
|
||||
"@kevisual/router": "latest",
|
||||
"@kevisual/use-config": "latest",
|
||||
"@kevisual/query": "latest",
|
||||
"ioredis": "latest",
|
||||
"minio": "latest",
|
||||
"pg": "latest",
|
||||
|
||||
Reference in New Issue
Block a user