feat(bin): add icon db fetch script
This commit is contained in:
75
bin/ingest.js
Normal file
75
bin/ingest.js
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
const fs = require("fs/promises");
|
||||||
|
const path = require("path");
|
||||||
|
const axios = require("axios");
|
||||||
|
const chalk = require("chalk");
|
||||||
|
|
||||||
|
const ICON_API_URL = "https://api.phosphoricons.com";
|
||||||
|
const PARAMS = new URLSearchParams([["release", "1.4"]]).toString();
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
try {
|
||||||
|
const res = await axios.get(`${ICON_API_URL}?${PARAMS}`);
|
||||||
|
if (res.data) {
|
||||||
|
let fileString = `\
|
||||||
|
import * as Icons from "phosphor-react";
|
||||||
|
import { IconEntry, IconCategory } from ".";
|
||||||
|
|
||||||
|
export const icons: ReadonlyArray<IconEntry> = [
|
||||||
|
`;
|
||||||
|
|
||||||
|
res.data.icons.forEach((icon) => {
|
||||||
|
let categories = "[";
|
||||||
|
icon.searchCategories?.forEach((c) => {
|
||||||
|
categories += `IconCategory.${c.toUpperCase()},`;
|
||||||
|
});
|
||||||
|
categories += "]";
|
||||||
|
|
||||||
|
fileString += `\
|
||||||
|
{
|
||||||
|
name: "${icon.name}",
|
||||||
|
categories: ${categories},
|
||||||
|
tags: ${JSON.stringify(["*new*", ...icon.tags])},
|
||||||
|
Icon: Icons.${icon.name
|
||||||
|
.split("-")
|
||||||
|
.map((substr) => substr.replace(/^\w/, (c) => c.toUpperCase()))
|
||||||
|
.join("")},
|
||||||
|
},
|
||||||
|
`;
|
||||||
|
console.log(`${chalk.inverse.green(" DONE ")} ${icon.name}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
fileString += `
|
||||||
|
];
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === "development") {
|
||||||
|
console.log(\`\${icons.length} icons\`);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const iconCount = (icons.length * 6)
|
||||||
|
.toString()
|
||||||
|
.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||||
|
|
||||||
|
`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await fs.writeFile(
|
||||||
|
path.join(__dirname, "../src/lib/new.ts"),
|
||||||
|
fileString
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
`${chalk.green(" DONE ")} ${res.data.icons.length} icons ingested`
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`${chalk.inverse.red(" FAIL ")} Could not write file`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.error(`${chalk.inverse.red(" FAIL ")} No data`);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
process.exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
@@ -42,8 +42,7 @@
|
|||||||
"build": "react-scripts build",
|
"build": "react-scripts build",
|
||||||
"test": "react-scripts test",
|
"test": "react-scripts test",
|
||||||
"eject": "react-scripts eject",
|
"eject": "react-scripts eject",
|
||||||
"predeploy": "npm run build",
|
"ingest": "node ./bin/ingest.js",
|
||||||
"deploy": "gh-pages -d build",
|
|
||||||
"format": "prettier --write \"./src/**/*.{js,jsx,ts,tsx,json,vue}\""
|
"format": "prettier --write \"./src/**/*.{js,jsx,ts,tsx,json,vue}\""
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
@@ -73,6 +72,8 @@
|
|||||||
"@types/react-list": "^0.8.5",
|
"@types/react-list": "^0.8.5",
|
||||||
"@types/react-virtualized": "^9.21.10",
|
"@types/react-virtualized": "^9.21.10",
|
||||||
"@types/tinycolor2": "^1.4.2",
|
"@types/tinycolor2": "^1.4.2",
|
||||||
|
"axios": "^0.24.0",
|
||||||
|
"chalk": "^4",
|
||||||
"typescript": "^3.9.6"
|
"typescript": "^3.9.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user