4chan-x/tools/rollup.js
Tuxedo Takodachi 567a1fe45e Squash and cleanup of the following:
- cca085e60090ca21edf0dee6aa012fc4c949809a
  start of import/export

- f816da146c32f010476872d15b58ec8301b9fdf2
  start of changing stuff until I can get a bundle

- c92adde147792356ff206107b2311590e8b2c054
  first bundle without errors

- e652dd2b785e355e0ac33566da7eaaaa19c7c539
  Bundling works with ts files

- 60fdb2539a757ca2f66258b21adf81246873893f
  meta info in compilation

- 8ccae783cbf65ac186d5669dedd9f945f7608694
  new build doesn't cause errors on page load as userscript

- 6fa11c42a05572779870f94b7ef4ea8dac373450
  work in progress: load userscript in browser and fix bugs

- b15c557d483de544a38a28cb78f25139d1d8421f
  migrated yotsuba templates to plain js

  the old templates caused some variable be in a wrong scope after
decaffeinate, causing them to be unreadable from the old template

  the old templates caused some variable be in a wrong scope after
decaffeinate, causing them to be unreadable from the old template

- 9d763e852fde74808ca14d5a8d6be45f51ae2765
  update readme

- 924eda8268bcfc4f1c0a83062ecd1d0d65bd92aa
  added more imports, and now the circular dependencies are haunting me

- ddd2d23315d801c7deaa28313833e667698aadd3
  jsx templates for escaped strings,
  more bug fixed from circular dependencies

- fee484dd447820d908c77b1e9d31235ab95a481c
  some fixes, clarify jsx

- e1d01d02eba5db2f604a5df786c525e95f32a2f9
  Unpacked extension
  more fixes

- 97d9090b712d20f7d851c82af84c65060f1a9c6e
  fixed class on post that caused catalog to appear empty

- 96a2c7b4a1e69f5812d1e53b2e4c90f6d8447b02
  A child class that's not supposed to run the parents constructor? That needs a workaround in es6 classes.

- fc06b4e1b2769550d4c69377b84d3ccacdb2e013
  changed jsx to make the tests pass

- 7b317b2a0feabe8caa547c76baf0c908b21592f1
  revert archive and banners to json
2023-03-15 21:01:03 +01:00

97 lines
2.9 KiB
JavaScript

import { rollup } from 'rollup';
import typescript from '@rollup/plugin-typescript';
import setupFileInliner from './rollup-plugin-inline-file.js';
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
import generateMetadata from '../src/meta/metadata.js';
import { copyFile, readFile, writeFile } from 'fs/promises';
import importBase64 from './rollup-plugin-base64.js';
import generateManifestJson from '../src/meta/manifestJson.js';
const __dirname = dirname(fileURLToPath(import.meta.url));
const buildDir = resolve(__dirname, '../builds/test/');
let channel = '';
if (process.argv.includes('-beta')) {
channel = '-beta';
} else if (process.argv.includes('-noupdate')) {
channel = '-noupdate';
}
(async () => {
const packageJson = JSON.parse(await readFile(resolve(__dirname, '../package.json'), 'utf-8'));
const metadata = await generateMetadata(packageJson, channel);
const license = await readFile(resolve(__dirname, '../LICENSE'), 'utf8');
const version = JSON.parse(await readFile(resolve(__dirname, '../version.json'), 'utf-8'));
const inlineFile = await setupFileInliner(packageJson);
const bundle = await rollup({
input: resolve(__dirname, '../src/main/Main.js'),
plugins: [
typescript(),
inlineFile({
include: ["**/*.html", "**/*.css"],
}),
importBase64({ include: ["**/*.png", "**/*.gif", "**/*.wav", "**/*.woff", "**/*.woff2"] }),
inlineFile({
include: "**/package.json",
wrap: false,
transformer(input) {
const data = JSON.parse(input);
return `export default ${JSON.stringify(data.meta, undefined, 1)};`;
}
}),
inlineFile({
include: "**/*.json",
exclude: "**/package.json",
wrap: false,
transformer(input) {
return `export default ${input};`;
}
})
]
});
/** @type {import('rollup').OutputOptions} */
const sharedBundleOpts = {
format: "iife",
generatedCode: {
// needed for possible circular dependencies
constBindings: false,
},
// Can't be none as long as the root file defined exports
// exports: 'none',
};
// user script
await bundle.write({
...sharedBundleOpts,
banner: metadata + license,
// file: '../builds/test/rollupOutput.js',
file: resolve(buildDir, `${packageJson.meta.path}${channel}.user.js`),
});
// chrome extension
const crxDir = resolve(buildDir, 'crx');
await bundle.write({
...sharedBundleOpts,
banner: license,
file: resolve(crxDir, 'script.js'),
});
await copyFile(resolve(__dirname, '../src/meta/eventPage.js'), resolve(crxDir, 'eventPage.js'));
writeFile(resolve(crxDir, 'manifest.json'), generateManifestJson(packageJson, version, channel));
for (const file of ['icon16.png', 'icon48.png', 'icon128.png']) {
await copyFile(resolve(__dirname, '../src/meta/', file), resolve(crxDir, file));
};
})();