Skip to content

Commit 71da5ab

Browse files
committed
fix: missing type declaration for class prop
I've also optimized `createTypesFile()` and type-template.d.ts to reduce the size of the generated file.
1 parent d9f63ae commit 71da5ab

File tree

5 files changed

+51
-25
lines changed

5 files changed

+51
-25
lines changed

.prettierrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"trailingComma": "es5",
33
"tabWidth": 4,
44
"semi": true,
5-
"singleQuote": false
5+
"singleQuote": false,
6+
"plugins": ["prettier-plugin-svelte"]
67
}

package-lock.json

+28-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
"main": "index.js",
1414
"types": "index.d.ts",
1515
"scripts": {
16-
"build": "node ./scripts/generate.cjs"
16+
"build": "node ./scripts/generate.js"
1717
},
1818
"devDependencies": {
1919
"@tabler/icons": "1.84.0",
20-
"prettier": "^2.2.1"
20+
"prettier": "^2.8.2",
21+
"prettier-plugin-svelte": "^2.9.0"
2122
},
2223
"peerDependencies": {
2324
"svelte": ">=3.31.0 <=4"

scripts/generate.cjs scripts/generate.js

+9-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
const fs = require("fs");
2-
const path = require("path");
3-
const prettier = require("prettier");
1+
import fs from "node:fs";
2+
import path, { dirname } from "node:path";
3+
import prettier, { format } from "prettier";
4+
import { fileURLToPath } from "node:url";
45

5-
const { format } = prettier;
6+
const __dirname = dirname(fileURLToPath(import.meta.url));
67

78
const SOURCE_ICONS_PATH = path.resolve(
89
__dirname,
910
"../node_modules/@tabler/icons/icons/"
1011
);
1112
const DIST_PATH = path.resolve(__dirname, "../");
1213
const DESTINATION_ICONS_PATH = path.resolve(__dirname, "../icons");
14+
const TYPES_PATH = path.resolve(DIST_PATH, "types");
1315

1416
const prettierOptions = prettier.resolveConfig(__dirname);
1517

@@ -62,9 +64,7 @@ function createComponentName(originalName) {
6264
}
6365

6466
function removeOldComponents() {
65-
const components = fs
66-
.readdirSync(DESTINATION_ICONS_PATH)
67-
.filter((file) => file.endsWith(".svelte"));
67+
const components = fs.readdirSync(DESTINATION_ICONS_PATH);
6868
for (const file of components) {
6969
fs.unlinkSync(path.join(DESTINATION_ICONS_PATH, file));
7070
}
@@ -92,7 +92,7 @@ async function generateNewComponents() {
9292

9393
fs.writeFileSync(
9494
path.resolve(DESTINATION_ICONS_PATH, `${componentName}.svelte`),
95-
format(source, { parser: "html", ...(await prettierOptions) })
95+
format(source, { parser: "svelte", ...(await prettierOptions) })
9696
);
9797
}
9898
}
@@ -119,13 +119,7 @@ async function createTypesFile() {
119119
const [originalName] = file.split(".");
120120
const componentName = createComponentName(originalName);
121121

122-
return `\
123-
export class ${componentName} extends SvelteComponentTyped<{
124-
color?: string;
125-
size?: string | number;
126-
strokeWidth?: string | number;
127-
}> {}\
128-
`;
122+
return `export class ${componentName} extends TablerIcon {}`;
129123
});
130124

131125
fs.writeFileSync(

scripts/types-template.d.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
11
import { SvelteComponentTyped } from "svelte";
2+
3+
type TablerIconProps = {
4+
color?: string;
5+
size?: string | number;
6+
strokeWidth?: string | number;
7+
class?: string;
8+
};
9+
10+
class TablerIcon extends SvelteComponentTyped<TablerIconProps> {}

0 commit comments

Comments
 (0)