Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use Sass with a batch script in Windows

In web projects on my local machine, I'm using a fairly simple Sass setup. In the same folder, I have /scss/style.scss and /css/style.css

So to run Sass while I work I just write this in a Ruby Terminal:

cd "C:\Users\Puppybeard\Documents\Aptana Studio 3 Workspace\Project Title"
sass --watch scss/style.scss:css/style.css

Works fine, but it's a little cumbersome, so I'm trying to figure out how to do the equivalent with a batch script. I've tried the following, but it's a complete disaster, and my computer tries to open an infinite amount of Ruby consoles.

cd "C:\Ruby193\bin"
start ruby
cd "C:\Users\Puppybeard\Documents\Aptana Studio 3 Workspace\Project Title"
sass --watch scss/style.scss:css/style.css
exit

I think what I need to do is to start Ruby running in the background, rather than open the Ruby exe. Does anyone know how, or is that even how Ruby works? Obviously, I'm new to Sass, Ruby and batch scripts, so any insight you can give me would be a big help, thanks.


EDIT: I got it working like this

cd "\Ruby193\bin"
sass --watch "C:\Users\Puppybeard\Documents\Aptana Studio 3 Workspace\Project Title\scss\style.scss:C:\Users\Puppybeard\Documents\Aptana Studio 3 Workspace\Project Title\css\style.css"

I think it should be neater, and suspect that sass needs to have it's $PATH set.


EDIT 2: I set the Path variable for Ruby, using these instructions: http://groups.google.com/group/beginning-rails/browse_thread/thread/1c68665013a60081

In my case, the path I needed to add was C:\Ruby193\bin Now the only line I need, when I have the script in the root of the web project, is:

sass --watch scss/style.scss:css/style.css

I could keep the part where I change directory to the location of the folders in if I wanted to have something that can run from anywhere on my computer. However, the fact that the script doesn't specify the project location means I can just copy it into any project where I use the same structure.

Worth the effort? In the long run, probably, yeah.

like image 218
daveyfaherty Avatar asked Jun 29 '12 09:06

daveyfaherty


People also ask

What can I do with a Windows batch file?

On Windows systems, this interpreter is known as cmd.exe. Running a batch file is a simple matter of just clicking on it. Batch files can also be run in a command prompt or the Start-Run line. In such case, the full path name must be used unless the file's path is in the path environment.

How do I write a batch script in Windows?

To create a Windows batch file, follow these steps: Open a text file, such as a Notepad or WordPad document. Add your commands, starting with @echo [off], followed by, each in a new line, title [title of your batch script], echo [first line], and pause. Save your file with the file extension BAT, for example, test.

Is Windows batch a scripting language?

The language is simply batch script . It is not a high level language like C++, but a simple interpreted scripting language.

Are batch scripts useful?

Batch scripting is a useful tool for Windows software developers, that enables command line instructions to be executed like files. Developers can automate plenty of tasks on servers and on their local machines using batch files.


2 Answers

Put your original two commands into your batch file. So the content of the .bat file would be:

cd "C:\Users\Puppybeard\Documents\Aptana Studio 3 Workspace\Project Title"
sass --watch scss/style.scss:css/style.css

Simple as that. A batch file like this runs each command on each line one after the other, as if you were typing each one individually.

like image 62
Charles Roper Avatar answered Sep 28 '22 02:09

Charles Roper


If you're trying to update multiple css files with a batch file like this:

scss A.scss ../CSS/A.css
scss B.scss ../CSS/B.css
echo Done.

...but only the first scss command line executes, and the batch file never completes, i.e. you never see the 'Done.', here is why and how to fix it:

scss is actually a buggy batch file that fails to return control to your batch file. I fixed this by bypassing the scss batch file and runing ruby and it's scss gem directly as follows:

ruby C:/Ruby193/bin/scss A.scss ../CSS/A.css
ruby C:/Ruby193/bin/scss B.scss ../CSS/B.css
echo Done.

You'll need to have your path pointed to ruby, or put an absolute path in above.

like image 35
Elliptical view Avatar answered Sep 28 '22 04:09

Elliptical view