mirror of
https://github.com/strapi/strapi.git
synced 2025-08-31 20:33:03 +00:00
Revert to node-fetch to lighten the packages
This commit is contained in:
parent
a655f861f5
commit
32c36bc9ac
@ -20,11 +20,11 @@
|
||||
"index.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"axios": "0.21.1",
|
||||
"chalk": "4.1.1",
|
||||
"commander": "6.1.0",
|
||||
"inquirer": "8.1.0",
|
||||
"js-yaml": "4.1.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"strapi-generate-new": "3.6.3"
|
||||
},
|
||||
"scripts": {
|
||||
|
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const inquirer = require('inquirer');
|
||||
const axios = require('axios');
|
||||
const fetch = require('node-fetch');
|
||||
const yaml = require('js-yaml');
|
||||
|
||||
/**
|
||||
@ -99,18 +99,16 @@ async function getPromptQuestions(projectName, template) {
|
||||
* @returns JSON template data
|
||||
*/
|
||||
async function getTemplateData() {
|
||||
try {
|
||||
const {
|
||||
data: { content },
|
||||
} = await axios.get(
|
||||
`https://api.github.com/repos/strapi/community-content/contents/templates/templates.yml`
|
||||
);
|
||||
|
||||
const buff = Buffer.from(content, 'base64');
|
||||
const stringified = buff.toString('utf-8');
|
||||
|
||||
return yaml.load(stringified);
|
||||
} catch (error) {
|
||||
const response = await fetch(
|
||||
`https://api.github.com/repos/strapi/community-content/contents/templates/templates.yml`
|
||||
);
|
||||
if (!response.ok) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { content } = await response.json();
|
||||
const buff = Buffer.from(content, 'base64');
|
||||
const stringified = buff.toString('utf-8');
|
||||
|
||||
return yaml.load(stringified);
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
"create-strapi-starter": "./index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "0.21.1",
|
||||
"chalk": "4.1.1",
|
||||
"ci-info": "3.1.1",
|
||||
"commander": "7.1.0",
|
||||
@ -25,6 +24,7 @@
|
||||
"git-url-parse": "11.4.4",
|
||||
"inquirer": "8.1.0",
|
||||
"js-yaml": "4.1.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"ora": "5.4.0",
|
||||
"strapi-generate-new": "3.6.3",
|
||||
"tar": "6.1.0"
|
||||
|
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const tar = require('tar');
|
||||
const axios = require('axios');
|
||||
const fetch = require('node-fetch');
|
||||
const parseGitUrl = require('git-url-parse');
|
||||
const chalk = require('chalk');
|
||||
|
||||
@ -29,19 +29,18 @@ function parseShorthand(starter) {
|
||||
* @param {string} repo The full name of the repository.
|
||||
*/
|
||||
async function getDefaultBranch(repo) {
|
||||
try {
|
||||
const {
|
||||
data: { default_branch },
|
||||
} = await axios.get(`https://api.github.com/repos/${repo}`);
|
||||
const response = await fetch(`https://api.github.com/repos/${repo}`);
|
||||
|
||||
return default_branch;
|
||||
} catch (error) {
|
||||
if (!response.ok) {
|
||||
stopProcess(
|
||||
`Could not find the starter information for ${chalk.yellow(
|
||||
repo
|
||||
)}. Make sure it is publicly accessible on github.`
|
||||
);
|
||||
}
|
||||
|
||||
const { default_branch } = await response.json();
|
||||
return default_branch;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,22 +81,17 @@ async function getRepoInfo(starter) {
|
||||
async function downloadGitHubRepo(repoInfo, tmpDir) {
|
||||
const { fullName, branch, usedShorthand } = repoInfo;
|
||||
|
||||
try {
|
||||
// Download from GitHub
|
||||
const codeload = `https://codeload.github.com/${fullName}/tar.gz/${branch}`;
|
||||
const { data } = await axios({
|
||||
url: codeload,
|
||||
method: 'GET',
|
||||
responseType: 'stream',
|
||||
});
|
||||
const codeload = `https://codeload.github.com/${fullName}/tar.gz/${branch}`;
|
||||
const response = await fetch(codeload);
|
||||
|
||||
await new Promise(resolve => {
|
||||
data.pipe(tar.extract({ strip: 1, cwd: tmpDir })).on('close', resolve);
|
||||
});
|
||||
} catch (error) {
|
||||
if (!response.ok) {
|
||||
const message = usedShorthand ? `using the shorthand` : `using the url`;
|
||||
stopProcess(`Could not download the repository ${message}: ${chalk.yellow(fullName)}.`);
|
||||
}
|
||||
|
||||
await new Promise(resolve => {
|
||||
response.body.pipe(tar.extract({ strip: 1, cwd: tmpDir })).on('close', resolve);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { getRepoInfo, downloadGitHubRepo };
|
||||
|
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const inquirer = require('inquirer');
|
||||
const axios = require('axios');
|
||||
const fetch = require('node-fetch');
|
||||
const yaml = require('js-yaml');
|
||||
|
||||
/**
|
||||
@ -87,17 +87,17 @@ async function getStarterQuestion() {
|
||||
* @returns JSON starter data
|
||||
*/
|
||||
async function getStarterData() {
|
||||
try {
|
||||
const {
|
||||
data: { content },
|
||||
} = await axios.get(
|
||||
`https://api.github.com/repos/strapi/community-content/contents/starters/starters.yml`
|
||||
);
|
||||
const buff = Buffer.from(content, 'base64');
|
||||
const stringified = buff.toString('utf-8');
|
||||
const response = await fetch(
|
||||
`https://api.github.com/repos/strapi/community-content/contents/starters/starters.yml`
|
||||
);
|
||||
|
||||
return yaml.load(stringified);
|
||||
} catch (error) {
|
||||
if (!response.ok) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { content } = await response.json();
|
||||
const buff = Buffer.from(content, 'base64');
|
||||
const stringified = buff.toString('utf-8');
|
||||
|
||||
return yaml.load(stringified);
|
||||
}
|
||||
|
@ -4861,7 +4861,7 @@ axios-mock-adapter@^1.19.0:
|
||||
fast-deep-equal "^3.1.3"
|
||||
is-buffer "^2.0.3"
|
||||
|
||||
axios@0.21.1, axios@^0.21.1:
|
||||
axios@^0.21.1:
|
||||
version "0.21.1"
|
||||
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8"
|
||||
integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==
|
||||
|
Loading…
x
Reference in New Issue
Block a user