1 | const inquirer = require( 'inquirer' );
|
2 | const chalk = require( 'chalk' );
|
3 | const nconf = require( 'nconf' );
|
4 | const sh = require( 'shelljs' );
|
5 | const prompt = require( '../lib/prompt' );
|
6 | const config = require( '../lib/config' );
|
7 | const util = require( '../lib/util' );
|
8 | const hosts = require( '../lib/hosts' );
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | async function remove() {
|
14 | if ( !util.localProjectsExist() ) {
|
15 | console.error( chalk`{red.bold No projects available.}` );
|
16 | process.exit( 1 );
|
17 | }
|
18 |
|
19 | const projObj = await inquirer.prompt( prompt.getDestroyPrompt() );
|
20 | console.log( chalk`{red.bold You are about to remove this project from your machine.}` );
|
21 | const confirmObj = await inquirer.prompt( prompt.getConfirmPrompt() );
|
22 |
|
23 | if ( confirmObj.answer ) {
|
24 | const slug = projObj.answer;
|
25 | const projects = nconf.get( 'local_projects' );
|
26 | const path = nconf.get( `local_projects:${slug}:path` );
|
27 | const containers = nconf.get( `local_projects:${slug}:containers` );
|
28 | const domainGroup = nconf.get( `local_projects:${slug}:hosts_domain_group` );
|
29 |
|
30 |
|
31 | if ( domainGroup ) {
|
32 | await hosts.remove( domainGroup );
|
33 | }
|
34 |
|
35 |
|
36 | if ( containers ) {
|
37 | containers.forEach( ( container ) => {
|
38 | sh.exec( `docker rm --volumes --force ${container}` );
|
39 | });
|
40 | }
|
41 |
|
42 |
|
43 | if ( path ) {
|
44 | sh.rm( '-rf', path );
|
45 | } else {
|
46 | console.log( chalk`{red.bold Path not found in selected project's config.}` );
|
47 | process.exit( 1 );
|
48 | }
|
49 |
|
50 |
|
51 | delete projects[slug];
|
52 | config.updateLocalProjects( projects );
|
53 | }
|
54 | }
|
55 |
|
56 | module.exports = remove;
|