2022-03-19 12:33:24 -05:00
|
|
|
|
import { globby as glob } from 'globby';
|
|
|
|
|
import { fileURLToPath } from 'node:url';
|
2022-03-19 12:34:21 -05:00
|
|
|
|
import { readFile } from 'node:fs/promises';
|
2024-01-23 16:28:28 -05:00
|
|
|
|
import { setOutput } from './utils.mjs';
|
2022-03-19 12:33:24 -05:00
|
|
|
|
|
2023-01-12 16:26:38 -05:00
|
|
|
|
const { GITHUB_REF = 'main' } = process.env;
|
|
|
|
|
const baseUrl = new URL(`https://github.com/withastro/astro/blob/${GITHUB_REF}/`);
|
2021-11-29 16:11:15 -05:00
|
|
|
|
|
2021-12-02 15:04:11 -05:00
|
|
|
|
const emojis = ['🎉', '🥳', '🚀', '🧑🚀', '🎊', '🏆', '✅', '🤩', '🤖', '🙌'];
|
2022-04-02 15:15:41 -05:00
|
|
|
|
const descriptors = [
|
|
|
|
|
'new releases',
|
|
|
|
|
'hot and fresh updates',
|
|
|
|
|
'shiny updates',
|
|
|
|
|
'exciting changes',
|
|
|
|
|
'package updates',
|
|
|
|
|
'awesome updates',
|
|
|
|
|
'bug fixes and features',
|
|
|
|
|
'updates',
|
|
|
|
|
];
|
2021-12-02 15:04:11 -05:00
|
|
|
|
const verbs = [
|
2024-01-23 16:28:28 -05:00
|
|
|
|
"just went out!",
|
|
|
|
|
"just launched!",
|
|
|
|
|
"now available!",
|
|
|
|
|
"in the wild!",
|
|
|
|
|
"now live!",
|
|
|
|
|
"hit the registry!",
|
|
|
|
|
"to share!",
|
|
|
|
|
"for you!",
|
|
|
|
|
"for y’all! 🤠",
|
|
|
|
|
"comin’ your way!",
|
|
|
|
|
"comin’ atcha!",
|
|
|
|
|
"comin’ in hot!",
|
|
|
|
|
"freshly minted on the blockchain! (jk)",
|
|
|
|
|
"[is] out (now with 100% more reticulated splines!)",
|
|
|
|
|
"(as seen on TV!)",
|
|
|
|
|
"just dropped!",
|
|
|
|
|
"– artisanally hand-crafted just for you.",
|
|
|
|
|
"– oh happy day!",
|
|
|
|
|
"– enjoy!",
|
|
|
|
|
"now out. Be the first on your block to download!",
|
|
|
|
|
"made with love 💕",
|
|
|
|
|
"[is] out! Our best [version] yet!",
|
|
|
|
|
"[is] here. DOWNLOAD! DOWNLOAD! DOWNLOAD!",
|
|
|
|
|
"... HUZZAH!",
|
|
|
|
|
"[has] landed!",
|
|
|
|
|
"landed! The internet just got a little more fun.",
|
|
|
|
|
"– from our family to yours.",
|
|
|
|
|
"– go forth and build!"
|
2021-12-02 15:04:11 -05:00
|
|
|
|
];
|
2023-01-12 16:26:38 -05:00
|
|
|
|
const extraVerbs = [
|
|
|
|
|
'new',
|
|
|
|
|
'here',
|
|
|
|
|
'released',
|
|
|
|
|
'freshly made',
|
|
|
|
|
'going out',
|
|
|
|
|
'hitting the registry',
|
|
|
|
|
'available',
|
|
|
|
|
'live now',
|
|
|
|
|
'hot and fresh',
|
|
|
|
|
'for you',
|
2023-01-12 16:28:30 -05:00
|
|
|
|
"comin' atcha",
|
|
|
|
|
];
|
2021-12-02 15:04:11 -05:00
|
|
|
|
|
|
|
|
|
function item(items) {
|
2021-12-22 16:11:05 -05:00
|
|
|
|
return items[Math.floor(Math.random() * items.length)];
|
2021-12-02 15:04:11 -05:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-07 17:08:49 -05:00
|
|
|
|
const plurals = new Map([
|
2021-12-22 16:11:05 -05:00
|
|
|
|
['is', 'are'],
|
|
|
|
|
['has', 'have'],
|
2021-12-07 17:09:46 -05:00
|
|
|
|
]);
|
2021-12-07 17:08:49 -05:00
|
|
|
|
|
|
|
|
|
function pluralize(text) {
|
2022-04-02 15:15:41 -05:00
|
|
|
|
return text.replace(/(\[([^\]]+)\])/gm, (_, _full, match) =>
|
|
|
|
|
plurals.has(match) ? plurals.get(match) : `${match}s`
|
|
|
|
|
);
|
2021-12-07 17:08:49 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function singularlize(text) {
|
2021-12-22 16:11:05 -05:00
|
|
|
|
return text.replace(/(\[([^\]]+)\])/gm, (_, _full, match) => `${match}`);
|
2021-12-07 17:08:49 -05:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-19 12:33:24 -05:00
|
|
|
|
const packageMap = new Map();
|
|
|
|
|
async function generatePackageMap() {
|
|
|
|
|
const packageRoot = new URL('../../packages/', import.meta.url);
|
2022-04-02 15:15:41 -05:00
|
|
|
|
const packages = await glob(['*/package.json', '*/*/package.json'], {
|
|
|
|
|
cwd: fileURLToPath(packageRoot),
|
|
|
|
|
});
|
2022-03-19 12:34:21 -05:00
|
|
|
|
await Promise.all(
|
|
|
|
|
packages.map(async (pkg) => {
|
|
|
|
|
const pkgFile = fileURLToPath(new URL(pkg, packageRoot));
|
|
|
|
|
const content = await readFile(pkgFile).then((res) => JSON.parse(res.toString()));
|
|
|
|
|
packageMap.set(content.name, `./packages/${pkg.replace('/package.json', '')}`);
|
|
|
|
|
})
|
|
|
|
|
);
|
2022-03-19 12:33:24 -05:00
|
|
|
|
}
|
2022-03-08 11:48:12 -05:00
|
|
|
|
|
2024-01-08 08:09:53 -05:00
|
|
|
|
async function generateMessage() {
|
2022-03-19 12:33:24 -05:00
|
|
|
|
await generatePackageMap();
|
2021-12-22 16:11:05 -05:00
|
|
|
|
const releases = process.argv.slice(2)[0];
|
|
|
|
|
const data = JSON.parse(releases);
|
|
|
|
|
const packages = await Promise.all(
|
|
|
|
|
data.map(({ name, version }) => {
|
2022-03-08 11:48:12 -05:00
|
|
|
|
const p = packageMap.get(name);
|
|
|
|
|
if (!p) {
|
|
|
|
|
throw new Error(`Unable to find entrypoint for "${name}"!`);
|
|
|
|
|
}
|
2022-04-02 15:15:41 -05:00
|
|
|
|
return {
|
|
|
|
|
name,
|
|
|
|
|
version,
|
|
|
|
|
url: new URL(`${p}/CHANGELOG.md#${version.replace(/\./g, '')}`, baseUrl).toString(),
|
|
|
|
|
};
|
2021-12-22 16:11:05 -05:00
|
|
|
|
})
|
|
|
|
|
);
|
2021-11-29 16:11:15 -05:00
|
|
|
|
|
2021-12-22 16:11:05 -05:00
|
|
|
|
const emoji = item(emojis);
|
|
|
|
|
const descriptor = item(descriptors);
|
|
|
|
|
const verb = item(verbs);
|
2021-12-02 15:04:11 -05:00
|
|
|
|
|
2023-01-12 16:26:38 -05:00
|
|
|
|
let message = '';
|
|
|
|
|
|
2021-12-22 16:11:05 -05:00
|
|
|
|
if (packages.length === 1) {
|
|
|
|
|
const { name, version, url } = packages[0];
|
2023-01-12 16:28:30 -05:00
|
|
|
|
message += `${emoji} \`${name}@${version}\` ${singularlize(
|
|
|
|
|
verb
|
|
|
|
|
)}\nRead the [release notes →](<${url}>)\n`;
|
2021-12-22 16:11:05 -05:00
|
|
|
|
} else {
|
2023-01-12 16:26:38 -05:00
|
|
|
|
message += `${emoji} Some ${descriptor} ${pluralize(verb)}\n\n`;
|
2021-12-22 16:11:05 -05:00
|
|
|
|
for (const { name, version, url } of packages) {
|
2023-01-12 16:26:38 -05:00
|
|
|
|
message += `• \`${name}@${version}\` Read the [release notes →](<${url}>)\n`;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (message.length < 2000) {
|
2024-01-26 10:16:27 -05:00
|
|
|
|
return message;
|
2023-01-12 16:26:38 -05:00
|
|
|
|
} else {
|
2023-01-12 16:28:30 -05:00
|
|
|
|
const { name, version, url } = packages.find((pkg) => pkg.name === 'astro') ?? packages[0];
|
2023-01-12 16:26:38 -05:00
|
|
|
|
message = `${emoji} Some ${descriptor} ${pluralize(verb)}\n\n`;
|
2023-01-12 16:28:30 -05:00
|
|
|
|
message += `• \`${name}@${version}\` Read the [release notes →](<${url}>)\n`;
|
2023-01-12 16:26:38 -05:00
|
|
|
|
|
2023-01-12 16:28:30 -05:00
|
|
|
|
message += `\nAlso ${item(extraVerbs)}:`;
|
2023-01-12 16:26:38 -05:00
|
|
|
|
|
2023-01-12 16:28:30 -05:00
|
|
|
|
const remainingPackages = packages.filter((p) => p.name !== name);
|
2023-01-12 16:26:38 -05:00
|
|
|
|
for (const { name, version, url } of remainingPackages) {
|
|
|
|
|
message += `\n• \`${name}@${version}\``;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (message.length < 2000) {
|
2024-01-08 08:09:53 -05:00
|
|
|
|
return message;
|
2023-01-12 16:26:38 -05:00
|
|
|
|
} else {
|
|
|
|
|
message = `${emoji} Some ${descriptor} ${pluralize(verb)}\n\n`;
|
2023-01-12 16:28:30 -05:00
|
|
|
|
message += `• \`${name}@${version}\` Read the [release notes →](<${url}>)\n`;
|
2023-01-12 16:26:38 -05:00
|
|
|
|
|
|
|
|
|
message += `\n\nAlso ${item(extraVerbs)}: ${remainingPackages.length} other packages!`;
|
2024-01-08 08:09:53 -05:00
|
|
|
|
return message;
|
2021-12-22 16:11:05 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-29 16:11:15 -05:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-08 08:09:53 -05:00
|
|
|
|
async function run() {
|
|
|
|
|
const content = await generateMessage();
|
2024-01-26 10:16:27 -05:00
|
|
|
|
console.log(content);
|
2024-01-23 16:28:28 -05:00
|
|
|
|
setOutput('DISCORD_MESSAGE', content);
|
2024-01-08 08:09:53 -05:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-29 16:11:15 -05:00
|
|
|
|
run();
|