Skip to content

Commit

Permalink
init package files; add TS, formatting; create manifest generator script
Browse files Browse the repository at this point in the history
  • Loading branch information
SutuSebastian committed Feb 20, 2024
1 parent 2bdf218 commit 516ad46
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.DS_Store
node_modules
manifest.json
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Themesberg
Copyright (c) 2024 Themesberg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Binary file added bun.lockb
Binary file not shown.
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "flowbite-icons",
"description": "Official Flowbite Icons library",
"keywords": [
"flowbite",
"icons",
"svg"
],
"homepage": "https://github.com/themesberg/flowbite-icons#readme",
"bugs": "https://github.com/themesberg/flowbite-icons/issues",
"repository": {
"type": "git",
"url": "git+https://github.com/themesberg/flowbite-icons.git"
},
"license": "MIT",
"type": "module",
"scripts": {
"format": "prettier . --write",
"format:check": "prettier .",
"generate-manifest": "bun run scripts/generate-manifest.ts",
"typecheck": "tsc"
},
"devDependencies": {
"@ianvs/prettier-plugin-sort-imports": "4.1.1",
"@types/bun": "^1.0.6",
"prettier": "3.2.5",
"prettier-plugin-packagejson": "2.4.11",
"typescript": "5.3.3"
}
}
7 changes: 7 additions & 0 deletions prettier.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import('prettier').Config} */
module.exports = {
plugins: [
"prettier-plugin-packagejson",
"@ianvs/prettier-plugin-sort-imports",
],
};
51 changes: 51 additions & 0 deletions scripts/generate-manifest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import fs from "node:fs/promises";
import path from "path";

async function readFiles(
directoryPath: string,
onReadFile: (filePath: string) => Promise<void>,
) {
const files = await fs.readdir(directoryPath);

for (const file of files) {
const filePath = path.join(directoryPath, file);
const stat = await fs.stat(filePath);

if (stat.isDirectory()) {
await readFiles(filePath, onReadFile);
} else {
await onReadFile(filePath);
}
}
}

const SVGS_PATH = "src";
const MANIFEST_PATH = "manifest.json";

const manifest: {
name: string;
style: string;
category: string;
svg: string;
}[] = [];

await readFiles(SVGS_PATH, async (filePath) => {
if (!filePath.endsWith(".svg")) return;

const relativePath = filePath.replace(`${SVGS_PATH}/`, "");

let [style, category, name] = relativePath.split("/");
name = name.split(".")[0];

const svg = await Bun.file(filePath).text();

manifest.push({ name, style, category, svg });
});

manifest.sort((a, b) => {
const x = a.name.toLowerCase();
const y = b.name.toLowerCase();
return x < y ? -1 : x > y ? 1 : 0;
});

await Bun.write(MANIFEST_PATH, JSON.stringify(manifest, null, 2));
20 changes: 20 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"lib": ["ESNext"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"allowJs": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

/* Linting */
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true
}
}

0 comments on commit 516ad46

Please sign in to comment.