Skip to content

Commit

Permalink
refactor(reset.js): refactored reset.js so we get the correct questions
Browse files Browse the repository at this point in the history
  • Loading branch information
Simen Daehlin committed Sep 5, 2022
1 parent 99c3561 commit 7b06a9a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 50 deletions.
58 changes: 18 additions & 40 deletions cli/reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ const {
constants,
spinner,
chalk,
setConfig,
config
config,
setConfig
} = require(`../utils`);
const { destroyHerokuApp } = require(`../providers/heroku`);
const { herokuQuestions } = require(`../core`);
const { getProviders } = require(`../core/questions`);
const prompts = require(`prompts`);

const FILES_TO_REMOVE = [
{
directory: `${process.cwd()}`,
Expand Down Expand Up @@ -92,50 +93,27 @@ const _resetProvider = async () => {
name: `provider`,
message: `What provider do you want to reset?`,
warn: `Not enabled yet`,
choices: [
{
title: `Heroku`,
value: `heroku`,
description: `Heroku Platform`
},
{
title: `Render`,
value: `render`,
description: `Render`
},
{
title: `AWS`,
value: `aws`,
description: `Amazon Web Services`,
disabled: true
},
{
title: `Digital Ocean`,
value: `digitalocean`,
description: `Digital Ocean App Platform`,
disabled: true
},
{
title: `Google`,
value: `Google`,
description: `Google Cloud Platform`,
disabled: true
}
]
},
{
type: prev => (prev === `heroku` ? `text` : null),
name: `projectName`,
message: `Project Name`,
validate: value => (value ? true : `Project name is required`)
choices: getProviders()
}
])
);

const { provider } = config;

switch (provider) {
case `heroku`:
await _resetFiles();
setConfig(
await prompts([
{
type: `text`,
name: `projectName`,
message: `Project Name`,
validate: value => (value ? true : `Project name is required`)
}
])
);
await destroyHerokuApp(config.providers.heroku);
await _resetFiles();
break;
case `render`:
await _resetFiles();
Expand Down
6 changes: 4 additions & 2 deletions core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const installDependecies = require(`./dependencies`);
const {
genericQuestions,
herokuQuestions,
renderQuestions
renderQuestions,
getProviders
} = require(`./questions`);
const { generateServer, generateDatabase } = require(`./generateFiles`);
const { configSetup } = require(`./configSetup`);
Expand All @@ -17,5 +18,6 @@ module.exports = {
renderQuestions,
generateServer,
configSetup,
useTool
useTool,
getProviders
};
16 changes: 10 additions & 6 deletions core/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const genericQuestions = async () => {
name: `provider`,
message: `What provider do you want to use?`,
warn: `Not enabled yet`,
choices: _getProviders()
choices: getProviders()
},
{
type: `text`,
Expand Down Expand Up @@ -55,12 +55,12 @@ const genericQuestions = async () => {
});
};

const herokuQuestions = async () => {
const herokuQuestions = async action => {
const questions = await prompts([
{
type: `select`,
name: `region`,
message: `What region do you want to deploy to? 🌍`,
message: `What region do you want to ${action}? 🌍`,
choices: _getRegions()
}
]);
Expand All @@ -85,7 +85,7 @@ const renderQuestions = async () => {
});
};

const _getProviders = () => {
const getProviders = () => {
let providerChoices = [];
for (const providerKey in config.providers) {
const provider = config.providers[providerKey];
Expand All @@ -102,8 +102,12 @@ const _getProviders = () => {

const _getRegions = () => {
const providerConfig = config.providers[config.provider];
console.log(providerConfig);
return providerConfig.regions;
};

module.exports = { genericQuestions, herokuQuestions, renderQuestions };
module.exports = {
genericQuestions,
herokuQuestions,
renderQuestions,
getProviders
};
2 changes: 1 addition & 1 deletion providers/heroku/heroku.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module.exports = {
async prebuild() {
await message(`This tool will only create NEW project on heroku`);
await detectHerokuCLI();
await herokuQuestions();
await herokuQuestions(`deploy to`);
},
async build(herokuConfig) {
await createHerokuFile(herokuConfig);
Expand Down
2 changes: 1 addition & 1 deletion utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const _config = {
packageManager: `yarn`,
projectType: `js`,
projectName: ``,
region: `eu`,
region: `global`,
files: [`server`, `database`],

strapiSecrets: {
Expand Down

0 comments on commit 7b06a9a

Please sign in to comment.