2022-12-31 15:21:57 +00:00
|
|
|
import fs from 'fs';
|
|
|
|
|
import path from 'path';
|
2023-10-15 03:33:48 +00:00
|
|
|
import { globSync } from 'glob';
|
|
|
|
|
import { projectRootPath } from './file';
|
2022-01-03 08:50:03 +00:00
|
|
|
|
2022-12-31 15:29:45 +00:00
|
|
|
export function joinPackagePath(...args: string[]) {
|
2022-12-31 15:21:57 +00:00
|
|
|
const pathList = Array.from(args);
|
2022-12-31 15:29:45 +00:00
|
|
|
const baseDir = path.join(joinProjectPath(), 'packages');
|
2022-01-03 08:50:03 +00:00
|
|
|
return path.join(baseDir, ...pathList);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-31 15:29:45 +00:00
|
|
|
export function joinProjectPath(...args: string[]) {
|
2023-10-15 03:33:48 +00:00
|
|
|
return projectRootPath(...args);
|
2022-01-03 08:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-31 15:21:57 +00:00
|
|
|
export function getTsConfig() {
|
2023-02-12 03:39:24 +00:00
|
|
|
const configPath = joinProjectPath('tsconfig.web.json');
|
2022-01-03 14:51:25 +00:00
|
|
|
const configStr = fs.readFileSync(configPath, { encoding: 'utf8' });
|
|
|
|
|
const config = JSON.parse(configStr);
|
|
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-15 03:33:48 +00:00
|
|
|
export function getRootPackageJSON() {
|
|
|
|
|
const configPath = joinProjectPath('package.json');
|
|
|
|
|
const configStr = fs.readFileSync(configPath, { encoding: 'utf8' });
|
|
|
|
|
const config = JSON.parse(configStr);
|
|
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getAllSubPackageDirs() {
|
|
|
|
|
const pkgDirs = globSync('*', {
|
|
|
|
|
cwd: joinProjectPath('packages'),
|
|
|
|
|
absolute: false
|
|
|
|
|
});
|
|
|
|
|
return pkgDirs;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-03 08:50:03 +00:00
|
|
|
module.exports = {
|
2022-12-31 15:29:45 +00:00
|
|
|
joinProjectPath,
|
|
|
|
|
joinPackagePath,
|
2023-10-15 03:33:48 +00:00
|
|
|
getTsConfig,
|
|
|
|
|
getRootPackageJSON,
|
|
|
|
|
getAllSubPackageDirs
|
2022-12-31 15:21:57 +00:00
|
|
|
};
|