2022-01-27 14:32:38 +08:00
|
|
|
/* eslint no-restricted-syntax:0, no-await-in-loop:0, no-restricted-syntax:0 */
|
2022-03-01 10:40:46 +08:00
|
|
|
import path from 'path';
|
2022-01-27 15:51:02 +08:00
|
|
|
import fse from 'fs-extra';
|
|
|
|
import glob from 'glob';
|
2022-01-27 14:32:38 +08:00
|
|
|
|
|
|
|
export default async function getPackages() {
|
2023-02-13 14:48:34 +08:00
|
|
|
const packageNames: string[] = [];
|
|
|
|
const packageDirs: string[] = [];
|
2022-01-27 14:32:38 +08:00
|
|
|
const rootPkgPath = path.join(process.cwd(), 'package.json');
|
|
|
|
const rootPkgContent = fse.readJSONSync(rootPkgPath);
|
|
|
|
|
|
|
|
for (const workspace of rootPkgContent.workspaces || []) {
|
2022-01-27 15:51:02 +08:00
|
|
|
const dirs = glob.sync(workspace);
|
2022-01-27 14:32:38 +08:00
|
|
|
for (const dir of dirs) {
|
|
|
|
if (fse.existsSync(path.resolve(dir, 'package.json'))) {
|
|
|
|
const pkgContent = fse.readJSONSync(path.resolve(dir, 'package.json'));
|
|
|
|
packageNames.push(pkgContent.name);
|
|
|
|
packageDirs.push(path.resolve(dir));
|
|
|
|
} else {
|
|
|
|
console.warn('Invalid workspace package:', dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { packageNames, packageDirs };
|
2023-02-13 14:48:34 +08:00
|
|
|
}
|