-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce TypeScript types for icons
- Loading branch information
1 parent
83c5cc1
commit 2e57c69
Showing
8 changed files
with
234 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,41 @@ | ||
{ | ||
"name": "@nulogy/icons", | ||
"version": "4.10.3", | ||
"description": "A collection of Nulogy's svg icons", | ||
"author": "Nulogy <[email protected]> (https://github.com/nulogy)", | ||
"homepage": "http://nulogy.design", | ||
"repository": "https://github.com/nulogy/nds-icons", | ||
"private": false, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"files": [ | ||
"/dist" | ||
], | ||
"main": "dist/main.js", | ||
"scripts": { | ||
"build": "node collect-icon-svgs && rollup -c" | ||
}, | ||
"devDependencies": { | ||
"svgi": "^1.1.1", | ||
"@babel/core": "^7.12.3", | ||
"@babel/plugin-transform-runtime": "^7.12.1", | ||
"@babel/preset-env": "^7.12.1", | ||
"@rollup/plugin-babel": "^5.2.1", | ||
"@semantic-release/changelog": "^5.0.1", | ||
"@semantic-release/commit-analyzer": "^8.0.1", | ||
"@semantic-release/git": "^9.0.0", | ||
"@semantic-release/github": "^7.1.1", | ||
"@semantic-release/npm": "^7.0.6", | ||
"@semantic-release/release-notes-generator": "^9.0.1", | ||
"babel-plugin-inline-json-import": "^0.3.2", | ||
"prettier": "3.2.5", | ||
"rollup": "^2.32.1", | ||
"semantic-release": "^17.2.1" | ||
} | ||
"name": "@nulogy/icons", | ||
"version": "4.10.3", | ||
"description": "A collection of Nulogy's svg icons", | ||
"author": "Nulogy <[email protected]> (https://github.com/nulogy)", | ||
"homepage": "http://nulogy.design", | ||
"repository": "https://github.com/nulogy/nds-icons", | ||
"private": false, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "dist/main.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "yarn generate:types && node src/collect-icon-svgs && rollup -c", | ||
"format": "prettier --write \"**/*.{ts,js}\"", | ||
"generate:types": "npx tsx src/generate-types.ts && yarn format" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.12.3", | ||
"@babel/plugin-transform-runtime": "^7.12.1", | ||
"@babel/preset-env": "^7.12.1", | ||
"@rollup/plugin-babel": "^5.2.1", | ||
"@semantic-release/changelog": "^5.0.1", | ||
"@semantic-release/commit-analyzer": "^8.0.1", | ||
"@semantic-release/git": "^9.0.0", | ||
"@semantic-release/github": "^7.1.1", | ||
"@semantic-release/npm": "^7.0.6", | ||
"@semantic-release/release-notes-generator": "^9.0.1", | ||
"babel-plugin-inline-json-import": "^0.3.2", | ||
"prettier": "^3.3.3", | ||
"rollup": "^2.32.1", | ||
"rollup-plugin-copy": "^3.5.0", | ||
"semantic-release": "^17.2.1", | ||
"svgi": "^1.1.1", | ||
"typescript": "^5.7.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
import babel from "@rollup/plugin-babel"; | ||
import copy from "rollup-plugin-copy"; | ||
|
||
export default { | ||
input: "index.js", | ||
input: "src/index.js", | ||
output: { | ||
name: "ndsIcons", | ||
file: "dist/main.js", | ||
format: "umd", | ||
}, | ||
plugins: [ | ||
babel({ | ||
/* exclude: globs to exclude */ | ||
exclude: ["./node_modules/**/*"], | ||
/* exclude: files to be transpiled by babel */ | ||
extensions: [".js", ".jsx", ".json"], | ||
}), | ||
copy({ | ||
targets: [{ src: "src/index.d.ts", dest: "dist" }], | ||
}), | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
const ASSETS_DIR = path.join(__dirname, "..", "assets"); | ||
const TYPES_FILE = path.join(__dirname, "index.d.ts"); | ||
|
||
function generateIconTypes() { | ||
const iconNames = fs | ||
.readdirSync(ASSETS_DIR) | ||
.filter((file) => file.endsWith(".svg")) | ||
.map((file) => file.replace(".svg", "")); | ||
|
||
const declarationContent = `declare module "@nulogy/icons" { | ||
export interface IconData { | ||
path: string[]; | ||
viewBox: string; | ||
} | ||
export type IconName = ${iconNames.map((name) => `"${name}"`).join(" | ")}; | ||
const icons: { [K in IconName]: IconData }; | ||
export default icons; | ||
}`; | ||
|
||
fs.writeFileSync(TYPES_FILE, declarationContent); | ||
|
||
console.log(`Generated types for ${iconNames.length} icons 🎉`); | ||
} | ||
|
||
generateIconTypes(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import icons from "../assets/icons.json"; | ||
|
||
export default icons; |
Oops, something went wrong.