Batch Ruby Sass Watch String - css

I would like to run Ruby/Sass from the directory root I have my all projects saved using a batch file.
Ruby version: 1.9.3
Sass version: 3.2.7
For instance:
D:\all-projects
I would like run SASS.bat from the root folder and it should automatically execute the watch function watch for sass on all projects, like this:
sass --watch D:\all-projects/sass:public/stylesheets
At the moment I got this:
#echo off
cmd.exe /E:ON /K C:\Ruby193\bin\setrbvars.bat
sass --watch D:\all-projects/sass:public/stylesheets
This starts only ruby in the root directory but does not run the watch function for Sass.
I'm looking for this solution because it would make the usage of Sass a lot easier and effective.
At the moment you have to run RUBY -> look up for the directory -> run sass --watch ...
How can I do this? What should I change in order to make this work?
I welcome all hints and helps.
Thanks in advanced.

Try this and see if it works:
#echo off
cmd.exe /E:ON /K C:\Ruby193\bin\setrbvars.bat
START /B sass --watch D:\all-projects\sass:public\stylesheets
PAUSE
I have created batch files for SASS in the past and did something similar to this. However I never had to run Ruby in the BATCH file. So I am sort of curious as to why you need to start ruby.
EDIT: (basic example)
This is all you should need to create a basic batch file with SASS.
-Create a Batch file called test.bat with the following code and save to your desktop.
#echo off
sass --watch file.scss
PAUSE
-Create a blank .scss file called test.scss and save to your desktop.
-Now run your batch file and it should create file.css and say...
>>> Sass is watching for changes. Press Ctrl-C to stop.
overwrite file.css

Related

sass error: No such file or directory

Sass is throwing an error on multiple projects on both of my computers when I try to compile the scss files to css. I'm using dart-sass. I'm typing the command in the terminal from the root of the projects and the file path is correct. I've tried both
sass --watch src/styles/scss:src/styles/css
and also just
sass src/styles/scss:src/styles/css
but the results are the same:
Error reading src/styles/scss:src/styles/css: no such file or directory.
As such I can't compile any of my style files.
filename is required to select directory
Try this sass --watch src/styles/scss/fileName.scss:src/styles/css
Okay, I figured out a solution if anyone else runs into this problem. You should uninstall dart sass from your computer(prefix this command with sudo if using mac):
npm uninstall sass -g
Then, install a stable version of ruby sass:
gem install sass
Now you should be able to run sass --watch src/styles/scss:src/styles/css and it will compile.
Note: If you were to do npm install sass that would install the latest version written in dart, which is what seems to have caused my problems.
In the terminal, I had to make my way to the file location and then run the command. Example:
Project Structure:
src
abc
prq
main.html
main.scss
When I launch the terminal, it defaults to src folder
PS C:\Users\src> sass --watch main.scss:main.css
Running command here will throw error:
Error reading main.scss: no such file or directory.
Now, browsing to prq directory & running command, will be successful.
PS C:\Users\src\abc\pqr> sass --watch main.scss:main.css
Compiled main.scss to main.css.
Sass is watching for changes. Press Ctrl-C to stop.

SASS Directory won't change

I keep trying to run sass --watch scss:css on a directory and unfortunately, the scss files are not compiling.
SASS does confirm that it's watching for changes, but I've noticed that it is looking in my Program Files directory.
My project with the actual SCSS and CSS files is in my C/username/documents/project/assets directory. If I try to enter that path explicitly in the sass --watch command, I get an error message.
How can I specify the correct directory so SASS will stop trying to compile my files in Program Files?
First make sure your sass is working well and you can try below option for compiling into different folder.
sass --watch input-dir:output-dir

Compiler for SASS

I just started using SASS in my project and I want a script to compile them and convert them to CSS files. Im planning to run this script only when I build.
I installed SASS in my system and SASS --watch doesn't seem to be the right approach here; as I told, I want a script that runs only when I build. I used to have one such script for LESS compiling, but couldn't find any for SASS.
Does anyone know of any such scripts?
Looking at the documentation, just run sass from the command line as part of your build script. An example for a one time use on a single file:
sass input.scss output.css
link:
From the command line, you can just do sass --update for a one-time compile from Sass to CSS. This will use whatever settings already exist in config.rb.

