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