summaryrefslogtreecommitdiff
path: root/scripts/notify/index.js
blob: 6427e91aaf5490151d1098991f4ec80ab26ba1ba (plain) (blame)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import path from 'path';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const baseUrl = new URL('https://github.com/withastro/astro/blob/main/');

const emojis = ['πŸŽ‰', 'πŸ₯³', 'πŸš€', 'πŸ§‘β€πŸš€', '🎊', 'πŸ†', 'βœ…', '🀩', 'πŸ€–', 'πŸ™Œ'];
const descriptors = ['new releases', 'hot and fresh updates', 'shiny updates', 'exciting changes', 'package updates', 'awesome updates', 'bug fixes and features', 'updates'];
const verbs = [
  '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!',
];

function item(items) {
  return items[Math.floor(Math.random() * items.length)];
}

const plurals = new Map([
  ['is', 'are'],
  ['has', 'have'],
]);

function pluralize(text) {
  return text.replace(/(\[([^\]]+)\])/gm, (_, _full, match) => (plurals.has(match) ? plurals.get(match) : `${match}s`));
}

function singularlize(text) {
  return text.replace(/(\[([^\]]+)\])/gm, (_, _full, match) => `${match}`);
}

async function run() {
  const releases = process.argv.slice(2)[0];
  const data = JSON.parse(releases);
  const packages = await Promise.all(
    data.map(({ name, version }) => {
      const p = path.relative('./', path.dirname(require.resolve(name))).replace(path.sep, '/');
      return { name, version, url: new URL(`${p}/CHANGELOG.md#${version.replace(/\./g, '')}`, baseUrl).toString() };
    })
  );

  const emoji = item(emojis);
  const descriptor = item(descriptors);
  const verb = item(verbs);

  if (packages.length === 1) {
    const { name, version, url } = packages[0];
    console.log(`${emoji} \`${name}@${version}\` ${singularlize(verb)}\nRead the [release notes β†’](<${url}>)`);
  } else {
    console.log(`${emoji} Some ${descriptor} ${pluralize(verb)}\n`);
    for (const { name, version, url } of packages) {
      console.log(`β€’ \`${name}@${version}\` Read the [release notes β†’](<${url}>)`);
    }
  }
}

run();