Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

strapi-generate-new

Package Overview
Dependencies
Maintainers
9
Versions
294
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

strapi-generate-new - npm Package Compare versions

Comparing version 3.6.2 to 3.6.3

lib/utils/fetch-github.js

57

lib/utils/merge-template.js

@@ -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"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc