UNPKG

4.99 kBMarkdownView Raw
1# grunty
2
3> Run any grunt plugin as NPM script without Gruntfile.js
4
5[![NPM][grunty-icon] ][grunty-url]
6
7[![Build status][grunty-ci-image] ][grunty-ci-url]
8[![dependencies][grunty-dependencies-image] ][grunty-dependencies-url]
9[![devdependencies][grunty-devdependencies-image] ][grunty-devdependencies-url]
10
11## Zero task configuration (defaults)
12
13Often I want to run a simple task as NPM script, but hate creating verbose Gruntfile, installing
14grunt dependencies, etc. Enter **grunty** - just specify the plugin's module, name and any options
15in the NPM script command. No global grunt installation is necessary.
16
17`npm install --save-dev grunty`
18
19then use in the `package.json`
20
21```json
22"scripts": {
23 "concat": "grunty grunt-contrib-concat concat --src=a.js,b.js --dest=dist/out.js",
24 "nice": "grunty grunt-nice-package nice-package"
25}
26```
27
28## Using configuration file
29
30You can even pass configuration using a JSON file or JS file (just export an object)
31
32For example, put grunt plugin configurations into `config.json`
33
34```json
35{
36 "concat": {
37 "default": {
38 "src:" ["a.js", "b.js"],
39 "dest": "dist/out.js"
40 }
41 }
42}
43```
44
45The add `config.json` to the NPM script line
46
47```json
48"scripts": {
49 "concat": "grunty grunt-contrib-concat concat config.json",
50}
51```
52
53You can see an example JSON config file in [test/concat.json](test/concat.json) which can be
54triggered using `npm run concat-config` command defined in the [package scripts](package.json).
55
56Similarly you can export the JavaScript object from a JS file for configuration,
57see [test/concat.js](test/concat.js)
58
59## Details
60
61Separate multiple values like filenames using `,` as in `--src=path/to/foo,path/to/bar`
62
63The plugin runs with the your local `package.json` attached to the config, thus you can use
64`pkg.name`, `pkg.description` and other properties.
65If the plugin requires more elaborate options, write `Gruntfile.js`.
66
67You do need to install the actual plugin and save reference in the `dev` dependencies.
68
69Read [Put mock data into Node require cache](http://glebbahmutov.com/blog/put-mock-data-into-node-require-cache/)
70to learn how this project fakes `gruntfile.js` without actually even saving mock one to disk.
71
72If you need to run an example and see diagnostic messages, you can using npm scripts and enabling
73the debug messages using [debug](https://www.npmjs.com/package/debug).
74For example to debug parsing config json
75
76 $ DEBUG=cli npm run concat-config
77 > grunty grunt-contrib-concat concat test/concat.json
78 grunty@0.1.2 - Run any grunt plugin as NPM script without Gruntfile.js
79 "Gleb Bahmutov <gleb.bahmutov@gmail.com>" https://github.com/bahmutov/grunty
80 cwd /Users/gleb/git/grunty
81 cli grunty options +0ms { tasks: [], npm: [] }
82 cli grunty plugin +2ms grunt-contrib-concat
83 cli grunty target +0ms concat
84 cli grunty config filename +1ms /grunty/test/concat.json
85
86### Small print
87
88Author: Gleb Bahmutov &copy; 2015
89
90* [@bahmutov](https://twitter.com/bahmutov)
91* [glebbahmutov.com](http://glebbahmutov.com)
92* [blog](http://glebbahmutov.com/blog/)
93
94License: MIT - do anything with the code, but don't blame me if it does not work.
95
96Spread the word: tweet, star on github, etc.
97
98Support: if you find any problems with this module, email / tweet /
99[open issue](https://github.com/bahmutov/grunty/issues) on Github
100
101## MIT License
102
103Copyright (c) 2015 Gleb Bahmutov
104
105Permission is hereby granted, free of charge, to any person
106obtaining a copy of this software and associated documentation
107files (the "Software"), to deal in the Software without
108restriction, including without limitation the rights to use,
109copy, modify, merge, publish, distribute, sublicense, and/or sell
110copies of the Software, and to permit persons to whom the
111Software is furnished to do so, subject to the following
112conditions:
113
114The above copyright notice and this permission notice shall be
115included in all copies or substantial portions of the Software.
116
117THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
118EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
119OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
120NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
121HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
122WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
123FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
124OTHER DEALINGS IN THE SOFTWARE.
125
126[grunty-icon]: https://nodei.co/npm/grunty.png?downloads=true
127[grunty-url]: https://npmjs.org/package/grunty
128[grunty-ci-image]: https://travis-ci.org/bahmutov/grunty.png?branch=master
129[grunty-ci-url]: https://travis-ci.org/bahmutov/grunty
130[grunty-dependencies-image]: https://david-dm.org/bahmutov/grunty.png
131[grunty-dependencies-url]: https://david-dm.org/bahmutov/grunty
132[grunty-devdependencies-image]: https://david-dm.org/bahmutov/grunty/dev-status.png
133[grunty-devdependencies-url]: https://david-dm.org/bahmutov/grunty#info=devDependencies