strapi-generate-new
Advanced tools
Comparing version 3.6.2 to 3.6.3
@@ -6,8 +6,7 @@ 'use strict'; | ||
const fse = require('fs-extra'); | ||
const fetch = require('node-fetch'); | ||
const tar = require('tar'); | ||
const _ = require('lodash'); | ||
const chalk = require('chalk'); | ||
const gitInfo = require('hosted-git-info'); | ||
const { getRepoInfo, downloadGitHubRepo } = require('./fetch-github'); | ||
// Specify all the files and directories a template can have | ||
@@ -36,15 +35,10 @@ const allowChildren = '*'; | ||
// Parse template info | ||
const repoInfo = getRepoInfo(scope.template); | ||
const { user, project } = repoInfo; | ||
console.log(`Installing ${chalk.yellow(`${user}/${project}`)} template.`); | ||
const repoInfo = await getRepoInfo(scope.template); | ||
const { fullName } = repoInfo; | ||
console.log(`Installing ${chalk.yellow(fullName)} template.`); | ||
// Download template repository to a temporary directory | ||
const templatePath = await fse.mkdtemp(path.join(os.tmpdir(), 'strapi-')); | ||
await downloadGitHubRepo(repoInfo, templatePath); | ||
try { | ||
await downloadGithubRepo(repoInfo, templatePath); | ||
} catch (error) { | ||
throw Error(`Could not download ${chalk.yellow(`${user}/${project}`)} repository.`); | ||
} | ||
// Make sure the downloaded template matches the required format | ||
@@ -55,3 +49,3 @@ const { templateConfig } = await checkTemplateRootStructure(templatePath, scope); | ||
// Merge contents of the template in the project | ||
const fullTemplateUrl = `https://github.com/${user}/${project}`; | ||
const fullTemplateUrl = `https://github.com/${fullName}`; | ||
await mergePackageJSON(rootPath, templateConfig, fullTemplateUrl); | ||
@@ -175,39 +169,2 @@ await mergeFilesAndDirectories(rootPath, templatePath); | ||
function getRepoInfo(template) { | ||
try { | ||
const { user, project, default: urlStrategy } = gitInfo.fromUrl(template); | ||
if (urlStrategy === 'https' || urlStrategy === 'http') { | ||
// A full GitHub URL was provided, return username and project directly | ||
return { user, project }; | ||
} | ||
if (urlStrategy === 'shortcut') { | ||
// A shorthand was provided, so prefix the project name with "strapi-template-" | ||
return { | ||
user, | ||
project: `strapi-template-${project}`, | ||
}; | ||
} | ||
} catch (error) { | ||
// If it's not a GitHub URL, then assume it's a shorthand for an official template | ||
return { | ||
user: 'strapi', | ||
project: `strapi-template-${template}`, | ||
}; | ||
} | ||
} | ||
async function downloadGithubRepo(repoInfo, templatePath) { | ||
// Download from GitHub | ||
const { user, project } = repoInfo; | ||
const codeload = `https://codeload.github.com/${user}/${project}/tar.gz/master`; | ||
const response = await fetch(codeload); | ||
if (!response.ok) { | ||
throw Error(`Could not download the ${chalk.green(`${user}/${project}`)} repository`); | ||
} | ||
await new Promise(resolve => { | ||
response.body.pipe(tar.extract({ strip: 1, cwd: templatePath })).on('close', resolve); | ||
}); | ||
} | ||
// Merge the template's template.json into the Strapi project's package.json | ||
@@ -214,0 +171,0 @@ async function mergePackageJSON(rootPath, templateConfig, templateUrl) { |
{ | ||
"name": "strapi-generate-new", | ||
"version": "3.6.2", | ||
"version": "3.6.3", | ||
"description": "Generate a new Strapi application.", | ||
@@ -20,3 +20,3 @@ "homepage": "https://strapi.io", | ||
"fs-extra": "^9.1.0", | ||
"hosted-git-info": "3.0.8", | ||
"git-url-parse": "^11.4.4", | ||
"inquirer": "^6.3.1", | ||
@@ -57,3 +57,3 @@ "lodash": "4.17.21", | ||
"license": "SEE LICENSE IN LICENSE", | ||
"gitHead": "43b947b2ba2f153dd6056e0710d7dcd92fb9bc7c" | ||
"gitHead": "0ab3503e3c68c0e794878324a866ce9e6cfe5d47" | ||
} |
50406
41
1188
4
+ Addedgit-url-parse@^11.4.4
+ Addedcall-bind-apply-helpers@1.0.1(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.1.1(transitive)
+ Addedfilter-obj@1.1.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.7(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedgit-up@4.0.5(transitive)
+ Addedgit-url-parse@11.6.0(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedis-ssh@1.4.0(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addednormalize-url@6.1.0(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedparse-path@4.0.4(transitive)
+ Addedparse-url@6.0.5(transitive)
+ Addedprotocols@1.4.82.0.1(transitive)
+ Addedqs@6.14.0(transitive)
+ Addedquery-string@6.14.1(transitive)
+ Addedside-channel@1.1.0(transitive)
+ Addedside-channel-list@1.0.0(transitive)
+ Addedside-channel-map@1.0.1(transitive)
+ Addedside-channel-weakmap@1.0.2(transitive)
+ Addedsplit-on-first@1.1.0(transitive)
+ Addedstrict-uri-encode@2.0.0(transitive)
- Removedhosted-git-info@3.0.8
- Removedhosted-git-info@3.0.8(transitive)
- Removedlru-cache@6.0.0(transitive)