From 2f3478ce0ca1569e97bb7eb651d90e2ac3a11038 Mon Sep 17 00:00:00 2001 From: winches <96854855+winchesHe@users.noreply.github.com> Date: Wed, 3 Apr 2024 02:12:17 +0800 Subject: [PATCH] feat: add update components script instead use static components (#12) * feat: add update components script instead use static components * feat: add manually control whether need to update @nextui-org/react * fix: optimize log * fix: optimize log * chore: update * fix: ci error * refactor: auto update the components.json --- .vscode/settings.json | 3 +- package.json | 6 +- pnpm-lock.yaml | 252 ++++++++++++++++++ src/constants/component.ts | 324 +----------------------- src/constants/components.json | 301 ++++++++++++++++++++++ src/constants/path.ts | 3 + src/scripts/helpers.ts | 117 +++++++++ src/scripts/path.ts | 6 + src/scripts/update/update-components.ts | 3 + tsup.config.ts | 2 +- 10 files changed, 693 insertions(+), 324 deletions(-) create mode 100644 src/constants/components.json create mode 100644 src/scripts/helpers.ts create mode 100644 src/scripts/path.ts create mode 100644 src/scripts/update/update-components.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 8fb55fd..ed4472a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,5 +5,6 @@ "editor.formatOnSave": false, "editor.codeActionsOnSave": { "source.fixAll.eslint": "explicit" - } + }, + "cSpell.words": ["nextui", "tailwindcss"] } diff --git a/package.json b/package.json index 2b2e679..155a06b 100644 --- a/package.json +++ b/package.json @@ -44,11 +44,14 @@ "link:cli": "pnpm link --global", "link:remove": "pnpm uninstall --global nextui-cli", "build": "tsup", + "update:components": "tsx src/scripts/update/update-components.ts", "lint": "eslint . --max-warnings=0", "lint:fix": "eslint . -max-warnings=0 --fix", "check:prettier": "prettier --check .", "check:types": "tsc --noEmit", - "prepare": "husky install" + "prepare": "husky install", + "postbuild": "pnpm run update:components", + "prepublishOnly": "pnpm run build" }, "dependencies": { "async-retry": "1.3.3", @@ -82,6 +85,7 @@ "husky": "8.0.3", "lint-staged": "14.0.1", "tsup": "7.2.0", + "tsx": "4.7.1", "typescript": "5.2.2" }, "engines": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5b2f8a2..59e312b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -94,6 +94,9 @@ devDependencies: tsup: specifier: 7.2.0 version: 7.2.0(ts-node@10.9.1)(typescript@5.2.2) + tsx: + specifier: 4.7.1 + version: 4.7.1 typescript: specifier: 5.2.2 version: 5.2.2 @@ -302,6 +305,15 @@ packages: '@jridgewell/trace-mapping': 0.3.9 dev: true + /@esbuild/aix-ppc64@0.19.12: + resolution: {integrity: sha512-bmoCYyWdEL3wDQIVbcyzRyeKLgk2WtWLTWz1ZIAZF/EGbNOwSA6ew3PftJ1PqMiOOGu0OyFMzG53L0zqIpPeNA==} + engines: {node: '>=12'} + cpu: [ppc64] + os: [aix] + requiresBuild: true + dev: true + optional: true + /@esbuild/android-arm64@0.18.20: resolution: {integrity: sha512-Nz4rJcchGDtENV0eMKUNa6L12zz2zBDXuhj/Vjh18zGqB44Bi7MBMSXjgunJgjRhCmKOjnPuZp4Mb6OKqtMHLQ==} engines: {node: '>=12'} @@ -311,6 +323,15 @@ packages: dev: true optional: true + /@esbuild/android-arm64@0.19.12: + resolution: {integrity: sha512-P0UVNGIienjZv3f5zq0DP3Nt2IE/3plFzuaS96vihvD0Hd6H/q4WXUGpCxD/E8YrSXfNyRPbpTq+T8ZQioSuPA==} + engines: {node: '>=12'} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: true + optional: true + /@esbuild/android-arm@0.18.20: resolution: {integrity: sha512-fyi7TDI/ijKKNZTUJAQqiG5T7YjJXgnzkURqmGj13C6dCqckZBLdl4h7bkhHt/t0WP+zO9/zwroDvANaOqO5Sw==} engines: {node: '>=12'} @@ -320,6 +341,15 @@ packages: dev: true optional: true + /@esbuild/android-arm@0.19.12: + resolution: {integrity: sha512-qg/Lj1mu3CdQlDEEiWrlC4eaPZ1KztwGJ9B6J+/6G+/4ewxJg7gqj8eVYWvao1bXrqGiW2rsBZFSX3q2lcW05w==} + engines: {node: '>=12'} + cpu: [arm] + os: [android] + requiresBuild: true + dev: true + optional: true + /@esbuild/android-x64@0.18.20: resolution: {integrity: sha512-8GDdlePJA8D6zlZYJV/jnrRAi6rOiNaCC/JclcXpB+KIuvfBN4owLtgzY2bsxnx666XjJx2kDPUmnTtR8qKQUg==} engines: {node: '>=12'} @@ -329,6 +359,15 @@ packages: dev: true optional: true + /@esbuild/android-x64@0.19.12: + resolution: {integrity: sha512-3k7ZoUW6Q6YqhdhIaq/WZ7HwBpnFBlW905Fa4s4qWJyiNOgT1dOqDiVAQFwBH7gBRZr17gLrlFCRzF6jFh7Kew==} + engines: {node: '>=12'} + cpu: [x64] + os: [android] + requiresBuild: true + dev: true + optional: true + /@esbuild/darwin-arm64@0.18.20: resolution: {integrity: sha512-bxRHW5kHU38zS2lPTPOyuyTm+S+eobPUnTNkdJEfAddYgEcll4xkT8DB9d2008DtTbl7uJag2HuE5NZAZgnNEA==} engines: {node: '>=12'} @@ -338,6 +377,15 @@ packages: dev: true optional: true + /@esbuild/darwin-arm64@0.19.12: + resolution: {integrity: sha512-B6IeSgZgtEzGC42jsI+YYu9Z3HKRxp8ZT3cqhvliEHovq8HSX2YX8lNocDn79gCKJXOSaEot9MVYky7AKjCs8g==} + engines: {node: '>=12'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + /@esbuild/darwin-x64@0.18.20: resolution: {integrity: sha512-pc5gxlMDxzm513qPGbCbDukOdsGtKhfxD1zJKXjCCcU7ju50O7MeAZ8c4krSJcOIJGFR+qx21yMMVYwiQvyTyQ==} engines: {node: '>=12'} @@ -347,6 +395,15 @@ packages: dev: true optional: true + /@esbuild/darwin-x64@0.19.12: + resolution: {integrity: sha512-hKoVkKzFiToTgn+41qGhsUJXFlIjxI/jSYeZf3ugemDYZldIXIxhvwN6erJGlX4t5h417iFuheZ7l+YVn05N3A==} + engines: {node: '>=12'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + /@esbuild/freebsd-arm64@0.18.20: resolution: {integrity: sha512-yqDQHy4QHevpMAaxhhIwYPMv1NECwOvIpGCZkECn8w2WFHXjEwrBn3CeNIYsibZ/iZEUemj++M26W3cNR5h+Tw==} engines: {node: '>=12'} @@ -356,6 +413,15 @@ packages: dev: true optional: true + /@esbuild/freebsd-arm64@0.19.12: + resolution: {integrity: sha512-4aRvFIXmwAcDBw9AueDQ2YnGmz5L6obe5kmPT8Vd+/+x/JMVKCgdcRwH6APrbpNXsPz+K653Qg8HB/oXvXVukA==} + engines: {node: '>=12'} + cpu: [arm64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + /@esbuild/freebsd-x64@0.18.20: resolution: {integrity: sha512-tgWRPPuQsd3RmBZwarGVHZQvtzfEBOreNuxEMKFcd5DaDn2PbBxfwLcj4+aenoh7ctXcbXmOQIn8HI6mCSw5MQ==} engines: {node: '>=12'} @@ -365,6 +431,15 @@ packages: dev: true optional: true + /@esbuild/freebsd-x64@0.19.12: + resolution: {integrity: sha512-EYoXZ4d8xtBoVN7CEwWY2IN4ho76xjYXqSXMNccFSx2lgqOG/1TBPW0yPx1bJZk94qu3tX0fycJeeQsKovA8gg==} + engines: {node: '>=12'} + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-arm64@0.18.20: resolution: {integrity: sha512-2YbscF+UL7SQAVIpnWvYwM+3LskyDmPhe31pE7/aoTMFKKzIc9lLbyGUpmmb8a8AixOL61sQ/mFh3jEjHYFvdA==} engines: {node: '>=12'} @@ -374,6 +449,15 @@ packages: dev: true optional: true + /@esbuild/linux-arm64@0.19.12: + resolution: {integrity: sha512-EoTjyYyLuVPfdPLsGVVVC8a0p1BFFvtpQDB/YLEhaXyf/5bczaGeN15QkR+O4S5LeJ92Tqotve7i1jn35qwvdA==} + engines: {node: '>=12'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-arm@0.18.20: resolution: {integrity: sha512-/5bHkMWnq1EgKr1V+Ybz3s1hWXok7mDFUMQ4cG10AfW3wL02PSZi5kFpYKrptDsgb2WAJIvRcDm+qIvXf/apvg==} engines: {node: '>=12'} @@ -383,6 +467,15 @@ packages: dev: true optional: true + /@esbuild/linux-arm@0.19.12: + resolution: {integrity: sha512-J5jPms//KhSNv+LO1S1TX1UWp1ucM6N6XuL6ITdKWElCu8wXP72l9MM0zDTzzeikVyqFE6U8YAV9/tFyj0ti+w==} + engines: {node: '>=12'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-ia32@0.18.20: resolution: {integrity: sha512-P4etWwq6IsReT0E1KHU40bOnzMHoH73aXp96Fs8TIT6z9Hu8G6+0SHSw9i2isWrD2nbx2qo5yUqACgdfVGx7TA==} engines: {node: '>=12'} @@ -392,6 +485,15 @@ packages: dev: true optional: true + /@esbuild/linux-ia32@0.19.12: + resolution: {integrity: sha512-Thsa42rrP1+UIGaWz47uydHSBOgTUnwBwNq59khgIwktK6x60Hivfbux9iNR0eHCHzOLjLMLfUMLCypBkZXMHA==} + engines: {node: '>=12'} + cpu: [ia32] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-loong64@0.18.20: resolution: {integrity: sha512-nXW8nqBTrOpDLPgPY9uV+/1DjxoQ7DoB2N8eocyq8I9XuqJ7BiAMDMf9n1xZM9TgW0J8zrquIb/A7s3BJv7rjg==} engines: {node: '>=12'} @@ -401,6 +503,15 @@ packages: dev: true optional: true + /@esbuild/linux-loong64@0.19.12: + resolution: {integrity: sha512-LiXdXA0s3IqRRjm6rV6XaWATScKAXjI4R4LoDlvO7+yQqFdlr1Bax62sRwkVvRIrwXxvtYEHHI4dm50jAXkuAA==} + engines: {node: '>=12'} + cpu: [loong64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-mips64el@0.18.20: resolution: {integrity: sha512-d5NeaXZcHp8PzYy5VnXV3VSd2D328Zb+9dEq5HE6bw6+N86JVPExrA6O68OPwobntbNJ0pzCpUFZTo3w0GyetQ==} engines: {node: '>=12'} @@ -410,6 +521,15 @@ packages: dev: true optional: true + /@esbuild/linux-mips64el@0.19.12: + resolution: {integrity: sha512-fEnAuj5VGTanfJ07ff0gOA6IPsvrVHLVb6Lyd1g2/ed67oU1eFzL0r9WL7ZzscD+/N6i3dWumGE1Un4f7Amf+w==} + engines: {node: '>=12'} + cpu: [mips64el] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-ppc64@0.18.20: resolution: {integrity: sha512-WHPyeScRNcmANnLQkq6AfyXRFr5D6N2sKgkFo2FqguP44Nw2eyDlbTdZwd9GYk98DZG9QItIiTlFLHJHjxP3FA==} engines: {node: '>=12'} @@ -419,6 +539,15 @@ packages: dev: true optional: true + /@esbuild/linux-ppc64@0.19.12: + resolution: {integrity: sha512-nYJA2/QPimDQOh1rKWedNOe3Gfc8PabU7HT3iXWtNUbRzXS9+vgB0Fjaqr//XNbd82mCxHzik2qotuI89cfixg==} + engines: {node: '>=12'} + cpu: [ppc64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-riscv64@0.18.20: resolution: {integrity: sha512-WSxo6h5ecI5XH34KC7w5veNnKkju3zBRLEQNY7mv5mtBmrP/MjNBCAlsM2u5hDBlS3NGcTQpoBvRzqBcRtpq1A==} engines: {node: '>=12'} @@ -428,6 +557,15 @@ packages: dev: true optional: true + /@esbuild/linux-riscv64@0.19.12: + resolution: {integrity: sha512-2MueBrlPQCw5dVJJpQdUYgeqIzDQgw3QtiAHUC4RBz9FXPrskyyU3VI1hw7C0BSKB9OduwSJ79FTCqtGMWqJHg==} + engines: {node: '>=12'} + cpu: [riscv64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-s390x@0.18.20: resolution: {integrity: sha512-+8231GMs3mAEth6Ja1iK0a1sQ3ohfcpzpRLH8uuc5/KVDFneH6jtAJLFGafpzpMRO6DzJ6AvXKze9LfFMrIHVQ==} engines: {node: '>=12'} @@ -437,6 +575,15 @@ packages: dev: true optional: true + /@esbuild/linux-s390x@0.19.12: + resolution: {integrity: sha512-+Pil1Nv3Umes4m3AZKqA2anfhJiVmNCYkPchwFJNEJN5QxmTs1uzyy4TvmDrCRNT2ApwSari7ZIgrPeUx4UZDg==} + engines: {node: '>=12'} + cpu: [s390x] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-x64@0.18.20: resolution: {integrity: sha512-UYqiqemphJcNsFEskc73jQ7B9jgwjWrSayxawS6UVFZGWrAAtkzjxSqnoclCXxWtfwLdzU+vTpcNYhpn43uP1w==} engines: {node: '>=12'} @@ -446,6 +593,15 @@ packages: dev: true optional: true + /@esbuild/linux-x64@0.19.12: + resolution: {integrity: sha512-B71g1QpxfwBvNrfyJdVDexenDIt1CiDN1TIXLbhOw0KhJzE78KIFGX6OJ9MrtC0oOqMWf+0xop4qEU8JrJTwCg==} + engines: {node: '>=12'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/netbsd-x64@0.18.20: resolution: {integrity: sha512-iO1c++VP6xUBUmltHZoMtCUdPlnPGdBom6IrO4gyKPFFVBKioIImVooR5I83nTew5UOYrk3gIJhbZh8X44y06A==} engines: {node: '>=12'} @@ -455,6 +611,15 @@ packages: dev: true optional: true + /@esbuild/netbsd-x64@0.19.12: + resolution: {integrity: sha512-3ltjQ7n1owJgFbuC61Oj++XhtzmymoCihNFgT84UAmJnxJfm4sYCiSLTXZtE00VWYpPMYc+ZQmB6xbSdVh0JWA==} + engines: {node: '>=12'} + cpu: [x64] + os: [netbsd] + requiresBuild: true + dev: true + optional: true + /@esbuild/openbsd-x64@0.18.20: resolution: {integrity: sha512-e5e4YSsuQfX4cxcygw/UCPIEP6wbIL+se3sxPdCiMbFLBWu0eiZOJ7WoD+ptCLrmjZBK1Wk7I6D/I3NglUGOxg==} engines: {node: '>=12'} @@ -464,6 +629,15 @@ packages: dev: true optional: true + /@esbuild/openbsd-x64@0.19.12: + resolution: {integrity: sha512-RbrfTB9SWsr0kWmb9srfF+L933uMDdu9BIzdA7os2t0TXhCRjrQyCeOt6wVxr79CKD4c+p+YhCj31HBkYcXebw==} + engines: {node: '>=12'} + cpu: [x64] + os: [openbsd] + requiresBuild: true + dev: true + optional: true + /@esbuild/sunos-x64@0.18.20: resolution: {integrity: sha512-kDbFRFp0YpTQVVrqUd5FTYmWo45zGaXe0X8E1G/LKFC0v8x0vWrhOWSLITcCn63lmZIxfOMXtCfti/RxN/0wnQ==} engines: {node: '>=12'} @@ -473,6 +647,15 @@ packages: dev: true optional: true + /@esbuild/sunos-x64@0.19.12: + resolution: {integrity: sha512-HKjJwRrW8uWtCQnQOz9qcU3mUZhTUQvi56Q8DPTLLB+DawoiQdjsYq+j+D3s9I8VFtDr+F9CjgXKKC4ss89IeA==} + engines: {node: '>=12'} + cpu: [x64] + os: [sunos] + requiresBuild: true + dev: true + optional: true + /@esbuild/win32-arm64@0.18.20: resolution: {integrity: sha512-ddYFR6ItYgoaq4v4JmQQaAI5s7npztfV4Ag6NrhiaW0RrnOXqBkgwZLofVTlq1daVTQNhtI5oieTvkRPfZrePg==} engines: {node: '>=12'} @@ -482,6 +665,15 @@ packages: dev: true optional: true + /@esbuild/win32-arm64@0.19.12: + resolution: {integrity: sha512-URgtR1dJnmGvX864pn1B2YUYNzjmXkuJOIqG2HdU62MVS4EHpU2946OZoTMnRUHklGtJdJZ33QfzdjGACXhn1A==} + engines: {node: '>=12'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /@esbuild/win32-ia32@0.18.20: resolution: {integrity: sha512-Wv7QBi3ID/rROT08SABTS7eV4hX26sVduqDOTe1MvGMjNd3EjOz4b7zeexIR62GTIEKrfJXKL9LFxTYgkyeu7g==} engines: {node: '>=12'} @@ -491,6 +683,15 @@ packages: dev: true optional: true + /@esbuild/win32-ia32@0.19.12: + resolution: {integrity: sha512-+ZOE6pUkMOJfmxmBZElNOx72NKpIa/HFOMGzu8fqzQJ5kgf6aTGrcJaFsNiVMH4JKpMipyK+7k0n2UXN7a8YKQ==} + engines: {node: '>=12'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + /@esbuild/win32-x64@0.18.20: resolution: {integrity: sha512-kTdfRcSiDfQca/y9QIkng02avJ+NCaQvrMejlsB3RRv5sE9rRoeBPISaZpKxHELzRxZyLvNts1P27W3wV+8geQ==} engines: {node: '>=12'} @@ -500,6 +701,15 @@ packages: dev: true optional: true + /@esbuild/win32-x64@0.19.12: + resolution: {integrity: sha512-T1QyPSDCyMXaO3pzBkF96E8xMkiRYbUEZADd29SyPGabqxMViNoii+NcK7eWJAEoU6RZyEm5lVSIjTmcdoB9HA==} + engines: {node: '>=12'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /@eslint-community/eslint-utils@4.4.0(eslint@8.50.0): resolution: {integrity: sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -1550,6 +1760,37 @@ packages: '@esbuild/win32-x64': 0.18.20 dev: true + /esbuild@0.19.12: + resolution: {integrity: sha512-aARqgq8roFBj054KvQr5f1sFu0D65G+miZRCuJyJ0G13Zwx7vRar5Zhn2tkQNzIXcBrNVsv/8stehpj+GAjgbg==} + engines: {node: '>=12'} + hasBin: true + requiresBuild: true + optionalDependencies: + '@esbuild/aix-ppc64': 0.19.12 + '@esbuild/android-arm': 0.19.12 + '@esbuild/android-arm64': 0.19.12 + '@esbuild/android-x64': 0.19.12 + '@esbuild/darwin-arm64': 0.19.12 + '@esbuild/darwin-x64': 0.19.12 + '@esbuild/freebsd-arm64': 0.19.12 + '@esbuild/freebsd-x64': 0.19.12 + '@esbuild/linux-arm': 0.19.12 + '@esbuild/linux-arm64': 0.19.12 + '@esbuild/linux-ia32': 0.19.12 + '@esbuild/linux-loong64': 0.19.12 + '@esbuild/linux-mips64el': 0.19.12 + '@esbuild/linux-ppc64': 0.19.12 + '@esbuild/linux-riscv64': 0.19.12 + '@esbuild/linux-s390x': 0.19.12 + '@esbuild/linux-x64': 0.19.12 + '@esbuild/netbsd-x64': 0.19.12 + '@esbuild/openbsd-x64': 0.19.12 + '@esbuild/sunos-x64': 0.19.12 + '@esbuild/win32-arm64': 0.19.12 + '@esbuild/win32-ia32': 0.19.12 + '@esbuild/win32-x64': 0.19.12 + dev: true + /escalade@3.1.1: resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==} engines: {node: '>=6'} @@ -3747,6 +3988,17 @@ packages: - ts-node dev: true + /tsx@4.7.1: + resolution: {integrity: sha512-8d6VuibXHtlN5E3zFkgY8u4DX7Y3Z27zvvPKVmLon/D4AjuKzarkUBTLDBgj9iTQ0hg5xM7c/mYiRVM+HETf0g==} + engines: {node: '>=18.0.0'} + hasBin: true + dependencies: + esbuild: 0.19.12 + get-tsconfig: 4.7.2 + optionalDependencies: + fsevents: 2.3.3 + dev: true + /type-check@0.4.0: resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==} engines: {node: '>= 0.8.0'} diff --git a/src/constants/component.ts b/src/constants/component.ts index a0ff158..9afe3aa 100644 --- a/src/constants/component.ts +++ b/src/constants/component.ts @@ -1,324 +1,6 @@ -// TODO:(winches)Temporary data for the components -export const nextUIComponents = [ - { - description: - 'Collapse display a list of high-level options that can expand/collapse to reveal more information.', - docs: 'https://nextui.org/docs/components/accordion', - name: 'accordion', - package: '@nextui-org/accordion', - status: 'stable', - version: '2.0.28' - }, - { - description: - 'An autocomplete combines a text input with a listbox, allowing users to filter a list of options to items matching a query.', - docs: 'https://nextui.org/docs/components/autocomplete', - name: 'autocomplete', - package: '@nextui-org/autocomplete', - status: 'newPost', - version: '2.0.10' - }, - { - description: - 'The Avatar component is used to represent a user, and displays the profile picture, initials or fallback icon.', - docs: 'https://nextui.org/docs/components/avatar', - name: 'avatar', - package: '@nextui-org/avatar', - status: 'stable', - version: '2.0.24' - }, - { - description: 'Badges are used as a small numerical value or status descriptor for UI elements.', - docs: 'https://nextui.org/docs/components/badge', - name: 'badge', - package: '@nextui-org/badge', - status: 'stable', - version: '2.0.24' - }, - { - description: - 'Breadcrumbs display a hierarchy of links to the current page or resource in an application.', - docs: 'https://nextui.org/docs/components/breadcrumbs', - name: 'breadcrumbs', - package: '@nextui-org/breadcrumbs', - status: 'newPost', - version: '2.0.4' - }, - { - description: 'Buttons allow users to perform actions and choose with a single tap.', - docs: 'https://nextui.org/docs/components/button', - name: 'button', - package: '@nextui-org/button', - status: 'stable', - version: '2.0.27' - }, - { - description: - 'Card is a container for text, photos, and actions in the context of a single subject.', - docs: 'https://nextui.org/docs/components/card', - name: 'card', - package: '@nextui-org/card', - status: 'stable', - version: '2.0.24' - }, - { - description: - 'Checkboxes allow users to select multiple items from a list of individual items, or to mark one individual item as selected.', - docs: 'https://nextui.org/docs/components/checkbox', - name: 'checkbox', - package: '@nextui-org/checkbox', - status: 'stable', - version: '2.0.25' - }, - { - description: - 'Chips help people enter information, make selections, filter content, or trigger actions.', - docs: 'https://nextui.org/docs/components/chip', - name: 'chip', - package: '@nextui-org/chip', - status: 'stable', - version: '2.0.25' - }, - { - description: 'Code is a component used to display inline code.', - docs: 'https://nextui.org/docs/components/code', - name: 'code', - package: '@nextui-org/code', - status: 'stable', - version: '2.0.24' - }, - { - description: '. A separator is a visual divider between two groups of content', - docs: 'https://nextui.org/docs/components/divider', - name: 'divider', - package: '@nextui-org/divider', - status: 'stable', - version: '2.0.25' - }, - { - description: 'A dropdown displays a list of actions or options that a user can choose.', - docs: 'https://nextui.org/docs/components/dropdown', - name: 'dropdown', - package: '@nextui-org/dropdown', - status: 'updated', - version: '2.1.17' - }, - { - description: 'A simple image component', - docs: 'https://nextui.org/docs/components/image', - name: 'image', - package: '@nextui-org/image', - status: 'stable', - version: '2.0.24' - }, - { - description: 'The input component is designed for capturing user input within a text field.', - docs: 'https://nextui.org/docs/components/input', - name: 'input', - package: '@nextui-org/input', - status: 'stable', - version: '2.1.17' - }, - { - description: - 'The keyboard key components indicates which key or set of keys used to execute a specificv action', - docs: 'https://nextui.org/docs/components/kbd', - name: 'kbd', - package: '@nextui-org/kbd', - status: 'stable', - version: '2.0.25' - }, - { - description: - 'Links allow users to click their way from page to page. This component is styled to resemble a hyperlink and semantically renders an <a>', - docs: 'https://nextui.org/docs/components/link', - name: 'link', - package: '@nextui-org/link', - status: 'updated', - version: '2.0.26' - }, - { - description: - 'A listbox displays a list of options and allows a user to select one or more of them.', - docs: 'https://nextui.org/docs/components/listbox', - name: 'listbox', - package: '@nextui-org/listbox', - status: 'updated', - version: '2.1.16' - }, - { - description: - 'A menu displays a list of options and allows a user to select one or more of them.', - docs: 'https://nextui.org/docs/components/menu', - name: 'menu', - package: '@nextui-org/menu', - status: 'stable', - version: '2.0.17' - }, - { - description: - 'Displays a dialog with a custom content that requires attention or provides additional information.', - docs: 'https://nextui.org/docs/components/modal', - name: 'modal', - package: '@nextui-org/modal', - status: 'stable', - version: '2.0.29' - }, - { - description: - 'A responsive navigation header positioned on top side of your page that includes support for branding, links, navigation, collapse and more.', - docs: 'https://nextui.org/docs/components/navbar', - name: 'navbar', - package: '@nextui-org/navbar', - status: 'stable', - version: '2.0.27' - }, - { - description: - 'The Pagination component allows you to display active page and navigate between multiple pages.', - docs: 'https://nextui.org/docs/components/pagination', - name: 'pagination', - package: '@nextui-org/pagination', - status: 'stable', - version: '2.0.27' - }, - { - description: 'A popover is an overlay element positioned relative to a trigger.', - docs: 'https://nextui.org/docs/components/popover', - name: 'popover', - package: '@nextui-org/popover', - status: 'stable', - version: '2.1.15' - }, - { - description: - 'Progress bars show either determinate or indeterminate progress of an operation over time.', - docs: 'https://nextui.org/docs/components/progress', - name: 'progress', - package: '@nextui-org/progress', - status: 'stable', - version: '2.0.25' - }, - { - description: - 'Radios allow users to select a single option from a list of mutually exclusive options.', - docs: 'https://nextui.org/docs/components/radio', - name: 'radio', - package: '@nextui-org/radio', - status: 'stable', - version: '2.0.25' - }, - { - description: - 'A simple implementation to display a ripple animation when the source component is clicked', - docs: 'https://nextui.org/docs/components/ripple', - name: 'ripple', - package: '@nextui-org/ripple', - status: 'stable', - version: '2.0.24' - }, - { - description: - 'A component that applies top and bottom shadows when content overflows on scroll.', - docs: 'https://nextui.org/docs/components/scroll-shadow', - name: 'scroll-shadow', - package: '@nextui-org/scroll-shadow', - status: 'stable', - version: '2.1.13' - }, - { - description: - 'A select displays a collapsible list of options and allows a user to select one of them.', - docs: 'https://nextui.org/docs/components/select', - name: 'select', - package: '@nextui-org/select', - status: 'stable', - version: '2.1.21' - }, - { - description: 'Skeleton is used to display the loading state of some component.', - docs: 'https://nextui.org/docs/components/skeleton', - name: 'skeleton', - package: '@nextui-org/skeleton', - status: 'stable', - version: '2.0.24' - }, - { - description: 'A slider allows a user to select one or more values within a range.', - docs: 'https://nextui.org/docs/components/slider', - name: 'slider', - package: '@nextui-org/slider', - status: 'newPost', - version: '2.2.6' - }, - { - description: 'Display a snippet of copyable code for the command line.', - docs: 'https://nextui.org/docs/components/snippet', - name: 'snippet', - package: '@nextui-org/snippet', - status: 'stable', - version: '2.0.31' - }, - { - description: - 'A flexible spacer component designed to create consistent spacing and maintain alignment in your layout.', - docs: 'https://nextui.org/docs/components/spacer', - name: 'spacer', - package: '@nextui-org/spacer', - status: 'stable', - version: '2.0.24' - }, - { - description: 'Loaders express an unspecified wait time or display the length of a process.', - docs: 'https://nextui.org/docs/components/spinner', - name: 'spinner', - package: '@nextui-org/spinner', - status: 'stable', - version: '2.0.25' - }, - { - description: - 'A switch is similar to a checkbox, but represents on/off values as opposed to selection.', - docs: 'https://nextui.org/docs/components/switch', - name: 'switch', - package: '@nextui-org/switch', - status: 'stable', - version: '2.0.25' - }, - { - description: 'Tables are used to display tabular data using rows and columns. ', - docs: 'https://nextui.org/docs/components/table', - name: 'table', - package: '@nextui-org/table', - status: 'stable', - version: '2.0.28' - }, - { - description: - 'Tabs organize content into multiple sections and allow users to navigate between them.', - docs: 'https://nextui.org/docs/components/tabs', - name: 'tabs', - package: '@nextui-org/tabs', - status: 'updated', - version: '2.0.26' - }, - { - description: 'A React Component for rendering dynamically positioned Tooltips', - docs: 'https://nextui.org/docs/components/tooltip', - name: 'tooltip', - package: '@nextui-org/tooltip', - status: 'stable', - version: '2.0.30' - }, - { - description: 'Flexible User Profile Component.', - docs: 'https://nextui.org/docs/components/user', - name: 'user', - package: '@nextui-org/user', - status: 'stable', - version: '2.0.25' - } -]; +import {getComponents} from 'src/scripts/helpers'; + +export const nextUIComponents = (await getComponents()).components; export const orderNextUIComponentKeys = ['package', 'version', 'status', 'docs'] as const; diff --git a/src/constants/components.json b/src/constants/components.json new file mode 100644 index 0000000..40bb89d --- /dev/null +++ b/src/constants/components.json @@ -0,0 +1,301 @@ +{ + "components": [ + { + "name": "accordion", + "package": "@nextui-org/accordion", + "version": "2.0.28", + "docs": "https://nextui.org/docs/components/accordion", + "description": "Collapse display a list of high-level options that can expand/collapse to reveal more information.", + "status": "stable" + }, + { + "name": "autocomplete", + "package": "@nextui-org/autocomplete", + "version": "2.0.10", + "docs": "https://nextui.org/docs/components/autocomplete", + "description": "An autocomplete combines a text input with a listbox, allowing users to filter a list of options to items matching a query.", + "status": "newPost" + }, + { + "name": "avatar", + "package": "@nextui-org/avatar", + "version": "2.0.24", + "docs": "https://nextui.org/docs/components/avatar", + "description": "The Avatar component is used to represent a user, and displays the profile picture, initials or fallback icon.", + "status": "stable" + }, + { + "name": "badge", + "package": "@nextui-org/badge", + "version": "2.0.24", + "docs": "https://nextui.org/docs/components/badge", + "description": "Badges are used as a small numerical value or status descriptor for UI elements.", + "status": "stable" + }, + { + "name": "breadcrumbs", + "package": "@nextui-org/breadcrumbs", + "version": "2.0.4", + "docs": "https://nextui.org/docs/components/breadcrumbs", + "description": "Breadcrumbs display a hierarchy of links to the current page or resource in an application.", + "status": "newPost" + }, + { + "name": "button", + "package": "@nextui-org/button", + "version": "2.0.27", + "docs": "https://nextui.org/docs/components/button", + "description": "Buttons allow users to perform actions and choose with a single tap.", + "status": "stable" + }, + { + "name": "card", + "package": "@nextui-org/card", + "version": "2.0.24", + "docs": "https://nextui.org/docs/components/card", + "description": "Card is a container for text, photos, and actions in the context of a single subject.", + "status": "stable" + }, + { + "name": "checkbox", + "package": "@nextui-org/checkbox", + "version": "2.0.25", + "docs": "https://nextui.org/docs/components/checkbox", + "description": "Checkboxes allow users to select multiple items from a list of individual items, or to mark one individual item as selected.", + "status": "stable" + }, + { + "name": "chip", + "package": "@nextui-org/chip", + "version": "2.0.25", + "docs": "https://nextui.org/docs/components/chip", + "description": "Chips help people enter information, make selections, filter content, or trigger actions.", + "status": "stable" + }, + { + "name": "code", + "package": "@nextui-org/code", + "version": "2.0.24", + "docs": "https://nextui.org/docs/components/code", + "description": "Code is a component used to display inline code.", + "status": "stable" + }, + { + "name": "divider", + "package": "@nextui-org/divider", + "version": "2.0.25", + "docs": "https://nextui.org/docs/components/divider", + "description": ". A separator is a visual divider between two groups of content", + "status": "stable" + }, + { + "name": "dropdown", + "package": "@nextui-org/dropdown", + "version": "2.1.17", + "docs": "https://nextui.org/docs/components/dropdown", + "description": "A dropdown displays a list of actions or options that a user can choose.", + "status": "updated" + }, + { + "name": "image", + "package": "@nextui-org/image", + "version": "2.0.24", + "docs": "https://nextui.org/docs/components/image", + "description": "A simple image component", + "status": "stable" + }, + { + "name": "input", + "package": "@nextui-org/input", + "version": "2.1.17", + "docs": "https://nextui.org/docs/components/input", + "description": "The input component is designed for capturing user input within a text field.", + "status": "stable" + }, + { + "name": "kbd", + "package": "@nextui-org/kbd", + "version": "2.0.25", + "docs": "https://nextui.org/docs/components/kbd", + "description": "The keyboard key components indicates which key or set of keys used to execute a specificv action", + "status": "stable" + }, + { + "name": "link", + "package": "@nextui-org/link", + "version": "2.0.26", + "docs": "https://nextui.org/docs/components/link", + "description": "Links allow users to click their way from page to page. This component is styled to resemble a hyperlink and semantically renders an <a>", + "status": "updated" + }, + { + "name": "listbox", + "package": "@nextui-org/listbox", + "version": "2.1.16", + "docs": "https://nextui.org/docs/components/listbox", + "description": "A listbox displays a list of options and allows a user to select one or more of them.", + "status": "updated" + }, + { + "name": "menu", + "package": "@nextui-org/menu", + "version": "2.0.17", + "docs": "https://nextui.org/docs/components/menu", + "description": "A menu displays a list of options and allows a user to select one or more of them.", + "status": "stable" + }, + { + "name": "modal", + "package": "@nextui-org/modal", + "version": "2.0.29", + "docs": "https://nextui.org/docs/components/modal", + "description": "Displays a dialog with a custom content that requires attention or provides additional information.", + "status": "stable" + }, + { + "name": "navbar", + "package": "@nextui-org/navbar", + "version": "2.0.27", + "docs": "https://nextui.org/docs/components/navbar", + "description": "A responsive navigation header positioned on top side of your page that includes support for branding, links, navigation, collapse and more.", + "status": "stable" + }, + { + "name": "pagination", + "package": "@nextui-org/pagination", + "version": "2.0.27", + "docs": "https://nextui.org/docs/components/pagination", + "description": "The Pagination component allows you to display active page and navigate between multiple pages.", + "status": "stable" + }, + { + "name": "popover", + "package": "@nextui-org/popover", + "version": "2.1.15", + "docs": "https://nextui.org/docs/components/popover", + "description": "A popover is an overlay element positioned relative to a trigger.", + "status": "stable" + }, + { + "name": "progress", + "package": "@nextui-org/progress", + "version": "2.0.25", + "docs": "https://nextui.org/docs/components/progress", + "description": "Progress bars show either determinate or indeterminate progress of an operation over time.", + "status": "stable" + }, + { + "name": "radio", + "package": "@nextui-org/radio", + "version": "2.0.25", + "docs": "https://nextui.org/docs/components/radio", + "description": "Radios allow users to select a single option from a list of mutually exclusive options.", + "status": "stable" + }, + { + "name": "ripple", + "package": "@nextui-org/ripple", + "version": "2.0.24", + "docs": "https://nextui.org/docs/components/ripple", + "description": "A simple implementation to display a ripple animation when the source component is clicked", + "status": "stable" + }, + { + "name": "scroll-shadow", + "package": "@nextui-org/scroll-shadow", + "version": "2.1.13", + "docs": "https://nextui.org/docs/components/scroll-shadow", + "description": "A component that applies top and bottom shadows when content overflows on scroll.", + "status": "stable" + }, + { + "name": "select", + "package": "@nextui-org/select", + "version": "2.1.21", + "docs": "https://nextui.org/docs/components/select", + "description": "A select displays a collapsible list of options and allows a user to select one of them.", + "status": "stable" + }, + { + "name": "skeleton", + "package": "@nextui-org/skeleton", + "version": "2.0.24", + "docs": "https://nextui.org/docs/components/skeleton", + "description": "Skeleton is used to display the loading state of some component.", + "status": "stable" + }, + { + "name": "slider", + "package": "@nextui-org/slider", + "version": "2.2.6", + "docs": "https://nextui.org/docs/components/slider", + "description": "A slider allows a user to select one or more values within a range.", + "status": "newPost" + }, + { + "name": "snippet", + "package": "@nextui-org/snippet", + "version": "2.0.31", + "docs": "https://nextui.org/docs/components/snippet", + "description": "Display a snippet of copyable code for the command line.", + "status": "stable" + }, + { + "name": "spacer", + "package": "@nextui-org/spacer", + "version": "2.0.24", + "docs": "https://nextui.org/docs/components/spacer", + "description": "A flexible spacer component designed to create consistent spacing and maintain alignment in your layout.", + "status": "stable" + }, + { + "name": "spinner", + "package": "@nextui-org/spinner", + "version": "2.0.25", + "docs": "https://nextui.org/docs/components/spinner", + "description": "Loaders express an unspecified wait time or display the length of a process.", + "status": "stable" + }, + { + "name": "switch", + "package": "@nextui-org/switch", + "version": "2.0.25", + "docs": "https://nextui.org/docs/components/switch", + "description": "A switch is similar to a checkbox, but represents on/off values as opposed to selection.", + "status": "stable" + }, + { + "name": "table", + "package": "@nextui-org/table", + "version": "2.0.28", + "docs": "https://nextui.org/docs/components/table", + "description": "Tables are used to display tabular data using rows and columns. ", + "status": "stable" + }, + { + "name": "tabs", + "package": "@nextui-org/tabs", + "version": "2.0.26", + "docs": "https://nextui.org/docs/components/tabs", + "description": "Tabs organize content into multiple sections and allow users to navigate between them.", + "status": "updated" + }, + { + "name": "tooltip", + "package": "@nextui-org/tooltip", + "version": "2.0.30", + "docs": "https://nextui.org/docs/components/tooltip", + "description": "A React Component for rendering dynamically positioned Tooltips", + "status": "stable" + }, + { + "name": "user", + "package": "@nextui-org/user", + "version": "2.0.25", + "docs": "https://nextui.org/docs/components/user", + "description": "Flexible User Profile Component.", + "status": "stable" + } + ], + "version": "0.0.0-dev-v2-20240331183656" +} diff --git a/src/constants/path.ts b/src/constants/path.ts index 4513e47..c79ed5a 100644 --- a/src/constants/path.ts +++ b/src/constants/path.ts @@ -1,4 +1,7 @@ import {resolve} from 'path'; +import {fileURLToPath} from 'url'; export const ROOT = process.cwd(); export const resolver = (path: string) => resolve(ROOT, path); + +export const COMPONENTS_PATH = resolve(fileURLToPath(import.meta.url), '../components.json'); diff --git a/src/scripts/helpers.ts b/src/scripts/helpers.ts new file mode 100644 index 0000000..aeea0ee --- /dev/null +++ b/src/scripts/helpers.ts @@ -0,0 +1,117 @@ +import {exec} from 'child_process'; +import {existsSync, readFileSync, writeFileSync} from 'fs'; + +import retry from 'async-retry'; + +import {Logger} from '@helpers/logger'; +import {COMPONENTS_PATH} from 'src/constants/path'; + +export type Components = { + name: string; + package: string; + version: string; + docs: string; + description: string; + status: string; +}[]; + +export type ComponentsJson = { + version: string; + components: Components; +}; + +export async function updateComponents() { + if (!existsSync(COMPONENTS_PATH)) { + // First time download the latest date from net + await autoUpdateComponents(); + + return; + } + // const latestVersion = await getLatestVersion('@nextui-org/react'); + // TODO:(winches) Remove this after the NextUI first release + const latestVersion = '0.0.0-dev-v2-20240331183656'; + + const components = JSON.parse(readFileSync(COMPONENTS_PATH, 'utf-8')) as ComponentsJson; + const currentVersion = components.version; + + if (currentVersion !== latestVersion) { + // After the first time, check the version and update + await autoUpdateComponents(); + + return; + } +} + +export async function getComponents() { + let components: ComponentsJson = {} as ComponentsJson; + + await updateComponents(); + + try { + components = JSON.parse(readFileSync(COMPONENTS_PATH, 'utf-8')) as ComponentsJson; + } catch (error) { + new Error(`Get components.json error: ${error}`); + } + + return components; +} + +export async function getLatestVersion(packageName: string): Promise { + return new Promise((resolve, reject) => { + exec(`npm view ${packageName} version`, (error, stdout) => { + if (error) { + Logger.error(`Get latest ${packageName} error: ${error}`); + reject(error); + } + resolve(stdout.trim()); + }); + }); +} + +const getUnpkgUrl = (version: string) => + `https://unpkg.com/@nextui-org/react@${version}/dist/components.json`; + +export async function autoUpdateComponents() { + // TODO:(winches) Remove this after the NextUI first release + const url = getUnpkgUrl('0.0.0-dev-v2-20240331183656'); + + const components = await downloadFile(url); + + const componentsJson = { + components, + // TODO:(winches) Remove this after the NextUI first release + version: '0.0.0-dev-v2-20240331183656' + }; + + writeFileSync(COMPONENTS_PATH, JSON.stringify(componentsJson, null, 2), 'utf-8'); +} + +export async function downloadFile(url: string): Promise { + let data; + + await retry( + async (bail) => { + try { + const result = await fetch(url, { + body: null, + headers: { + 'Content-Type': 'application/json', + accept: + 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' + }, + method: 'GET', + mode: 'cors' + }); + + data = JSON.parse(await result.text()); + } catch (error) { + bail(error); + } + }, + { + retries: 3 + } + ); + + return data; +} diff --git a/src/scripts/path.ts b/src/scripts/path.ts new file mode 100644 index 0000000..69a6079 --- /dev/null +++ b/src/scripts/path.ts @@ -0,0 +1,6 @@ +import {resolve} from 'path'; +import {fileURLToPath} from 'url'; + +export const ROOT = resolve(fileURLToPath(import.meta.url), '../..'); + +export const resolver = (path: string) => resolve(ROOT, path); diff --git a/src/scripts/update/update-components.ts b/src/scripts/update/update-components.ts new file mode 100644 index 0000000..2b75165 --- /dev/null +++ b/src/scripts/update/update-components.ts @@ -0,0 +1,3 @@ +import {updateComponents} from '../helpers'; + +updateComponents(); diff --git a/tsup.config.ts b/tsup.config.ts index 392c3fd..34bfc0b 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -12,7 +12,7 @@ export default defineConfig((options) => { skipNodeModulesBundle: true, sourcemap: true, splitting: false, - target: 'es2019', + target: 'esnext', treeshake: true, tsconfig: 'tsconfig.json' };