Reputation: 35963
I have a Gruntfile to install some npm and make other function.
The problem is that: the download of npm works fine but download node_modules globally in
/User/my_user/node_modules
I'd want that the gruntfile download nom locally inside my project dynamically without specify path.
this is a part of my grunt file:
module.exports = function(grunt) {
grunt.initConfig({
shell: {
install: {
options: {
stdout: true,
stderr: true
},
command: [
"npm install grunt-contrib-sass",
"npm install node-sass",
"npm install grunt-contrib-less",
"npm install less",
"npm install grunt-contrib-watch",
"npm install grunt-contrib-clean",
"npm install grunt-contrib-copy",
"npm install grunt-csso",
"npm install grunt-deployments"
].join("&&")
},
install_test: {
options: {
stdout: true,
stderr: true
},
command: [
"sudo npm install -g phantomjs",
"npm install -g casperjs",
"mkdir app/Test/Frontend",
"sudo chmod -R 777 app/Test/Frontend"
].join("&&")
},
}
});
grunt.loadNpmTasks("grunt-contrib-less");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-shell");
grunt.loadNpmTasks("grunt-csso");
grunt.loadNpmTasks("grunt-rsync");
grunt.registerTask("install", [
"shell:cake_tmp",
"shell:install",
"shell:install_test"
]);
};
and after I do this:
sudo npm install grunt
sudo npm install grunt-shell
grunt install
return me error that it doesn't find modules because aren't locally but globally..
How can I solve?
Thanks
Upvotes: 1
Views: 3592
Reputation: 894
Thats a very crude way of doing the job. Ideally, all of that should go in to package.json
in your root folder. put this in you package.json
after making necessary changes if any and execute npm install
it will install the packages locally and preinstall
hook will install global packages beforing executing install.
{
"name": "appname",
"version": "0.0.0",
"dependencies": {},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-sass": "*",
"node-sass": "*",
"less": "*",
"grunt-concurrent": "*",
"grunt-contrib-clean": "*",
"grunt-contrib-watch": "*",
"grunt-contrib-less": "*",
"grunt-contrib-copy": "*",
"grunt-shell": "*",
"grunt-csso": "*",
"grunt-deployments": "*"
},
"engines": {
"node": ">=0.8.0"
},
"scripts": {
"test": "grunt test",
"preinstall": "sudo npm install -g phantomjs && npm install -g casperjs"
}
}
npm gives hooks called preinstall,install,postinstall etc., use them to do -g
installs.
follow this LINK for more info
Other tasks you can include in your Gruntfile.js
as shell
targets
Upvotes: 2