Mirror: A frag-canvas custom element to apply Shadertoy fragment shaders to a canvas or image/video element
1const { config } = require('dotenv');
2const { getInfo } = require('@changesets/get-github-info');
3
4config();
5
6const REPO = 'kitten/frag-canvas-element';
7const SEE_LINE = /^See:\s*(.*)/i;
8const TRAILING_CHAR = /[.;:]$/g;
9const listFormatter = new Intl.ListFormat('en-US');
10
11const getSummaryLines = cs => {
12 let lines = cs.summary.trim().split(/\r?\n/);
13 if (!lines.some(line => /```/.test(line))) {
14 lines = lines.map(l => l.trim()).filter(Boolean);
15 const size = lines.length;
16 if (size > 0) {
17 lines[size - 1] = lines[size - 1].replace(TRAILING_CHAR, '');
18 }
19 }
20 return lines;
21};
22
23/** Creates a "(See X)" string from a template */
24const templateSeeRef = links => {
25 const humanReadableLinks = links.filter(Boolean).map(link => {
26 if (typeof link === 'string') return link;
27 return link.pull || link.commit;
28 });
29
30 const size = humanReadableLinks.length;
31 if (size === 0) return '';
32
33 const str = listFormatter.format(humanReadableLinks);
34 return `(See ${str})`;
35};
36
37const changelogFunctions = {
38 getDependencyReleaseLine: async (changesets, dependenciesUpdated) => {
39 if (dependenciesUpdated.length === 0) return '';
40
41 const dependenciesLinks = await Promise.all(
42 changesets.map(async cs => {
43 if (!cs.commit) return undefined;
44
45 const lines = getSummaryLines(cs);
46 const prLine = lines.find(line => SEE_LINE.test(line));
47 if (prLine) {
48 const match = prLine.match(SEE_LINE);
49 return (match && match[1].trim()) || undefined;
50 }
51
52 const { links } = await getInfo({
53 repo: REPO,
54 commit: cs.commit,
55 });
56
57 return links;
58 })
59 );
60
61 let changesetLink = '- Updated dependencies';
62
63 const seeRef = templateSeeRef(dependenciesLinks);
64 if (seeRef) changesetLink += ` ${seeRef}`;
65
66 const detailsLinks = dependenciesUpdated.map(dep => {
67 return ` - ${dep.name}@${dep.newVersion}`;
68 });
69
70 return [changesetLink, ...detailsLinks].join('\n');
71 },
72 getReleaseLine: async (changeset, type) => {
73 let pull, commit, user;
74
75 const lines = getSummaryLines(changeset);
76 const prLineIndex = lines.findIndex(line => SEE_LINE.test(line));
77 if (prLineIndex > -1) {
78 const match = lines[prLineIndex].match(SEE_LINE);
79 pull = (match && match[1].trim()) || undefined;
80 lines.splice(prLineIndex, 1);
81 }
82
83 const [firstLine, ...futureLines] = lines;
84
85 if (changeset.commit && !pull) {
86 const { links } = await getInfo({
87 repo: REPO,
88 commit: changeset.commit,
89 });
90
91 pull = links.pull || undefined;
92 commit = links.commit || undefined;
93 user = links.user || undefined;
94 }
95
96 let annotation = '';
97 if (type === 'patch' && /^\s*fix/i.test(firstLine)) {
98 annotation = '⚠️ ';
99 }
100
101 let str = `- ${annotation}${firstLine}`;
102 if (futureLines.length > 0) {
103 str += `\n${futureLines.map(l => ` ${l}`).join('\n')}`;
104 }
105
106 const endsWithParagraph = /(?<=(?:[!;?.]|```) *)$/g;
107 if (user && !endsWithParagraph) {
108 str += `, by ${user}`;
109 } else {
110 str += `\nSubmitted by ${user}`;
111 }
112
113 if (pull || commit) {
114 const seeRef = templateSeeRef([pull || commit]);
115 if (seeRef) str += ` ${seeRef}`;
116 }
117
118 return str;
119 },
120};
121
122module.exports = {
123 ...changelogFunctions,
124 default: changelogFunctions,
125};