mirror of
https://github.com/iconify/iconify.git
synced 2025-01-24 07:38:29 +00:00
63 lines
1.4 KiB
TypeScript
63 lines
1.4 KiB
TypeScript
import type { PathList, PackageInfo } from './types';
|
|
import { rootDir } from './dirs';
|
|
import { addToPath, findSubdirs } from './dirs';
|
|
import { getFixPackageName, getPackageInfo } from './package';
|
|
|
|
/**
|
|
* Workspaces cache
|
|
*/
|
|
let workspaces: PackageInfo[];
|
|
|
|
/**
|
|
* Find workspaces
|
|
*/
|
|
export function findWorkspaces(): PackageInfo[] {
|
|
if (!workspaces) {
|
|
workspaces = [];
|
|
|
|
// Get name of current package
|
|
const fixPackageName = getFixPackageName();
|
|
|
|
function checkWorkspace(path: PathList) {
|
|
const info = getPackageInfo(path);
|
|
if (
|
|
info &&
|
|
info.name !== fixPackageName &&
|
|
!workspaces.find((item) => item.name === info.name)
|
|
) {
|
|
workspaces.push({
|
|
...info,
|
|
path,
|
|
});
|
|
}
|
|
}
|
|
|
|
function checkEntry(parentPath: PathList, parts: PathList) {
|
|
const nextParts = parts.slice(0);
|
|
const next = nextParts.shift();
|
|
const subdirs =
|
|
next === '*'
|
|
? Object.keys(findSubdirs(parentPath, false))
|
|
: [next];
|
|
|
|
subdirs.forEach((subdir) => {
|
|
const dir = addToPath(parentPath, subdir);
|
|
if (nextParts.length) {
|
|
checkEntry(dir, nextParts);
|
|
} else {
|
|
checkWorkspace(dir);
|
|
}
|
|
});
|
|
}
|
|
|
|
// Check all workspaces from lerna.json
|
|
const rootPackageJSON = require(rootDir + '/lerna.json');
|
|
rootPackageJSON.packages?.forEach((value: string) => {
|
|
checkEntry([], value.split('/'));
|
|
});
|
|
}
|
|
|
|
// Cache and return result
|
|
return workspaces;
|
|
}
|