物业代码生成
This commit is contained in:
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);
|
||||
}
|
67
scripts/turbo-run/src/run.ts
Normal file
67
scripts/turbo-run/src/run.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { execaCommand, getPackages } from '@vben/node-utils';
|
||||
|
||||
import { cancel, isCancel, select } from '@clack/prompts';
|
||||
|
||||
interface RunOptions {
|
||||
command?: string;
|
||||
}
|
||||
|
||||
export async function run(options: RunOptions) {
|
||||
const { command } = options;
|
||||
if (!command) {
|
||||
console.error('Please enter the command to run');
|
||||
process.exit(1);
|
||||
}
|
||||
const { packages } = await getPackages();
|
||||
// const appPkgs = await findApps(process.cwd(), packages);
|
||||
// const websitePkg = packages.find(
|
||||
// (item) => item.packageJson.name === '@vben/website',
|
||||
// );
|
||||
|
||||
// 只显示有对应命令的包
|
||||
const selectPkgs = packages.filter((pkg) => {
|
||||
return (pkg?.packageJson as Record<string, any>)?.scripts?.[command];
|
||||
});
|
||||
|
||||
let selectPkg: string | symbol;
|
||||
if (selectPkgs.length > 1) {
|
||||
selectPkg = await select<string>({
|
||||
message: `Select the app you need to run [${command}]:`,
|
||||
options: selectPkgs.map((item) => ({
|
||||
label: item?.packageJson.name,
|
||||
value: item?.packageJson.name,
|
||||
})),
|
||||
});
|
||||
|
||||
if (isCancel(selectPkg) || !selectPkg) {
|
||||
cancel('👋 Has cancelled');
|
||||
process.exit(0);
|
||||
}
|
||||
} else {
|
||||
selectPkg = selectPkgs[0]?.packageJson?.name ?? '';
|
||||
}
|
||||
|
||||
if (!selectPkg) {
|
||||
console.error('No app found');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
execaCommand(`pnpm --filter=${selectPkg} run ${command}`, {
|
||||
stdio: 'inherit',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤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;
|
||||
// });
|
||||
|
||||
// return appPackages;
|
||||
// }
|
Reference in New Issue
Block a user