@strapi/generate-new
Advanced tools
Comparing version 4.2.0 to 4.3.0-beta.1
@@ -17,3 +17,13 @@ /* eslint-disable no-unreachable */ | ||
const LANGUAGES = { | ||
javascript: 'JavaScript', | ||
typescript: 'TypeScript', | ||
}; | ||
module.exports = async scope => { | ||
if (!scope.useTypescript) { | ||
const language = await askAboutLanguages(scope); | ||
scope.useTypescript = language === LANGUAGES.typescript; | ||
} | ||
await trackUsage({ event: 'didChooseCustomDatabase', scope }); | ||
@@ -161,1 +171,15 @@ | ||
} | ||
async function askAboutLanguages() { | ||
const { language } = await inquirer.prompt([ | ||
{ | ||
type: 'list', | ||
name: 'language', | ||
message: 'Choose your preferred language', | ||
choices: Object.values(LANGUAGES), | ||
default: LANGUAGES.javascript, | ||
}, | ||
]); | ||
return language; | ||
} |
@@ -17,4 +17,5 @@ 'use strict'; | ||
const packageJSON = require('./resources/json/package.json'); | ||
const packageJSON = require('./resources/json/common/package.json'); | ||
const createDatabaseConfig = require('./resources/templates/database.js'); | ||
const createAdminConfig = require('./resources/templates/admin-config.js'); | ||
const createEnvFile = require('./resources/templates/env.js'); | ||
@@ -26,18 +27,37 @@ | ||
const { rootPath } = scope; | ||
const { rootPath, useTypescript } = scope; | ||
const resources = join(__dirname, 'resources'); | ||
const language = useTypescript ? 'ts' : 'js'; | ||
try { | ||
// copy files | ||
await fse.copy(join(resources, 'files'), rootPath); | ||
await fse.copy(join(resources, 'files', language), rootPath); | ||
// copy dot files | ||
await fse.writeFile(join(rootPath, '.env'), createEnvFile()); | ||
const dotFiles = await fse.readdir(join(resources, 'dot-files')); | ||
await Promise.all( | ||
dotFiles.map(name => { | ||
return fse.copy(join(resources, 'dot-files', name), join(rootPath, `.${name}`)); | ||
}) | ||
); | ||
const copyDotFilesFromSubDirectory = subDirectory => { | ||
const files = fse.readdirSync(join(resources, 'dot-files', subDirectory)); | ||
return Promise.all( | ||
files.map(file => { | ||
const src = join(resources, 'dot-files', subDirectory, file); | ||
const dest = join(rootPath, `.${file}`); | ||
return fse.copy(src, dest); | ||
}) | ||
); | ||
}; | ||
// Copy common dot files | ||
copyDotFilesFromSubDirectory('common'); | ||
// Copy JS dot files | ||
// For now we only support javascript and typescript, so if we're not using | ||
// typescript, then we can assume we're using javascript. We'll need to change | ||
// this behavior when we'll abstract the supported languages even more. | ||
if (!useTypescript) { | ||
copyDotFilesFromSubDirectory('js'); | ||
} | ||
await trackUsage({ event: 'didCopyProjectFiles', scope }); | ||
@@ -63,11 +83,29 @@ | ||
if (useTypescript) { | ||
const tsJSONDir = join(__dirname, 'resources', 'json', 'ts'); | ||
const filesMap = { | ||
'tsconfig-admin.json.js': 'src/admin', | ||
'tsconfig-server.json.js': '.', | ||
}; | ||
for (const [fileName, path] of Object.entries(filesMap)) { | ||
const srcPath = join(tsJSONDir, fileName); | ||
const destPath = join(rootPath, path, 'tsconfig.json'); | ||
const json = require(srcPath)(); | ||
await fse.writeJSON(destPath, json, { spaces: 2 }); | ||
} | ||
} | ||
// ensure node_modules is created | ||
await fse.ensureDir(join(rootPath, 'node_modules')); | ||
// create config/database.js | ||
// create config/database | ||
await fse.writeFile( | ||
join(rootPath, `config/database.js`), | ||
join(rootPath, `config/database.${language}`), | ||
createDatabaseConfig({ | ||
client, | ||
connection, | ||
useTypescript, | ||
}) | ||
@@ -77,2 +115,6 @@ ); | ||
// create config/server.js | ||
await fse.writeFile( | ||
join(rootPath, `config/admin.${language}`), | ||
createAdminConfig({ useTypescript }) | ||
); | ||
await trackUsage({ event: 'didCopyConfigurationFiles', scope }); | ||
@@ -79,0 +121,0 @@ |
@@ -10,3 +10,3 @@ 'use strict'; | ||
const createCLIDatabaseProject = require('./create-cli-db-project'); | ||
const createCustomizeProject = require('./create-customized-project'); | ||
const createCustomizedProject = require('./create-customized-project'); | ||
const createQuickStartProject = require('./create-quickstart-project'); | ||
@@ -32,3 +32,3 @@ | ||
// create a project with full list of questions | ||
return createCustomizeProject(scope); | ||
return createCustomizedProject(scope); | ||
}; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
const crypto = require('crypto'); | ||
const uuid = require('uuid/v4'); | ||
const uuid = require('uuid').v4; | ||
const sentry = require('@sentry/node'); | ||
@@ -59,2 +59,3 @@ // FIXME | ||
additionalsDependencies: {}, | ||
useTypescript: Boolean(cliArguments.typescript), | ||
}; | ||
@@ -61,0 +62,0 @@ |
@@ -7,4 +7,7 @@ 'use strict'; | ||
module.exports = ({ connection, client }) => { | ||
const tmpl = fs.readFileSync(path.join(__dirname, 'database-templates', `${client}.template`)); | ||
module.exports = ({ connection, client, useTypescript }) => { | ||
const language = useTypescript ? 'ts' : 'js'; | ||
const tmpl = fs.readFileSync( | ||
path.join(__dirname, language, 'database-templates', `${client}.template`) | ||
); | ||
const compile = _.template(tmpl); | ||
@@ -11,0 +14,0 @@ |
@@ -89,2 +89,4 @@ 'use strict'; | ||
useYarn: scope.useYarn, | ||
useTypescriptOnServer: scope.useTypescript, | ||
useTypescriptOnAdmin: scope.useTypescript, | ||
}; | ||
@@ -116,2 +118,4 @@ | ||
useYarn: scope.useYarn.toString(), | ||
useTypescriptOnServer: scope.useTypescript, | ||
useTypescriptOnAdmin: scope.useTypescript, | ||
noRun: (scope.runQuickstartApp !== true).toString(), | ||
@@ -118,0 +122,0 @@ }; |
{ | ||
"name": "@strapi/generate-new", | ||
"version": "4.2.0", | ||
"version": "4.3.0-beta.1", | ||
"description": "Generate a new Strapi application.", | ||
@@ -55,3 +55,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "12c8ee3b2d95fe417de4d939db0311a0513bd8da" | ||
"gitHead": "9d6555398960c39159d66bb4eea3bcb0362e37e3" | ||
} |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
62912
69
1344
2
15