Skip to content

Commit

Permalink
feat(cli): adding clean command
Browse files Browse the repository at this point in the history
  • Loading branch information
reel committed Aug 2, 2017
1 parent 240d009 commit ed90bf7
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 5 deletions.
5 changes: 3 additions & 2 deletions packages/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ const argv = require('minimist')(process.argv.slice(2));
const command = argv._.shift();

switch (command) {
case 'server':
case 'clean':
case 'console':
case 'init':
case 'new':
case 'console':
case 'server':
case 'start-henri':
const cmd = require(`./scripts/${command}`);
cmd(argv);
Expand Down
12 changes: 10 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"chalk": "^2.0.1",
"cross-spawn": "^5.1.0",
"fs-extra": "^4.0.1",
"minimist": "^1.2.0"
"inquirer": "^3.2.1",
"minimist": "^1.2.0",
"rimraf": "^2.6.1"
},
"devDependencies": {
"@types/chalk": "^0.4.31",
Expand All @@ -25,5 +27,11 @@
"@types/minimist": "^1.2.0",
"@types/node": "^8.0.10"
},
"commands": ["server", "new", "init", "console"]
"commands": [
"server",
"new",
"init",
"console",
"clean"
]
}
66 changes: 66 additions & 0 deletions packages/cli/scripts/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Adding henri:clean cli
// might have to add inquirer

const path = require('path');

const inquirer = require('inquirer');
const fs = require('fs-extra');
const rimraf = require('rimraf');

const { validInstall } = require('./utils');

const main = async () => {
if (!validInstall()) {
console.log(`
Seems like you are not in an henri project.
Aborting...
`);
process.exit(1);
}
// Base list of potential junk to clean
const initials = [
'.tmp',
'node_modules',
'app/views/.cache',
'app/views/.next',
'app/something',
];

// Keep only existing directories/files
const existing = initials.filter(dir =>
fs.existsSync(path.resolve(process.cwd(), dir))
);
const choices = existing.map(dir => {
return { name: dir };
});

inquirer
.prompt([
{
type: 'checkbox',
message: 'Choose folders to delete',
name: 'ans',
choices: choices,
},
])
.then(answer => {
if (answer.ans && answer.ans.lenght < 1) {
console.log(`
I will not delete anything.
`);
process.exit(0);
}
for (let dir of answer.ans) {
console.log(`> Deleting ${dir}`);
rimraf.sync(path.resolve(process.cwd(), dir));
}
})
.catch(err => {
console.dir(err);
process.exit(1);
});
// Check if valid project and wipe temp folders
};

module.exports = main;
28 changes: 27 additions & 1 deletion packages/cli/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ chalk@1.1.3, chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3:
strip-ansi "^3.0.0"
supports-color "^2.0.0"

chalk@^2.0.1:
chalk@^2.0.0, chalk@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.0.1.tgz#dbec49436d2ae15f536114e76d14656cdbc0f44d"
dependencies:
Expand Down Expand Up @@ -2096,6 +2096,25 @@ inquirer@3.1.1:
strip-ansi "^3.0.0"
through "^2.3.6"

inquirer@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-3.2.1.tgz#06ceb0f540f45ca548c17d6840959878265fa175"
dependencies:
ansi-escapes "^2.0.0"
chalk "^2.0.0"
cli-cursor "^2.1.0"
cli-width "^2.0.0"
external-editor "^2.0.4"
figures "^2.0.0"
lodash "^4.3.0"
mute-stream "0.0.7"
run-async "^2.2.0"
rx-lite "^4.0.8"
rx-lite-aggregates "^4.0.8"
string-width "^2.1.0"
strip-ansi "^4.0.0"
through "^2.3.6"

interpret@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.0.3.tgz#cbc35c62eeee73f19ab7b10a801511401afc0f90"
Expand Down Expand Up @@ -4507,6 +4526,13 @@ string-width@^2.0.0:
is-fullwidth-code-point "^2.0.0"
strip-ansi "^4.0.0"

string-width@^2.1.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e"
dependencies:
is-fullwidth-code-point "^2.0.0"
strip-ansi "^4.0.0"

string_decoder@^0.10.25, string_decoder@~0.10.x:
version "0.10.31"
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94"
Expand Down

0 comments on commit ed90bf7

Please sign in to comment.