Skip to content

Commit

Permalink
Merge pull request #16 from strapi-community/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Eventyret authored Sep 14, 2022
2 parents e221c84 + c694ead commit 61a4df5
Show file tree
Hide file tree
Showing 63 changed files with 2,454 additions and 2,127 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"extends": ["eslint:recommended", "plugin:import/recommended"],
"parserOptions": {
"ecmaVersion": "latest"
},
Expand Down
30 changes: 21 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,30 @@ _Note_ that **RESET** will delete the `everything` from heroku related to the pr

- Easy deploy of your project to some cloud platforms

## 🌤 Cloud Support

Default - Create enviroments for strapi project, user will need to push to version control and deploy to cloud provider
🚀 - Automatic - Creating apps, databases, setting up env variables.
🚝 - Semi Automatic - Creating configuration files. Some manual steps required.

| **Provider** | Is Supported | Semi Automatic 🚝 / Automatic 🚀 | ⚙️ Notes |
| ------------- | ------------ | -------------------------------- | -------------------------------------------- |
| Heroku || 🚀 | Manual deployment |
| Render || 🚝 | Push to repo, connect repo to render website |
| AWS ||| Not Added yet |
| Google ||| Not Added yet |
| Digital Ocean ||| Not Added yet |
| Platform.sh ||| Not Added yet |
| Railway.app ||| Not Added yet |

## 🖐 Requirements

Supported Strapi Versions:

| Strapi Version | Is Compatible | Last Tested |
| --------------- | ------------- | ----------- |
| v3.x.x || Never |
| v4.0.x || Never |
| v4.1.x || Never |
| v4.2.x || Never |
| v4.3.x || Never |
| Future Versions || Never |
| Strapi Version | Is Compatible |
| -------------- | ------------- |
| v3 ||
| v4 ||

**This tool will not work with Strapi v3 projects as it utilizes the V4 folder format that don't exist in the v3!**

Expand All @@ -77,7 +89,7 @@ If interested please feel free to email the lead maintainer Simen at: simen@dehl

### Contributors

- [Daedalus](https://github.com/ComfortablyCoding)
- [@ComfortablyCoding / Daedalus](https://github.com/ComfortablyCoding)

## ⭐️ Show your support

Expand Down
4 changes: 3 additions & 1 deletion cli/cli.js → cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ const options = {
flags
};

module.exports = meow(helpText, options);
module.exports = {
getArgs: () => meow(helpText, options)
};
23 changes: 23 additions & 0 deletions cli/commands/generate/generate.js
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
};
50 changes: 50 additions & 0 deletions cli/commands/generate/generateConfigFiles.js
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
};
33 changes: 33 additions & 0 deletions cli/commands/generate/getDetectableSettings.js
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
};
3 changes: 3 additions & 0 deletions cli/commands/generate/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { generate } = require(`./generate`);

module.exports = { name: `generate`, invoke: generate };
15 changes: 15 additions & 0 deletions cli/commands/generate/internalGenerateHooks.js
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);
}
}
};
35 changes: 35 additions & 0 deletions cli/commands/generate/triggerGenerateHooks.js
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
};
5 changes: 5 additions & 0 deletions cli/commands/help.js
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 };
10 changes: 10 additions & 0 deletions cli/commands/index.js
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;
27 changes: 27 additions & 0 deletions cli/commands/reset/deleteEnvDirs.js
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
};
3 changes: 3 additions & 0 deletions cli/commands/reset/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { reset } = require(`./reset`);

module.exports = { name: `reset`, invoke: reset };
32 changes: 32 additions & 0 deletions cli/commands/reset/reset.js
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 };
15 changes: 15 additions & 0 deletions cli/commands/reset/triggerResetHooks.js
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
};
19 changes: 7 additions & 12 deletions cli/index.js
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
};
16 changes: 0 additions & 16 deletions cli/init.js

This file was deleted.

12 changes: 0 additions & 12 deletions cli/log.js

This file was deleted.

10 changes: 0 additions & 10 deletions cli/message.js

This file was deleted.

Loading

0 comments on commit 61a4df5

Please sign in to comment.