Skip to content

Commit

Permalink
fork
Browse files Browse the repository at this point in the history
Signed-off-by: Edaz <[email protected]>
  • Loading branch information
edazpotato committed Nov 24, 2021
1 parent 3104ffb commit 47f9805
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
61 changes: 61 additions & 0 deletions packages/astro-feather-icons/build.js
Original file line number Diff line number Diff line change
@@ -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';
}
---
<svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} fill="none" viewBox="0 0 24 24" stroke={color || "currentColor"} stroke-width={strokeWidth} stroke-linecap="round" stroke-linejoin="round" class={\`feather feather-${
icon.name
} \${customClass}\`}>${feather[icon.name]}</svg>
`;

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 =
// '/// <reference types="svelte" />\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");
});
38 changes: 38 additions & 0 deletions packages/astro-feather-icons/package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> (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"
}
}

0 comments on commit 47f9805

Please sign in to comment.