Skip to content

Commit

Permalink
fix: check if registry file already exist to append the content inste…
Browse files Browse the repository at this point in the history
…ad of overwrite it
  • Loading branch information
JLAcostaEC committed Feb 19, 2025
1 parent 2882201 commit a485f51
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/tricky-games-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@jlacostaec/svgtosvelte': patch
---

fix: check if registry file already exist to append the content instead of overwrite it
10 changes: 9 additions & 1 deletion src/svg-to-svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,18 @@ export function convertSvgsToSvelte(sourceDir: string, destDir: string, options:

if (registry) {
const registryDataPath = path.join(destDir, 'registry.json');

if (fs.existsSync(indexFilePath)) {
const existingRegistryData = JSON.parse(fs.readFileSync(registryDataPath, 'utf8'));
registryData.push(...existingRegistryData);
}

fs.writeFileSync(registryDataPath, JSON.stringify(registryData, null, 2), 'utf8');
console.log(`Created registry file: ${registryDataPath}`);

reexports.push(`export { default as registry } from './registry.json';`);
if (!existingIndexContent.includes("export { default as registry } from './registry.json';")) {
reexports.push(`export { default as registry } from './registry.json';`);
}
}

const finalIndexContent = [existingIndexContent.trim(), ...reexports].filter(Boolean).join('\n') + '\n';
Expand Down
2 changes: 1 addition & 1 deletion test/svgtosvelte.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe.each(VARIANTS)('SVGToSvelte ($casing - TS: $useTypeScript - Reg: $regis

it('Run Svelte Check', async () => {
try {
const output = execSync('pnpm svelte-check --workspace test/');
const output = execSync(`pnpm svelte-check --workspace ${OUTPUT_DIR}`);
expect(output.toString()).toContain('svelte-check found 0 errors and 0 warnings');
} catch (e) {
console.log(e.stdout.toString());
Expand Down

0 comments on commit a485f51

Please sign in to comment.