mirror of https://github.com/GooseMod/GooseMod
[Rollup] Custom plugin (instead of Bash script)
parent
0ce48c2042
commit
05ea218e41
@ -1,21 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm -rf dist
|
||||
|
||||
npx rollup -c
|
||||
|
||||
# Replace <hash> in file with hash of the built file
|
||||
hash="$(sha512sum dist/index.js | cut -d" " -f1)"
|
||||
|
||||
echo $hash
|
||||
|
||||
sed -i "s/<hash>/$hash/g" dist/index.js
|
||||
|
||||
changelog="$(node building/generateChangelogJson.js)"
|
||||
|
||||
echo $changelog
|
||||
|
||||
sed -i "s/<changelog>/$changelog/g" dist/index.js
|
||||
|
||||
# Remove the auto-added map comment line as to not trigger the client trying to get the map
|
||||
# sed -i '$ d' dist/index.js
|
@ -1,55 +0,0 @@
|
||||
import { readFileSync, writeFileSync } from 'fs';
|
||||
|
||||
const changelog = readFileSync('CHANGELOG.md', 'utf8');
|
||||
const firstRelease = changelog.split(/^##/m)[1].trim();
|
||||
|
||||
const split = firstRelease.split('\n');
|
||||
|
||||
let versionHeader = split[0];
|
||||
const headerSplit = versionHeader.split(' ');
|
||||
|
||||
const version = headerSplit[0];
|
||||
const date = headerSplit[1].replace(/[\[\]]/g, '');
|
||||
|
||||
let body = split.slice(2).map((x) => x.trim().replace('- ', '')).filter((x) => x.length > 0);
|
||||
|
||||
body = body.map((x, i) => {
|
||||
if (x.startsWith('###')) {
|
||||
let type = 'added';
|
||||
|
||||
x = x.replace('### ', '').replace(/\[(.*)\]/, (_, _type) => {
|
||||
type = _type;
|
||||
|
||||
return '';
|
||||
}).trim();
|
||||
|
||||
x = `${i !== 0 ? '\n' : ''}${x} {${type}${i === 0 ? ' marginTop' : ''}}\n======================\n`;
|
||||
} else {
|
||||
/* const split = x.split(/,/);
|
||||
|
||||
if (split.length === 1) {
|
||||
x = `* **${x}.**`;
|
||||
} else {
|
||||
const main = split[0].trim();
|
||||
let sub = split.slice(1).join(', ').trim();
|
||||
sub = sub[0].toUpperCase() + sub.substring(1);
|
||||
|
||||
x = `* **${main}.** ${sub}.`;
|
||||
} */
|
||||
|
||||
x = `* ${x}`;
|
||||
}
|
||||
|
||||
return x;
|
||||
});
|
||||
|
||||
const json = {
|
||||
version,
|
||||
date,
|
||||
|
||||
body: body.join('\n')
|
||||
};
|
||||
|
||||
console.log(JSON.stringify(json).replaceAll(`\\"`, `\\\\\\"`).replaceAll(`"`, `\\\\\\"`).replaceAll(`\\n`, `\\\\\\\\n`).replaceAll('/', '\\/'));
|
||||
|
||||
// writeFileSync('../out/latestChangelogRelease.json', JSON.stringify(json));
|
@ -0,0 +1,44 @@
|
||||
import { readFileSync } from 'fs';
|
||||
|
||||
export default () => {
|
||||
const changelog = readFileSync('CHANGELOG.md', 'utf8');
|
||||
const firstRelease = changelog.split(/^##/m)[1].trim();
|
||||
|
||||
const split = firstRelease.split('\n');
|
||||
|
||||
let versionHeader = split[0];
|
||||
const headerSplit = versionHeader.split(' ');
|
||||
|
||||
const version = headerSplit[0];
|
||||
const date = headerSplit[1].replace(/[\[\]]/g, '');
|
||||
|
||||
let body = split.slice(2).map((x) => x.trim().replace('- ', '')).filter((x) => x.length > 0);
|
||||
|
||||
body = body.map((x, i) => {
|
||||
if (x.startsWith('###')) {
|
||||
let type = 'added';
|
||||
|
||||
x = x.replace('### ', '').replace(/\[(.*)\]/, (_, _type) => {
|
||||
type = _type;
|
||||
|
||||
return '';
|
||||
}).trim();
|
||||
|
||||
x = `${i !== 0 ? '\n' : ''}${x} {${type}${i === 0 ? ' marginTop' : ''}}\n======================\n`;
|
||||
} else {
|
||||
x = `* ${x}`;
|
||||
}
|
||||
|
||||
return x;
|
||||
});
|
||||
|
||||
const json = {
|
||||
version,
|
||||
date,
|
||||
|
||||
body: body.join('\n')
|
||||
};
|
||||
|
||||
return JSON.stringify(json).replaceAll('`', '\\`').replaceAll(`\\n`, `\\\\n`);
|
||||
};
|
||||
// console.log(JSON.stringify(json).replaceAll(`\\"`, `\\\\\\"`).replaceAll(`"`, `\\\\\\"`).replaceAll(`\\n`, `\\\\\\\\n`).replaceAll('/', '\\/'));
|
@ -0,0 +1,20 @@
|
||||
import { exec } from 'child_process';
|
||||
|
||||
import genChangelog from './genChangelog';
|
||||
|
||||
|
||||
export default () => {
|
||||
const changelog = genChangelog();
|
||||
|
||||
return {
|
||||
name: 'goosemod',
|
||||
|
||||
renderChunk: (code) => {
|
||||
const commitHash = await new Promise((res) => exec(`git rev-parse HEAD`, (_err, stdout) => res(stdout.trim())));
|
||||
|
||||
return code
|
||||
.replace('<changelog>', changelog)
|
||||
.replace('<hash>', commitHash);
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Reference in new issue