/
monoman.config.ts
167 lines (151 loc) · 4.9 KB
/
monoman.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import path from 'node:path'
import { readFile } from 'node:fs/promises'
import { existsSync } from 'node:fs'
import { dedupeDeps, defineConfig } from 'monoman'
import fg from 'fast-glob'
import { docsLink, githubLink } from './macros/repo'
import type { Options } from 'tsup'
function getPkgName(filePath: string) {
const relative = path.relative(__dirname, filePath)
const [, pkgName] = relative.split(path.sep)
return pkgName
}
let packageManager: string | undefined
export default defineConfig([
{
include: ['packages/*/package.json'],
type: 'json',
async contents(data: Record<string, any>, { filePath }) {
const pkgRoot = path.resolve(filePath, '..')
const pkgSrc = path.resolve(pkgRoot, 'src')
const pkgName = getPkgName(filePath)
const isESM = data.type === 'module'
const cjsPrefix = isESM ? 'c' : ''
const esmPrefix = isESM ? '' : 'm'
const descriptions: Record<string, string> = {
'define-options': 'Add defineOptions macro for Vue <script setup>.',
macros: 'Explore more macros and syntax sugar to Vue.',
volar: 'Volar plugin for Vue Macros.',
devtools: 'Devtools plugin for Vue Macros.',
api: 'General API for Vue Macros.',
astro: 'Astro integration of Vue Macros.',
}
if (!data.private) {
data.description =
descriptions[pkgName] || `${pkgName} feature from Vue Macros.`
data.keywords = [
'vue-macros',
'macros',
'vue',
'sfc',
'setup',
'script-setup',
pkgName,
]
}
data.license = 'MIT'
data.homepage = docsLink
data.bugs = { url: `${githubLink}/issues` }
data.repository = {
type: 'git',
url: `git+${githubLink}.git`,
directory: `packages/${pkgName}`,
}
// data.author = '三咲智子 <[email protected]>'
data.engines = { node: '>=16.14.0' }
if (!existsSync(path.resolve(pkgRoot, 'index.js'))) {
data.files = ['dist']
if ((await fg('*.d.ts', { cwd: pkgRoot })).length > 0) {
data.files.push('*.d.ts')
}
} else {
data.files = ['index.js']
}
data.files.sort()
const tsupFile = path.resolve(pkgRoot, 'tsup.config.ts')
if (!data.meta?.skipExports && existsSync(tsupFile)) {
const tsupConfig: Options = await import(tsupFile)
const format = tsupConfig.format || []
const hasCJS = format.includes('cjs')
const hasESM = format.includes('esm')
const entries = (
await fg(tsupConfig.entry as string[], {
cwd: pkgRoot,
absolute: true,
})
).map((file) => path.basename(path.relative(pkgSrc, file), '.ts'))
data.exports = {
...Object.fromEntries(
entries
.map((entry) => {
const key = entry === 'index' ? '.' : `./${entry}`
const exports: Record<string, any> = {
dev: `./src/${entry}.ts`,
}
if (hasCJS) exports.require = `./dist/${entry}.${cjsPrefix}js`
if (hasESM) exports.import = `./dist/${entry}.${esmPrefix}js`
return [key, exports] as const
})
.sort(([a], [b]) => a.localeCompare(b)),
),
'./*': ['./*', './*.d.ts'],
}
const onlyIndex = entries.length === 1 && entries[0] === 'index'
if (onlyIndex) delete data.typesVersions
else
data.typesVersions = {
'*': {
'*': ['./dist/*', './*'],
},
}
}
if (
Object.keys(data.dependencies || {}).includes('unplugin') ||
data?.meta?.plugin
) {
data.keywords.push('unplugin')
}
return data
},
},
{
include: ['packages/*/README.md'],
exclude: ['packages/define-options/README.md'],
type: 'text',
async contents(_, ctx) {
const pkgPath = path.resolve(path.dirname(ctx.filePath), 'package.json')
const pkg = JSON.parse(await readFile(pkgPath, 'utf-8'))
const pkgName = pkg.name
return `# ${pkgName} [![npm](https://img.shields.io/npm/v/${pkgName}.svg)](https://npmjs.com/package/${pkgName})\n
Please refer to [README.md](${githubLink}#readme)\n`
},
},
...dedupeDeps({
include: [
'package.json',
'packages/*/package.json',
'playground/*/package.json',
],
exclude: ['playground/vue2/package.json'],
}),
...dedupeDeps({
include: [
'package.json',
'packages/*/package.json',
'playground/*/package.json',
],
ignores: ['vue'],
}),
{
include: ['package.json', 'packages/*/package.json'],
type: 'json',
contents(data: Record<string, any>) {
if (!packageManager) {
packageManager = data.packageManager
} else {
data.packageManager = packageManager
}
return data
},
},
])