-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprepublish.ts
42 lines (36 loc) · 1.32 KB
/
prepublish.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
import * as fs from 'node:fs'
import { join, relative, resolve } from 'node:path'
import { getExports } from './utils/exports.js'
const packageJsonPath = join(import.meta.dirname, '../src/package.json')
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'))
const exports = getExports({
onEntry: ({ entryName, name, parentEntryName }) => {
const modulePath = (dist?: string) => {
let path = './'
if (dist) path += `${dist}/`
if (dist || (parentEntryName && parentEntryName !== 'core'))
path += `${parentEntryName}/`
if (dist || name !== 'index') path += name
return path
}
try {
fs.mkdirSync(resolve(import.meta.dirname, '../src', entryName))
} catch {}
fs.writeFileSync(
resolve(import.meta.dirname, '../src', entryName, 'package.json'),
JSON.stringify(
{
type: 'module',
types: relative(modulePath(), modulePath('_dist')) + '.d.ts',
main: relative(modulePath(), modulePath('_dist')) + '.js',
},
null,
2,
),
)
},
})
packageJson.exports = exports.dist
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
fs.cpSync(join(import.meta.dirname, '../.github/README.md'), './src/README.md')
fs.cpSync(join(import.meta.dirname, '../LICENSE'), './src/LICENSE')