Some checks failed
Deploy Website on push / Deploy Push Element Ftp (push) Waiting to run
Lock Threads / action (push) Has been cancelled
Issue Close Require / close-issues (push) Has been cancelled
Close stale issues / stale (push) Has been cancelled
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / CI OK (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Deploy Website on push / Rerun on failure (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
47 lines
970 B
TypeScript
47 lines
970 B
TypeScript
import { dirname } from 'node:path';
|
|
|
|
import {
|
|
getPackages as getPackagesFunc,
|
|
getPackagesSync as getPackagesSyncFunc,
|
|
} from '@manypkg/get-packages';
|
|
import { findUpSync } from 'find-up';
|
|
|
|
/**
|
|
* 查找大仓的根目录
|
|
* @param cwd
|
|
*/
|
|
function findMonorepoRoot(cwd: string = process.cwd()) {
|
|
const lockFile = findUpSync('pnpm-lock.yaml', {
|
|
cwd,
|
|
type: 'file',
|
|
});
|
|
return dirname(lockFile || '');
|
|
}
|
|
|
|
/**
|
|
* 获取大仓的所有包
|
|
*/
|
|
function getPackagesSync() {
|
|
const root = findMonorepoRoot();
|
|
return getPackagesSyncFunc(root);
|
|
}
|
|
|
|
/**
|
|
* 获取大仓的所有包
|
|
*/
|
|
async function getPackages() {
|
|
const root = findMonorepoRoot();
|
|
|
|
return await getPackagesFunc(root);
|
|
}
|
|
|
|
/**
|
|
* 获取大仓指定的包
|
|
*/
|
|
async function getPackage(pkgName: string) {
|
|
const { packages } = await getPackages();
|
|
return packages.find((pkg) => pkg.packageJson.name === pkgName);
|
|
}
|
|
|
|
export { findMonorepoRoot, getPackage, getPackages, getPackagesSync };
|