When performing a global install of Gulp, should you install "gulp" or "gulp-cli"? - macos

The Gulp github page says to run
npm install --global gulp-cli
but nearly every tutorial I've come across says to run
npm install -g gulp
Is there any substantial difference between the two options?

They are two different modules, gulp is intended to be installed locally for the project, and gulp-cli globally, this allows you to use different versions of gulp for different projects.
It's mostly a legacy thing, in the past there were no gulp-cli. The gulp team got more knowledge and decided to split it up.
It's recommended to use gulp-cli globally, and gulp locally.
And the Getting Started documentation also prompts you, to delete any globally installed gulp module.
There is no difference between --global and -g the latter is just a shorthand flag.

Related

yarn berry run how to run installed packages

I see with yarn berry I get the plug'n'play feature instead of node_modules/
I couldn't find anything to suggest it supports running from installed packages.
For example with npm a workflow might be to run the installed version of webpack:
$ npm install --save-dev webpack
$ node node_modules/webpack/bin/webpack ...
A globally installed webpack might not be the same version. Worse yet, during Docker deployment, I get what's installed locally, the only node and npm are available globally. I thought I can do a preinstall script that does npm install -g yarn; yarn set version berry but then I'm not sure how to do webpack, jest, babel, etc, and the thought that I should have to install them all globally during the same preinstall hackaround seems like several steps backwards.
Is there some way to run from locally-installed packages that I'm missing?
I saw this possibly related question - Yarn Berry - Run a Node Script Directly
But the answer there seems a bit off the point - I'm not running any js, I'm trying to type in a package.json script, i.e. something that can run from the shell.
Why not just use yarn run <bin> (or simply yarn <bin>)? If you are in a repository set to use yarn berry, that will run any package bin file.
yarn node <file> will run any .js file with Plug n' Play set up. No need to install those dependencies globally, except for maybe yarn classic.
I was trying to do yarn some-bin and kept getting:
Couldn't find a script named "some-bin".
I eventually figured out it was because the package that provides some-bin is installed inside a workspace and not at the root of my project. So instead I had to run:
yarn workspace my-workspace some-bin
And that worked.

Do I have to install grunt locally or is it just best practice ...?

or neither.
I installed both grunt-cli and grunt globally as such
inst_grunt(){
# installs the grung-cli to
# /usr/local/lib/node_modules/grunt-cli
sudo npm install -g grunt-cli
# installs grunt based upon the package.json file to
# /usr/local/lib/node_modules/Grunt
sudo npm install -g
}
I thought I could simply run
grunt --gruntfile /Users/a/root/config/Gruntfile.js watch
as stated here:
How do I run grunt from a different folder than my root project
but alas I get this error:
as-MacBook-Air:config a$ grunt --gruntfile
/Users/a/root/config/Gruntfile.js grunt-cli: The grunt command line
interface. (v0.1.13)
Fatal error: Unable to find local grunt.
If you're seeing this message, either a Gruntfile wasn't found or
grunt hasn't been installed locally to your project. For more
information about installing and configuring grunt, please see the
Getting Started guide:
http://gruntjs.com/getting-started
The grunt file is there so I'm assuming it is looking for a local grunt installation.
You do have to install it locally in order to call functions on it within the gruntfile.
This way your project can specify what version of Grunt should be used (edit) in your package.json file.

I Installed npm But Cannot Install DocPad

Obviously I need to download DocPad (file(s)) before I can do an npm install, but it simply isn't clear to me what to download, etc. I know the file(s) I need are on GitHub, but I don't have the background to understand what I'm looking at. Can you give me, or point me to, a "Download DocPad for Dummies" instructions? Thank you.
To extend on #sindis's comment
When you install Node, you will also install npm, which serves as the node package manager.
npm allows you to install packages globally using the -g flag, which installs a package that has been published to npm (such as DocPad) to wherever the npm global installation directory is, and make DocPad's command line tools available to you.
So by installing DocPad with npm install -g docpad#6.78 (6.78 is the version of DocPad that the command above wishes to install) we will install DocPad to the global npm installation directory, which makes the command line tool docpad available for your use.
I've updated the DocPad installation guide to be a bit clearer about this, suggestions welcome.
The installation of DocPad is all controlled by NPM. So once that is installed, all you should need to do to install DocPad is run the npm command, as others have said, npm install docpad -g.
Now, the gotcha in windows is that you might need to execute this command with elevated rights - ie Administrator. Windows doesn't like you installing programs in its root program directory.

Can't build a Web Project in TeamCity

