Skip to content

Commit bf877ab

Browse files
rowanoultonKent C. Dodds
authored and
Kent C. Dodds
committed
feat(prefixes): Add improved prefixing (#4)
* 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
1 parent c75cba6 commit bf877ab

7 files changed

+28
-41
lines changed

.all-contributorsrc

+11
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@
3737
"code",
3838
"test"
3939
]
40+
},
41+
{
42+
"login": "rowanoulton",
43+
"name": "Rowan Oulton",
44+
"avatar_url": "https://avatars.githubusercontent.com/u/185649?v=3",
45+
"profile": "http://travelog.io",
46+
"contributions": [
47+
"code",
48+
"doc",
49+
"test"
50+
]
4051
}
4152
]
4253
}

README.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ All the benefits of npm scripts without the cost of a bloated package.json and l
99
[![MIT License][license-badge]][LICENSE]
1010
[![PRs Welcome][prs-badge]](http://makeapullrequest.com)
1111
[![Commitizen friendly][commitizen-badge]][commitizen]
12-
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors)
12+
[![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors)
1313

1414
## The problem
1515

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

68+
And these prefixes can go as deep as you like!
69+
70+
```console
71+
npm start b.p # will run the production build script
72+
```
73+
6874
And if you want to speed things up even more, you can install [`npm-quick-run`][quick-run] and then:
6975

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

234240
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
235-
| [![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) |
236-
| :---: | :---: | :---: |
241+
| [![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) |
242+
| :---: | :---: | :---: | :---: |
237243
<!-- ALL-CONTRIBUTORS-LIST:END -->
238244

239245
This project follows the [all-contributors][all-contributors] specification.

ROADMAP.md

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
## Want to do
44

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

97
## Might do

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"lodash.camelcase": "4.1.1",
3131
"lodash.contains": "2.4.3",
3232
"lodash.find": "4.3.0",
33-
"lodash.get": "4.2.1",
3433
"lodash.isempty": "4.2.1",
3534
"lodash.isfunction": "3.0.8",
3635
"lodash.isplainobject": "4.0.4",
@@ -39,6 +38,7 @@
3938
"lodash.kebabcase": "4.0.1",
4039
"lodash.merge": "4.3.5",
4140
"lodash.remove": "4.3.0",
41+
"prefix-matches": "0.0.9",
4242
"shell-escape": "0.2.0",
4343
"spawn-command": "0.0.2"
4444
},

src/get-script-to-run.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import resolveScriptObjectToString from './resolve-script-object-to-string'
2-
import get from 'lodash.get'
3-
import prefixToScriptName from './prefix-to-script-name'
2+
import prefixMatches from 'prefix-matches'
43
import kebabAndCamelCasify from './kebab-and-camel-casify'
54

65
export default getScriptToRun
76

87
function getScriptToRun(config, input) {
98
config = kebabAndCamelCasify(config)
10-
input = prefixToScriptName(input, config)[0] || input // allow prefix
11-
const script = get(config, input)
9+
const script = prefixMatches(input, config)[0]
1210
return resolveScriptObjectToString(script)
1311
}

src/get-script-to-run.test.js

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ test('allows a prefix to be provided', t => {
66
t.is(script, 'stuff')
77
})
88

9+
test('allows a multi-level prefix to be provided', t => {
10+
const script = getScriptToRun({build: {watch: 'watch stuff'}}, 'b.w')
11+
t.is(script, 'watch stuff')
12+
})
13+
914
test('falls back to using `get` for the full name if no prefix is provided', t => {
1015
const script = getScriptToRun({build: {watch: 'watch stuff'}}, 'build.watch')
1116
t.is(script, 'watch stuff')

src/prefix-to-script-name.js

-31
This file was deleted.

0 commit comments

Comments
 (0)