feat(bin): update fetch script to take CLI args

This commit is contained in:
rektdeckard
2021-12-12 00:27:14 -05:00
parent e242bcc660
commit 887617e523
3 changed files with 326 additions and 259 deletions

View File

@@ -1,15 +1,33 @@
#!/usr/bin/env node #!/usr/bin/env node
"use strict";
const fs = require("fs/promises"); const fs = require("fs/promises");
const path = require("path"); const path = require("path");
const axios = require("axios"); const axios = require("axios");
const chalk = require("chalk"); const chalk = require("chalk");
const { Command } = require("commander");
const { version } = require("../package.json");
const ICON_API_URL = "https://api.phosphoricons.com"; const ICON_API_URL = "https://api.phosphoricons.com";
const PARAMS = new URLSearchParams([["release", "1.4"]]).toString();
async function main() { async function main() {
const program = new Command();
program
.version(version)
.option(
"-r --release <version>",
"Fetch icons from Phosphor API and compile to internal data structure"
)
.option("-p --published", "Published status of icons")
.option("-P, --no-published", "Published status of icons")
.option("-q --query <text>", "Fulltext search term")
.option("-n --name <name>", "Exact icon namee match");
program.parse(process.argv);
const params = new URLSearchParams(Object.entries(program.opts())).toString();
try { try {
const res = await axios.get(`${ICON_API_URL}?${PARAMS}`); const res = await axios.get(`${ICON_API_URL}?${params}`);
if (res.data) { if (res.data) {
let fileString = `\ let fileString = `\
import * as Icons from "phosphor-react"; import * as Icons from "phosphor-react";

View File

@@ -20,6 +20,15 @@
], ],
"repository": "github:phosphor-icons/phosphor-home", "repository": "github:phosphor-icons/phosphor-home",
"private": true, "private": true,
"scripts": {
"analyze": "source-map-explorer 'build/static/js/*.js'",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"fetch": "node ./bin/fetch.js",
"format": "prettier --write \"./src/**/*.{js,jsx,ts,tsx,json,vue}\""
},
"dependencies": { "dependencies": {
"file-saver": "^2.0.2", "file-saver": "^2.0.2",
"framer-motion": "^3.10.0", "framer-motion": "^3.10.0",
@@ -36,14 +45,21 @@
"svg2png-converter": "^1.0.0", "svg2png-converter": "^1.0.0",
"tinycolor2": "^1.4.2" "tinycolor2": "^1.4.2"
}, },
"scripts": { "devDependencies": {
"analyze": "source-map-explorer 'build/static/js/*.js'", "@testing-library/jest-dom": "^4.2.4",
"start": "react-scripts start", "@testing-library/react": "^9.3.2",
"build": "react-scripts build", "@testing-library/user-event": "^7.1.2",
"test": "react-scripts test", "@types/file-saver": "^2.0.1",
"eject": "react-scripts eject", "@types/jest": "^24.0.0",
"ingest": "node ./bin/ingest.js", "@types/node": "^12.0.0",
"format": "prettier --write \"./src/**/*.{js,jsx,ts,tsx,json,vue}\"" "@types/react": "^16.9.46",
"@types/react-dom": "^16.9.8",
"@types/react-virtualized": "^9.21.10",
"@types/tinycolor2": "^1.4.2",
"axios": "^0.24.0",
"chalk": "^4",
"commander": "^8.3.0",
"typescript": "^3.9.6"
}, },
"eslintConfig": { "eslintConfig": {
"extends": "react-app" "extends": "react-app"
@@ -59,21 +75,5 @@
"last 1 firefox version", "last 1 firefox version",
"last 1 safari version" "last 1 safari version"
] ]
},
"devDependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"@types/file-saver": "^2.0.1",
"@types/jest": "^24.0.0",
"@types/node": "^12.0.0",
"@types/react": "^16.9.46",
"@types/react-dom": "^16.9.8",
"@types/react-list": "^0.8.5",
"@types/react-virtualized": "^9.21.10",
"@types/tinycolor2": "^1.4.2",
"axios": "^0.24.0",
"chalk": "^4",
"typescript": "^3.9.6"
} }
} }

File diff suppressed because it is too large Load Diff