Skip to content

Commit 829a9a6

Browse files
committed
release updates
1 parent 0965926 commit 829a9a6

File tree

5 files changed

+123
-0
lines changed

5 files changed

+123
-0
lines changed

release/core/promote/index.ts

+31
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,48 @@
11
import { promote_flags_config } from '../../utils/flags-config';
22
import { parseRawFlags } from '../../utils/parse-args';
3+
<<<<<<< Updated upstream
34
import { getGitState } from '../../utils/git';
45
import { printHelpDocs } from '../../help/docs';
6+
=======
7+
import { GIT_TAG, getAllPackagesForGitTag, getGitState } from '../../utils/git';
8+
import { printHelpDocs } from '../../help/docs';
9+
import { Package } from '../../utils/package';
10+
import { SEMVER_VERSION } from '../../utils/channel';
11+
>>>>>>> Stashed changes
512

613
export async function promoteToLTS(args: string[]) {
714
// get user supplied config
815
const config = await parseRawFlags(args.slice(1), promote_flags_config);
16+
<<<<<<< Updated upstream
17+
=======
18+
const gitTag: GIT_TAG = `v${config.full.get('version') as SEMVER_VERSION}`;
19+
>>>>>>> Stashed changes
920

1021
if (config.full.get('help')) {
1122
return printHelpDocs(args);
1223
}
1324

25+
<<<<<<< Updated upstream
26+
const dryRun = config.full.get('dry_run') as boolean;
27+
28+
console.log(config.full);
29+
=======
30+
const packages = await getAllPackagesForGitTag(gitTag);
31+
const versionsToPromote = getPublicPackageVersions(packages);
1432
const dryRun = config.full.get('dry_run') as boolean;
1533

1634
console.log(config.full);
35+
console.log(gitTag);
36+
console.log(versionsToPromote);
37+
}
38+
39+
export async function getPublicPackageVersions(packages: Map<string, Package>): Promise<Map<string, SEMVER_VERSION>> {
40+
const publicPackages = new Map<string, SEMVER_VERSION>();
41+
packages.forEach((pkg, name) => {
42+
if (!pkg.pkgData.private) {
43+
publicPackages.set(name, pkg.pkgData.version);
44+
}
45+
});
46+
return publicPackages;
47+
>>>>>>> Stashed changes
1748
}

release/core/publish/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ import { printHelpDocs } from '../../help/docs';
55
import { bumpAllPackages, restorePackagesForDryRun } from './steps/bump-versions';
66
import { generatePackageTarballs } from './steps/generate-tarballs';
77
import { printStrategy } from './steps/print-strategy';
8+
<<<<<<< Updated upstream
89
import { applyStrategy, gatherPackages, loadStrategy } from './steps/generate-strategy';
910
import { confirmStrategy } from './steps/confirm-strategy';
1011
import { publishPackages } from './steps/publish-packages';
12+
=======
13+
import { applyStrategy } from './steps/generate-strategy';
14+
import { confirmStrategy } from './steps/confirm-strategy';
15+
import { publishPackages } from './steps/publish-packages';
16+
import { gatherPackages, loadStrategy } from '../../utils/package';
17+
>>>>>>> Stashed changes
1118

1219
export async function executePublish(args: string[]) {
1320
// get user supplied config

release/core/publish/steps/generate-strategy.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1+
<<<<<<< Updated upstream
12
import { getFile } from '../../../utils/json-file';
23
import { GIT_STATE } from '../../../utils/git';
34
import { STRATEGY_TYPE, CHANNEL, npmDistTagForChannelAndVersion, TYPE_STRATEGY } from '../../../utils/channel';
45
import { Glob } from 'bun';
56
import { APPLIED_STRATEGY, PACKAGEJSON, Package } from '../../../utils/package';
7+
=======
8+
import { GIT_STATE } from '../../../utils/git';
9+
import { CHANNEL, npmDistTagForChannelAndVersion } from '../../../utils/channel';
10+
11+
import { APPLIED_STRATEGY, Package, STRATEGY } from '../../../utils/package';
12+
>>>>>>> Stashed changes
613
import { getNextVersion } from '../../utils/next-version';
714
import path from 'path';
815

916
const PROJECT_ROOT = process.cwd();
1017

18+
<<<<<<< Updated upstream
1119
export interface STRATEGY {
1220
config: {
1321
packageRoots: string[];
@@ -59,6 +67,8 @@ export async function loadStrategy() {
5967
return data;
6068
}
6169

70+
=======
71+
>>>>>>> Stashed changes
6272
function sortByName(map: Map<string, { name: string }>) {
6373
const sorted = [...map.values()];
6474
sorted.sort((a, b) => {

release/utils/git.ts

+15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import chalk from 'chalk';
22
import { branchForChannelAndVersion, CHANNEL, channelForBranch, SEMVER_VERSION, VALID_BRANCHES } from './channel';
33
import { getFile } from './json-file';
44
import { exec } from './cmd';
5+
<<<<<<< Updated upstream
6+
=======
7+
import { gatherPackages, loadStrategy, Package } from './package';
8+
import path from 'path';
9+
>>>>>>> Stashed changes
510

611
export type LTS_TAG = `lts-${number}-${number}`;
712
export type RELEASE_TAG = `release-${number}-${number}`;
@@ -151,9 +156,19 @@ export async function getGitState(options: Map<string, boolean | string | number
151156
return _GIT_STATE;
152157
}
153158

159+
<<<<<<< Updated upstream
154160
export async function getAllPackagesForGitTag(tag: GIT_TAG): Promise<string[]> {
155161
await exec(['mkdir', '-p', `./tmp/${tag}`]);
156162
await exec({ cmd: ['git', 'checkout', tag], env: { ...process.env, GIT_WORK_TREE: `./tmp/${tag}` } });
157163
const info = JSON.parse(gitInfo) as Record<string, unknown>;
158164
return info.versions[tag] as string[];
165+
=======
166+
export async function getAllPackagesForGitTag(tag: GIT_TAG): Promise<Map<string, Package>> {
167+
await exec(['mkdir', '-p', `./tmp/${tag}`]);
168+
await exec({ cmd: ['git', 'checkout', tag], env: { ...process.env, GIT_WORK_TREE: `./tmp/${tag}` } });
169+
170+
const tmpDir = path.join(process.cwd(), `./tmp/${tag}`);
171+
const strategy = await loadStrategy(tmpDir);
172+
return gatherPackages(strategy.config, tmpDir);
173+
>>>>>>> Stashed changes
159174
}

release/utils/package.ts

+60
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
<<<<<<< Updated upstream
12
import { JSONFile } from './json-file';
23
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
39

410
export class Package {
511
declare filePath: string;
@@ -66,3 +72,57 @@ export type APPLIED_STRATEGY = {
6672
distTag: NPM_DIST_TAG;
6773
pkgDir: string;
6874
};
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

Comments
 (0)