Giter Site home page Giter Site logo

load-grunt-tasks's Introduction

load-grunt-tasks

Load multiple grunt tasks using globbing patterns

Usually you would have to load each task one by one, which is unnecessarily cumbersome.

This module will read the dependencies/devDependencies/peerDependencies/optionalDependencies in your package.json and load grunt tasks that match the provided patterns.

Before

grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-recess');
grunt.loadNpmTasks('grunt-sizediff');
grunt.loadNpmTasks('grunt-svgmin');
grunt.loadNpmTasks('grunt-styl');
grunt.loadNpmTasks('grunt-php');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-bower-requirejs');

After

require('load-grunt-tasks')(grunt);

Install

$ npm install --save-dev load-grunt-tasks

Usage

// Gruntfile.js
module.exports = grunt => {
	// Load all grunt tasks matching the ['grunt-*', '@*/grunt-*'] patterns
	require('load-grunt-tasks')(grunt);

	grunt.initConfig({});
	grunt.registerTask('default', []);
};

Examples

Load all grunt tasks

require('load-grunt-tasks')(grunt);

Equivalent to:

require('load-grunt-tasks')(grunt, {pattern: ['grunt-*', '@*/grunt-*']});

Load all grunt-contrib tasks

require('load-grunt-tasks')(grunt, {pattern: 'grunt-contrib-*'});

Load all grunt-contrib tasks and another non-contrib task

require('load-grunt-tasks')(grunt, {pattern: ['grunt-contrib-*', 'grunt-shell']});

Load all grunt-contrib tasks excluding one

You can exclude tasks using the negate ! globbing pattern:

require('load-grunt-tasks')(grunt, {pattern: ['grunt-contrib-*', '!grunt-contrib-coffee']});

Set custom path to package.json

require('load-grunt-tasks')(grunt, {config: '../package'});

Only load from devDependencies

require('load-grunt-tasks')(grunt, {scope: 'devDependencies'});

Only load from devDependencies and dependencies

require('load-grunt-tasks')(grunt, {scope: ['devDependencies', 'dependencies']});

All options in use

require('load-grunt-tasks')(grunt, {
	pattern: 'grunt-contrib-*',
	config: '../package.json',
	scope: 'devDependencies',
	requireResolution: true
});

Options

pattern

Type: string | string[]
Default: ['grunt-*', '@*/grunt-*'] (Glob pattern)

config

Type: string | object
Default: Path to nearest package.json

scope

Type: string | string[]
Default: ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']
Values: 'dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies', 'bundledDependencies'

requireResolution

Type: boolean
Default: false

Traverse up the file hierarchy looking for dependencies like require(), rather than the default grunt-like behavior of loading tasks only in the immediate node_modules directory.

load-grunt-tasks's People

Contributors

arthurvr avatar kevva avatar kirbysayshi avatar nunospot avatar okhomenko avatar paladox avatar philippsimon avatar radkodinev avatar richienb avatar sboudrias avatar sindresorhus avatar sulmanen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

load-grunt-tasks's Issues

Naming

Why not grunt-load-tasks?

Pattern docs need a tweak

in you docs you are passing an object literal. Your code is expecting an array so rather than

require('load-grunt-tasks')(grunt, {pattern: ['grunt-contrib-*', '!grunt-contrib-coffee']});

I believe it should be

require('load-grunt-tasks')(grunt, ['grunt-contrib-*', '!grunt-contrib-coffee']);

Otherwise it tries to call map() on the object

Ability to filter tasks not to be loaded

Tasks loaded using require within the options cause an error if they have been already loaded using loadNpmTasks. Specifically use the use of grunt-template-jasmine-requirejs and grunt-template-jasmine-istanbul

It's not necessary to grunt.loadNpmTasks('grunt-template-jasmine-requirejs') because it is loaded using require within the options..

Only works with devDependencies

Is there any particular reason it's only working with devDep ?
Because I've a project based on Grunt that have a lot of grunt-* as dependencies (cause it's published as a package on npm).

NPM cannot install dependencies

When trying to do npm i --save-dev load-grunt-tasks, I end up with this error :

No compatible version found: findup-sync@'^0.1.2'

I'm not really sure but the problem might be the "^" character, because npm also adds :

Valid install targets: ["0.1.0","0.1.1","0.1.2"]

The error happened with node v0.10.2 and npm v1.2.15 (ARM build, I run it on a RasPi)
However the installation worked perfectly fine on a PC with Ubuntu installed and node v0.10.15 + npm v1.2.18.

Lazy load tasks

Hey guys.
This module saves the need for having to write npmLoadTask over and over which is great.
However it really hurts performance especially for task that fork such as sass / coffeescript generation.

