Skip to content

Commit

Permalink
feat(prefixes): Add improved prefixing (#4)
Browse files Browse the repository at this point in the history
* feat(prefixes): Add improved prefixing

Leverage prefix-matches module to support nested prefixes (e.g. "w.j" ==> watch.javascript)

* feat(prefixes): Wholly remove non-prefix resolution

Fallback to lodash.get no longer required. If prefixMatches doesn't find it, neither will
lodash.get. This also gets code coverage up to 100% again :)

* feat(prefixes): Bump dependency version

... to avoid strict mode + const complaints in build

* feat(prefixes): Bump dependency version

... again, to reverse strict-mode removal of prefix-matches module

* feat(prefixes): Bump dependency version

Bump version of prefix-matches, to fix 'use strict' / const issues

* feat(prefixes): Bump dependency version

Adds support for node 0.12 + 0.10

* docs(prefixes): Add notes about deeper prefixing support

* docs(prefixes): Adjust for bad merge

* docs(prefixes): Pure vanity: adding self to contributors list
  • Loading branch information
rowanoulton authored and Kent C. Dodds committed May 4, 2016
1 parent c75cba6 commit bf877ab
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 41 deletions.
11 changes: 11 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@
"code",
"test"
]
},
{
"login": "rowanoulton",
"name": "Rowan Oulton",
"avatar_url": "https://avatars.githubusercontent.com/u/185649?v=3",
"profile": "http://travelog.io",
"contributions": [
"code",
"doc",
"test"
]
}
]
}
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ All the benefits of npm scripts without the cost of a bloated package.json and l
[![MIT License][license-badge]][LICENSE]
[![PRs Welcome][prs-badge]](http://makeapullrequest.com)
[![Commitizen friendly][commitizen-badge]][commitizen]
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors)

## The problem

Expand Down Expand Up @@ -65,6 +65,12 @@ But the fun doesn't end there! You can use a prefix:
npm start b # will run the build script
```

And these prefixes can go as deep as you like!

```console
npm start b.p # will run the production build script
```

And if you want to speed things up even more, you can install [`npm-quick-run`][quick-run] and then:

```console
Expand Down Expand Up @@ -232,8 +238,8 @@ benefits of npm scripts I wanted to keep).
Thanks goes to these people ([emoji key][emojis]):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [![Kent C. Dodds](https://avatars.githubusercontent.com/u/1500684?v=3&s=100)<br /><sub>Kent C. Dodds</sub>](http://kent.doddsfamily.us)<br />[💻](https://github.com/kentcdodds/p-s/commits?author=kentcdodds) [📖](https://github.com/kentcdodds/p-s/commits?author=kentcdodds) 🚇 💡 | [![David Wells](https://avatars.githubusercontent.com/u/532272?v=3&s=100)<br /><sub>David Wells</sub>](http://davidwells.io)<br />[💻](https://github.com/kentcdodds/p-s/commits?author=DavidWells) | [![Abhishek Shende](https://avatars.githubusercontent.com/u/802242?v=3&s=100)<br /><sub>Abhishek Shende</sub>](https://twitter.com/abhishekisnot)<br />[💻](https://github.com/kentcdodds/p-s/commits?author=abhishekisnot) [⚠️](https://github.com/kentcdodds/p-s/commits?author=abhishekisnot) |
| :---: | :---: | :---: |
| [![Kent C. Dodds](https://avatars.githubusercontent.com/u/1500684?v=3&s=100)<br /><sub>Kent C. Dodds</sub>](http://kent.doddsfamily.us)<br />[💻](https://github.com/kentcdodds/p-s/commits?author=kentcdodds) [📖](https://github.com/kentcdodds/p-s/commits?author=kentcdodds) 🚇 💡 | [![David Wells](https://avatars.githubusercontent.com/u/532272?v=3&s=100)<br /><sub>David Wells</sub>](http://davidwells.io)<br />[💻](https://github.com/kentcdodds/p-s/commits?author=DavidWells) | [![Abhishek Shende](https://avatars.githubusercontent.com/u/802242?v=3&s=100)<br /><sub>Abhishek Shende</sub>](https://twitter.com/abhishekisnot)<br />[💻](https://github.com/kentcdodds/p-s/commits?author=abhishekisnot) [⚠️](https://github.com/kentcdodds/p-s/commits?author=abhishekisnot) | [![Rowan Oulton](https://avatars.githubusercontent.com/u/185649?v=3&s=100)<br /><sub>Rowan Oulton</sub>](http://travelog.io)<br />[💻](https://github.com/kentcdodds/p-s/commits?author=rowanoulton) [📖](https://github.com/kentcdodds/p-s/commits?author=rowanoulton) [⚠️](https://github.com/kentcdodds/p-s/commits?author=rowanoulton) |
| :---: | :---: | :---: | :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors][all-contributors] specification.
Expand Down
2 changes: 0 additions & 2 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

## Want to do

- Add improved prefixing. Right now you can prefix the entire name of a script, but you couldn't prefix something like
`test.watch` as `t.w` and I think that'd be sweet
- Add the ability to specify multiple scripts that run in series (right now the solution is to just `&&`)

## Might do
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"lodash.camelcase": "4.1.1",
"lodash.contains": "2.4.3",
"lodash.find": "4.3.0",
"lodash.get": "4.2.1",
"lodash.isempty": "4.2.1",
"lodash.isfunction": "3.0.8",
"lodash.isplainobject": "4.0.4",
Expand All @@ -39,6 +38,7 @@
"lodash.kebabcase": "4.0.1",
"lodash.merge": "4.3.5",
"lodash.remove": "4.3.0",
"prefix-matches": "0.0.9",
"shell-escape": "0.2.0",
"spawn-command": "0.0.2"
},
Expand Down
6 changes: 2 additions & 4 deletions src/get-script-to-run.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import resolveScriptObjectToString from './resolve-script-object-to-string'
import get from 'lodash.get'
import prefixToScriptName from './prefix-to-script-name'
import prefixMatches from 'prefix-matches'
import kebabAndCamelCasify from './kebab-and-camel-casify'

export default getScriptToRun

function getScriptToRun(config, input) {
config = kebabAndCamelCasify(config)
input = prefixToScriptName(input, config)[0] || input // allow prefix
const script = get(config, input)
const script = prefixMatches(input, config)[0]
return resolveScriptObjectToString(script)
}
5 changes: 5 additions & 0 deletions src/get-script-to-run.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ test('allows a prefix to be provided', t => {
t.is(script, 'stuff')
})

test('allows a multi-level prefix to be provided', t => {
const script = getScriptToRun({build: {watch: 'watch stuff'}}, 'b.w')
t.is(script, 'watch stuff')
})

test('falls back to using `get` for the full name if no prefix is provided', t => {
const script = getScriptToRun({build: {watch: 'watch stuff'}}, 'build.watch')
t.is(script, 'watch stuff')
Expand Down
31 changes: 0 additions & 31 deletions src/prefix-to-script-name.js

This file was deleted.

0 comments on commit bf877ab

Please sign in to comment.