feat: switch to undici (#58)

This commit is contained in:
Evo
2022-07-10 11:09:22 +05:30
committed by GitHub
parent 83e841a341
commit c4f8e45bdc
4 changed files with 33 additions and 3714 deletions

3712
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -30,26 +30,19 @@
},
"homepage": "https://sern-handler.js.org",
"dependencies": {
"axios": "^0.27.2",
"colorette": "^2.0.16",
"commander": "^9.3.0",
"execa": "^6.1.0",
"find-up": "6.3.0",
"ora": "^6.1.0",
"prompts": "2.4.2"
"prompts": "2.4.2",
"undici": "^5.6.1"
},
"devDependencies": {
"@favware/npm-deprecate": "1.0.4",
"@types/prompts": "2.0.14",
"cz-conventional-changelog": "3.3.0",
"eslint": "8.19.0",
"prettier": "2.7.1"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public"

View File

@@ -1,6 +1,6 @@
import { pluginsQ } from '../prompts/plugin.js';
import prompts from 'prompts';
import axios from 'axios';
import { fetch } from 'undici';
import fs from 'fs';
import { greenBright } from 'colorette';
const { prompt } = prompts;
@@ -31,14 +31,18 @@ export async function plugins() {
* @returns File
*/
async function download(url) {
const res = await axios.default.get(url);
const data = res.data;
const data = await fetch(url, { method: 'GET' })
.then((res) => res.text())
.catch(() => null);
if (!data) throw new Error('Download failed! Kindly contact developers');
const dir = `${process.cwd()}/src/plugins`;
const filedir = `${process.cwd()}/src/plugins/${url.split('/').pop()}`;
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
const file = fs.writeFileSync(filedir, data);
return file;
}

View File

@@ -1,13 +1,17 @@
import axios from 'axios';
import { fetch } from 'undici';
import { getLang } from '../utilities/getLang.js';
async function gimmechoices() {
const lang =
(await getLang()) === 'typescript' ? 'TypeScript' : 'JavaScript';
(await getLang().catch(() => null)) === 'typescript'
? 'TypeScript'
: 'JavaScript';
const link = `https://api.github.com/repos/sern-handler/awesome-plugins/contents/${lang}`;
const resp = await axios.default.get(link).catch(() => null);
const resp = await fetch(link).catch(() => null);
if (!resp) return { title: 'No plugins found!', value: '', disabled: true };
const { data } = resp;
const data = await resp.json();
const choices = data.map(
(/** @type {{ name: string; download_url: string; }} */ e) => ({
title: e.name,