diff --git a/svg-generator/__snapshots__/index.spec.js.snap b/svg-generator/__snapshots__/index.spec.js.snap index f57cb1c..ef379fc 100644 --- a/svg-generator/__snapshots__/index.spec.js.snap +++ b/svg-generator/__snapshots__/index.spec.js.snap @@ -76,3 +76,13 @@ export const groupTwoIcons = [childOneIcon, childTwoIcon]; }, ] `; + +exports[`createTree should create the type file 1`] = ` +"export {}; +declare global { + interface SvgIcons { + icons: 'foo' | 'bar' | 'foo-bar'; + } +} +" +`; diff --git a/svg-generator/generator.ts b/svg-generator/generator.ts index f7463ed..9e80492 100644 --- a/svg-generator/generator.ts +++ b/svg-generator/generator.ts @@ -17,7 +17,7 @@ export function generateSVGIcons(config: Config | null) { removeOldIcons(resolve(mergedConfig.outputPath)); const virtualTree = createTree(mergedConfig.srcPath, mergedConfig.outputPath, mergedConfig); - const names: string[] = []; + let names: string[] = []; if (mergedConfig.rootBarrelFile) { const allExports = virtualTree @@ -27,16 +27,18 @@ export function generateSVGIcons(config: Config | null) { outputFileSync(join(mergedConfig.outputPath, `${mergedConfig.rootBarrelFileName}.ts`), allExports, { encoding: 'utf-8', }); + + names = virtualTree.filter(({ name }) => name !== INDEX).map(({ name }) => name); } else { virtualTree.forEach(({ path, content, name }) => { name !== INDEX && names.push(name); outputFileSync(path, content, { encoding: 'utf-8' }); }); - - outputFileSync(`${mergedConfig.typesPath}/types/svg.d.ts`, createTypeFile(names), { - encoding: 'utf-8', - }); } + + outputFileSync(`${mergedConfig.typesPath}/types/svg.d.ts`, createTypeFile(names), { + encoding: 'utf-8', + }); } function removeOldIcons(outputPath: string) { diff --git a/svg-generator/index.spec.ts b/svg-generator/index.spec.ts index 3175496..b9e2367 100644 --- a/svg-generator/index.spec.ts +++ b/svg-generator/index.spec.ts @@ -1,11 +1,11 @@ import mock from 'mock-fs'; +import { createTypeFile } from './create-types'; import { createTree } from './tree'; import { defaults } from './types'; const srcPath = `src/assets/svg`; describe('createTree', () => { - it('should create the correct tree', () => { mock({ [`${srcPath}/one.svg`]: 'one', @@ -27,4 +27,7 @@ describe('createTree', () => { expect(result).toMatchSnapshot(); }); + it('should create the type file', () => { + expect(createTypeFile(['foo', 'bar', 'foo-bar'])).toMatchSnapshot(); + }); });