There's a nice little module called https://github.com/raphaeleidus/grunt-lazyload which has helped us in the past shave heaps of time off initialisation.

Would it be possible to incorporate in some way?

Fail with descriptive error if package.json is missing

Issuehunt badges

It would be good to fail with a descriptive error if package.json is missing.

Clearly, others have had the same issue.

Loading "Gruntfile.js" tasks...ERROR
>> TypeError: Cannot read property 'dependencies' of null
Warning: Task "rsync" not found. Use --force to continue.

IssueHunt Summary

nunospot nunospot has been rewarded.

Backers (Total: $20.00)

Submitted pull Requests


Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

Stopped working on Ubuntu 13.10 Virtual Box

One of our developers started getting this error this morning:

>> Error: Cannot find module 'load-grunt-tasks'

We can see the package in node_modules. He didn't do any updates Friday or today, and we haven't changed the list of Grunt tasks we use in months. He did a complete uninstall of node.js, npm, and all node modules, and reinstalled using the node v.0.10.29 tarball, npm install && npm update, but the problem persists.

Replacing load-grunt-tasks with the original calls to grunt.loadNpmTasks works as expected, but that's obviously suboptimal because load-grunt-tasks is too awesome not to use. :(

node: v0.10.29
npm: 1.4.14

I'm sure this report doesn't contain enough information to help you diagnose the issue, so please advise what else I can supply. Thanks!

os.tmpDir() is deprecated

Using require('load-grunt-tasks')(grunt); as expected throws the following warning:

(node:33960) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.

Unsure if this is called by load-grunt-tasks directly, or some nested dependency.

Load own tasks from custom folder

How can I come from this:

    grunt.loadNpmTasks("grunt-ts");
    grunt.loadNpmTasks("grunt-run");
    grunt.loadNpmTasks("grunt-tslint");
    grunt.loadTasks("./grunt/tasks/");

To this:

require("load-grunt-tasks")(grunt, {
        pattern: [
            "grunt-*",
            "@*/grunt-*",
            "./grunt/tasks/",
        ],
    });

Warning: Task "myTask:dev" not found. Use --force to continue.

Some ideas?

ps: underneath the grunt/tasks folder is a task file named myTask.js.

Problem When Loading Certain Tasks

When I load the "grunt-jasmine-runner" task, grunt throws an error and none of the other tasks load. I am sure it is "grunt-jasmine-runner" because when I remove that from my devDependencies, load-grunt-tasks works as normal. Here is the relevant line in my Gruntfile:

require('load-grunt-tasks')(grunt, {scope: 'devDependencies'});

In my package.json, I load the "grunt-jasmine-runner" task like this:

{
"devDependencies": {
"grunt-jasmine-runner": "latest"
}
}

The latest version happens to be version 0.6.0. When I include this line, I get this output in Git Bash:

$ grunt
Loading "jasmine.js" tasks...ERROR

c:\repos\konneka\node_modules\grunt\lib\grunt\log.js:103
writeln('>> '.red + grunt.util..trim(msg).replace(/\n/g, '\n>> '.red));
^
TypeError: Cannot read property '
' of undefined
at Object.log.warn (c:\repos\konneka\node_modules\grunt\lib\grunt\log.js:103:35)
at Object.log.error (c:\repos\konneka\node_modules\grunt\lib\grunt\log.js:111:12)
at Object.log.verbose.(anonymous function) [as error](c:reposkonnekanode_modulesgruntlibg
runtlog.js:208:14)
at loadTask (c:\repos\konneka\node_modules\grunt\lib\grunt\task.js:341:42)
at Task.task.init (c:\repos\konneka\node_modules\grunt\lib\grunt\task.js:437:5)
at Object.grunt.tasks (c:\repos\konneka\node_modules\grunt\lib\grunt.js:117:8)
at Object.module.exports as cli
at Object. (c:\Users\Sean\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt:45:20)

at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)

However, when I do not include that line, everything runs fine. I assume it has something to do with the file "jasmine.js", meaning it's probably a problem with grunt-jasmine-runner, not load-grunt-tasks, but I am making it an issue here because if there is an issue between these two, there could easily be an issue between grunt-load-tasks and any other grunt task.

So what's the problem? Thanks.

Default to only `scope: 'dependencies'` when NODE_ENV="production"

In production we only need a subset of the packages installed, so I've put packages relating to deploying in dependencies and those relating to testing/development in devDependencies. Prod will then use npm install --production compared to npm install used locally.

However prod then needs the following in Gruntfile.js:

require('load-grunt-tasks')(grunt, {scope: 'dependencies'});

...whereas locally I would need:

