-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add vip dev-env purge command logic (#1537)
* Add vip dev-env purge command logic * Fix most linting errors w/ `npm lint:fix` The linting errors due to spaces were auto fixed nicely. I think the errors with the await statements might need more thought. I frankenstien'd `vip-dev-env-list` with `vip-dev-env-delete`. My rationale was to send the delete command, wait for its success, then send the next one. The linter doesn't like this loop though. * Silence `no-await-in-loop` lint warnings, for now * Fix linting errors * Add confirmation prompt and existence of environments * Update tracking tags to purge and move some code out of loop * Update src/bin/vip-dev-env-purge.js Co-authored-by: Volodymyr Kolesnykov <[email protected]> * Move trackingInfo around * Remove irrelevant es-lint ignores --------- Co-authored-by: Michelle Byrnes <[email protected]> Co-authored-by: Rebecca Hum <[email protected]> Co-authored-by: Volodymyr Kolesnykov <[email protected]>
- Loading branch information
1 parent
b1fe947
commit 296b129
Showing
3 changed files
with
93 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import chalk from 'chalk'; | ||
import debugLib from 'debug'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import command from '../lib/cli/command'; | ||
import { DEV_ENVIRONMENT_FULL_COMMAND } from '../lib/constants/dev-environment'; | ||
import { | ||
getEnvTrackingInfo, | ||
handleCLIException, | ||
validateDependencies, | ||
promptForBoolean, | ||
} from '../lib/dev-environment/dev-environment-cli'; | ||
import { | ||
destroyEnvironment, | ||
getAllEnvironmentNames, | ||
} from '../lib/dev-environment/dev-environment-core'; | ||
import { bootstrapLando } from '../lib/dev-environment/dev-environment-lando'; | ||
import { trackEvent } from '../lib/tracker'; | ||
|
||
const debug = debugLib( '@automattic/vip:bin:dev-environment' ); | ||
|
||
const examples = [ | ||
{ | ||
usage: `${ DEV_ENVIRONMENT_FULL_COMMAND } purge`, | ||
description: 'Destroys all local dev environments', | ||
}, | ||
{ | ||
usage: `${ DEV_ENVIRONMENT_FULL_COMMAND } purge --force`, | ||
description: 'Destroys all local dev environments without prompting', | ||
}, | ||
]; | ||
|
||
command() | ||
.option( 'soft', 'Keep config files needed to start an environment intact' ) | ||
.option( 'force', 'Removes prompt that verifies if user wants to destroy all environments' ) | ||
.examples( examples ) | ||
.argv( process.argv, async ( arg, opt ) => { | ||
debug( 'Args: ', arg, 'Options: ', opt ); | ||
|
||
const allEnvNames = getAllEnvironmentNames(); | ||
const lando = await bootstrapLando(); | ||
|
||
if ( allEnvNames.length === 0 ) { | ||
console.log( 'No environments to purge!' ); | ||
return; | ||
} | ||
|
||
if ( ! opt.force ) { | ||
const purge = await promptForBoolean( | ||
'Are you sure you want to purge ALL existing dev environments?', | ||
true | ||
); | ||
|
||
if ( ! purge ) { | ||
return; | ||
} | ||
} | ||
|
||
const trackingInfo = { all: true }; | ||
await trackEvent( 'dev_env_purge_command_execute', trackingInfo ); | ||
await validateDependencies( lando, '' ); | ||
const removeFiles = ! ( opt.soft || false ); | ||
|
||
try { | ||
for ( const slug of allEnvNames ) { | ||
try { | ||
// eslint-disable-next-line no-await-in-loop | ||
await destroyEnvironment( lando, slug, removeFiles ); | ||
|
||
const message = chalk.green( '✓' ) + ' Environment destroyed.\n'; | ||
console.log( message ); | ||
} catch ( error ) { | ||
const trackingInfoChild = getEnvTrackingInfo( slug ); | ||
// eslint-disable-next-line no-await-in-loop | ||
await handleCLIException( error, 'dev_env_purge_command_error', trackingInfoChild ); | ||
process.exitCode = 1; | ||
} | ||
} | ||
await trackEvent( 'dev_env_purge_command_success', trackingInfo ); | ||
} catch ( error ) { | ||
await handleCLIException( error, 'dev_env_purge_command_error', trackingInfo ); | ||
process.exitCode = 1; | ||
} | ||
} ); |
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