how to watch changes in whole directory/folder containing many sass files

How could I trace changes in whole directory containing many sass files ? I'm using the following command to watch changes in sass
file:
sass --watch style.scss:style.css
But how to watch changes in whole directory/folder containing many sass files.
Simply use the command sass --watch <input folder>:<output folder>, like this:
$ ls -l
css/ sass/
$ sass --watch sass:css
Where <input folder> contains the Sass files and <output folder> that hosts the generated CSS files.
Expanding the answer by piouPiouM a little:
Output files will be created with the same names as input files except ending with .css.
<input folder> and <output folder> can be the same.
Both folders can be the present working directory, so the following is valid:
$ sass --watch .:.
Go to you terminal and get to you folder then wrote:
sass --watch .
this will watch all sass files and convert to css files with the same name.
also you can do it in this way:
sass --watch ~/user/youUser/workspace/project/styles/
I hope this can help you.
I ended up doing this without using Grunt or Sass-watch:
npm install -g watch
watch "sass assets/app.scss assets/dist/app.css" assets/css
if you are in your current folder then do the following to watch it.
F:\sass tutorial>sass --watch ./:./
Just in case someone faces with this issue in 2018:
sass Website refers to Ruby Sass that is been deprecated.
and as now (May 2018) if you install dart sass via npm , it does not support --watch command
What to do:
you need to install node-sass globaly , like:
npm install node-sass -g
and then restart the command line , then use this code:
node-sass --watch scss/styles.scss css/styles.css
to compile your scass files to css.
basically node-sass supports --watch command and we use that to compile our scss codes to regular css files.
and just in case you get an error like this at the first time that you save your .scss file:
{
"status": 3,
"message": "File to read not found or unreadable: yourdirectory/scss/styles.scss",
"formatted": "Internal Error: File to read not found or unreadable: yourdirectory/scss/styles.scss\n"
}
what you need to do is save it again, it will work correctly!
According to the information, you can use the next command line:
sass --watch .
Source: http://sassbreak.com/watch-your-sass/#what-does---watch-do
You can create one sass file which includes the rest of the files, and then just watch this file.
Alternately, look into Grunt and the very good grunt-contrib-compass plugin
You can set sass to watch all the .scss files(for my case i got several .scss files in src/static folder) to compile, but before install it globally:
npm i -g sass
then go to the project folder and type command below:
sass --watch $(pwd)/src/static
also you can wrap it in npm script in package.json, like
"scripts": {
"sass:watch": "sass --watch $(pwd)/src/static"
}
and run it by this command:
npm run sass:watch

Unable to compile an existing project because Compass can't find it

I just installed the foundation in my application base directory by executing the following command:
compass create myprojectname -r zurb-foundation --using foundation
Now I have open the sass/_settings.scss file and I have un-comment the 66th line that is the following:
$include-html-classes: true;
finaly, I try to compile my foundation project in order to include the html classes by executing the following command:
compass compile
but I am getting the following result in my command prompt:
Nothing to compile. If you're trying to starta new project, you have left off the directory argument.
Run "compass -h" to get help.
also, based on this page : http://foundation.zurb.com/old-docs/f3/compass.php I try to compile my scss code by using the command:
compass watch
but again I am getting the same message as with compile argument next to compass.
Note: I am executing the above commands in the same directory I run the first command for the foundation project creationg.
Note: I am very new user on compass, sass, foundation framework. Actually, today is the first time I am using them, so I am not expirienced user. Please be kind with me :)
Is there anybody to help me with that ?
When you use compass create [directory_name], Compass creates your project within ./[directory_name] relative from your current directory (running compass create without the directory name would have created the project in the current directory). In order to compile or watch a Compass project, you need to do either of the following things:
Tell Compass where your project is via compass compile [path_to_config.rb]
Change to the directory where config.rb is found and run compass compile
Alternately, you could move your config.rb to where you want to run your command. Just make sure you edit the paths to directories configured within said file.

Resources