I am using TeamCity as my CI server(mac).I am trying to build a web project. When I use grunt serve or grunt buildproduction after changing directory to the cloned folder,it's working perfectly fine.But when I do this via TeamCity server it is giving an error You need to have Ruby and Compass installed and in your system PATH for this task to work and gets aborted due to warnings. Ruby and Compass is already installed in the server.Please help me on this.
rm -rf $(pwd)/node_modules/*
rm -rf $(pwd)/bower_components/*
npm cache clear
npm install
npm install bower
npm install grunt-ftp-push --save-dev
bower install
grunt buildproduction
This is the Command Line buildstep which I used in Teamcity..
I would say you probably use a different user or the shell environment is different (interactive vs non-interactive) when you run these commands manually and when it runs through TC it can't find those packages in the environment/PATH

Grunt installed but not working - "Command not found" on Mavericks

I'm trying to use grunt with sass and have been following these guides:
http://gruntjs.com/getting-started
http://benfrain.com/lightning-fast-sass-compiling-with-libsass-node-sass-and-grunt-sass/
http://www.hongkiat.com/blog/grunt-command-not-found/
I've:
Intsalled node.js
Installed the command-line version of grunt: sudo npm install -g grunt -cli
Added the path from the grunt installer to my bash profile: export PATH=/usr/local/lib/node_modules/grunt/bin:$PATH
Made the profile an executable: source ~/.bash_profile
Setup package.json and Gruntfile.js files in my project root
Installed grunt into the project: cd /path/to/project/root/ and sudo npm install
But when I try to run grunt I see: command not found
It's the same if I run: grunt --version
I wasn't sure if the bash path needs /bin on the end as per the blog posted above but have tried it both ways:
/usr/local/lib/node_modules/grunt/ and /usr/local/lib/node_modules/grunt/bin/
I've also run the grunt installer several times but didn't see any errors so am positive it's installed - can anyone see what I'm doing wrong? I'm running OSX mavericks incase this is the issue.
Any pointers in the right direction would be much appreciated.
Cheers
You have a typo in your command. The package is named grunt-cli without the space.
Update the command to:
sudo npm install -g grunt-cli
And all should work as expected.
Hope this solution also might be helpful to someone. In my case it was a bit trickier.
In command line type the following command
npm install grunt-cli -g
This will show you the location where the grun client is installed:
Copy this location and paste it into a file browser. Was this in my case.
C:\Users\zkhaymed\AppData\Roaming\npm\node_modules\grunt-cli\bin
This will open you the location of a grunt file.
Click on the address line of the location and copy it as a text clicking on the right mouse button.
Now go to the Advanced properties of the system at control panel, and paste this address into a System variables and user variables without deleting the other variables.
I was having a very similar issue, hopefully this helps.
1) You want to check where node and npm are actually installed. If you used a package manager, such as Homebrew or MacPorts, there may be an issue with the location. Just use the downloadable installer from node.js website. Make sure to use the current version, not the long term support (LTS). The installer will install node and npm in /usr/local/bin, which should already be in your PATH. If you already have node/npm installed you can use which node and which npm to see where they are currently located. You should see /usr/local/bin/node and /usr/local/bin/npm, respectively. You will need to update npm after installing with npm update -g npm. This may require sudo.
2) Once node and npm are correctly installed/updated go to the project's root directory (where you have the Gruntfile.js and package.json) and install Grunt using npm install grunt --save-dev. Remember that Grunt After doing so you should see a new folder called node_modules.
3) Make sure to do the previous step before installing the CLI. You can use Grunt's getting started documentation to help guide you the rest of the way. Just be aware that the instructions for installing Grunt are further down the page than installing the CLI, which makes it somewhat confusing. When Grunt and Grunt-CLI are installed run npm install and run grunt in the command line to execute your Gruntfile.js.
You should now be able to see the versions installed. Note that if you are outside of a project's root directory you will not see a version of Grunt but you will see the Grunt-CLI version. This is because the CLI was installed globally (used from any directory/subdirectory) but Grunt is installed on a per-project basis.
Hopefully this helps!
I just ran into this scenario as well. The following worked for me:
Try deleting C:/Users/{username}/AppData/Roaming/npm and C:/Users/{username}/AppData/Roaming/npm-cache (if it exists) and reinstalling global npm modules.
Source: https://github.com/nodejs/node/issues/29287
I had to add this to the PATH (on a Mac after brew install node ):
export NPM_HOME=/usr/local/Cellar/node/6.3.1/libexec/npm
The npm install was not effective, no matter what args I passed to it.

Resources