require('load-grunt-tasks')(grunt);

But the latter then results in errors like this on production:

>> Local Npm module "grunt-eslint" not found. Is it installed?
>> Local Npm module "grunt-html-angular-validate" not found. Is it installed?

What would be great, is if load-grunt-tasks used the value of NODE_ENV or --production (or some other alternative) to determine which of the above to default to, when scope isn't specified.

This would avoid having to use this pattern:

    if (grunt.option('production')) {
        require('load-grunt-tasks')(grunt, {scope: 'dependencies'});
    } else {
        require('load-grunt-tasks')(grunt);
    }

...and would then go along nicely with the behaviour of npm install --production (which only installs packages from dependencies and not devDependencies).

Deprecate in favor of matchdep?

matchdep...

  1. is more generalized: it just returns an array of strings
  2. supports peerDependencies, which is how Grunt "collections" will work in the future gruntjs/grunt-contrib#168
  3. doesn't use process.cwd() so will work inside Grunt "collections"
  4. has unit tests

I know it's a little more to type.

// This is very succinct.
require('load-grunt-tasks')(grunt);

// This trades verbosity for generalization / unambiguity.
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

Thoughts?

npm scope support

The load-grunt-tasks module does not support grunt task modules installed via npm scopes.

I believe line 17 could be changed from ['grunt-*'] to ['grunt-*', '@*/grunt-*'].

Not an issue but a code-maintainability warning

One of our developers used this plugin to auto-wire-up the npm packages to our gruntfile.

The problem is now that we want to clean-up the gruntfile and prune no-longer-used npm dependencies.

Alas we can no longer explicitly see which ones we are using from our gruntfile. I now have to manually trace them back.

When having the node_modules on a different folder, the plugin is unable to find those

Hi I've this workspace were we have different folders each with it's own gruntfile, they're different apps,
The plugin allows me to set the path for the package.json file but it doesn't for the node_modules folder it doesn't even try to look for it on the same folder level as the package.json, I think this is something that deserves to be included since the node_modules folder tends to be huge, real huge... By now we'll work with links...

Thanks,

Martin

Fails to Load "grunt-lib-contrib"

Running grunt with grunt-lib-contrib installed and in my package.json file, while it doesn't kill the script, I get the following output:

Dre@MONSTROSITY /E/Dev Stuff/Incubation_Tank/bitnami-redmine-updater
$ npm install --save grunt-lib-contrib
npm WARN package.json [email protected] No repository field.
npm http GET https://registry.npmjs.org/grunt-lib-contrib
npm http 304 https://registry.npmjs.org/grunt-lib-contrib
npm http GET https://registry.npmjs.org/zlib-browserify/0.0.1
npm http 304 https://registry.npmjs.org/zlib-browserify/0.0.1
[email protected] node_modules\grunt-lib-contrib
└── [email protected]

Dre@MONSTROSITY /E/Dev Stuff/Incubation_Tank/bitnami-redmine-updater
$ grunt
>> Local Npm module "grunt-lib-contrib" not found. Is it installed?

Running "uglify:build" (uglify) task
>> Destination (dest/output.js) not written because src files were empty.

Done, without errors.

This is a squeaky clean project, absolutely no coding has been done yet. So, do the node modules perhaps need to have a specific structure to load correctly here, or is this an error in load-grunt-tasks..?

Or could it even be that grunt-lib-contrib is simply trying to do things that normal grunt plugins don't do..

Duplicate task names

I'm trying to use two tasks:

  • grunt-bower-requirejs
  • grunt-bower-task

The problem is that both reference the same bower task name.

If I load the manually I can do something like:

grunt.loadNpmTasks('grunt-bower-requirejs');
grunt.renameTask('bower', 'requireBower');
grunt.loadNpmTasks('grunt-bower-task');

Is it possible to do something similar using load-grunt-tasks?

Bug when loading plugin with scope in the name.

require("load-grunt-tasks")(grunt, {requireResolution: true});

When using requireResolution on true, it doesn't load packages with scope in the name like @scope/grunt-my-plugin.

