-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost-build.cjs
More file actions
39 lines (35 loc) · 1.27 KB
/
post-build.cjs
File metadata and controls
39 lines (35 loc) · 1.27 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
33
34
35
36
37
38
39
import { readFileSync, readdirSync, writeFileSync, copyFileSync } from 'fs'
// append our api modules to `exports` in `package.json` then write it to `./dist`
const pkg = JSON.parse(readFileSync('package.json', 'utf8'))
const modules = readdirSync('src')
.filter((e) => e !== 'helpers')
.map((mod) => mod.replace('.ts', ''))
const outputPkg = {
...pkg,
exports: Object.assign(
{},
...modules.map((mod) => {
const temp = {}
let key = `./${mod}`
if (mod === 'index') {
key = '.'
}
temp[key] = {
import: `./${mod}.js`,
require: `./${mod}.cjs`,
}
return temp
}),
// if for some reason in the future we manually add something in the `exports` field
// this will ensure it doesn't get overwritten by the logic above
{ ...(pkg.exports || {}) }
),
}
writeFileSync('dist/package.json', JSON.stringify(outputPkg, undefined, 2))
// copy necessary files like `CHANGELOG.md` , `README.md` and Licenses to `./dist`
const dir = readdirSync('.')
const files = [
...dir.filter((f) => f.startsWith('LICENSE')),
...dir.filter((f) => f.endsWith('.md')),
]
files.forEach((f) => copyFileSync(f, `dist/${f}`))