-
Notifications
You must be signed in to change notification settings - Fork 330
/
Copy pathnotify.mjs
62 lines (53 loc) · 2.26 KB
/
notify.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { fileURLToPath } from 'node:url';
import fs from 'fs-extra';
import { globby as glob } from 'globby';
const { GITHUB_REF = 'main' } = process.env;
const baseUrl = new URL(`https://github.com/clerkinc/javascript/blob/${GITHUB_REF}/`);
/**
* @returns {Promise<Map<string,{ version: string, path: string }>>}
*/
async function createPackageMap() {
const map = new Map();
const packagesRoot = new URL('../packages/', import.meta.url);
const packages = await glob(['*/package.json', '*/*/package.json'], { cwd: fileURLToPath(packagesRoot) });
await Promise.all(
packages.map(async pkg => {
const packageJsonPath = fileURLToPath(new URL(pkg, packagesRoot));
const packageJson = fs.readJSONSync(packageJsonPath);
if (!packageJson.private && packageJson.version) {
const version = packageJson.version;
const path = `./packages/${pkg.replace('/package.json', '')}`;
map.set(packageJson.name, { version, path });
}
}),
);
return map;
}
const releasedPackages = JSON.parse(process.argv[2]);
const prNumber = process.argv[3];
// console.debug({ releasedPackages, prNumber });
const packageMap = await createPackageMap();
const packages = releasedPackages.map(({ name, version }) => {
const pkg = packageMap.get(name);
if (!pkg) {
throw new Error(`Unable to find entrypoint for "${name}"!`);
}
const url = new URL(`${pkg.path}/CHANGELOG.md#${version.replace(/\./g, '')}`, baseUrl).toString();
return { name, version, url };
});
// Slack is using their own Markdown format, see:
// https://api.slack.com/reference/surfaces/formatting#basics
// https://app.slack.com/block-kit-builder
let message = '';
message += `*Javascript SDKs - Stable Release - ${new Date().toLocaleDateString('en-US')}*\n\n`;
for (const { name, version, url } of packages) {
message += `• \`${name}@${version}\` - <${url}|release notes>\n`;
}
// TODO: Get PR number using the GitHub API
// if (prNumber) {
// message += `\nView <https://github.com/clerkinc/javascript/pull/${prNumber}|release PR>`;
// }
message += `\nView <https://github.com/clerkinc/javascript/pulls?q=is%3Apr+is%3Aclosed+Version+Packages+in%3Atitle+merged%3A${new Date()
.toISOString()
.slice(0, 10)}|all release PRs for this day>`;
console.log(JSON.stringify(message));