forked from exteditor/ghostbird
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbarrelsby.ts
More file actions
32 lines (28 loc) · 1.07 KB
/
Copy pathbarrelsby.ts
File metadata and controls
32 lines (28 loc) · 1.07 KB
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
import { rm } from "node:fs/promises"
import { join } from "node:path"
import { argv } from "node:process"
import { fileURLToPath } from "node:url"
import { Barrelsby } from "barrelsby/bin/index.js"
import type { Arguments } from "barrelsby/bin/options/options"
import type { Plugin, PluginContext } from "rolldown"
import tsconfig from "../tsconfig.json" with { type: "json" }
/** Runs barrelsby before building */
export const barrelsby = (opts: Arguments = {}): Plugin => ({
name: "barrelsby",
buildStart(this: PluginContext): Promise<void> {
return runBarrelsby(this, opts)
},
})
export function runBarrelsby(log: Pick<Console, "info" | "warn">, opts: Arguments): Promise<void> {
log.info("Generating index.ts")
const args = Object.assign({}, tsconfig.barrelsby, opts)
Barrelsby(args)
// We don't want src/index.ts
return rm(join(args.directory, args.name)).catch((e) => {
log.warn(`Failed to remove ${args.directory}/${args.name}: ${e}`)
})
}
// This runs at `yarn install`
if (argv[1] === fileURLToPath(import.meta.url)) {
await runBarrelsby(console, {})
}