-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from strapi-community/development
Development
- Loading branch information
Showing
63 changed files
with
2,454 additions
and
2,127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const { buildConfig } = require(`../../../config`); | ||
const { askGenerateQuestions } = require(`../../../core/questions`); | ||
const { getDetectableSettings } = require(`./getDetectableSettings`); | ||
const { triggerGenerateHooks } = require(`./triggerGenerateHooks`); | ||
|
||
const generate = async () => { | ||
const { packageManager, projectType } = await getDetectableSettings(); | ||
|
||
const generateAnswers = await askGenerateQuestions(); | ||
|
||
// load configs | ||
let config = buildConfig({ | ||
...generateAnswers, | ||
packageManager, | ||
projectType | ||
}); | ||
|
||
await triggerGenerateHooks(config); | ||
}; | ||
|
||
module.exports = { | ||
generate | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const chalk = require(`chalk`); | ||
const { pathExists } = require(`fs-extra`); | ||
const path = require(`path`); | ||
const { spinner } = require(`../../../utils`); | ||
const { file, getTemplate } = require(`../../../core`); | ||
const outputs = require(`../../outputs`); | ||
|
||
const generateConfigFiles = async config => { | ||
const fileExtension = config.projectType; | ||
const environment = config.env; | ||
const dirPath = path.join(process.cwd(), `config`, `env`, config.env); | ||
|
||
for (const fileName of config.files) { | ||
const projectFilePath = `config/env/${environment}/${fileName}.${fileExtension}`; | ||
const filePath = path.join(dirPath, `${fileName}.${fileExtension}`); | ||
|
||
spinner.start(`Checking for existing ${projectFilePath}`); | ||
const hasExistingConfigFile = await pathExists(filePath); | ||
if (hasExistingConfigFile) { | ||
spinner.stopAndPersist({ | ||
symbol: `🕵️♀️ `, | ||
text: `Detected ${chalk.yellow(`${projectFilePath}`)} \n` | ||
}); | ||
|
||
const backedUp = await file.backup(filePath); | ||
spinner.stopAndPersist({ | ||
text: `${chalk.yellow(projectFilePath)} was backed up ${ | ||
backedUp ? `successfully` : `unsuccessfuly` | ||
} \n` | ||
}); | ||
} | ||
|
||
const generatedFile = await file.generate( | ||
filePath, | ||
getTemplate(fileName, fileExtension) | ||
); | ||
if (generatedFile) { | ||
spinner.stopAndPersist({ | ||
symbol: `⚙️ `, | ||
text: `Configured ${chalk.bold.green(`${projectFilePath}`)} \n` | ||
}); | ||
} else { | ||
outputs.error(`Unable to generate the ${fileName} configuration file`); | ||
} | ||
} | ||
}; | ||
|
||
module.exports = { | ||
generateConfigFiles | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const chalk = require(`chalk`); | ||
const { spinner, detect } = require(`../../../utils`); | ||
|
||
const getDetectableSettings = async () => { | ||
// package manager | ||
spinner.start(` 💻 Detecting package manager... `); | ||
const packageManager = await detect.packageManager(); | ||
spinner.stopAndPersist({ | ||
symbol: `📦 `, | ||
text: `${chalk.bold.yellow(packageManager.toUpperCase())} detected \n` | ||
}); | ||
|
||
// project type | ||
spinner.start(` 💻 Detecting Project type... `); | ||
const projectType = await detect.projectType(); | ||
const projectTypeColoredText = | ||
projectType === `ts` | ||
? chalk.bold.blueBright(`TypeScript`) | ||
: chalk.bold.yellow(`JavaScript`); | ||
spinner.stopAndPersist({ | ||
symbol: `🍿 `, | ||
text: `${projectTypeColoredText} project detected \n` | ||
}); | ||
|
||
return { | ||
packageManager, | ||
projectType | ||
}; | ||
}; | ||
|
||
module.exports = { | ||
getDetectableSettings | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { generate } = require(`./generate`); | ||
|
||
module.exports = { name: `generate`, invoke: generate }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const { generateDockerFile, installDependencies } = require(`../../../core`); | ||
const { generateConfigFiles } = require(`./generateConfigFiles`); | ||
|
||
module.exports = { | ||
async internalprebuild({ config }) { | ||
await generateConfigFiles(config); | ||
await installDependencies(config.packageManager); | ||
}, | ||
|
||
async internalpostbuild({ config }) { | ||
if (config.useDocker) { | ||
await generateDockerFile(config); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const { loadProviderConfig } = require(`../../../config`); | ||
const internalGenerateHooks = require(`./internalGenerateHooks`); | ||
|
||
const triggerGenerateHooks = async config => { | ||
const providerConfig = loadProviderConfig(config.provider); | ||
|
||
// setup hooks | ||
const { hooks } = require(`${config.providersDir}/${config.provider}`); | ||
|
||
// init hooks | ||
config.hooks.addHooks({ | ||
...hooks, | ||
...internalGenerateHooks | ||
}); | ||
|
||
// trigger provider setup | ||
// provider specific pre build | ||
await config.hooks.callHook(`prebuild`, { providerConfig, config }); | ||
|
||
// general internal pre build | ||
await config.hooks.callHook(`internalprebuild`, { providerConfig, config }); | ||
|
||
// provider specific build | ||
await config.hooks.callHook(`build`, { providerConfig, config }); | ||
|
||
// provider specific post build | ||
await config.hooks.callHook(`postbuild`, { providerConfig, config }); | ||
|
||
// general internal pre build | ||
await config.hooks.callHook(`internalpostbuild`, { providerConfig, config }); | ||
}; | ||
|
||
module.exports = { | ||
triggerGenerateHooks | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const help = args => { | ||
args.showHelp(0); | ||
}; | ||
|
||
module.exports = { name: `help`, invoke: help }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const generate = require(`./generate`); | ||
const reset = require(`./reset`); | ||
const help = require(`./help`); | ||
const commands = { | ||
generate, | ||
reset, | ||
help | ||
}; | ||
|
||
module.exports = commands; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const chalk = require(`chalk`); | ||
const path = require(`path`); | ||
const { file } = require(`../../../core`); | ||
const { spinner } = require(`../../../utils`); | ||
const outputs = require(`../../outputs`); | ||
|
||
const deleteEnvDirs = async environments => { | ||
const directory = `${process.cwd()}/config/env`; | ||
|
||
for (const env of environments) { | ||
const folderPath = path.join(directory, env); | ||
const removedEnv = await file.remove(folderPath); | ||
|
||
if (removedEnv) { | ||
spinner.stopAndPersist({ | ||
symbol: `🧹 `, | ||
text: `Cleand up ${chalk.yellow(`${folderPath}`)} folder \n` | ||
}); | ||
} else { | ||
outputs.error(`Unable to clean ${chalk.yellow(`${folderPath}`)}`); | ||
} | ||
} | ||
}; | ||
|
||
module.exports = { | ||
deleteEnvDirs | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { reset } = require(`./reset`); | ||
|
||
module.exports = { name: `reset`, invoke: reset }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const chalk = require(`chalk`); | ||
const { spinner, detect } = require(`../../../utils`); | ||
const { buildConfig } = require(`../../../config`); | ||
const { askResetQuestions } = require(`../../../core/questions`); | ||
const { deleteEnvDirs } = require(`./deleteEnvDirs`); | ||
const { triggerResetHooks } = require(`./triggerResetHooks`); | ||
|
||
const reset = async () => { | ||
const projectType = await detect.projectType(); | ||
|
||
const detectedProviderName = await detect.provider(); | ||
const { environments, provider } = await askResetQuestions( | ||
detectedProviderName | ||
); | ||
|
||
const config = buildConfig({ projectType, provider }); | ||
|
||
spinner.start(` 🦄 ${chalk.yellow(`Searching for our directories...`)} `); | ||
await deleteEnvDirs(environments); | ||
spinner.stopAndPersist({ | ||
symbol: `🦄`, | ||
text: ` Directory search ${chalk.yellow(` completed`)} \n` | ||
}); | ||
await triggerResetHooks(config); | ||
|
||
spinner.stopAndPersist({ | ||
symbol: `🧹 `, | ||
text: `Project ${chalk.yellow(`cleaned`)} \n` | ||
}); | ||
}; | ||
|
||
module.exports = { reset }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const { loadProviderConfig } = require(`../../../config`); | ||
|
||
const triggerResetHooks = async config => { | ||
const providerConfig = loadProviderConfig(config.provider); | ||
// setup hooks | ||
const { hooks } = require(`${config.providersDir}/${providerConfig.name}`); | ||
// init provider hooks | ||
config.hooks.addHooks(hooks); | ||
// trigger provider specific destroy | ||
await config.hooks.callHook(`destroy`, { providerConfig, config }); | ||
}; | ||
|
||
module.exports = { | ||
triggerResetHooks | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
const init = require(`./init`); | ||
const cli = require(`./cli`); | ||
const log = require(`./log`); | ||
const quickStart = require(`./quickstart`); | ||
const { resetProvider } = require(`./reset`); | ||
const message = require(`./message`); | ||
const { getArgs } = require(`./args`); | ||
const commands = require(`./commands`); | ||
const outputs = require(`./outputs`); | ||
|
||
module.exports = { | ||
init, | ||
cli, | ||
log, | ||
quickStart, | ||
resetProvider, | ||
message | ||
getArgs, | ||
commands, | ||
outputs | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.