-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
61 lines (55 loc) · 1.54 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { writeFile, mkdir } from 'fs/promises';
import path from 'path';
import { pascalCase, pascalCaseTransformMerge } from 'pascal-case';
import iconObject from './remixicon.glyph.json' with { type: 'json' };
const indexPath = path.resolve('./src/lib/index.js');
const iconDir = path.resolve('./src/lib/icons');
const component = (icon) => {
const paths = iconObject[icon].path;
const pathMarkup = paths.map((path) => `<path d="${path}"></path>`).join('');
return `<script lang="ts">
export let size = '1em';
export let color = 'currentColor';
export let label= '';
let customClass = '';
export { customClass as class };
</script>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
width={size}
height={size}
fill={color}
aria-label={label ? label : undefined}
aria-hidden={!label ? 'true' : undefined}
role={label ? 'img' : undefined}
class="remixicon ri-${icon} {customClass}"
{...$$restProps}
>
${pathMarkup}
</svg>
`;
};
const pascalCaseName = (name) => {
return pascalCase('ri-' + name, {
transform: pascalCaseTransformMerge,
});
};
let main = '';
(async () => {
for (const icon of Object.keys(iconObject)) {
const iconName = pascalCaseName(icon);
console.log(`Building ${iconName}...`);
await mkdir(iconDir, {
recursive: true,
});
await writeFile(
path.resolve(`${iconDir}/${iconName}.svelte`),
component(icon),
'utf-8'
);
main += `export { default as ${iconName} } from './icons/${iconName}.svelte';\n`;
}
console.log('Building index.js...');
await writeFile(indexPath, main);
})();