PEE/build.js

42 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-12-22 21:58:20 +00:00
/* eslint-disable */
2022-01-01 22:49:13 +00:00
const { spawnSync } = require('child_process');
2021-12-22 21:58:20 +00:00
const { writeFileSync, readFileSync } = require('fs');
2022-01-01 22:49:13 +00:00
let res = spawnSync("git", ["rev-list", "--count", "HEAD"]);
let rev = +res.stdout;
2021-12-22 21:58:20 +00:00
const extheader = `// ==UserScript==
2022-01-01 22:49:13 +00:00
// @name PNGExtraEmbed
// @namespace https://coom.tech/
// @version 0.${rev}
2021-12-22 21:58:20 +00:00
// @description uhh
// @author You
2022-01-01 15:33:05 +00:00
// @match https://boards.4channel.org/*/thread/*
// @match https://boards.4chan.org/*/thread/*
2021-12-22 21:58:20 +00:00
// @icon https://www.google.com/s2/favicons?domain=4channel.org
// @require https://unpkg.com/web-streams-polyfill/dist/polyfill.min.js
2022-01-01 22:49:13 +00:00
// @updateURL https://git.coom.tech/coomdev/PEE/raw/branch/%e4%b8%ad%e5%87%ba%e3%81%97/main.user.js
2021-12-22 21:58:20 +00:00
// @grant GM_xmlhttpRequest
2022-01-01 18:10:25 +00:00
// @grant GM.xmlHttpRequest
2021-12-22 21:58:20 +00:00
// @run-at document-start
// @connect 4chan.org
// @connect 4channel.org
// @connect i.4cdn.org
// ==/UserScript==
`;
(async () => {
2022-01-01 20:02:45 +00:00
let res = await require('esbuild').build({
2021-12-22 21:58:20 +00:00
entryPoints: ['src/main.ts'],
bundle: true,
outfile: 'dist/main.js',
define: {
global: 'window'
2022-01-01 20:02:45 +00:00
},
inject: ['./esbuild.inject.js'],
metafile: true
2021-12-22 21:58:20 +00:00
});
2022-01-01 20:02:45 +00:00
console.log(Object.entries(res.metafile.inputs).sort((a, b) => a[1].bytes - b[1].bytes).map(e => `${e[0]} -> ${e[1].bytes}`).join('\n'));
2021-12-22 21:58:20 +00:00
writeFileSync('./main.user.js', extheader + readFileSync('./dist/main.js'));
})();