-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: standardize build for UI and plugin (#57)
Co-authored-by: Richard Herman <[email protected]>
- Loading branch information
Showing
1 changed file
with
32 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")]; |