|
| 1 | +<<<<<<< Updated upstream |
1 | 2 | import { JSONFile } from './json-file';
|
2 | 3 | import { NPM_DIST_TAG, SEMVER_VERSION, STRATEGY_TYPE, TYPE_STRATEGY } from './channel';
|
| 4 | +======= |
| 5 | +import { JSONFile, getFile } from './json-file'; |
| 6 | +import { NPM_DIST_TAG, SEMVER_VERSION, STRATEGY_TYPE, TYPE_STRATEGY } from './channel'; |
| 7 | +import { Glob } from 'bun'; |
| 8 | +>>>>>>> Stashed changes |
3 | 9 |
|
4 | 10 | export class Package {
|
5 | 11 | declare filePath: string;
|
@@ -66,3 +72,57 @@ export type APPLIED_STRATEGY = {
|
66 | 72 | distTag: NPM_DIST_TAG;
|
67 | 73 | pkgDir: string;
|
68 | 74 | };
|
| 75 | +<<<<<<< Updated upstream |
| 76 | +======= |
| 77 | + |
| 78 | +export interface STRATEGY { |
| 79 | + config: { |
| 80 | + packageRoots: string[]; |
| 81 | + }; |
| 82 | + defaults: { |
| 83 | + stage: STRATEGY_TYPE; |
| 84 | + types: TYPE_STRATEGY; |
| 85 | + }; |
| 86 | + rules: Record< |
| 87 | + string, |
| 88 | + { |
| 89 | + stage: STRATEGY_TYPE; |
| 90 | + types: TYPE_STRATEGY; |
| 91 | + } |
| 92 | + >; |
| 93 | +} |
| 94 | + |
| 95 | +function buildGlob(dirPath: string) { |
| 96 | + return `${dirPath}/package.json`; |
| 97 | +} |
| 98 | + |
| 99 | +export async function gatherPackages(config: STRATEGY['config'], cwd: string = process.cwd()) { |
| 100 | + const packages: Map<string, Package> = new Map(); |
| 101 | + |
| 102 | + // add root |
| 103 | + const rootFilePath = `${cwd}/package.json`; |
| 104 | + const rootFile = getFile<PACKAGEJSON>(rootFilePath); |
| 105 | + const rootPkgData = await rootFile.read(); |
| 106 | + packages.set('root', new Package(rootFilePath, rootFile, rootPkgData)); |
| 107 | + |
| 108 | + // add other packages |
| 109 | + for (const dirPath of config.packageRoots) { |
| 110 | + const glob = new Glob(buildGlob(dirPath)); |
| 111 | + |
| 112 | + // Scans the current working directory and each of its sub-directories recursively |
| 113 | + for await (const filePath of glob.scan(cwd)) { |
| 114 | + const file = getFile<PACKAGEJSON>(filePath); |
| 115 | + const pkgData = await file.read(); |
| 116 | + packages.set(pkgData.name, new Package(filePath, file, pkgData)); |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + return packages; |
| 121 | +} |
| 122 | + |
| 123 | +export async function loadStrategy(cwd: string = process.cwd()) { |
| 124 | + const file = getFile<STRATEGY>(`${cwd}/release/strategy.json`); |
| 125 | + const data = await file.read(); |
| 126 | + return data; |
| 127 | +} |
| 128 | +>>>>>>> Stashed changes |
0 commit comments