From 44767175533e9cf0da585d183f4e5f91ad22e7d3 Mon Sep 17 00:00:00 2001 From: Northword Date: Tue, 28 Nov 2023 22:26:10 +0800 Subject: [PATCH 1/9] =?UTF-8?q?chore:=20=E4=BF=AE=E6=94=B9`ts-node`?= =?UTF-8?q?=E4=B8=BA`tsx`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 17 ++- pnpm-lock.yaml | 393 ++++++++++++++++++++++++++++++++++++------------- tsconfig.json | 4 + 3 files changed, 307 insertions(+), 107 deletions(-) diff --git a/package.json b/package.json index 6cf632a..b96cb93 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,10 @@ "description": "Zotero 插件合集", "main": "index.js", "scripts": { - "get-info": "cd src && ts-node index.ts releases && cd ..", - "get-chart": "cd src && ts-node index.ts charts && cd ..", - "debug": "cross-env NODE_ENV=development npm run get-chart", + "get-info": "cd src && tsx index.ts releases && cd ..", + "get-chart": "cd src && tsx index.ts charts && cd ..", + "debug:info": "cross-env NODE_ENV=development npm run get-info", + "debug:chart": "cross-env NODE_ENV=development npm run get-chart", "website": "docsify serve docs", "test": "echo \"Error: no test specified\" && exit 1" }, @@ -23,8 +24,11 @@ "type": "module", "devDependencies": { "@highcharts/dashboards": "^1.1.2", + "@types/adm-zip": "^0.5.5", "@types/node": "^20.10.0", + "@types/xml2js": "^0.4.14", "@vitalets/google-translate-api": "^9.2.0", + "adm-zip": "^0.5.10", "cross-env": "^7.0.3", "docsify-cli": "^4.4.4", "franc-min": "^6.1.0", @@ -32,7 +36,10 @@ "highcharts": "^11.2.0", "markdown-table-ts": "^1.0.3", "octokit": "^3.1.2", - "ts-node": "^10.9.1", - "typescript": "^5.3.2" + "typescript": "^5.3.2", + "xml2js": "^0.6.2" + }, + "dependencies": { + "tsx": "^4.6.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 20d3090..26fbe03 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,16 +4,30 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false +dependencies: + tsx: + specifier: ^4.6.0 + version: 4.6.0 + devDependencies: '@highcharts/dashboards': specifier: ^1.1.2 version: 1.1.2(highcharts@11.2.0) + '@types/adm-zip': + specifier: ^0.5.5 + version: 0.5.5 '@types/node': specifier: ^20.10.0 version: 20.10.0 + '@types/xml2js': + specifier: ^0.4.14 + version: 0.4.14 '@vitalets/google-translate-api': specifier: ^9.2.0 version: 9.2.0 + adm-zip: + specifier: ^0.5.10 + version: 0.5.10 cross-env: specifier: ^7.0.3 version: 7.0.3 @@ -35,21 +49,212 @@ devDependencies: octokit: specifier: ^3.1.2 version: 3.1.2 - ts-node: - specifier: ^10.9.1 - version: 10.9.1(@types/node@20.10.0)(typescript@5.3.2) typescript: specifier: ^5.3.2 version: 5.3.2 + xml2js: + specifier: ^0.6.2 + version: 0.6.2 packages: - /@cspotcode/source-map-support@0.8.1: - resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==} + /@esbuild/android-arm64@0.18.20: + resolution: {integrity: sha512-Nz4rJcchGDtENV0eMKUNa6L12zz2zBDXuhj/Vjh18zGqB44Bi7MBMSXjgunJgjRhCmKOjnPuZp4Mb6OKqtMHLQ==} engines: {node: '>=12'} - dependencies: - '@jridgewell/trace-mapping': 0.3.9 - dev: true + cpu: [arm64] + os: [android] + requiresBuild: true + dev: false + optional: true + + /@esbuild/android-arm@0.18.20: + resolution: {integrity: sha512-fyi7TDI/ijKKNZTUJAQqiG5T7YjJXgnzkURqmGj13C6dCqckZBLdl4h7bkhHt/t0WP+zO9/zwroDvANaOqO5Sw==} + engines: {node: '>=12'} + cpu: [arm] + os: [android] + requiresBuild: true + dev: false + optional: true + + /@esbuild/android-x64@0.18.20: + resolution: {integrity: sha512-8GDdlePJA8D6zlZYJV/jnrRAi6rOiNaCC/JclcXpB+KIuvfBN4owLtgzY2bsxnx666XjJx2kDPUmnTtR8qKQUg==} + engines: {node: '>=12'} + cpu: [x64] + os: [android] + requiresBuild: true + dev: false + optional: true + + /@esbuild/darwin-arm64@0.18.20: + resolution: {integrity: sha512-bxRHW5kHU38zS2lPTPOyuyTm+S+eobPUnTNkdJEfAddYgEcll4xkT8DB9d2008DtTbl7uJag2HuE5NZAZgnNEA==} + engines: {node: '>=12'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + + /@esbuild/darwin-x64@0.18.20: + resolution: {integrity: sha512-pc5gxlMDxzm513qPGbCbDukOdsGtKhfxD1zJKXjCCcU7ju50O7MeAZ8c4krSJcOIJGFR+qx21yMMVYwiQvyTyQ==} + engines: {node: '>=12'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + + /@esbuild/freebsd-arm64@0.18.20: + resolution: {integrity: sha512-yqDQHy4QHevpMAaxhhIwYPMv1NECwOvIpGCZkECn8w2WFHXjEwrBn3CeNIYsibZ/iZEUemj++M26W3cNR5h+Tw==} + engines: {node: '>=12'} + cpu: [arm64] + os: [freebsd] + requiresBuild: true + dev: false + optional: true + + /@esbuild/freebsd-x64@0.18.20: + resolution: {integrity: sha512-tgWRPPuQsd3RmBZwarGVHZQvtzfEBOreNuxEMKFcd5DaDn2PbBxfwLcj4+aenoh7ctXcbXmOQIn8HI6mCSw5MQ==} + engines: {node: '>=12'} + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: false + optional: true + + /@esbuild/linux-arm64@0.18.20: + resolution: {integrity: sha512-2YbscF+UL7SQAVIpnWvYwM+3LskyDmPhe31pE7/aoTMFKKzIc9lLbyGUpmmb8a8AixOL61sQ/mFh3jEjHYFvdA==} + engines: {node: '>=12'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@esbuild/linux-arm@0.18.20: + resolution: {integrity: sha512-/5bHkMWnq1EgKr1V+Ybz3s1hWXok7mDFUMQ4cG10AfW3wL02PSZi5kFpYKrptDsgb2WAJIvRcDm+qIvXf/apvg==} + engines: {node: '>=12'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@esbuild/linux-ia32@0.18.20: + resolution: {integrity: sha512-P4etWwq6IsReT0E1KHU40bOnzMHoH73aXp96Fs8TIT6z9Hu8G6+0SHSw9i2isWrD2nbx2qo5yUqACgdfVGx7TA==} + engines: {node: '>=12'} + cpu: [ia32] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@esbuild/linux-loong64@0.18.20: + resolution: {integrity: sha512-nXW8nqBTrOpDLPgPY9uV+/1DjxoQ7DoB2N8eocyq8I9XuqJ7BiAMDMf9n1xZM9TgW0J8zrquIb/A7s3BJv7rjg==} + engines: {node: '>=12'} + cpu: [loong64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@esbuild/linux-mips64el@0.18.20: + resolution: {integrity: sha512-d5NeaXZcHp8PzYy5VnXV3VSd2D328Zb+9dEq5HE6bw6+N86JVPExrA6O68OPwobntbNJ0pzCpUFZTo3w0GyetQ==} + engines: {node: '>=12'} + cpu: [mips64el] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@esbuild/linux-ppc64@0.18.20: + resolution: {integrity: sha512-WHPyeScRNcmANnLQkq6AfyXRFr5D6N2sKgkFo2FqguP44Nw2eyDlbTdZwd9GYk98DZG9QItIiTlFLHJHjxP3FA==} + engines: {node: '>=12'} + cpu: [ppc64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@esbuild/linux-riscv64@0.18.20: + resolution: {integrity: sha512-WSxo6h5ecI5XH34KC7w5veNnKkju3zBRLEQNY7mv5mtBmrP/MjNBCAlsM2u5hDBlS3NGcTQpoBvRzqBcRtpq1A==} + engines: {node: '>=12'} + cpu: [riscv64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@esbuild/linux-s390x@0.18.20: + resolution: {integrity: sha512-+8231GMs3mAEth6Ja1iK0a1sQ3ohfcpzpRLH8uuc5/KVDFneH6jtAJLFGafpzpMRO6DzJ6AvXKze9LfFMrIHVQ==} + engines: {node: '>=12'} + cpu: [s390x] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@esbuild/linux-x64@0.18.20: + resolution: {integrity: sha512-UYqiqemphJcNsFEskc73jQ7B9jgwjWrSayxawS6UVFZGWrAAtkzjxSqnoclCXxWtfwLdzU+vTpcNYhpn43uP1w==} + engines: {node: '>=12'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@esbuild/netbsd-x64@0.18.20: + resolution: {integrity: sha512-iO1c++VP6xUBUmltHZoMtCUdPlnPGdBom6IrO4gyKPFFVBKioIImVooR5I83nTew5UOYrk3gIJhbZh8X44y06A==} + engines: {node: '>=12'} + cpu: [x64] + os: [netbsd] + requiresBuild: true + dev: false + optional: true + + /@esbuild/openbsd-x64@0.18.20: + resolution: {integrity: sha512-e5e4YSsuQfX4cxcygw/UCPIEP6wbIL+se3sxPdCiMbFLBWu0eiZOJ7WoD+ptCLrmjZBK1Wk7I6D/I3NglUGOxg==} + engines: {node: '>=12'} + cpu: [x64] + os: [openbsd] + requiresBuild: true + dev: false + optional: true + + /@esbuild/sunos-x64@0.18.20: + resolution: {integrity: sha512-kDbFRFp0YpTQVVrqUd5FTYmWo45zGaXe0X8E1G/LKFC0v8x0vWrhOWSLITcCn63lmZIxfOMXtCfti/RxN/0wnQ==} + engines: {node: '>=12'} + cpu: [x64] + os: [sunos] + requiresBuild: true + dev: false + optional: true + + /@esbuild/win32-arm64@0.18.20: + resolution: {integrity: sha512-ddYFR6ItYgoaq4v4JmQQaAI5s7npztfV4Ag6NrhiaW0RrnOXqBkgwZLofVTlq1daVTQNhtI5oieTvkRPfZrePg==} + engines: {node: '>=12'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: false + optional: true + + /@esbuild/win32-ia32@0.18.20: + resolution: {integrity: sha512-Wv7QBi3ID/rROT08SABTS7eV4hX26sVduqDOTe1MvGMjNd3EjOz4b7zeexIR62GTIEKrfJXKL9LFxTYgkyeu7g==} + engines: {node: '>=12'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: false + optional: true + + /@esbuild/win32-x64@0.18.20: + resolution: {integrity: sha512-kTdfRcSiDfQca/y9QIkng02avJ+NCaQvrMejlsB3RRv5sE9rRoeBPISaZpKxHELzRxZyLvNts1P27W3wV+8geQ==} + engines: {node: '>=12'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: false + optional: true /@highcharts/dashboards@1.1.2(highcharts@11.2.0): resolution: {integrity: sha512-MJRLTObjUcfiiFUZFeuz+5/mbuJQkCq4l2e1U39DqA/Ym1mHacFpRk0XrJgpkqgJVP/Yrtr/hkyC2+iJrWAV4g==} @@ -59,22 +264,6 @@ packages: highcharts: 11.2.0 dev: true - /@jridgewell/resolve-uri@3.1.1: - resolution: {integrity: sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==} - engines: {node: '>=6.0.0'} - dev: true - - /@jridgewell/sourcemap-codec@1.4.15: - resolution: {integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==} - dev: true - - /@jridgewell/trace-mapping@0.3.9: - resolution: {integrity: sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==} - dependencies: - '@jridgewell/resolve-uri': 3.1.1 - '@jridgewell/sourcemap-codec': 1.4.15 - dev: true - /@octokit/app@14.0.2: resolution: {integrity: sha512-NCSCktSx+XmjuSUVn2dLfqQ9WIYePGP95SDJs4I9cn/0ZkeXcPkaoCLl64Us3dRKL2ozC7hArwze5Eu+/qt1tg==} engines: {node: '>= 18'} @@ -323,20 +512,10 @@ packages: defer-to-connect: 1.1.3 dev: true - /@tsconfig/node10@1.0.9: - resolution: {integrity: sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==} - dev: true - - /@tsconfig/node12@1.0.11: - resolution: {integrity: sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==} - dev: true - - /@tsconfig/node14@1.0.3: - resolution: {integrity: sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==} - dev: true - - /@tsconfig/node16@1.0.4: - resolution: {integrity: sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==} + /@types/adm-zip@0.5.5: + resolution: {integrity: sha512-YCGstVMjc4LTY5uK9/obvxBya93axZOVOyf2GSUulADzmLhYE45u2nAssCs/fWBs1Ifq5Vat75JTPwd5XZoPJw==} + dependencies: + '@types/node': 20.10.0 dev: true /@types/aws-lambda@8.10.129: @@ -375,6 +554,12 @@ packages: '@types/node': 20.10.0 dev: true + /@types/xml2js@0.4.14: + resolution: {integrity: sha512-4YnrRemBShWRO2QjvUin8ESA41rH+9nQGLUGZV/1IDhi3SL9OhdpNC/MrulTWuptXKwhx/aDxE7toV0f/ypIXQ==} + dependencies: + '@types/node': 20.10.0 + dev: true + /@vitalets/google-translate-api@9.2.0: resolution: {integrity: sha512-w98IPWGuexlGmh8Y19AxF6cgWT0U5JLevVNDKEuFpTWtBC9z3YtDWKTDxF3nPP1k9bWicuB1V7I7YfHoZiDScw==} engines: {node: '>=14'} @@ -386,15 +571,9 @@ packages: - encoding dev: true - /acorn-walk@8.3.0: - resolution: {integrity: sha512-FS7hV565M5l1R08MXqo8odwMTB02C2UqzB17RVgu9EyuYFBqJZ3/ZY97sQD5FewVu1UyDFc1yztUDrAwT0EypA==} - engines: {node: '>=0.4.0'} - dev: true - - /acorn@8.11.2: - resolution: {integrity: sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==} - engines: {node: '>=0.4.0'} - hasBin: true + /adm-zip@0.5.10: + resolution: {integrity: sha512-x0HvcHqVJNTPk/Bw8JbLWlWoo6Wwnsug0fnYYro1HBrjxZ3G7/AZk7Ahv8JwDe1uIcz8eBqvu86FuF1POiG7vQ==} + engines: {node: '>=6.0'} dev: true /aggregate-error@3.1.0: @@ -453,10 +632,6 @@ packages: picomatch: 2.3.1 dev: true - /arg@4.1.3: - resolution: {integrity: sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==} - dev: true - /before-after-hook@2.2.3: resolution: {integrity: sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==} dev: true @@ -656,10 +831,6 @@ packages: p-event: 4.2.0 dev: true - /create-require@1.1.1: - resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} - dev: true - /cross-env@7.0.3: resolution: {integrity: sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==} engines: {node: '>=10.14', npm: '>=6', yarn: '>=1'} @@ -740,11 +911,6 @@ packages: engines: {node: '>= 0.8', npm: 1.2.8000 || >= 1.4.16} dev: true - /diff@4.0.2: - resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==} - engines: {node: '>=0.3.1'} - dev: true - /docsify-cli@4.4.4: resolution: {integrity: sha512-NAZgg6b0BsDuq/Pe+P19Qb2J1d+ZVbS0eGkeCNxyu4F9/CQSsRqZqAvPJ9/0I+BCHn4sgftA2jluqhQVzKzrSA==} engines: {node: '>= 10', npm: '>= 6'} @@ -843,6 +1009,36 @@ packages: strip-ansi: 6.0.1 dev: true + /esbuild@0.18.20: + resolution: {integrity: sha512-ceqxoedUrcayh7Y7ZX6NdbbDzGROiyVBgC4PriJThBKSVPWnnFHZAkfI1lJT8QFkOwH4qOS2SJkS4wvpGl8BpA==} + engines: {node: '>=12'} + hasBin: true + requiresBuild: true + optionalDependencies: + '@esbuild/android-arm': 0.18.20 + '@esbuild/android-arm64': 0.18.20 + '@esbuild/android-x64': 0.18.20 + '@esbuild/darwin-arm64': 0.18.20 + '@esbuild/darwin-x64': 0.18.20 + '@esbuild/freebsd-arm64': 0.18.20 + '@esbuild/freebsd-x64': 0.18.20 + '@esbuild/linux-arm': 0.18.20 + '@esbuild/linux-arm64': 0.18.20 + '@esbuild/linux-ia32': 0.18.20 + '@esbuild/linux-loong64': 0.18.20 + '@esbuild/linux-mips64el': 0.18.20 + '@esbuild/linux-ppc64': 0.18.20 + '@esbuild/linux-riscv64': 0.18.20 + '@esbuild/linux-s390x': 0.18.20 + '@esbuild/linux-x64': 0.18.20 + '@esbuild/netbsd-x64': 0.18.20 + '@esbuild/openbsd-x64': 0.18.20 + '@esbuild/sunos-x64': 0.18.20 + '@esbuild/win32-arm64': 0.18.20 + '@esbuild/win32-ia32': 0.18.20 + '@esbuild/win32-x64': 0.18.20 + dev: false + /escape-goat@2.1.1: resolution: {integrity: sha512-8/uIhbG12Csjy2JEW7D9pHbreaVaS/OpN3ycnyvElTdwM5n6GY6W6e2IPemfvGZeUMqZ9A/3GqIZMgKnBhAw/Q==} engines: {node: '>=8'} @@ -923,7 +1119,6 @@ packages: engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} os: [darwin] requiresBuild: true - dev: true optional: true /get-caller-file@2.0.5: @@ -950,6 +1145,12 @@ packages: pump: 3.0.0 dev: true + /get-tsconfig@4.7.2: + resolution: {integrity: sha512-wuMsz4leaj5hbGgg4IvDU0bqJagpftG5l5cXIAvo8uZrqn0NJqwtfupTN00VnkQJPcIRrxYrm1Ue24btpCha2A==} + dependencies: + resolve-pkg-maps: 1.0.0 + dev: false + /glob-parent@5.1.2: resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} engines: {node: '>= 6'} @@ -1279,10 +1480,6 @@ packages: semver: 6.3.1 dev: true - /make-error@1.3.6: - resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} - dev: true - /markdown-table-ts@1.0.3: resolution: {integrity: sha512-lYrp7FXmBqpmGmsEF92WnSukdgYvLm15FPIODZOx9+3nobkxJxjBYcszqZf5VqTjBtISPSNC7zjU9o3zwpL6AQ==} dev: true @@ -1562,6 +1759,10 @@ packages: resolution: {integrity: sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng==} dev: true + /resolve-pkg-maps@1.0.0: + resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==} + dev: false + /responselike@1.0.2: resolution: {integrity: sha512-/Fpe5guzJk1gPqdJLJR5u7eG/gNY4nImjbRDaVWVMRhne55TCmj2i9Q+54PBRfatRC8v/rIiv9BN0pMd9OV5EQ==} dependencies: @@ -1572,6 +1773,10 @@ packages: resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} dev: true + /sax@1.3.0: + resolution: {integrity: sha512-0s+oAmw9zLl1V1cS9BtZN7JAd0cW5e0QH4W3LWEK6a4LaLEA2OTpGYWDY+6XasBLtz6wkm3u1xRw95mRuJ59WA==} + dev: true + /semver-diff@3.1.1: resolution: {integrity: sha512-GX0Ix/CJcHyB8c4ykpHGIAvLyOwOobtM/8d+TQkAd81/bEjgPHrfba41Vpesr7jX/t8Uh+R3EX9eAS5be+jQYg==} engines: {node: '>=8'} @@ -1751,36 +1956,16 @@ packages: n-gram: 2.0.2 dev: true - /ts-node@10.9.1(@types/node@20.10.0)(typescript@5.3.2): - resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} + /tsx@4.6.0: + resolution: {integrity: sha512-HLHaDQ78mly4Pd5co6tWQOiNVYoYYAPUcwSSZK4bcs3zSEsg+/67LS/ReHook0E7DKPfe1J5jc0ocIhUrnaR4w==} + engines: {node: '>=18.0.0'} hasBin: true - peerDependencies: - '@swc/core': '>=1.2.50' - '@swc/wasm': '>=1.2.50' - '@types/node': '*' - typescript: '>=2.7' - peerDependenciesMeta: - '@swc/core': - optional: true - '@swc/wasm': - optional: true dependencies: - '@cspotcode/source-map-support': 0.8.1 - '@tsconfig/node10': 1.0.9 - '@tsconfig/node12': 1.0.11 - '@tsconfig/node14': 1.0.3 - '@tsconfig/node16': 1.0.4 - '@types/node': 20.10.0 - acorn: 8.11.2 - acorn-walk: 8.3.0 - arg: 4.1.3 - create-require: 1.1.1 - diff: 4.0.2 - make-error: 1.3.6 - typescript: 5.3.2 - v8-compile-cache-lib: 3.0.1 - yn: 3.1.1 - dev: true + esbuild: 0.18.20 + get-tsconfig: 4.7.2 + optionalDependencies: + fsevents: 2.3.3 + dev: false /tweezer.js@1.5.0: resolution: {integrity: sha512-aSiJz7rGWNAQq7hjMK9ZYDuEawXupcCWgl3woQQSoDP2Oh8O4srWb/uO1PzzHIsrPEOqrjJ2sUb9FERfzuBabQ==} @@ -1866,10 +2051,6 @@ packages: engines: {node: '>= 0.4.0'} dev: true - /v8-compile-cache-lib@3.0.1: - resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} - dev: true - /webidl-conversions@3.0.1: resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} dev: true @@ -1940,6 +2121,19 @@ packages: engines: {node: '>=8'} dev: true + /xml2js@0.6.2: + resolution: {integrity: sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA==} + engines: {node: '>=4.0.0'} + dependencies: + sax: 1.3.0 + xmlbuilder: 11.0.1 + dev: true + + /xmlbuilder@11.0.1: + resolution: {integrity: sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==} + engines: {node: '>=4.0'} + dev: true + /y18n@4.0.3: resolution: {integrity: sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==} dev: true @@ -1984,8 +2178,3 @@ packages: y18n: 4.0.3 yargs-parser: 18.1.3 dev: true - - /yn@3.1.1: - resolution: {integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==} - engines: {node: '>=6'} - dev: true diff --git a/tsconfig.json b/tsconfig.json index 1e519d6..de37a39 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "target": "ESNext", "moduleResolution": "Node", "outDir": "dist", + "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true, "isolatedModules": false, @@ -14,6 +15,9 @@ "resolveJsonModule": true, "inlineSourceMap": true }, + "include": ["src"], + // "include": ["src", "typings", "../zotero-types"], + "exclude": ["build", "dist", "**/temp**", "node_modules"], "ts-node": { "esm": true, "experimentalSpecifierResolution": "node" From 8f989d470626f875a98fc30af773182c11000b1c Mon Sep 17 00:00:00 2001 From: Northword Date: Tue, 28 Nov 2023 22:27:50 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E4=BB=8E=20xpi=20=E5=8C=85=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=20id=20=E5=92=8C=20description?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/get_plugins_info.ts | 49 +++++++++++++++++++++++++++++++++++------ src/index.ts | 9 +++++--- src/plugins.ts | 2 ++ 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/get_plugins_info.ts b/src/get_plugins_info.ts index 718f6cc..a50eecf 100644 --- a/src/get_plugins_info.ts +++ b/src/get_plugins_info.ts @@ -1,6 +1,8 @@ import fs from "fs"; import { franc } from "franc-min"; -import translate from "google-translate-api-x"; +// import translate from "google-translate-api-x"; +import AdmZip from "adm-zip"; +import { parseString } from "xml2js"; import { PluginInfo } from "./plugins"; import { writeFile } from "./utils"; import { octokit } from "."; @@ -38,11 +40,11 @@ export async function progressPlugins(plugins: PluginInfo[]) { // desc = resp.data.description; // }); } - } else { - desc = "无简介"; } + plugin.description = desc; plugin.star = resp.data.stargazers_count; + plugin.watchers = resp.data.watchers_count; }); // 作者信息 @@ -107,9 +109,9 @@ export async function progressPlugins(plugins: PluginInfo[]) { if (!asset) { console.log(` ${plugin.name} ${release.currentVersion} 不存在 XPI`); - // throw new Error( - // `${plugin.name} ${release.currentVersion} 不存在 XPI` - // ); + throw new Error( + `${plugin.name} ${release.currentVersion} 不存在 XPI` + ); return; } @@ -146,7 +148,40 @@ export async function progressPlugins(plugins: PluginInfo[]) { }; }); - // return release; + if (plugin.releases.length > 1 && release.targetZoteroVersion == "6") + continue; + + // 拆 XPI 包 + const zip = new AdmZip(`${dist}/xpi/${release.assetId}.xpi`); + const zipEntries = zip.getEntries(); + const zipEntryNames = zipEntries.map((zipEntrie) => zipEntrie.entryName); + + if (zipEntryNames.includes("manifest.json")) { + const fileData = zip + .getEntry("manifest.json")! + .getData() + .toString("utf8"); + const manifestData = JSON.parse(fileData); + plugin.id = manifestData.applications.zotero.id; + plugin.description = + plugin.description || manifestData.description || ""; + } else if (zipEntryNames.includes("install.rdf")) { + const fileData = zip + .getEntry("install.rdf")! + .getData() + .toString("utf8"); + parseString(fileData, (err, result) => { + const manifestData = result; //JSON.parse(result); + plugin.id = + manifestData["RDF:RDF"]["RDF:Description"][0]["$"]["em:id"]; + plugin.description = + plugin.description || + manifestData["RDF:RDF"]["RDF:Description"][0]["$"][ + "em:description" + ] || + ""; + }); + } } } return plugins; diff --git a/src/index.ts b/src/index.ts index 8fd4260..03614fb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,14 @@ import { Octokit } from "octokit"; -import { plugins } from "./plugins"; +// import { plugins } from "./plugins"; +import { plugins as pluginsProd } from "./plugins"; +import { test as pluginsDev } from "./plugins"; import { writeFile } from "./utils"; import getChartOptions from "./charts"; import { progressPlugins } from "./get_plugins_info"; import { renderMarkdown } from "./renderMarkdown"; -// 仅供测试使用 -// import { test as plugins } from "./plugins"; +const plugins = + process.env.NODE_ENV == "development" ? pluginsDev : pluginsProd; if (!process.env.GITHUB_TOKEN) throw new Error("GITHUB_TOKEN 未设置"); export const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN }); @@ -36,6 +38,7 @@ async function main(mode: "releases" | "charts" | string) { `${dist}/plugins.json`, JSON.stringify(pluginsInfoDist, null, 2) ); + writeFile(`${dist}/plugins.min.json`, JSON.stringify(pluginsInfoDist)); console.log("处理 Markdown"); const markdownContent = await renderMarkdown(pluginsInfoDist); diff --git a/src/plugins.ts b/src/plugins.ts index ae468b4..dcbcdd4 100644 --- a/src/plugins.ts +++ b/src/plugins.ts @@ -42,8 +42,10 @@ export interface PluginInfo { assetId?: number; }>; + id?: string; description?: string; star?: number; + watchers?: number; author?: { name: string; url: string; From 0057cec669ed4515eb0f813957ef522f6cfa81d3 Mon Sep 17 00:00:00 2001 From: Northword Date: Tue, 28 Nov 2023 22:43:23 +0800 Subject: [PATCH 3/9] update deps --- package.json | 4 +--- pnpm-lock.yaml | 61 +++++++++++++++++++++++++------------------------- 2 files changed, 31 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index b96cb93..fa3afbe 100644 --- a/package.json +++ b/package.json @@ -36,10 +36,8 @@ "highcharts": "^11.2.0", "markdown-table-ts": "^1.0.3", "octokit": "^3.1.2", + "tsx": "^4.6.0", "typescript": "^5.3.2", "xml2js": "^0.6.2" - }, - "dependencies": { - "tsx": "^4.6.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 26fbe03..f828130 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,11 +4,6 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false -dependencies: - tsx: - specifier: ^4.6.0 - version: 4.6.0 - devDependencies: '@highcharts/dashboards': specifier: ^1.1.2 @@ -49,6 +44,9 @@ devDependencies: octokit: specifier: ^3.1.2 version: 3.1.2 + tsx: + specifier: ^4.6.0 + version: 4.6.0 typescript: specifier: ^5.3.2 version: 5.3.2 @@ -64,7 +62,7 @@ packages: cpu: [arm64] os: [android] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/android-arm@0.18.20: @@ -73,7 +71,7 @@ packages: cpu: [arm] os: [android] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/android-x64@0.18.20: @@ -82,7 +80,7 @@ packages: cpu: [x64] os: [android] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/darwin-arm64@0.18.20: @@ -91,7 +89,7 @@ packages: cpu: [arm64] os: [darwin] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/darwin-x64@0.18.20: @@ -100,7 +98,7 @@ packages: cpu: [x64] os: [darwin] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/freebsd-arm64@0.18.20: @@ -109,7 +107,7 @@ packages: cpu: [arm64] os: [freebsd] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/freebsd-x64@0.18.20: @@ -118,7 +116,7 @@ packages: cpu: [x64] os: [freebsd] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/linux-arm64@0.18.20: @@ -127,7 +125,7 @@ packages: cpu: [arm64] os: [linux] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/linux-arm@0.18.20: @@ -136,7 +134,7 @@ packages: cpu: [arm] os: [linux] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/linux-ia32@0.18.20: @@ -145,7 +143,7 @@ packages: cpu: [ia32] os: [linux] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/linux-loong64@0.18.20: @@ -154,7 +152,7 @@ packages: cpu: [loong64] os: [linux] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/linux-mips64el@0.18.20: @@ -163,7 +161,7 @@ packages: cpu: [mips64el] os: [linux] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/linux-ppc64@0.18.20: @@ -172,7 +170,7 @@ packages: cpu: [ppc64] os: [linux] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/linux-riscv64@0.18.20: @@ -181,7 +179,7 @@ packages: cpu: [riscv64] os: [linux] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/linux-s390x@0.18.20: @@ -190,7 +188,7 @@ packages: cpu: [s390x] os: [linux] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/linux-x64@0.18.20: @@ -199,7 +197,7 @@ packages: cpu: [x64] os: [linux] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/netbsd-x64@0.18.20: @@ -208,7 +206,7 @@ packages: cpu: [x64] os: [netbsd] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/openbsd-x64@0.18.20: @@ -217,7 +215,7 @@ packages: cpu: [x64] os: [openbsd] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/sunos-x64@0.18.20: @@ -226,7 +224,7 @@ packages: cpu: [x64] os: [sunos] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/win32-arm64@0.18.20: @@ -235,7 +233,7 @@ packages: cpu: [arm64] os: [win32] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/win32-ia32@0.18.20: @@ -244,7 +242,7 @@ packages: cpu: [ia32] os: [win32] requiresBuild: true - dev: false + dev: true optional: true /@esbuild/win32-x64@0.18.20: @@ -253,7 +251,7 @@ packages: cpu: [x64] os: [win32] requiresBuild: true - dev: false + dev: true optional: true /@highcharts/dashboards@1.1.2(highcharts@11.2.0): @@ -1037,7 +1035,7 @@ packages: '@esbuild/win32-arm64': 0.18.20 '@esbuild/win32-ia32': 0.18.20 '@esbuild/win32-x64': 0.18.20 - dev: false + dev: true /escape-goat@2.1.1: resolution: {integrity: sha512-8/uIhbG12Csjy2JEW7D9pHbreaVaS/OpN3ycnyvElTdwM5n6GY6W6e2IPemfvGZeUMqZ9A/3GqIZMgKnBhAw/Q==} @@ -1119,6 +1117,7 @@ packages: engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} os: [darwin] requiresBuild: true + dev: true optional: true /get-caller-file@2.0.5: @@ -1149,7 +1148,7 @@ packages: resolution: {integrity: sha512-wuMsz4leaj5hbGgg4IvDU0bqJagpftG5l5cXIAvo8uZrqn0NJqwtfupTN00VnkQJPcIRrxYrm1Ue24btpCha2A==} dependencies: resolve-pkg-maps: 1.0.0 - dev: false + dev: true /glob-parent@5.1.2: resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} @@ -1761,7 +1760,7 @@ packages: /resolve-pkg-maps@1.0.0: resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==} - dev: false + dev: true /responselike@1.0.2: resolution: {integrity: sha512-/Fpe5guzJk1gPqdJLJR5u7eG/gNY4nImjbRDaVWVMRhne55TCmj2i9Q+54PBRfatRC8v/rIiv9BN0pMd9OV5EQ==} @@ -1965,7 +1964,7 @@ packages: get-tsconfig: 4.7.2 optionalDependencies: fsevents: 2.3.3 - dev: false + dev: true /tweezer.js@1.5.0: resolution: {integrity: sha512-aSiJz7rGWNAQq7hjMK9ZYDuEawXupcCWgl3woQQSoDP2Oh8O4srWb/uO1PzzHIsrPEOqrjJ2sUb9FERfzuBabQ==} From e4d6e0582fb9574a72f4d1833ad624759f39269b Mon Sep 17 00:00:00 2001 From: Northword Date: Tue, 28 Nov 2023 22:47:14 +0800 Subject: [PATCH 4/9] update ci node version --- .github/workflows/charts.yml | 2 +- .github/workflows/plugins-info.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/charts.yml b/.github/workflows/charts.yml index 4da59df..dbb4ee6 100644 --- a/.github/workflows/charts.yml +++ b/.github/workflows/charts.yml @@ -24,7 +24,7 @@ jobs: - name: Setup Node uses: actions/setup-node@v3 with: - node-version: "18.x" + node-version: "20.x" registry-url: "https://registry.npmjs.org" cache: pnpm diff --git a/.github/workflows/plugins-info.yml b/.github/workflows/plugins-info.yml index f20e766..ac50111 100644 --- a/.github/workflows/plugins-info.yml +++ b/.github/workflows/plugins-info.yml @@ -27,7 +27,7 @@ jobs: - name: Setup Node uses: actions/setup-node@v3 with: - node-version: "18.x" + node-version: "20.x" registry-url: "https://registry.npmjs.org" cache: pnpm From 24f90eb315a0667d4f5937847aed2d50bd47ee46 Mon Sep 17 00:00:00 2001 From: Northword Date: Wed, 29 Nov 2023 11:11:26 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E6=AD=A3=E5=88=99=E5=8C=B9=E9=85=8Did?= =?UTF-8?q?=E5=92=8Cdesc=20=E6=97=A0=E6=B3=95=E6=AD=A3=E7=A1=AE=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=88=B0=E6=9E=81=E4=B8=AA=E5=88=AB=E6=8F=92=E4=BB=B6?= =?UTF-8?q?id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + src/get_plugins_info.ts | 23 ++++++++++------------- tsconfig.json | 2 +- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 8dd396d..4309ff2 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ package-lock.json dist # tmp +**/*temp**.ts **/*.bak **/*.new **/examples.ts diff --git a/src/get_plugins_info.ts b/src/get_plugins_info.ts index a50eecf..9acdddb 100644 --- a/src/get_plugins_info.ts +++ b/src/get_plugins_info.ts @@ -2,7 +2,7 @@ import fs from "fs"; import { franc } from "franc-min"; // import translate from "google-translate-api-x"; import AdmZip from "adm-zip"; -import { parseString } from "xml2js"; +import * as xml2js from "xml2js"; import { PluginInfo } from "./plugins"; import { writeFile } from "./utils"; import { octokit } from "."; @@ -155,7 +155,6 @@ export async function progressPlugins(plugins: PluginInfo[]) { const zip = new AdmZip(`${dist}/xpi/${release.assetId}.xpi`); const zipEntries = zip.getEntries(); const zipEntryNames = zipEntries.map((zipEntrie) => zipEntrie.entryName); - if (zipEntryNames.includes("manifest.json")) { const fileData = zip .getEntry("manifest.json")! @@ -170,17 +169,15 @@ export async function progressPlugins(plugins: PluginInfo[]) { .getEntry("install.rdf")! .getData() .toString("utf8"); - parseString(fileData, (err, result) => { - const manifestData = result; //JSON.parse(result); - plugin.id = - manifestData["RDF:RDF"]["RDF:Description"][0]["$"]["em:id"]; - plugin.description = - plugin.description || - manifestData["RDF:RDF"]["RDF:Description"][0]["$"][ - "em:description" - ] || - ""; - }); + const id = (fileData.match(/em:id="(.*?)"/) ?? + fileData.match(/(.*?)<\/em:id>/) ?? ["", "NOT FOUND"])[1]; + const desc = (fileData.match(/em:description="(.*?)"/) ?? + fileData.match(/(.*?)<\/em:description>/) ?? [ + "", + "NOT FOUND", + ])[1]; + plugin.id = plugin.id ?? id; + plugin.description = plugin.description ?? desc; } } } diff --git a/tsconfig.json b/tsconfig.json index de37a39..9265b0b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,7 +17,7 @@ }, "include": ["src"], // "include": ["src", "typings", "../zotero-types"], - "exclude": ["build", "dist", "**/temp**", "node_modules"], + "exclude": ["build", "dist", "node_modules"], "ts-node": { "esm": true, "experimentalSpecifierResolution": "node" From ef6b626e7b86840d48e4e27b2272de0a765b2ddb Mon Sep 17 00:00:00 2001 From: Northword Date: Wed, 29 Nov 2023 15:09:11 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E5=AF=B9rdf=EF=BC=8C=E9=80=9A=E8=BF=87xml2?= =?UTF-8?q?js=E8=8E=B7=E5=8F=96id=EF=BC=8C=E9=80=9A=E8=BF=87=E6=AD=A3?= =?UTF-8?q?=E5=88=99=E8=8E=B7=E5=8F=96desc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/get_plugins_info.ts | 344 ++++++++++++++++++++++------------------ src/index.ts | 16 +- src/plugins.ts | 6 +- 4 files changed, 201 insertions(+), 167 deletions(-) diff --git a/package.json b/package.json index fa3afbe..2a12d5c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Zotero 插件合集", "main": "index.js", "scripts": { - "get-info": "cd src && tsx index.ts releases && cd ..", + "get-info": "cd src && tsx index.ts fetchPlugins && cd ..", "get-chart": "cd src && tsx index.ts charts && cd ..", "debug:info": "cross-env NODE_ENV=development npm run get-info", "debug:chart": "cross-env NODE_ENV=development npm run get-chart", diff --git a/src/get_plugins_info.ts b/src/get_plugins_info.ts index 9acdddb..0c53f59 100644 --- a/src/get_plugins_info.ts +++ b/src/get_plugins_info.ts @@ -8,178 +8,212 @@ import { writeFile } from "./utils"; import { octokit } from "."; import { dist } from "."; -export async function progressPlugins(plugins: PluginInfo[]) { - for (const plugin of plugins) { +export async function fetchPlugins(plugins: PluginInfo[]) { + for (let plugin of plugins) { console.log(`开始处理 ${plugin.name}`); - const repoParts = plugin.repo.split("/"), - owner = repoParts[0], - repo = repoParts[1]; + await fetchPlugin(plugin); + process.env.NODE_ENV == "development" + ? writeFile( + `${dist}/plugins-debug.json`, + JSON.stringify(plugins, null, 2) + ) + : ""; + } + return plugins; +} - // 仓库信息:插件简介 - await octokit - .request("GET /repos/{owner}/{repo}", { - owner: owner, - repo: repo, - }) - .then(async (resp) => { - let desc = ""; - if (resp.data.description) { - if (franc(resp.data.description) == "cmn") { - desc = resp.data.description; - } else { - desc = resp.data.description; - // 翻译 - // console.log("需要翻译"); - // await translate(resp.data.description, { to: "zh-CN" }) - // .then((res) => { - // console.log(res.text); - // desc = res.text; - // }) - // .catch((e) => { - // console.log(e); - // desc = resp.data.description; - // }); - } +async function fetchPlugin(plugin: PluginInfo) { + const repoParts = plugin.repo.split("/"), + owner = repoParts[0], + repo = repoParts[1]; + + // 仓库信息:插件简介 + await octokit + .request("GET /repos/{owner}/{repo}", { + owner: owner, + repo: repo, + }) + .then(async (resp) => { + let desc = ""; + if (resp.data.description) { + if (franc(resp.data.description) == "cmn") { + desc = resp.data.description; + } else { + desc = resp.data.description; + // 翻译 + // console.log("需要翻译"); + // await translate(resp.data.description, { to: "zh-CN" }) + // .then((res) => { + // console.log(res.text); + // desc = res.text; + // }) + // .catch((e) => { + // console.log(e); + // desc = resp.data.description; + // }); } + } - plugin.description = desc; - plugin.star = resp.data.stargazers_count; - plugin.watchers = resp.data.watchers_count; - }); + plugin.description = desc; + plugin.star = resp.data.stargazers_count; + plugin.watchers = resp.data.watchers_count; + }); - // 作者信息 - await octokit - .request("GET /users/{username}", { - username: owner, - }) - .then((resp) => { - plugin.author = { - name: resp.data.name || owner, - url: resp.data.blog || resp.data.html_url, - avatar: resp.data.avatar_url, - }; - }); + // 作者信息 + await octokit + .request("GET /users/{username}", { + username: owner, + }) + .then((resp) => { + plugin.author = { + name: resp.data.name || owner, + url: resp.data.blog || resp.data.html_url, + avatar: resp.data.avatar_url, + }; + }); - // 发行版 - for (const release of plugin.releases) { - async function getRelease() { - if (release.tagName == "latest") { - const resp = await octokit.request( - "GET /repos/{owner}/{repo}/releases/latest", - { - owner: owner, - repo: repo, - } - ); - return resp.data; - } else if (release.tagName == "pre") { - const resp = await octokit.request( - "GET /repos/{owner}/{repo}/releases", - { - owner: owner, - repo: repo, - } - ); - return resp.data.filter((item) => item.prerelease === true)[0]; - } else { - const resp = await octokit.request( - "GET /repos/{owner}/{repo}/releases/tags/{tag}", - { - owner: owner, - repo: repo, - tag: release.tagName, - } - ); - return resp.data; - } + // 发行版 + for (const release of plugin.releases) { + async function getRelease() { + if (release.tagName == "latest") { + const resp = await octokit.request( + "GET /repos/{owner}/{repo}/releases/latest", + { + owner: owner, + repo: repo, + } + ); + return resp.data; + } else if (release.tagName == "pre") { + const resp = await octokit.request( + "GET /repos/{owner}/{repo}/releases", + { + owner: owner, + repo: repo, + } + ); + return resp.data.filter((item) => item.prerelease === true)[0]; + } else { + const resp = await octokit.request( + "GET /repos/{owner}/{repo}/releases/tags/{tag}", + { + owner: owner, + repo: repo, + tag: release.tagName, + } + ); + return resp.data; + } + } + + await getRelease().then(async (resp) => { + release.currentVersion = resp.tag_name; + + const asset = resp.assets + .filter((asset) => { + return asset.content_type === "application/x-xpinstall"; + }) + .sort((a, b) => { + const dateA = new Date(a.updated_at); + const dateB = new Date(b.updated_at); + // 使用时间戳进行比较 + return dateB.getTime() - dateA.getTime(); + })[0]; + + if (!asset) { + console.log(` ${plugin.name} ${release.currentVersion} 不存在 XPI`); + throw new Error(`${plugin.name} ${release.currentVersion} 不存在 XPI`); + return; } - await getRelease().then(async (resp) => { - release.currentVersion = resp.tag_name; - const asset = resp.assets - .filter((asset) => { - return asset.content_type === "application/x-xpinstall"; + if (!fs.existsSync(`${dist}/xpi/${asset.id}.xpi`)) { + const xpiFlie = await octokit.rest.repos + .getReleaseAsset({ + owner: owner, + repo: repo, + asset_id: asset.id, + headers: { + Accept: "application/octet-stream", + }, }) - .sort((a, b) => { - const dateA = new Date(a.updated_at); - const dateB = new Date(b.updated_at); - // 使用时间戳进行比较 - return dateB.getTime() - dateA.getTime(); - })[0]; + .then((resp) => { + writeFile( + `${dist}/xpi/${asset.id}.xpi`, + Buffer.from(resp.data as unknown as ArrayBuffer) + ); + }); + } - if (!asset) { - console.log(` ${plugin.name} ${release.currentVersion} 不存在 XPI`); - throw new Error( - `${plugin.name} ${release.currentVersion} 不存在 XPI` - ); - return; - } + release.assetId = asset.id; + release.releaseData = asset.updated_at; + release.downloadCount = asset.download_count; + release.xpiDownloadUrl = { + github: asset.browser_download_url, + gitee: `https://gitee.com/northword/zotero-plugins/raw/gh-pages/dist/xpi/${release.assetId}.xpi`, + ghProxy: `https://ghproxy.com/?q=${encodeURI( + asset.browser_download_url + )}`, + jsdeliver: `https://cdn.jsdelivr.net/gh/northword/zotero-plugins@gh-pages/dist/xpi/${release.assetId}.xpi`, + kgithub: asset.browser_download_url.replace( + "github.com", + "kkgithub.com" + ), + }; + }); - if (!fs.existsSync(`${dist}/xpi/${asset.id}.xpi`)) { - const xpiFlie = await octokit.rest.repos - .getReleaseAsset({ - owner: owner, - repo: repo, - asset_id: asset.id, - headers: { - Accept: "application/octet-stream", - }, - }) - .then((resp) => { - return resp.data as unknown as ArrayBuffer; - }); + // if (plugin.releases.length > 1 && release.targetZoteroVersion == "6") + // continue; - writeFile(`${dist}/xpi/${asset.id}.xpi`, Buffer.from(xpiFlie)); - } - release.assetId = asset.id; - release.releaseData = asset.updated_at; - release.downloadCount = asset.download_count; - release.xpiDownloadUrl = { - github: asset.browser_download_url, - gitee: `https://gitee.com/northword/zotero-plugins/raw/gh-pages/dist/xpi/${release.assetId}.xpi`, - ghProxy: `https://ghproxy.com/?q=${encodeURI( - asset.browser_download_url - )}`, - jsdeliver: `https://cdn.jsdelivr.net/gh/northword/zotero-plugins@gh-pages/dist/xpi/${release.assetId}.xpi`, - kgithub: asset.browser_download_url.replace( - "github.com", - "kkgithub.com" - ), - }; - }); + // 拆 XPI 包 + const zip = new AdmZip(`${dist}/xpi/${release.assetId}.xpi`); + const zipEntries = zip.getEntries(); + const zipEntryNames = zipEntries.map((zipEntrie) => zipEntrie.entryName); + if (zipEntryNames.includes("manifest.json")) { + const fileData = zip + .getEntry("manifest.json")! + .getData() + .toString("utf8"); + const manifestData = JSON.parse(fileData); + release.id = manifestData.applications.zotero.id; + plugin.description = plugin.description || manifestData.description || ""; + // todo: 适配多语言,当值为 `__MSG_description__` 是前往 i18n 目录获取 + } else if (zipEntryNames.includes("install.rdf")) { + const fileData = zip.getEntry("install.rdf")!.getData().toString("utf8"); - if (plugin.releases.length > 1 && release.targetZoteroVersion == "6") - continue; + // 从 install.rdf 中获取 id + function replaceRDF(name: string) { + return name.replace("RDF:", ""); + } + xml2js.parseString( + fileData, + { + mergeAttrs: true, + attrNameProcessors: [replaceRDF], + tagNameProcessors: [replaceRDF], + }, + (err, result) => { + const manifestData = result; //JSON.parse(result); + // console.log(util.inspect(result, false, null)); + release.id = manifestData["RDF"]["Description"] + .map((Description: any) => { + // console.log(Description); + if (Description["about"] == "urn:mozilla:install-manifest") { + return Description["em:id"][0]; + } + }) + .filter((id: string | undefined) => id !== undefined)[0]; + } + ); - // 拆 XPI 包 - const zip = new AdmZip(`${dist}/xpi/${release.assetId}.xpi`); - const zipEntries = zip.getEntries(); - const zipEntryNames = zipEntries.map((zipEntrie) => zipEntrie.entryName); - if (zipEntryNames.includes("manifest.json")) { - const fileData = zip - .getEntry("manifest.json")! - .getData() - .toString("utf8"); - const manifestData = JSON.parse(fileData); - plugin.id = manifestData.applications.zotero.id; - plugin.description = - plugin.description || manifestData.description || ""; - } else if (zipEntryNames.includes("install.rdf")) { - const fileData = zip - .getEntry("install.rdf")! - .getData() - .toString("utf8"); - const id = (fileData.match(/em:id="(.*?)"/) ?? - fileData.match(/(.*?)<\/em:id>/) ?? ["", "NOT FOUND"])[1]; - const desc = (fileData.match(/em:description="(.*?)"/) ?? + // 从 install.rdf 中获取 description + plugin.description = + plugin.description ?? + (fileData.match(/em:description="(.*?)"/) ?? fileData.match(/(.*?)<\/em:description>/) ?? [ "", - "NOT FOUND", + "NO desc", ])[1]; - plugin.id = plugin.id ?? id; - plugin.description = plugin.description ?? desc; - } } } - return plugins; + return plugin; } diff --git a/src/index.ts b/src/index.ts index 03614fb..79d90c2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ import { plugins as pluginsProd } from "./plugins"; import { test as pluginsDev } from "./plugins"; import { writeFile } from "./utils"; import getChartOptions from "./charts"; -import { progressPlugins } from "./get_plugins_info"; +import { fetchPlugins } from "./get_plugins_info"; import { renderMarkdown } from "./renderMarkdown"; const plugins = @@ -15,10 +15,10 @@ export const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN }); export const dist = "../docs/dist"; export function args() { - return <"releases" | "charts">process.argv.slice(2)[0]; + return <"fetchPlugins" | "charts">process.argv.slice(2)[0]; } -async function main(mode: "releases" | "charts" | string) { +async function main(mode: "fetchPlugins" | "charts" | string) { const quotaStart = (await octokit.rest.rateLimit.get()).data.rate; console.log(quotaStart); @@ -31,14 +31,10 @@ async function main(mode: "releases" | "charts" | string) { console.log("开始处理"); switch (mode) { - case "releases": + case "fetchPlugins": { - let pluginsInfoDist = await progressPlugins(plugins); - writeFile( - `${dist}/plugins.json`, - JSON.stringify(pluginsInfoDist, null, 2) - ); - writeFile(`${dist}/plugins.min.json`, JSON.stringify(pluginsInfoDist)); + let pluginsInfoDist = await fetchPlugins(plugins); + writeFile(`${dist}/plugins.json`, JSON.stringify(pluginsInfoDist)); console.log("处理 Markdown"); const markdownContent = await renderMarkdown(pluginsInfoDist); diff --git a/src/plugins.ts b/src/plugins.ts index dcbcdd4..66143b7 100644 --- a/src/plugins.ts +++ b/src/plugins.ts @@ -29,6 +29,11 @@ export interface PluginInfo { */ tagName: "latest" | "pre" | string; + /** + * 插件 ID,自 XPI 中提取 + */ + id?: string; + currentVersion?: string; xpiDownloadUrl?: { github: string; @@ -42,7 +47,6 @@ export interface PluginInfo { assetId?: number; }>; - id?: string; description?: string; star?: number; watchers?: number; From 19d8535d84dc3f06b9543a79d32041d2b1428360 Mon Sep 17 00:00:00 2001 From: Northword Date: Wed, 29 Nov 2023 15:54:17 +0800 Subject: [PATCH 7/9] tweak --- src/get_plugins_info.ts | 15 +++++---------- src/index.ts | 2 +- src/plugins.ts | 10 +++++----- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/get_plugins_info.ts b/src/get_plugins_info.ts index 0c53f59..3e22ed1 100644 --- a/src/get_plugins_info.ts +++ b/src/get_plugins_info.ts @@ -12,12 +12,7 @@ export async function fetchPlugins(plugins: PluginInfo[]) { for (let plugin of plugins) { console.log(`开始处理 ${plugin.name}`); await fetchPlugin(plugin); - process.env.NODE_ENV == "development" - ? writeFile( - `${dist}/plugins-debug.json`, - JSON.stringify(plugins, null, 2) - ) - : ""; + writeFile(`${dist}/plugins.json`, JSON.stringify(plugins, null, 2)); } return plugins; } @@ -174,7 +169,8 @@ async function fetchPlugin(plugin: PluginInfo) { .getData() .toString("utf8"); const manifestData = JSON.parse(fileData); - release.id = manifestData.applications.zotero.id; + // plugin.id = release.id = manifestData.applications.zotero.id; + plugin.id = manifestData.applications.zotero.id; plugin.description = plugin.description || manifestData.description || ""; // todo: 适配多语言,当值为 `__MSG_description__` 是前往 i18n 目录获取 } else if (zipEntryNames.includes("install.rdf")) { @@ -194,7 +190,7 @@ async function fetchPlugin(plugin: PluginInfo) { (err, result) => { const manifestData = result; //JSON.parse(result); // console.log(util.inspect(result, false, null)); - release.id = manifestData["RDF"]["Description"] + plugin.id = manifestData["RDF"]["Description"] .map((Description: any) => { // console.log(Description); if (Description["about"] == "urn:mozilla:install-manifest") { @@ -204,7 +200,7 @@ async function fetchPlugin(plugin: PluginInfo) { .filter((id: string | undefined) => id !== undefined)[0]; } ); - + // plugin.id = plugin.id ?? release.id; // 从 install.rdf 中获取 description plugin.description = plugin.description ?? @@ -215,5 +211,4 @@ async function fetchPlugin(plugin: PluginInfo) { ])[1]; } } - return plugin; } diff --git a/src/index.ts b/src/index.ts index 79d90c2..a7e0de3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -34,7 +34,7 @@ async function main(mode: "fetchPlugins" | "charts" | string) { case "fetchPlugins": { let pluginsInfoDist = await fetchPlugins(plugins); - writeFile(`${dist}/plugins.json`, JSON.stringify(pluginsInfoDist)); + writeFile(`${dist}/plugins.min.json`, JSON.stringify(pluginsInfoDist)); console.log("处理 Markdown"); const markdownContent = await renderMarkdown(pluginsInfoDist); diff --git a/src/plugins.ts b/src/plugins.ts index 66143b7..c866698 100644 --- a/src/plugins.ts +++ b/src/plugins.ts @@ -29,10 +29,7 @@ export interface PluginInfo { */ tagName: "latest" | "pre" | string; - /** - * 插件 ID,自 XPI 中提取 - */ - id?: string; + // id?: string; currentVersion?: string; xpiDownloadUrl?: { @@ -46,7 +43,10 @@ export interface PluginInfo { downloadCount?: number; assetId?: number; }>; - + /** + * 插件 ID,自 XPI 中提取 + */ + id?: string; description?: string; star?: number; watchers?: number; From e2e39d25a0385d147f239bb76537b7eb5aceefb2 Mon Sep 17 00:00:00 2001 From: Northword Date: Wed, 29 Nov 2023 16:11:50 +0800 Subject: [PATCH 8/9] =?UTF-8?q?CI=E4=B8=8D=E8=BE=93=E5=87=BAdebug=E7=94=A8?= =?UTF-8?q?=E7=9A=84plugin-debug.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/get_plugins_info.ts | 7 ++++++- src/index.ts | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/get_plugins_info.ts b/src/get_plugins_info.ts index 3e22ed1..84d7a6a 100644 --- a/src/get_plugins_info.ts +++ b/src/get_plugins_info.ts @@ -12,7 +12,12 @@ export async function fetchPlugins(plugins: PluginInfo[]) { for (let plugin of plugins) { console.log(`开始处理 ${plugin.name}`); await fetchPlugin(plugin); - writeFile(`${dist}/plugins.json`, JSON.stringify(plugins, null, 2)); + process.env.CI + ? writeFile( + `${dist}/plugins-debug.json`, + JSON.stringify(plugins, null, 2) + ) + : ""; } return plugins; } diff --git a/src/index.ts b/src/index.ts index a7e0de3..79d90c2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -34,7 +34,7 @@ async function main(mode: "fetchPlugins" | "charts" | string) { case "fetchPlugins": { let pluginsInfoDist = await fetchPlugins(plugins); - writeFile(`${dist}/plugins.min.json`, JSON.stringify(pluginsInfoDist)); + writeFile(`${dist}/plugins.json`, JSON.stringify(pluginsInfoDist)); console.log("处理 Markdown"); const markdownContent = await renderMarkdown(pluginsInfoDist); From ed9451b4be6d12df2d3316868921c879002301f0 Mon Sep 17 00:00:00 2001 From: Northword Date: Wed, 29 Nov 2023 22:27:34 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E7=BA=A0=E6=AD=A3watcher=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E4=B8=BAsubscribers=5Fcount=20resolve:=20/~https://github.com/zo?= =?UTF-8?q?tero-chinese/zotero-plugins/pull/49#discussion=5Fr1409283252?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/get_plugins_info.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/get_plugins_info.ts b/src/get_plugins_info.ts index 84d7a6a..78218a6 100644 --- a/src/get_plugins_info.ts +++ b/src/get_plugins_info.ts @@ -56,7 +56,7 @@ async function fetchPlugin(plugin: PluginInfo) { plugin.description = desc; plugin.star = resp.data.stargazers_count; - plugin.watchers = resp.data.watchers_count; + plugin.watchers = resp.data.subscribers_count; }); // 作者信息