-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.ts
74 lines (68 loc) · 1.61 KB
/
rollup.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import typescript from "@rollup/plugin-typescript";
import { Plugin, RollupOptions } from "rollup";
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
const packageJson = require("./package.json");
const banner = `/**
* Camomile, the workflow automation toolset
* https://github.com/camomilejs/camomile
*
* @version ${packageJson.version}
* @license ${packageJson.license}
*/`;
/**
* Plugin that generates a CLI file with the correct shebang
*
* Source: https://github.com/rollup/rollup/blob/69c099c9248d150fcb99c80c97b52adfda30fabc/build-plugins/add-cli-entry.ts
*
* @returns Rollup plugin
*/
function addCliEntry(): Plugin {
return {
buildStart() {
this.emitFile({
fileName: "bin/camomile.js",
id: "src/cli.ts",
preserveSignature: false,
type: "chunk",
});
},
name: "add-cli-entry",
renderChunk(code, chunkInfo) {
if (chunkInfo.fileName === "bin/camomile.js") {
return {
code: `#!/usr/bin/env node\n\n${code}`,
};
}
// eslint-disable-next-line unicorn/no-null
return null;
},
};
}
const build: RollupOptions = {
input: {
"camomile.js": "./src/camomile.ts",
},
external: ["commander"],
output: {
banner,
chunkFileNames: "shared/[name].js",
dir: "dist",
entryFileNames: "[name]",
externalLiveBindings: false,
format: "es",
freeze: false,
manualChunks: {
camomile: ["./src/camomile.ts"],
},
},
plugins: [
json(),
commonjs({ include: "node_modules/**" }),
typescript(),
addCliEntry(),
],
};
export default build;