create-strapi-starter
Advanced tools
Comparing version 3.5.2 to 3.5.4-next.0
'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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
15064
12
336
0
2
336
+ Added@sentry/core@6.2.3(transitive)
+ Added@sentry/hub@6.2.3(transitive)
+ Added@sentry/minimal@6.2.3(transitive)
+ Added@sentry/node@6.2.3(transitive)
+ Added@sentry/tracing@6.2.3(transitive)
+ Added@sentry/types@6.2.3(transitive)
+ Added@sentry/utils@6.2.3(transitive)
+ Addedcommander@7.1.0(transitive)
+ Addedstrapi-generate-new@3.5.4-next.0(transitive)
- Removed@sentry/core@6.2.0(transitive)
- Removed@sentry/hub@6.2.0(transitive)
- Removed@sentry/minimal@6.2.0(transitive)
- Removed@sentry/node@6.2.0(transitive)
- Removed@sentry/tracing@6.2.0(transitive)
- Removed@sentry/types@6.2.0(transitive)
- Removed@sentry/utils@6.2.0(transitive)
- Removedcommander@6.1.0(transitive)
- Removedstrapi-generate-new@3.5.2(transitive)
Updatedcommander@7.1.0