Skip to content

Commit

Permalink
feat(destroyherokuapp): now fetching users apps instead of ask for th…
Browse files Browse the repository at this point in the history
…e name
  • Loading branch information
Simen Daehlin committed Sep 14, 2022
1 parent 791f873 commit b9e8756
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
18 changes: 0 additions & 18 deletions core/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ const askResetQuestions = async detectedProvider => {
message: `Is ${detectedProvider} the provider you want to reset?`
}
]);
if (detectedProvider === `Heroku`) {
await getProjectName();
}
if (providerConfirmation) {
return { environments, provider: detectedProvider };
}
Expand All @@ -109,24 +106,9 @@ const askResetQuestions = async detectedProvider => {
choices: getProviders()
}
]);
if (provider === `Heroku`) {
await getProjectName();
}
return { environments, provider };
};

const getProjectName = async () => {
const projectName = await prompts([
{
type: `text`,
name: `projectName`,
message: `Project Name`,
validate: value => (value ? true : `Project name is required`)
}
]);
buildConfig(projectName);
};

const getProviders = () => {
let providerChoices = [];
for (const providerKey in loadProviders()) {
Expand Down
43 changes: 33 additions & 10 deletions providers/heroku/destroyHerokuApp.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
const chalk = require(`chalk`);
const shell = require(`shelljs`);
const { spinner } = require(`../../utils`);
const prompts = require(`prompts`);

const destroyHerokuApp = async ({ config, herokuConfig }) => {
const projectName = config.projectName;
spinner.stopAndPersist({
symbol: `💀 `,
text: `Tearing down ${chalk.magenta.bold(
projectName.toUpperCase()
)} on ${chalk.magenta.bold(`Heroku`)}`
});

shell.exec(
`HEROKU_API_KEY="${herokuConfig.apiToken}" heroku apps:destroy ${projectName} --confirm ${projectName}`
const test = shell.exec(
`HEROKU_API_KEY="${herokuConfig.apiToken}" heroku apps --json -p`,
{ silent: true }
);

// map over test and return title and value
const herokuApps = JSON.parse(test.stdout).map(app => {
return {
title: app.name,
value: app.name
};
});
let { apps } = await prompts([
{
type: `multiselect`,
name: `apps`,
message: `Pick the environments to clean`,
choices: herokuApps,
min: 1,
hint: `- Space to select. Return to submit`
}
]);
for (const app of apps) {
spinner.start(` 🦄 Tearing down ${chalk.magenta.bold(app.toUpperCase())}`);
shell.exec(
`HEROKU_API_KEY="${herokuConfig.apiToken}" heroku apps:destroy ${app} --confirm ${app}`,
{ silent: true }
);
spinner.stopAndPersist({
symbol: `💀`,
text: chalk.yellow(`Teared ${app} down from strapi \n`)
});
}

spinner.stopAndPersist({
symbol: `🤠 `,
text: `Note from ${chalk.magenta(
Expand Down

0 comments on commit b9e8756

Please sign in to comment.