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 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | async function remove( program ) {
|
15 | const optionProject = program.args[0].project;
|
16 | const optionForce = program.args[0].force;
|
17 |
|
18 | if ( !util.localProjectsExist() ) {
|
19 | console.error( chalk`{red.bold No projects available.}` );
|
20 | process.exit( 1 );
|
21 | }
|
22 |
|
23 |
|
24 | let projectResponse;
|
25 | if ( optionProject ) {
|
26 | projectResponse = optionProject;
|
27 | } else {
|
28 | const projObj = await inquirer.prompt( prompt.getAvailableProjectsPrompt() );
|
29 | projectResponse = projObj.answer;
|
30 | console.log( chalk`{red.bold You are about to remove this project from your machine.}` );
|
31 | }
|
32 | const slug = projectResponse;
|
33 |
|
34 | let confirmResponse;
|
35 | if ( optionForce ) {
|
36 | confirmResponse = optionForce;
|
37 | } else {
|
38 | const confirmObj = await inquirer.prompt( prompt.getConfirmPrompt() );
|
39 | confirmResponse = confirmObj.answer;
|
40 | }
|
41 |
|
42 | if ( confirmResponse ) {
|
43 | const projects = nconf.get( 'local_projects' );
|
44 | const path = nconf.get( `local_projects:${slug}:path` );
|
45 | const containers = nconf.get( `local_projects:${slug}:containers` );
|
46 |
|
47 |
|
48 | if ( containers ) {
|
49 | containers.forEach( ( container ) => {
|
50 | sh.exec( `docker rm --volumes --force ${container}` );
|
51 | });
|
52 | }
|
53 |
|
54 |
|
55 | if ( path ) {
|
56 | sh.rm( '-rf', path );
|
57 | } else {
|
58 | console.log( chalk`{red.bold Path not found in selected project's config.}` );
|
59 | process.exit( 1 );
|
60 | }
|
61 |
|
62 |
|
63 | delete projects[slug];
|
64 | config.updateLocalProjects( projects );
|
65 |
|
66 | console.log( chalk`{green Removed ${slug}.}` );
|
67 | }
|
68 | }
|
69 |
|
70 | module.exports = remove;
|