mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-22 22:16:18 +08:00
feat: Support multiple application launch scripts
This commit is contained in:
3
scripts/turbo-run/README.md
Normal file
3
scripts/turbo-run/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# @vben/vsh
|
||||
|
||||
shell 脚本工具集合
|
3
scripts/turbo-run/bin/turbo-run.mjs
Executable file
3
scripts/turbo-run/bin/turbo-run.mjs
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import('../dist/index.mjs');
|
7
scripts/turbo-run/build.config.ts
Normal file
7
scripts/turbo-run/build.config.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { defineBuildConfig } from 'unbuild';
|
||||
|
||||
export default defineBuildConfig({
|
||||
clean: true,
|
||||
declaration: true,
|
||||
entries: ['src/index'],
|
||||
});
|
29
scripts/turbo-run/package.json
Normal file
29
scripts/turbo-run/package.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "@vben/turbo-run",
|
||||
"version": "5.0.0",
|
||||
"private": true,
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"stub": "pnpm unbuild --stub"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"bin": {
|
||||
"turbo-run": "./bin/turbo-run.mjs"
|
||||
},
|
||||
"main": "./dist/index.mjs",
|
||||
"module": "./dist/index.mjs",
|
||||
"exports": {
|
||||
".": {
|
||||
"default": "./dist/index.mjs"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@clack/prompts": "^0.7.0",
|
||||
"@vben/node-utils": "workspace:*",
|
||||
"cac": "^6.7.14"
|
||||
}
|
||||
}
|
29
scripts/turbo-run/src/index.ts
Normal file
29
scripts/turbo-run/src/index.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { colors, consola } from '@vben/node-utils';
|
||||
|
||||
import { cac } from 'cac';
|
||||
|
||||
import { run } from './run';
|
||||
|
||||
try {
|
||||
const turboRun = cac('turbo-run');
|
||||
|
||||
turboRun
|
||||
.command('[script]')
|
||||
.usage(`Run turbo interactively.`)
|
||||
.action(async (command: string) => {
|
||||
run({ command });
|
||||
});
|
||||
|
||||
// Invalid command
|
||||
turboRun.on('command:*', () => {
|
||||
consola.error(colors.red('Invalid command!'));
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
turboRun.usage('turbo-run');
|
||||
turboRun.help();
|
||||
turboRun.parse();
|
||||
} catch (error) {
|
||||
consola.error(error);
|
||||
process.exit(1);
|
||||
}
|
63
scripts/turbo-run/src/run.ts
Normal file
63
scripts/turbo-run/src/run.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import type { Package } from '@vben/node-utils';
|
||||
|
||||
import { join } from 'node:path';
|
||||
|
||||
import { $, fs, getPackages } from '@vben/node-utils';
|
||||
|
||||
import { cancel, isCancel, multiselect } from '@clack/prompts';
|
||||
|
||||
interface RunOptions {
|
||||
command?: string;
|
||||
}
|
||||
|
||||
export async function run(options: RunOptions) {
|
||||
const { command } = options;
|
||||
const { packages } = await getPackages();
|
||||
const appPkgs = await findApps(process.cwd(), packages);
|
||||
|
||||
const selectApps = await multiselect<any, string>({
|
||||
message: `Select the app you need to run [${command}]:`,
|
||||
options: appPkgs.map((item) => ({ label: item, value: item })),
|
||||
required: true,
|
||||
});
|
||||
|
||||
if (isCancel(selectApps)) {
|
||||
cancel('👋 Has cancelled');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (selectApps.length === 1) {
|
||||
$.verbose = true;
|
||||
// 让控制台显示颜色
|
||||
process.env.FORCE_COLOR = '1';
|
||||
await $`pnpm --filter=${selectApps[0]} run ${command} `;
|
||||
return;
|
||||
}
|
||||
const filters = [];
|
||||
for (const app of selectApps) {
|
||||
filters.push(`--filter=${app}`);
|
||||
}
|
||||
$.verbose = true;
|
||||
// 让控制台显示颜色
|
||||
process.env.FORCE_COLOR = '1';
|
||||
await $`turbo run ${command} ${filters}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤app包
|
||||
* @param root
|
||||
* @param packages
|
||||
*/
|
||||
async function findApps(root: string, packages: Package[]) {
|
||||
// apps内的
|
||||
const appPackages = packages
|
||||
.filter((pkg) => {
|
||||
const viteConfigExists = fs.existsSync(join(pkg.dir, 'vite.config.mts'));
|
||||
return pkg.dir.startsWith(join(root, 'apps')) && viteConfigExists;
|
||||
})
|
||||
.map((pkg) => {
|
||||
return pkg.packageJson.name;
|
||||
});
|
||||
|
||||
return appPackages;
|
||||
}
|
6
scripts/turbo-run/tsconfig.json
Normal file
6
scripts/turbo-run/tsconfig.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"extends": "@vben/tsconfig/node.json",
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
@@ -26,7 +26,6 @@
|
||||
"cac": "^6.7.14",
|
||||
"circular-dependency-scanner": "^2.2.2",
|
||||
"depcheck": "^1.4.7",
|
||||
"publint": "^0.2.9",
|
||||
"zx": "^8.1.4"
|
||||
"publint": "^0.2.9"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user