How to use blackcoffee with grunt watch - node.js

I was hoping that grunt-contrib-coffee could work with blackcoffee but it seems that it uses the coffee-script npm module directly instead of calling the coffee executable which would have invoked blackcoffee. I have looked around to see if there are any pre-existing Grunt plugins for blackcoffee but this doesn't seem to be the case.
Any recommendations as to how to go about configuring Grunt so that grunt watch will let me compile my blackcoffee code?

don't know if that works, but i think it should:
fork grunt-contrib-coffee
rename it in your package.json to grunt-blackcoffee
replace coffee-script dependency, and replace with blackcoffee in your package.json
search for the coffee-script require in the grunt task, currently it's here:
return require('coffee-script').compile(code, coffeeOptions);
and replace it with
return require('blackcoffee').compile(code, coffeeOptions);
publish it to npm
if you don't want to publish to npm, you can install packages from git:
$ npm install git+ssh://your-git-repo.git --save

Related

All the npm package not installed globally can't be executed directly

Symptom:
I can't execute the npm packages directly that are not installed globally. But I can execute it by npm scripts. How to fix it?
For example:
I installed gulp under the project:
npm install gulp --save-dev
Then I try to execute it by
gulp
zsh: command not found: gulp
But if I add a npm script to package.json:
"scripts": {
"test": "mocha --require intelli-espower-loader && gulp test",
"start": "gulp"
},
Then run
npm start
It can get executed without problem.
P.S.
Same issue with the mocha package, I can't execute mocha directly but I can execute npm test without problem.
Help Wanted:
What I can do to fix that issue?
Notice:
I'm not saying that I want to execute them globally, I just want to execute them under the project.
I don't know where goes wrong, but they are executable not long ago, just don't work recently!
In addition to #Ion's answer: You might need to add the path to the environment variables. In windows OS, it would be %AppData%\npm. For packages installed locally, you should be able to run them like
.\node_modules\.bin\gulp
If you want to execute them globally install with the -g flag
npm install gulp -g
To run directly you could also do ./node_modules/.bin/gulp
That is because the package not installed globally doesn't create a reference in the root node_modules folder . If you want to specifically use the local installed version to run globally on terminal then go to you environment variables and set the path to ./node_modules/gulp/bin/gulp.js or alternatively configure your npm to use the mentioned location as the gulp and execute node_modules/.bin/gulp
You have two choices:
Install the executable modules globally:
npm install -g gulp
This is good if it's a tool you use often (for many different projects). For gulp specifically, the globally installed gulp will also check to see if the project has its own gulp installed (in node_modules) and run that version of gulp. This means that each project can have its own version of gulp. But not all tools have this feature.
Use npx:
npx gulp
Newer versions of npm ships with a command called npx which will search through your project's node_modules directory to find a module to execute. This means you don't need to install project specific tools globally. Apart form avoiding global installs of commands (which may or may not be a security issue) it also allows you to install project specific versions of tools.
If your npm installation does not have npx you can install it from npm itself:
npm install -g npx

npm use local modules

I've just installed the babel-cli module locally to my project but when I run babel test.js in the terminal it outputs that the *command babel is uknown*.
What I figured out is that npm is trying to find the module in my globally installed modules instead of my project modules, how can I fix it?
Sorry for the silly question but I'm not finding a solution.
You can either
Use the babel installed in you project - node_modules/.bin/babel test.js
Add a script in your package.json and run it via npm - npm run <script_name>. npm will use the version of babel installed in your project
When you run babel. It looks for global npm directory and can't find it there.
2 ways but one is redundant.
You can link your local path to global npm directory which is
redundant and wont work for the next project. Don't never do this.
Or install it globally. That how npm works for now.
There is a discussion on that. And here is a good article. http://www.joezimjs.com/javascript/no-more-global-npm-packages/

gulp-util now included in npm install of gulp?

