Skip to content

Commit

Permalink
feat: silent command on bin
Browse files Browse the repository at this point in the history
  • Loading branch information
kissxp committed Apr 19, 2022
1 parent 3ac2f03 commit 69beebe
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 27 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ clearPath("dist");
```

### options
> These options can only be changed when using `clear-path` in JS.

```js
clearPath("dist", {
Expand All @@ -63,14 +62,16 @@ clearPath("dist", {
})
```

#### options.silent
### options.silent

**Default:** `false`\
If set to true, will not console log deleted files.

#### options.callback
> You can activate options.silent from cli commands using `clear-path --silent` or `clear-path --routine:{routine_name} --silent`
If you declara a function in your `options.callback`, will execute after deleting files.
### options.callback

If you declara a function in your `options.callback`, it will execute after deleting files.

## Multiple clear-path routines

Expand Down
3 changes: 0 additions & 3 deletions backlog.md

This file was deleted.

29 changes: 20 additions & 9 deletions bin/clear-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ const getRoutine = ( args ) => {
return undefined;
};

const clearPathArrayOrString = ( pathsToDelete ) => {
const clearPathArrayOrString = ( pathsToDelete, options ) => {
if ( typeof( pathsToDelete ) === "string" ) {
clearPath( pathsToDelete );
clearPath( pathsToDelete, options );
return;
}

if ( Array.isArray( pathsToDelete ) ) {
for ( const path of pathsToDelete ) {
clearPath( path );
clearPath( path, options );
}
return;
}
Expand All @@ -50,8 +50,20 @@ const clearPathArrayOrString = ( pathsToDelete ) => {
};

const runScript = () => {
const { argv } = process;
const isSilent = argv.includes( "--silent" );

// Script start message
info( chalk.gray( "> clear-path.js" ) );
if ( !isSilent ) {
info( chalk.gray( "> clear-path.js" ) );
}

const config = {
silent: false,
callback: false
};

config.silent = isSilent;

const explorer = cosmiconfig( "clearpath" );

Expand All @@ -64,18 +76,17 @@ const runScript = () => {
const pathsToDelete = filterConfig( result.config );

if ( pathsToDelete.routine ) {
const args = process.argv.slice( 2 );
const argRoutine = getRoutine( args );
const argRoutine = getRoutine( argv.slice( 2 ) );

if ( argRoutine ) {
const routineToRun = pathsToDelete.routine[argRoutine];

if ( routineToRun ) {
return clearPathArrayOrString( routineToRun );
return clearPathArrayOrString( routineToRun, config );
}

if ( pathsToDelete.routine.default ) {
return clearPathArrayOrString( pathsToDelete.routine.default );
return clearPathArrayOrString( pathsToDelete.routine.default, config );
}

return displayError( `routine '${argRoutine}' not found` );
Expand All @@ -84,7 +95,7 @@ const runScript = () => {
return displayError( "missing routine parameter" );
}

clearPathArrayOrString( pathsToDelete );
clearPathArrayOrString( pathsToDelete, config );

} )
.catch( ( error ) => {
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clear-path",
"version": "1.3.0",
"version": "1.3.1",
"type": "module",
"description": "A node library for deleting a path if exists using del",
"license": "MIT",
Expand Down Expand Up @@ -47,7 +47,7 @@
},
"devDependencies": {
"@babel/eslint-parser": "^7.17.0",
"eslint": "^8.12.0",
"eslint": "^8.13.0",
"husky": "^7.0.4",
"lint-staged": "^12.3.8"
},
Expand Down

0 comments on commit 69beebe

Please sign in to comment.