/
prepare-release.ts
57 lines (48 loc) · 1.76 KB
/
prepare-release.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
import { findUpSync } from 'find-up'
import fs from 'fs-extra'
import { globbySync } from 'globby'
import path, { dirname } from 'path'
import { match } from 'ts-pattern'
const generateExports = () => {
const paths = globbySync('src/**/index.ts')
const exports: Record<string, unknown> = {}
for (const p of paths) {
const keyPath = p.replace('src', '.').replace('/index.ts', '')
exports[keyPath] = {
types: `${keyPath}/index.d.ts`,
import: `${keyPath}/index.mjs`,
require: `${keyPath}/index.cjs`,
}
}
exports['./package.json'] = './package.json'
return exports
}
const generateKeywords = () =>
globbySync(['src'], { onlyDirectories: true, deep: 1 })
.map((component) => component.replace('src/', ''))
.map((component) => component.replace('-', ' '))
const main = async () => {
const packageName = process.argv.slice(2)[0]
const dirName = packageName.split('/')[1]
const root = dirname(findUpSync('pnpm-lock.yaml')!)
process.chdir(
match(dirName)
.with('anatomy', () => path.join(root, 'packages', dirName))
.otherwise(() => path.join(root, 'packages', 'frameworks', dirName)),
)
const packageJson = await fs.readJson('package.json')
// Note: At the time Solid does not support path imports like vue or react
if (dirName !== 'solid') {
packageJson.main = 'index.cjs'
packageJson.module = 'index.mjs'
packageJson.types = 'index.d.ts'
packageJson.files = ['./']
packageJson.exports = generateExports()
}
packageJson.keywords = generateKeywords()
await fs.writeJson('dist/package.json', packageJson, { spaces: 2 })
await fs.copy('README.md', 'dist/README.md')
await fs.copy(path.join(root, 'LICENSE'), 'dist/LICENSE')
await fs.copy('CHANGELOG.md', 'dist/CHANGELOG.md')
}
main()