-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (35 loc) · 1.4 KB
/
index.js
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
import { getArgs, read, write, buildIcons, getIconGroups, getIconVariants } from './utils.js'
const updatePackageJson = async (distFolder = './dist', path = './package.json') => {
const pkg = JSON.parse(await read(path))
pkg.exports = {}
pkg.exports['.'] = { import: './index.js' }
const groups = await getIconGroups()
for (const group of groups) {
const variants = await getIconVariants(group)
for (const variant of variants) {
let exportPath = `${group}/${variant}`
console.log('Exporting', exportPath)
if (group === 'Base') exportPath = variant
const referencePath = `${distFolder}/${group}/${variant}/`
pkg.exports[`./${exportPath}`] = {
types: `${referencePath}index.d.ts`,
import: `${referencePath}index.js`
}
pkg.exports[`./${exportPath}/*`] = pkg.exports[`./${exportPath}/*.js`] = {
types: `${referencePath}*.d.ts`,
import: `${referencePath}*.js`
}
}
}
await write(path, JSON.stringify(pkg, null, 2) + '\n')
}
async function main () {
const args = getArgs(process.argv)
if (args.error) return console.error(args.error)
console.log(`Building icons... (${args.sourceFolder} -> ${args.distFolder})`)
await buildIcons(args.sourceFolder, args.distFolder)
console.log('Updating package.json...')
await updatePackageJson(args.distFolder)
return console.log('Finished building package.')
}
main()