-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathicons.ts
37 lines (30 loc) · 868 Bytes
/
icons.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
import { readdir } from 'node:fs/promises';
import { addImports, addTypeTemplate, defineNuxtModule, useLogger } from '@nuxt/kit';
import { resolve } from 'pathe';
export default defineNuxtModule({
meta: {
name: 'icons',
},
async setup(_options, nuxt) {
const logger = useLogger('icons');
const icons = await readdir(
resolve(nuxt.options.rootDir, './public/svg'),
);
const iconPathsDefinition = icons
.map((icon) => JSON.stringify(icon.split('.')[0]))
.join(' | ');
const { dst } = addTypeTemplate({
write: true,
filename: './types/icons.d.ts',
getContents: () => {
return `export type IconName = ${iconPathsDefinition};`;
},
});
addImports({
type: true,
from: dst,
name: 'IconName',
});
logger.info(`Added ${icons.length} icons types`);
},
});