How can I keep grunt separate from my source files? - bash

I've spent about a day trying to figure this out.
What I finally did was a bash script:
gw() {
# runs grunt using this path
cd ~/root_install/grunt
grunt watch &
cd ~/root
}
My install file are in root_install and my source file are in root.
Note installing the grunt task runner globally is deprecated.
Note that setting the location of the Gruntfile.js does not work as it appears to need a local installation of the task runner.
This seems to be the deal killer.
But alas, application files I want separate from my source files and Grunt is an application.
What I have works, but it is a bit hackish as I don't want to spend any more time on this.

Related

why compiler is used for sass files while they can be run through terminal

Can anyone please help explain this? I am new at using Sass. But I cant understand why people use compiler for sass files when they can be run through terminal.
I actually had the same question some time ago when I was learning SASS.
I kept wondering why most tutorials involved using GRUNT / GULP or some kind of task runner when there where sass proprietary commands even for live-watching your files with a command such as:
sass --watch app/sass:public/stylesheets
I will quote myself here in the question (that no one answered) just to share my experience with SASS compiling:
Grunt: using grunt-contrib-sass - Everything has worked smoothly; I chose this one over grunt-sass for no particular reason, but I've read that the latter uses libsass(c++) which is faster than the traditional ruby Sass.
Gulp: using gulp:sass - I often encounter an error when watching
files, it doesn´t find some partials, but if you save again,
everything is fine (this is addressed in their common issues -this
solution hasn't worked for me though), also it doesn't generate sass
maps as a default you have to use gulp-sourcemaps on top.
Straight from Console: no task runners - Works fine so far, generates
sourcemaps, and lets you know where there's an error, just like with
Grunt and Gulp.
So after working on different projects using SASS I'd say the reasons are:
Tutorials popularized the use of task runners when using SASS in its early times
In a project, you rarely use SASS just by itself, you most likely want to run other tasks, so it makes sense to add your SASS task to the flow, which saves time and makes sense.
It's easier to run a simple command such as gulp sass or just gulp to run the default gulp task (that should include the sass task) than to remember a long command in which you have to put the paths over and over again.
After a while I realized that you can use NPM scripts in your package.json to run the SASS command line tools like so:
"scripts": {
"sass": "sass --watch app/sass:public/stylesheets --style compressed"
},
And then run it from the command line: npm run sass
the above requires no configuration and you don't have to remember the whole command by heart.
To conclude, there is nothing wrong in using the CMD SASS without other compilers/task runners, just use whatever you feel most comfortable with.

How can I run grunt with global path?

When I run 'grunt' at commend line, error occurred 'enable to find local grunt.'
Because, in my directory there is no grunt module. I want to run grunt with global path and not contain node_modules in my project folder. The more adding node_modules in my project the slower running a project.
In my project, there is only Gruntfile.js except for any other node_modules.
How can I run grunt and grunt sub modules with global path?
I can't find solution about this problem anywhere.

Source map error when attempting to run grunt server

I'm unable to access my sass files when running grunt server. Not sure if this is just a file path/permission error or something greater.
Running sudo grunt server gives the same output
grunt server
Running "server" task
Running "clean:dist" (clean) task
Running "copy:video_fonts" (copy) task
Copied 4 files
Running "copy:video_js" (copy) task
Copied 1 files
Running "concurrent:dist" (concurrent) task
Warning: Error: Error generating source map: couldn't determine public URL for the source stylesheet.
No filename is available so there's nothing for the source map to link to.
on line of standard input
Use --trace for backtrace. Use --force to continue.
Aborted due to warnings.
%
I get the following error in my browser when I run grunt server --force
Sass::SyntaxError: Error generating source map: couldn't determine public URL for the source stylesheet.
No filename is available so there's nothing for the source map to link to.
I had the same problem on a grunt task that was perfectly working a couple of days ago. I suppose the problem was in some misalignment between the modules for that project (specifically grunt-contrib-sass) and the version of SASS installed.
I solved the problem by upgrading SASS, removing the node_modules folder inside my project and re-installing them.
I am sorry I cannot provide you any reason why it worked, but it did.
Update:
$ rm -R node_modules
$ npm install
Try:
$ grunt --debug --verbose sass
To get more info about what's happening while grunt runs.
S.

OS-independent grunt script command in NPM package.json

When the command grunt is run in a Windows shell in the same path as the grunt.js file, Windows opts to run grunt.js using the Windows Script Host. The recommended path is to explicitly call grunt.cmd.
That's all fine and dandy, but what can I do if I want to create an OS-independent script command in my NPM package.json? I can't do this if I want to also run in *nix:
"scripts": {
"dox": "grunt.cmd dox"
}
Any pointers? Or, is there a big piece of the puzzle that I'm missing? (I'm equally new to both NPM and Grunt).
I've found the solution in creating a grunt.bat file that just calls grunt.cmd:
#grunt.cmd %*
Therefore, on Windows, just invoking grunt triggers the batch file since it gets higher priority than Windows Scripting Host's picking up of grunt.js. On Linux, the regular grunt binary gets picked up. This works cross-platform for me now.
I've got the same problem: when there is tslint.js file in the root dir of the package and an npm script in package.json just calls tslint, jscript is fired by npm instead of node, resulting in "Microsoft JScript compilation error" popup.
A workaround is removing .JS from PATHEXT environment variable.

How execute a self contained rake build?

We have an application which is compiled using Rake (on windows). We have a new requirement that one of our clients needs to compile the source code in their own environment using a bat file.
So I need to find a way to execute a rake build without installing anything on the host environment (i.e. everything required to do the build needs to be in the source directory, ruby, gems, etc...) from a batch file.
Anyone have any clues how I could get started with this?
Download and install ruby to a folder inside your project (do not add it to your PATH). After go to this folder and delete any "uninstall" file. Go to the folder again with the console (cmd and then use cd path\to\ruby\folder) and run gem install ... to install everything you need. After add a .bat file to run your app. Something like:
#echo off
rubyfolder\bin\ruby.exe myscript.rb
This is a fully portable ruby installation, you can put it in any computer and it will work as well. (I use it as a portable ruby in my pendrive to let me play everywhere with ruby!)
PS.: rake is a script from bin, you can open it with:
rubyfolder\bin\ruby.exe rubyfolder\bin\rake

Resources