From 0b0bf01ca6b4e8361037b643fc81c2d6c25d4731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez=20Jim=C3=A9nez?= Date: Thu, 16 Sep 2021 15:33:04 +0200 Subject: [PATCH] chore: refactor --- .eslintrc.json | 7 +--- .npmrc | 1 - lib/test.ts | 10 ------ package.json | 12 +++---- lib/finder.ts => src/index.ts | 23 ++++++------- src/test.ts | 12 +++++++ tsconfig.json | 7 ++-- yarn.lock | 64 +++++++++++++++++++++-------------- 8 files changed, 72 insertions(+), 64 deletions(-) delete mode 100644 .npmrc delete mode 100644 lib/test.ts rename lib/finder.ts => src/index.ts (95%) create mode 100644 src/test.ts diff --git a/.eslintrc.json b/.eslintrc.json index 1b36e2a..09c2e42 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,8 +1,3 @@ { - "extends": "@antfu/eslint-config", - "rules": { - "@typescript-eslint/no-unused-vars": "off", - "react/react-in-jsx-scope": "off", - "react/no-unknown-property": "off" - } + "extends": "@antfu" } diff --git a/.npmrc b/.npmrc deleted file mode 100644 index bf2e764..0000000 --- a/.npmrc +++ /dev/null @@ -1 +0,0 @@ -shamefully-hoist=true diff --git a/lib/test.ts b/lib/test.ts deleted file mode 100644 index ed3be0d..0000000 --- a/lib/test.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { collection, locate } from './finder' - -const test = async(): Promise => { - const fa = locate('fa') - console.log(fa) - const faLib = await collection('fa') - console.log(faLib) -} - -test() diff --git a/package.json b/package.json index 0da8e8e..659814b 100644 --- a/package.json +++ b/package.json @@ -16,20 +16,20 @@ "composer.md", "readme.md" ], - "main": "dist/finder.js", - "module": "dist/finder.mjs", - "types": "dist/finder.d.ts", + "main": "dist/index.js", + "module": "dist/index.mjs", + "types": "dist/index.d.ts", "homepage": "https://iconify.design/icon-sets/", "bugs": "https://github.com/iconify/collections-json/issues", "scripts": { - "build": "rimraf dist && tsup lib/finder.ts --format cjs,esm --dts", - "test": "esno lib/test.ts" + "build": "rimraf dist && tsup src/index.ts --format cjs,esm --dts", + "test": "esno src/test.ts" }, "dependencies": { "upath": "^2.0.1" }, "devDependencies": { - "@antfu/eslint-config": "^0.8.2", + "@antfu/eslint-config": "^0.9.0", "@types/node": "^16.9.1", "@typescript-eslint/eslint-plugin": "^4.31.0", "eslint": "^7.32.0", diff --git a/lib/finder.ts b/src/index.ts similarity index 95% rename from lib/finder.ts rename to src/index.ts index 7bebb43..7c185ee 100644 --- a/lib/finder.ts +++ b/src/index.ts @@ -383,25 +383,24 @@ export interface IconifyJSON extends IconifyOptional, IconifyMetaData { // This is used to reduce duplication. } +/** + * Collection info map + */ +export type IconifyMetaDataCollection = { + [prefix: string]: IconifyMetaData +} + const _dirname = typeof __dirname !== 'undefined' ? __dirname : dirname(fileURLToPath(import.meta.url)) const dir = resolve(_dirname, '..') -/** - * Get root directory of this package - * (not really useful in Node.js because require can do it, but added anyway to match php code) - * - * @returns {string} - */ -const rootDir = () => dir - /** * Locate JSON file * * @param {string} name Collection name * @returns {string} Path to collection json file */ -const locate = (name: string): PathLike => `${dir}/json/${name}.json` +export const locate = (name: string): PathLike => `${dir}/json/${name}.json` /** * Loads a collection. @@ -419,15 +418,15 @@ export const loadCollection = async(path: PathLike): Promise => { * @param {string} name The name of the collection * @return {Promise} */ -export const collection = async(name: string): Promise => { +export const lookupCollection = async(name: string): Promise => { return await loadCollection(locate(name)) } /** * Get list of collections info. * - * @return {Promise} + * @return {Promise} */ -export const collections = async(): Promise => { +export const lookupCollections = async(): Promise => { return JSON.parse(await fs.readFile(`${dir}/collections.json`, 'utf8')) } diff --git a/src/test.ts b/src/test.ts new file mode 100644 index 0000000..b2e1cc9 --- /dev/null +++ b/src/test.ts @@ -0,0 +1,12 @@ +import { lookupCollection, locate, lookupCollections } from '.' + +const test = async(): Promise => { + const fa = locate('fa') + console.log(fa) + const faLib = await lookupCollection('fa') + console.log(faLib) + const allCollections = await lookupCollections() + console.log(allCollections.fa) +} + +test() diff --git a/tsconfig.json b/tsconfig.json index 7261d62..e48de55 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,20 +1,19 @@ { "compilerOptions": { - "baseUrl": ".", "module": "ESNext", "target": "es2017", - "lib": ["ESNext", "DOM"], + "lib": ["ESNext"], "esModuleInterop": true, "strict": true, "strictNullChecks": true, "moduleResolution": "Node", "resolveJsonModule": true, "skipLibCheck": true, - "jsx": "preserve" }, "exclude": [ "**/dist", "**/node_modules", - "**/test" + "**/test", + "dist" ] } diff --git a/yarn.lock b/yarn.lock index f096c56..8fd6612 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -"@antfu/eslint-config-basic@^0.8.1": - version "0.8.1" - resolved "https://registry.yarnpkg.com/@antfu/eslint-config-basic/-/eslint-config-basic-0.8.1.tgz#38938504c324ab2b210ba6e08d60275e565dae59" - integrity sha512-LUukPMgwvUTFxnsdMzi6zGmTCmqOul64BYs57R0YOKKxsza/ZvB/Wx3kwgsTxHUcc8i10mw9pAf8RhpHT35RcQ== +"@antfu/eslint-config-basic@^0.9.0": + version "0.9.0" + resolved "https://registry.yarnpkg.com/@antfu/eslint-config-basic/-/eslint-config-basic-0.9.0.tgz#88e6c272df2e359dbd4e90f824d8959480f7dd92" + integrity sha512-jiNycDenS19pppDvaa0oO3wWr4WDIog5Dz6WernBk+FsCyC7UzPfnG1KB3L/sovNVBB80wLZ7anGXZn0gKEHrQ== dependencies: eslint-config-standard "^16.0.3" eslint-plugin-eslint-comments "^3.2.0" @@ -19,38 +19,52 @@ jsonc-eslint-parser "^1.3.1" yaml-eslint-parser "^0.4.1" -"@antfu/eslint-config-react@^0.8.2": - version "0.8.2" - resolved "https://registry.yarnpkg.com/@antfu/eslint-config-react/-/eslint-config-react-0.8.2.tgz#29f68136e7facf3fd7fd86cb5ce66e35d3a853f0" - integrity sha512-HBneMnAHIwV5UTVIKOcfXWnXnHdEndoIjggra9PyJwQjjQahNhT73N7l8c7IjwcQ6NkDOI151SmOQQxi418Yzw== +"@antfu/eslint-config-react@^0.9.0": + version "0.9.0" + resolved "https://registry.yarnpkg.com/@antfu/eslint-config-react/-/eslint-config-react-0.9.0.tgz#ff5a7fc6466e2d213d2c822498373116400529c2" + integrity sha512-5b4PHHamJfMTfzmcUb7rDg9oH34delky8ZmTJ+r5LLfbbPdIthYLS9Ybns5v3q6rjhhTsfHOQz3gxp9604tYbQ== dependencies: - "@antfu/eslint-config-ts" "^0.8.2" + "@antfu/eslint-config-ts" "^0.9.0" eslint-plugin-react "^7.25.1" -"@antfu/eslint-config-ts@^0.8.2": - version "0.8.2" - resolved "https://registry.yarnpkg.com/@antfu/eslint-config-ts/-/eslint-config-ts-0.8.2.tgz#b4af9fc21a7fa46cf0839c3dff89c035235d1fd2" - integrity sha512-Rx1pGmt6mFTJ+ZZGZXLdWqYezViPWgbLbyPxajqP7rTctzo7bvd6T3qBTMCL5ZbxV+sdaTlYxM1eFN9t2ug/CA== +"@antfu/eslint-config-ts@^0.9.0": + version "0.9.0" + resolved "https://registry.yarnpkg.com/@antfu/eslint-config-ts/-/eslint-config-ts-0.9.0.tgz#8a04b56a5694381ff1c8657782185c37c437a91a" + integrity sha512-FXLLgMVjh5MpBvMteYQeQ9vkeL/cV5vig7IRoAJIpG1E5cbE+ENJt6w1YBf45PLQmoV/eZZID7cnT8ZOJ9VJfQ== dependencies: - "@antfu/eslint-config-basic" "^0.8.1" + "@antfu/eslint-config-basic" "^0.9.0" "@typescript-eslint/eslint-plugin" "^4.31.0" "@typescript-eslint/parser" "^4.31.0" -"@antfu/eslint-config-vue@^0.8.2": - version "0.8.2" - resolved "https://registry.yarnpkg.com/@antfu/eslint-config-vue/-/eslint-config-vue-0.8.2.tgz#3e3ff66f6e30dad9e30fc85429c0dbabdc2cf0e2" - integrity sha512-m5HLvnyhbTj2kSrddNeQoUIZ+BY7AgWZel7CVkMPajx8SACh4DpYcNFezuwjCwcCM5A/ZulktSKqdF9rEzKWBg== +"@antfu/eslint-config-vue@^0.9.0": + version "0.9.0" + resolved "https://registry.yarnpkg.com/@antfu/eslint-config-vue/-/eslint-config-vue-0.9.0.tgz#ea3b625b3af01e441295877dd32934a29010d10a" + integrity sha512-h1Ab6TdcZyhQhBJIjr3CrI6U66x/izRddTQeF/OrjEyLz6HjeASbUOMgDQhmH9u47+6RP68cR6Wnjls/rlZb2g== dependencies: - "@antfu/eslint-config-ts" "^0.8.2" + "@antfu/eslint-config-ts" "^0.9.0" eslint-plugin-vue "7.17.0" -"@antfu/eslint-config@^0.8.2": - version "0.8.2" - resolved "https://registry.yarnpkg.com/@antfu/eslint-config/-/eslint-config-0.8.2.tgz#aecc0283f65105e42278734e533804c41c88cc0f" - integrity sha512-MqNrYl30gIPPIPIKVPqc3aQs5DAi9JVohsZHvBw3KeplbJK0SZujDnlaeGxeC7D0Zp+Z4E/D8KxefgJHz1G8Kw== +"@antfu/eslint-config@^0.9.0": + version "0.9.0" + resolved "https://registry.yarnpkg.com/@antfu/eslint-config/-/eslint-config-0.9.0.tgz#ed62a2c7c4e88b45356d1f925dd8a85e9aaac950" + integrity sha512-oQ6kNRHfF7PqZocX2+mfvY/oNdLGPjysb9huVJzMji7QtLAVL5+25Mm/kzJEIfcFWxRpDqctOcflXLYFnXiroA== dependencies: - "@antfu/eslint-config-react" "^0.8.2" - "@antfu/eslint-config-vue" "^0.8.2" + "@antfu/eslint-config-react" "^0.9.0" + "@antfu/eslint-config-vue" "^0.9.0" + "@typescript-eslint/eslint-plugin" "^4.31.0" + "@typescript-eslint/parser" "^4.31.0" + eslint-config-standard "^16.0.3" + eslint-plugin-eslint-comments "^3.2.0" + eslint-plugin-html "^6.1.2" + eslint-plugin-import "^2.24.2" + eslint-plugin-jsonc "^1.6.0" + eslint-plugin-node "^11.1.0" + eslint-plugin-promise "^5.1.0" + eslint-plugin-unicorn "^35.0.0" + eslint-plugin-vue "7.17.0" + eslint-plugin-yml "^0.10.0" + jsonc-eslint-parser "^1.3.1" + yaml-eslint-parser "^0.4.1" "@babel/code-frame@7.12.11": version "7.12.11"