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 |
|
13 | Often I want to run a simple task as NPM script, but hate creating verbose Gruntfile, installing
|
14 | grunt dependencies, etc. Enter **grunty** - just specify the plugin's module, name and any options
|
15 | in the NPM script command. No global grunt installation is necessary.
|
16 |
|
17 | `npm install --save-dev grunty`
|
18 |
|
19 | then 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 |
|
30 | You can even pass configuration using a JSON file or JS file (just export an object)
|
31 |
|
32 | For 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 |
|
45 | The 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 |
|
53 | You can see an example JSON config file in [test/concat.json](test/concat.json) which can be
|
54 | triggered using `npm run concat-config` command defined in the [package scripts](package.json).
|
55 |
|
56 | Similarly you can export the JavaScript object from a JS file for configuration,
|
57 | see [test/concat.js](test/concat.js)
|
58 |
|
59 | ## Details
|
60 |
|
61 | Separate multiple values like filenames using `,` as in `--src=path/to/foo,path/to/bar`
|
62 |
|
63 | The plugin runs with the your local `package.json` attached to the config, thus you can use
|
64 | `pkg.name`, `pkg.description` and other properties.
|
65 | If the plugin requires more elaborate options, write `Gruntfile.js`.
|
66 |
|
67 | You do need to install the actual plugin and save reference in the `dev` dependencies.
|
68 |
|
69 | Read [Put mock data into Node require cache](http://glebbahmutov.com/blog/put-mock-data-into-node-require-cache/)
|
70 | to learn how this project fakes `gruntfile.js` without actually even saving mock one to disk.
|
71 |
|
72 | If you need to run an example and see diagnostic messages, you can using npm scripts and enabling
|
73 | the debug messages using [debug](https://www.npmjs.com/package/debug).
|
74 | For 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 |
|
88 | Author: Gleb Bahmutov © 2015
|
89 |
|
90 | * [@bahmutov](https://twitter.com/bahmutov)
|
91 | * [glebbahmutov.com](http://glebbahmutov.com)
|
92 | * [blog](http://glebbahmutov.com/blog/)
|
93 |
|
94 | License: MIT - do anything with the code, but don't blame me if it does not work.
|
95 |
|
96 | Spread the word: tweet, star on github, etc.
|
97 |
|
98 | Support: 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 |
|
103 | Copyright (c) 2015 Gleb Bahmutov
|
104 |
|
105 | Permission is hereby granted, free of charge, to any person
|
106 | obtaining a copy of this software and associated documentation
|
107 | files (the "Software"), to deal in the Software without
|
108 | restriction, including without limitation the rights to use,
|
109 | copy, modify, merge, publish, distribute, sublicense, and/or sell
|
110 | copies of the Software, and to permit persons to whom the
|
111 | Software is furnished to do so, subject to the following
|
112 | conditions:
|
113 |
|
114 | The above copyright notice and this permission notice shall be
|
115 | included in all copies or substantial portions of the Software.
|
116 |
|
117 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
118 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
119 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
120 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
121 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
122 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
123 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
124 | OTHER 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
|