ok, so I didn't find my answer in the already asked questions. I recently had to reload my node to include trying to reload all the globally loaded 'things' (that I could remember).
Back when I was learning "Gulp", I remember having to do a separate install for gulp-util. But when I looked in the node > node_modules folder, I see where gulp-util was already loaded as a sub module of gulp. This was also a duplicated and exact version as to my separate install of gulp-util.
So does gulp (npm install -g gulp), now come with gulp-util as a part of its install process. So doing a separate install of gulp-util is pointless and overkill?? Or do I still need to do it???
Yes, you still need.
The fact that gulp-util is a submodule (along with any other) of gulp just means that gulp uses it, but doesn't mean that you don't need to include it.
If you want to get gulp-util from gulp you can do something like it:
var gutil = require('gulp/node_modules/gulp-util')
But, I strongly advise you not to.
Anyway, gulp is a build tool, overkill shouldn't be a concern here since you won't ship it or its rendundant submodules for the client.

"grunt install" returns error on Ubuntu

I get the following error when I try to run "grunt install" on a Ubuntu 14.04 box that has the latest nodejs installed from NodeSource.
jit-grunt: Plugin for the "install" task not found. If you have
installed the plugin already, please setting the static mapping. See
https://github.com/shootaroo/jit-grunt#static-mappings
Warning: Task "install" failed. Use --force to continue.
Aborted due to warnings.
Here is the part of Gruntfile.js related to jit-grunt:
require('jit-grunt')(grunt, {
express: 'grunt-express-server',
useminPrepare: 'grunt-usemin',
ngtemplates: 'grunt-angular-templates',
cdnify: 'grunt-google-cdn',
protractor: 'grunt-protractor-runner',
injector: 'grunt-asset-injector',
buildcontrol: 'grunt-build-control'
});
Can someone point to the right direction?
What is the grunt install task? Can you please paste your package.json file here so we may see your dependencies?
The reason jit-grunt is outputting that error is because it cannot find a node module folder named grunt-contrib-install, grunt-install, or install, with a tasks/ folder with JS files that register a Grunt task named install.
Do you mean either of these packages? If so, you have to call them via their registered task names:
- https://www.npmjs.org/package/grunt-npm-install – grunt npm-install
- https://www.npmjs.org/package/grunt-auto-install – grunt auto_install
For the grunt-auto-install package, you will need to add it to jit-grunt's static mappings, like you have with grunt-express-server and others.
If it's not the above, apart from "maybe you mistyped?", the only other answer I can offer is similar to the assumption #waqas-ahmed made: that you mean to install dependencies and devDependencies from your package.json file, and that perhaps you mean to call npm install, not grunt install.
Try as below:
1) npm install -g grunt-cli
This will put the grunt command in your system path, allowing it to be run from any directory.
Note that installing grunt-cli does not install the Grunt task runner! The job of the Grunt CLI is simple: run the version of Grunt which has been installed next to a Gruntfile. This allows multiple versions of Grunt to be installed on the same machine simultaneously.
2) npm install grunt --save-dev
The easiest way to add Grunt and gruntplugins to an existing package.json is with the command npm install --save-dev. Not only will this install locally, but it will automatically be added to the devDependencies section, using a tilde version range.
for further assistance follow this link
http://gruntjs.com/getting-started

Where did the grunt min task go?

I watched many tutorials on grunt where some min task was used. I couldn't find any plugins referring to similar task. I would guess that devs have updated it and renamed to uglify am i right? And another issue i had was the installation of grunt. Can it still be installed globally, or should i install grunt-cli globally and grunt locally in order to use it for my local projects??
This:
sudo npm install -g grunt
doesn't work for me,
only:
sudo npm install -g grunt-cli
npm install grunt --save-dev
Is the first method deprecated?
Edit:
Here is the video i'm refering to: http://www.youtube.com/watch?v=q3Sqljpr-Vc
There are many different min libraries including these by the core grunt team:
grunt-contrib-cssmin (grunt-contrib-mincss is the older version)
grunt-contrib-htmlmin
grunt-contrib-imagemin
grunt-contrib-uglify <== for js minification
It is likely the one you are referring to is the uglify plugin, but hard to tell without knowing which tutorial you were watching.
As to installing, the second form is correct for grunt 4.x as described in the documentation
I saw the same tutorial and I couldn't found min task too. 'min' seems using uglify internally so you can use uglify directly.
decalre task in gruntfile.js
uglify: {
dist: {
src: foo.js,
dest: foo.min.js
}
}
load plugin
grunt.loadNpmTasks('grunt-contrib-uglify');
and run
$ grunt uglify

Resources