-
Notifications
You must be signed in to change notification settings - Fork 21
/
build.js
43 lines (37 loc) · 1.77 KB
/
build.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
const path = require('path')
const feather = require('feather-icons/dist/icons.json')
const { pascalCase } = require('pascal-case')
const fs = require('fs-extra')
const handleComponentName = name => name.replace(/\-(\d+)/, '$1')
const component = (icon) =>
`<script>
export let size = "24";
export let strokeWidth = 2;
let customClass = "";
export { customClass as class };
if (size !== "100%") {
size = size.slice(-1) === 'x'
? size.slice(0, size.length -1) + 'em'
: parseInt(size) + 'px';
}
</script>
<svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="{strokeWidth}" stroke-linecap="round" stroke-linejoin="round" class="feather feather-${icon.name} {customClass}">${feather[icon.name]}</svg>
`
const icons = Object.keys(feather).map(name => ({
name,
pascalCasedComponentName: pascalCase(`${handleComponentName(name)}-icon`),
kebabCasedComponentName: `${handleComponentName(name)}-icon`
}))
Promise.all(icons.map(icon => {
const filepath = `./src/icons/${icon.pascalCasedComponentName}.svelte`
return fs.ensureDir(path.dirname(filepath))
.then(() => fs.writeFile(filepath, component(icon), 'utf8'))
})).then(async () => {
const main = icons
.map(icon => `export { default as ${icon.pascalCasedComponentName} } from './icons/${icon.pascalCasedComponentName}.svelte'`)
.join('\n\n')
const types = '/// <reference types="svelte" />\nimport {SvelteComponent} from "svelte"\n' +
icons.map(icon => `export class ${icon.pascalCasedComponentName} extends SvelteComponent<{size?: string, strokeWidth?: number, class?: string}> {}`).join("\n")
await fs.outputFile("index.d.ts", types, 'utf8');
return await fs.outputFile('./src/index.js', main, 'utf8')
})