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

create-strapi-starter

Package Overview
Dependencies
Maintainers
1
Versions
1205
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-strapi-starter - npm Package Compare versions

Comparing version 3.5.2 to 3.5.4-next.0

utils/logger.js

25

create-strapi-starter.js
'use strict';
const commander = require('commander');
const packageJson = require('./package.json');

@@ -26,14 +27,22 @@ const buildStarter = require('./utils/build-starter');

.option('--dbforce', 'Overwrite database content if any')
.description('create a new strapi starter application')
.action((directory, starterUrl, program) => {
.description(
'Create a fullstack monorepo application using the strapi backend template specified in the provided starter'
)
.action((directory, starterUrl, programArgs) => {
const projectArgs = { projectName: directory, starterUrl };
buildStarter(projectArgs, program);
buildStarter(projectArgs, programArgs).catch(error => {
console.error(error.message);
process.exit(1);
});
});
// Show help if not enough arguments are present
if (process.argv.length < 4) {
program.help();
program.exitOverride();
try {
program.parse(process.argv);
} catch (err) {
if (err.exitCode && err.exitCode != 0) {
program.outputHelp();
}
}
program.parse(process.argv);
{
"name": "create-strapi-starter",
"version": "3.5.2",
"version": "3.5.4-next.0",
"description": "Generate a new Strapi application.",

@@ -21,3 +21,3 @@ "license": "SEE LICENSE IN LICENSE",

"ci-info": "3.1.1",
"commander": "6.1.0",
"commander": "7.1.0",
"execa": "5.0.0",

@@ -28,3 +28,3 @@ "fs-extra": "9.1.0",

"ora": "5.3.0",
"strapi-generate-new": "3.5.2",
"strapi-generate-new": "3.5.4-next.0",
"tar": "6.1.0"

@@ -51,3 +51,3 @@ },

},
"gitHead": "231263a3535658bab1e9492c6aaaed8692d62a53"
"gitHead": "5505efd304bb27c5e78f4467de676cb70fa02e1e"
}

@@ -12,3 +12,3 @@ # Create strapi starter

```
yarn create strapi-starter my-project
yarn create strapi-starter my-project starter-url
```

@@ -19,3 +19,3 @@

```
npx create-strapi-starter my-project
npx create-strapi-starter my-project starter-url
```

@@ -29,3 +29,3 @@

yarn global add create-strapi-app
create-strapi-starter my-app
create-strapi-starter my-project starter-url
```

@@ -37,3 +37,3 @@

npm install -g create-strapi-app
create-strapi-starter my-app
create-strapi-starter my-project starter-url
```

@@ -7,12 +7,13 @@ 'use strict';

const ora = require('ora');
const ciEnv = require('ci-info');
const chalk = require('chalk');
const generateNewApp = require('strapi-generate-new');
const ora = require('ora');
const ciEnv = require('ci-info');
const hasYarn = require('./has-yarn');
const { runInstall, runApp, initGit } = require('./child-process');
const { getRepoInfo, downloadGithubRepo } = require('./fetch-github');
const logger = require('./logger');
const stopProcess = require('./stop-process');

@@ -22,5 +23,9 @@ /**

*/
function readStarterJson(filePath) {
const data = fse.readFileSync(filePath);
return JSON.parse(data);
function readStarterJson(filePath, starterUrl) {
try {
const data = fse.readFileSync(filePath);
return JSON.parse(data);
} catch (err) {
stopProcess(`Could not find ${chalk.yellow('starter.json')} in ${chalk.yellow(starterUrl)}`);
}
}

@@ -32,25 +37,29 @@

*/
function initPackageJson(rootPath, projectName) {
async function initPackageJson(rootPath, projectName) {
const packageManager = hasYarn ? 'yarn --cwd' : 'npm run --prefix';
fse.writeJson(
join(rootPath, 'package.json'),
{
name: projectName,
private: true,
version: '0.0.0',
scripts: {
'develop:backend': `${packageManager} backend develop`,
'develop:frontend': `wait-on http://localhost:1337/admin && ${packageManager} frontend develop --open`,
develop: 'npm-run-all -p develop:*',
try {
await fse.writeJson(
join(rootPath, 'package.json'),
{
name: projectName,
private: true,
version: '0.0.0',
scripts: {
'develop:backend': `${packageManager} backend develop`,
'develop:frontend': `wait-on http://localhost:1337/admin && ${packageManager} frontend develop`,
develop: 'FORCE_COLOR=1 npm-run-all -l -p develop:*',
},
devDependencies: {
'npm-run-all': '4.1.5',
'wait-on': '5.2.1',
},
},
devDependencies: {
'npm-run-all': '4.1.5',
'wait-on': '5.2.1',
},
},
{
spaces: 2,
}
);
{
spaces: 2,
}
);
} catch (err) {
stopProcess(`Failed to create ${chalk.yellow(`package.json`)} in ${chalk.yellow(rootPath)}`);
}
}

@@ -93,11 +102,7 @@

const { full_name } = await getRepoInfo(starterUrl);
// Download repo inside tmp dir
try {
await downloadGithubRepo(starterUrl, tmpDir);
} catch (err) {
throw Error(`Could not download ${chalk.yellow(`${full_name}`)} repository.`);
}
await downloadGithubRepo(starterUrl, tmpDir);
// Read starter package json for template url
const starterJson = readStarterJson(join(tmpDir, 'starter.json'));
const starterJson = readStarterJson(join(tmpDir, 'starter.json'), starterUrl);

@@ -108,12 +113,26 @@ // Project directory

try {
await fse.ensureDir(rootPath);
} catch (error) {
stopProcess(`Failed to create ${chalk.yellow(rootPath)}: ${error.message}`);
}
// Copy the downloaded frontend folder to the project folder
await fse.copy(join(tmpDir, 'frontend'), join(rootPath, 'frontend'), {
overwrite: true,
recursive: true,
});
const frontendPath = join(rootPath, 'frontend');
const starterDir = (await fse.pathExists(join(tmpDir, 'starter'))) ? 'starter' : 'frontend';
try {
await fse.copy(join(tmpDir, starterDir), frontendPath, {
overwrite: true,
recursive: true,
});
} catch (error) {
stopProcess(`Failed to create ${chalk.yellow(frontendPath)}: ${error.message}`);
}
// Delete temporary directory
await fse.remove(tmpDir);
console.log(`Creating Strapi starter frontend at ${chalk.green(`${rootPath}/frontend`)}.`);
console.log(`Creating Strapi starter frontend at ${chalk.yellow(frontendPath)}.`);

@@ -123,7 +142,9 @@ // Install frontend dependencies

await installWithLogs(join(rootPath, 'frontend'));
await installWithLogs(frontendPath);
const fullUrl = `https://github.com/${full_name}`;
// Set command options for Strapi app
const generateStrapiAppOptions = {
...program,
starter: fullUrl,
template: starterJson.template,

@@ -144,3 +165,3 @@ run: false,

} catch (err) {
console.error(err);
logger.warn(`Failed to create file: ${chalk.yellow('.gitignore')}`);
}

@@ -147,0 +168,0 @@

@@ -6,2 +6,3 @@ 'use strict';

const hasYarn = require('./has-yarn');
const logger = require('./logger');

@@ -41,3 +42,7 @@ /**

});
} catch (err) {
logger.warn(`Could not initialize a git repository`);
}
try {
await execa(`git`, [`add`, `-A`], { cwd: rootPath });

@@ -49,3 +54,3 @@

} catch (err) {
console.error(err);
logger.warn(`Could not create initial git commit`);
}

@@ -52,0 +57,0 @@ }

@@ -7,3 +7,19 @@ 'use strict';

const chalk = require('chalk');
const stopProcess = require('./stop-process');
function getShortcut(starter) {
let full_name;
// Determine if it is another organization
if (starter.includes('/')) {
const [org, project] = starter.split('/');
full_name = `${org}/strapi-starter-${project}`;
} else {
full_name = `strapi/strapi-starter-${starter}`;
}
return {
full_name,
usedShortcut: true,
};
}
/**

@@ -13,15 +29,15 @@ * @param {string} repo The path to repo

async function getDefaultBranch(repo) {
try {
const response = await fetch(`https://api.github.com/repos/${repo}`);
const response = await fetch(`https://api.github.com/repos/${repo}`);
if (!response.ok) {
throw Error(`Could not fetch the default branch`);
}
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();
const { default_branch } = await response.json();
return default_branch;
} catch (err) {
console.error(err);
}
return default_branch;
}

@@ -33,30 +49,18 @@

async function getRepoInfo(starter) {
try {
const repoInfo = await parseGitUrl(starter);
const { name, full_name, ref, protocols } = repoInfo;
const repoInfo = await parseGitUrl(starter);
const { name, full_name, ref, protocols, source } = repoInfo;
if (protocols.length === 0) {
throw Error('Could not detect an acceptable URL');
}
if (protocols.length === 0) {
return getShortcut(starter);
}
return {
name,
full_name,
ref,
};
} catch (err) {
// If it's not a GitHub URL, then assume it's a shorthand
let full_name;
// Determine if it is another organization
if (starter.includes('/')) {
const [org, project] = starter.split('/');
full_name = `${org}/strapi-starter-${project}`;
} else {
full_name = `strapi/strapi-starter-${starter}`;
}
if (source !== 'github.com') {
stopProcess(`Github URL not found for: ${chalk.yellow(starter)}`);
}
return {
full_name,
};
}
return {
name,
full_name,
ref,
};
}

@@ -69,3 +73,3 @@

async function downloadGithubRepo(starterUrl, tmpDir) {
const { name, full_name, ref } = await getRepoInfo(starterUrl);
const { full_name, ref, usedShortcut } = await getRepoInfo(starterUrl);
const default_branch = await getDefaultBranch(full_name);

@@ -77,5 +81,7 @@

const codeload = `https://codeload.github.com/${full_name}/tar.gz/${branch}`;
const response = await fetch(codeload);
if (!response.ok) {
throw Error(`Could not download the ${chalk.green(`${name}`)} repository`);
const message = usedShortcut ? `using the shortcut` : `using the url`;
stopProcess(`Could not download the repository ${message}: ${chalk.yellow(`${starterUrl}`)}`);
}

@@ -82,0 +88,0 @@

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