diff --git a/bun.lockb b/bun.lockb index 1a5a101..7537551 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 4165713..c56c171 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "@carbon/pictograms": "12.43.0", "@types/bun": "latest", "culls": "^0.1.1", - "sveld": "latest", "svelte": "^5.0.3", "typescript": "latest" }, diff --git a/src/index.ts b/src/index.ts index 804d027..0b000b6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,5 @@ import buildInfo from "@carbon/pictograms/metadata.json" assert { type: "json" }; import { $ } from "bun"; -import { ComponentParser } from "sveld"; -import type { ParsedExports } from "sveld/lib/parse-exports"; -import writeTsDefinitions from "sveld/lib/writer/writer-ts-definitions"; import { devDependencies, name } from "../package.json" assert { type: "json" }; import { template } from "./template"; @@ -11,56 +8,64 @@ export const buildPictograms = async () => { await $`rm -rf lib`; await $`mkdir lib`; - const parser = new ComponentParser(); - const components = new Map(); - const exports: ParsedExports = {}; + let definitions = `import type { SvelteComponentTyped } from "svelte"; +import type { SvelteHTMLElements } from "svelte/elements"; - let imports = ""; +type RestProps = SvelteHTMLElements["svg"]; + +export interface CarbonPictogramProps extends RestProps { + /** + * Specify the pictogram title. + * @default undefined + */ + title?: string; + + [key: \`data-\${string}\`]: any; +} + +export declare class CarbonPictogram extends SvelteComponentTyped< + CarbonPictogramProps, + Record, + {} +> {}\n\n`; + + let libExport = ""; const pictograms: string[] = []; buildInfo.icons.forEach(async ({ output }) => { const { moduleName } = output[0]; - imports += `export { default as ${moduleName} } from "./${moduleName}.svelte";\n`; pictograms.push(moduleName); - const source = template(output[0]); - const ts_file_path = `./${moduleName}.svelte.d.ts`; + definitions += `export declare class ${moduleName} extends CarbonPictogram {}\n`; + libExport += `export { default as ${moduleName} } from "./${moduleName}.svelte";\n`; - components.set(moduleName, { - moduleName, - filePath: ts_file_path, - ...parser.parseSvelteComponent(source, { - moduleName, - filePath: ts_file_path, - }), - }); + const fileName = `lib/${moduleName}.svelte`; - exports[moduleName] = { - source: `./${moduleName}.svelte`, - default: false, - }; - - await Bun.write(`lib/${moduleName}.svelte`, source); + Bun.write(fileName, template(output[0])); + Bun.write( + fileName + ".d.ts", + `export { ${moduleName} as default } from "./";\n` + ); }); - const metadata = `${pictograms.length} pictograms from @carbon/pictograms@${devDependencies["@carbon/pictograms"]}`; + const packageMetadata = `${pictograms.length} pictograms from @carbon/pictograms@${devDependencies["@carbon/pictograms"]}`; - await writeTsDefinitions(components, { - preamble: `// Type definitions for ${name}\n// ${metadata}\n\n`, - exports, - inputDir: "lib", - outDir: "lib", - }); + await Bun.write( + "lib/index.d.ts", + `// Type definitions for ${name} +// ${packageMetadata} - await Bun.write("lib/index.js", imports); +${definitions}` + ); + await Bun.write("lib/index.js", libExport); await Bun.write( "PICTOGRAM_INDEX.md", ` # Pictogram Index -> ${metadata} +> ${packageMetadata} ## Usage diff --git a/src/template.ts b/src/template.ts index 67b2511..9aa5b66 100644 --- a/src/template.ts +++ b/src/template.ts @@ -27,6 +27,6 @@ export function template({ descriptor }: PictogramOutput) { {title} {...attributes} {...$$restProps}> - ${descriptor.content.map((element) => toString(element)).join("")} + ${descriptor.content.map(toString).join("")} `; } diff --git a/tests/index.test.ts b/tests/index.test.ts index 803cf9c..09c4905 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -7,7 +7,7 @@ test("imports", async () => { const pictograms = await buildPictograms(); expect(pictograms.length).toEqual(1187); expect(pictograms).toMatchSnapshot(); -}, 30_000); +}); test("template", () => { const props: PictogramOutput = {