In your code, this expression: resolvePkg(path.join(pkgName, 'tasks') evaluates to null.

npm install fails for v0.8.x with "No compatible version found" with the latest version

Because of an issue in node v0.8.x with the new default semver range operator added by npm when doing npm install <package-name> --save, one of the builds that uses the latest load-grunt-tasks version (0.4.0) is failing:

npm ERR! Error: No compatible version found: multimatch@'^0.1.0'
npm ERR! Valid install targets:
npm ERR! ["0.1.0"]
npm ERR!     at installTargetsError (/home/travis/.nvm/v0.8.26/lib/node_modules/npm/lib/cache.js:719:10)
npm ERR!     at /home/travis/.nvm/v0.8.26/lib/node_modules/npm/lib/cache.js:641:10
npm ERR!     at saved (/home/travis/.nvm/v0.8.26/lib/node_modules/npm/node_modules/npm-registry-client/lib/get.js:138:7)
npm ERR!     at Object.oncomplete (fs.js:297:15)
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>

Please see this issue (that should have been raised at npm) that is related.

Listing grunt tasks fails for v4.0.0

The following error appeared once using the latest version:

Failed to list grunt tasks in mti\Gruntfile.js: failed to parse tasks from json

  • Edit settings

Reading "Gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks.
Loading "Gruntfile.js" tasks...ERROR

SyntaxError: Unexpected token =
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (C:\workspace\mti\node_modules\coffeescript\lib\coffee-script\register.js:45:36)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:20:19)
at Object.module.exports (C:\workspace\mti\Gruntfile.js:3:3)
at loadTask (C:\workspace\mti\node_modules\grunt\lib\grunt\task.js:315:10)
at Task.task.init (C:\workspace\mti\node_modules\grunt\lib\grunt\task.js:434:5)
at Object.grunt.tasks (C:\workspace\mti\node_modules\grunt\lib\grunt.js:111:8)
at Object.module.exports [as cli] (C:\workspace\mti\node_modules\grunt\lib\grunt\cli.js:27:9)
at Object. (C:\workspace\mti\node_modules\grunt-cli\bin\grunt:44:20)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:148:18)
at node.js:405:3

Error: Cannot find module 'deployd'

Hellow everybody:
I try the plugin and the task grunt registered can't execut correctly. Powershell prompts like the following:

Loading "deployd.js" tasks...ERROR
>> Error: Cannot find module 'deployd'

Or the more errors

PS F:\PHPnow-1.5.6\htdocs\portal_new> grunt verify             
Loading "deployd.js" tasks...ERROR
>> Error: Cannot find module 'deployd'
>> Local Npm module "autoprefixer" not found. Is it installed?
>> Local Npm module "rolypoly" not found. Is it installed?
>> Local Npm module "pushover" not found. Is it installed?
>> Local Npm module "load-grunt-tasks" not found. Is it installed?
Warning: Task "regex-replace" not found. Use --force to continue.

[email protected]

Best Regards

Local Npm module *** not found. Is it installed?

I started to get this message with 0.1.1

Local Npm module *** not found. Is it installed?

For several packages. They are still loaded I'm just getting that annoying message.

Local Npm module "express" not found. Is it installed?
Local Npm module "connect-livereload" not found. Is it installed?
Local Npm module "load-grunt-tasks" not found. Is it installed?
Local Npm module "time-grunt" not found. Is it installed?
Local Npm module "grunt" not found. Is it installed?

If i comment out "patterns.push('!grunt', '!grunt-cli');" everything works ok.

  • Windows
  • node 0.10.19
  • npm 1.3.11
  • grunt-cli 0.1.9
  • grunt 0.4.1

When will this land in Grunt itself?

I found this and decided I should really quit programming, since I never even thought of doing something like this :)

Will this land in Grunt proper ever?

README.md doesn't match actual usage

in doc
require('load-grunt-tasks')(grunt, {pattern: ['grunt-contrib-*', '!grunt-contrib-coffee']});

in code
module.exports = function (grunt, patterns, pkg) {

Local Npm module "grunt-XXXXX" not found. Is it installed?

The plugin works fine for me until I uninstall a grunt plugin. Once I do this and run any task I get the following errors. The uninstall seems to have worked as they are no longer in my node_modules folder but it must be still being reference somewhere, but not in my Gruntfile.js as I only have the require('load-grunt-tasks')(grunt); command specified. Any ideas?

capture

Does not load grunt packages from dependencies, only devDependencies

I have included an example project here with all my "grunt-" packages in the dependencies of my package.json. When I move them to the devDependencies, everything works just fine. Am I doing something wrong or is there an issue. According to the ReadMe, I should be able to load "grunt-" packages from dependencies, devDependencies, or peerDependencies.

Here is my example project.

https://github.com/williamsb/ember-grunt-example/tree/load_tasks

To replicate, run the following commands:

npm install
grunt test

Grunt Load Task Peer Dependency

@sindresorhus

Load-Grunt-Tasks 3.5.2 requires Grunt 1.0.1 however when I install grunt, it brings up the peer inavalid error. I checked your package.json and everything seems fine.

What would cause the error?

Move to use matchdep

Hey there. Thanks for this module. Just wanted to know why you chose not to use the node-matchdep module as it appears to match your exact use case?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.