Skip to content

Commit

Permalink
Add descriptions to scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
omrilotan committed Nov 27, 2019
1 parent 918b635 commit b4ce3cf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,40 @@
$ npm i -g @lets/run
```

Simply run. You'll get an interactive menu.
## Simply run. You'll get an interactive menu.
```
$ run
```

Pass arguments. Arguments will be forwarded to the selected script
## Pass arguments. Arguments will be forwarded to the selected script
```
run --color
```

Otherwise you will get a chance to add in arguments after selecting the script to run

You can also run dependencies executables:
## You can also run dependencies executables:

![](https://user-images.githubusercontent.com/516342/69226314-9e72c180-0b88-11ea-8fc2-fd5ff3aac71f.gif)

## Create descriptive entries using package.json property: `scripts:descriptions`

```json
{
...
"scripts": {
"lint": "eslint '**/*.js'",
"start": "./bin.js"
},
"scripts:descriptions": {
"lint": "Check code syntax"
}
...
}
```

![](https://user-images.githubusercontent.com/516342/69716427-a4314f80-1112-11ea-957f-3385b9e0155a.png)

### aliases

run, lets-run
6 changes: 4 additions & 2 deletions lib/choose/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const { prompt } = require('inquirer');
require('colors');

module.exports = async function choose(scripts, { executables }) {
module.exports = async function choose(pkg, { executables }) {
const { scripts, 'scripts:descriptions': descriptions = {} } = pkg;

if (!scripts) { return executables ? 'executables' : null; }

const entries = Object.entries(scripts);
Expand All @@ -10,7 +12,7 @@ module.exports = async function choose(scripts, { executables }) {

const choices = entries.map(
([value, content]) => ({
name: `${value.yellow.bold}: ${content}`,
name: `${value.yellow.bold}: ${descriptions[value] || content}`,
value,
}),
).concat(
Expand Down
6 changes: 4 additions & 2 deletions lib/getCommand/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ const exist = require('@does/exist');
require('colors');
const choose = require('../choose');

module.exports = async function getCommand({scripts}) {
module.exports = async function getCommand(pkg) {
const bins = resolve('.', 'node_modules', '.bin');
const script = await choose(scripts, {
const script = await choose(pkg, {
executables: await exist(bins),
});



if (script === null) {
console.log('No scripts or executables found'.bold);
process.exit(0);
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lets/run",
"version": "1.2.0",
"version": "1.3.0",
"description": "👟 run npm scripts interactively",
"keywords": [
"npm",
Expand All @@ -22,9 +22,11 @@
},
"scripts": {
"lint": "eslint '**/*.js'",
"start": "./bin.js",
"say something": "echo \"Hey, buddy!\"",
"#": "echo \"This is not a comment\""
"start": "./bin.js"
},
"scripts:descriptions": {
"lint": "Check code syntax",
"#": "Comment"
},
"dependencies": {
"@does/exist": "^1.0.0",
Expand Down

0 comments on commit b4ce3cf

Please sign in to comment.