From 47f98057152efb85128d8fd073e693ac57db743f Mon Sep 17 00:00:00 2001 From: Edaz Date: Wed, 24 Nov 2021 14:30:02 +1300 Subject: [PATCH] fork Signed-off-by: Edaz --- packages/astro-feather-icons/build.js | 61 +++++++++++++++++++++++ packages/astro-feather-icons/package.json | 38 ++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 packages/astro-feather-icons/build.js create mode 100644 packages/astro-feather-icons/package.json diff --git a/packages/astro-feather-icons/build.js b/packages/astro-feather-icons/build.js new file mode 100644 index 0000000..40e1197 --- /dev/null +++ b/packages/astro-feather-icons/build.js @@ -0,0 +1,61 @@ +const path = require("path"); +const feather = require("feather-icons/dist/icons.json"); +const { pascalCase } = require("pascal-case"); +const fs = require("fs-extra"); + +const handleComponentName = (name) => name.replace(/\-(\d+)/, "$1"); + +const component = (icon) => + `--- + export interface Props { + size?: string | number; + strokeWidth?: number; + class?: string; + color?: string; + } + let { size = "100%", strokeWidth = 2, class: customClass = "", color } = Astro.props; + + if (size !== "100%") { + const stringSize = size + ""; + size = stringSize.slice(-1) === 'x' + ? stringSize.slice(0, stringSize.length -1) + 'em' + : parseInt(stringSize) + 'px'; + } +--- + +${feather[icon.name]} +`; + +const icons = Object.keys(feather).map((name) => ({ + name, + pascalCasedComponentName: pascalCase(`${handleComponentName(name)}-icon`), + kebabCasedComponentName: `${handleComponentName(name)}-icon`, +})); + +Promise.all( + icons.map((icon) => { + const filepath = `./dist/icons/${icon.pascalCasedComponentName}.astro`; + return fs + .ensureDir(path.dirname(filepath)) + .then(() => fs.writeFile(filepath, component(icon), "utf8")); + }) +).then(async () => { + const main = icons + .map( + (icon) => + `export { default as ${icon.pascalCasedComponentName} } from './icons/${icon.pascalCasedComponentName}.astro'` + ) + .join("\n\n"); + // const types = + // '/// \nimport {SvelteComponentTyped} from "svelte/internal"\n' + + // icons + // .map( + // (icon) => + // `export class ${icon.pascalCasedComponentName} extends SvelteComponentTyped<{size?: string, strokeWidth?: number, class?: string}> {}` + // ) + // .join("\n"); + // await fs.outputFile("index.d.ts", types, "utf8"); + return await fs.outputFile("./dist/index.js", main, "utf8"); +}); diff --git a/packages/astro-feather-icons/package.json b/packages/astro-feather-icons/package.json new file mode 100644 index 0000000..d0ad415 --- /dev/null +++ b/packages/astro-feather-icons/package.json @@ -0,0 +1,38 @@ +{ + "name": "astro-feather-icons", + "description": "Feather icons for Astro (based on svelte-feather-icons by dylanblokhuis)", + "version": "0.1.0", + "author": "edazpotato (https://edaz.codes/)", + "repository": { + "url": "edazpotato/astro-feather-icons", + "type": "git" + }, + "exports": "./dist/index.js", + "module": "./dist/index.js", + "main": "./dist/index.js", + "files": [ + "dist" + ], + "types": "index.d.ts", + "license": "MIT", + "scripts": { + "build:icons": "node build", + "build": "npm run build:icons", + "prepublishOnly": "npm run build" + }, + "devDependencies": { + "@rollup/plugin-node-resolve": "^13.0.0", + "feather-icons": "4.28.0", + "fs-extra": "^10.0.0", + "pascal-case": "^3.1.2", + "path": "^0.12.7" + }, + "keywords": [ + "astro", + "feather icons", + "astro-component" + ], + "dependencies": { + "astro": "^0.21.3" + } +}