Skip to content

Commit

Permalink
chore: standardize build for UI and plugin (#57)
Browse files Browse the repository at this point in the history
Co-authored-by: Richard Herman <[email protected]>
  • Loading branch information
GeekyEggo and GeekyEggo authored Oct 11, 2024
1 parent f2515bc commit 86176ee
Showing 1 changed file with 32 additions and 66 deletions.
98 changes: 32 additions & 66 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,95 +1,61 @@
import nodeResolve from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import { dirname, resolve } from "node:path";
import { dirname, join, parse, resolve } from "node:path";
import url from "node:url";

const isWatching = !!process.env.ROLLUP_WATCH;
const external = ["ws", "@elgato/schemas/streamdeck/plugins"];

const output = {
banner: `/**!
const banner = `/**!
* @author Elgato
* @module elgato/streamdeck
* @license MIT
* @copyright Copyright (c) Corsair Memory Inc.
*/`,
sourcemap: isWatching,
sourcemapPathTransform: (relativeSourcePath, sourcemapPath) => {
return url.pathToFileURL(resolve(dirname(sourcemapPath), relativeSourcePath)).href;
},
};

/**
* Generates a wrapped DTS file.
* @param {string} index File path to the index.d.ts file.
* @returns The wrapped DTS file.
*/
function dts(index) {
return `import streamDeck from "${index}";
export * from "${index}";
export default streamDeck;`;
}
*/`;

/**
* Rollup configuration.
* Defines a rollup configuration for the specified input and output.
* @param {string} input Path to the input TypeScript file, with "src/" omitted.
* @param {string} output Path to the desired output JavaScript file, with "dist/" omitted.
* @returns Rollup configuration.
*/
export default [
/**
* Main build.
*/
{
input: "src/plugin/index.ts",
function defineConfig(input, output) {
return {
input: join("src", input),
output: {
...output,
file: `dist/index.js`,
},
external,
plugins: [
typescript({
tsconfig: "src/plugin/tsconfig.build.json",
mapRoot: isWatching ? "./" : undefined,
}),
nodeResolve(),
{
name: "emit-dts",
generateBundle() {
this.emitFile({
fileName: "index.d.ts",
source: dts("../types/plugin"),
type: "asset",
});
},
banner,
file: join("dist", output),
sourcemap: isWatching,
sourcemapPathTransform: (relativeSourcePath, sourcemapPath) => {
return url.pathToFileURL(resolve(dirname(sourcemapPath), relativeSourcePath)).href;
},
],
},

/**
* Browser build.
*/
{
input: "src/ui/index.ts",
output: {
...output,
file: `dist/browser.js`,
},
external,
external: ["ws", "@elgato/schemas/streamdeck/plugins"],
plugins: [
typescript({
tsconfig: "src/ui/tsconfig.build.json",
tsconfig: join("src", dirname(input), "tsconfig.build.json"),
mapRoot: isWatching ? "./" : undefined,
}),
nodeResolve(),
{
name: "emit-dts",
generateBundle() {
const types = `"../types/${dirname(input)}"`;
this.emitFile({
fileName: "browser.d.ts",
source: dts("../types/ui"),
fileName: `${parse(output).name}.d.ts`,
type: "asset",
source: `${banner}
import streamDeck from ${types};
export * from ${types};
export default streamDeck;
`,
});
},
},
],
},
];
};
}

/**
* Rollup configuration.
*/
export default [defineConfig("plugin/index.ts", "index.js"), defineConfig("ui/index.ts", "browser.js")];

0 comments on commit 86176ee

Please sign in to comment.