Project + --- CoffeeScripts | \ --- roast.coffee + --- JavaScripts | --- Tools | + --- CoffeeScript | + --- CygwinLite | + --- NAnt | \ --- NodeJs \ --- compile.bat
compile.bat in the project root, which will compile all the scripts from the CoffeScripts folder to the JavaScripts folder.roast.coffee ": roast = (what) ->
"Roasted # {what}"
console.log roast 'coffee!' git clone http://github.com/jashkenas/coffee-script.git
coffee --version ":C: \ Project \ Tools \ CoffeeScript \ bin > node coffee --version CoffeeScript version 0.9.4
D: \ > node / cygdrive / C / Project / Tools / CoffeeScript / bin / coffee --version CoffeeScript version 0.9.4
coffee.bat " coffee.bat , which you need to save to its bin-directory:@pushd. @cd / d% ~ dp0 @node coffee% * @popd
D: \ > C: \ Project \ Tools \ CoffeeScript \ bin \ coffee --version CoffeeScript version 0.9.4
roast.coffee and get the result on the console: C: \ Project
> Tools \ CoffeeScript \ bin \ coffee -c -p /cygdrive/C/Project/CoffeeScripts/roast.coffee
(function () {
var roast;
roast = function (what) {
return "Roasted" + (what);
};
console.log (roast ('coffee!'));
}). call (this);
cygpath -a -u windows-filename
C: \ Project \ Tools \ CygwinLite \ bin > cygpath.exe -a -u cygpath.exe /cygdrive/c/Project/Tools/CygwinLite/bin/cygpath.exe
@echo off
REM Folder with source scripts
set sourceDir = CoffeeScripts
REM Folder for compiled scripts
set destDir = JavaScripts
REM Folders Used Utilities
set cygwinDir = Tools \ CygwinLite \ bin
set coffeeDir = Tools \ CoffeeScript \ bin
set nodeDir = Tools \ nodejs
REM Get the unix paths for the destination folder and before the coffee compiler script
for / f %% o in ('% cygwinDir% \ cygpath.exe -a -u "% destDir%"') do set outputPath = %% o
for / f %% c in ('% cygwinDir% \ cygpath.exe -a -u "% coffeeDir% \ coffee"') do set coffeePath = %% c
REM For each coffee-script ...
for %% f in (% sourceDir% \ *. coffee) do (
REM ... we get its unix-way, ...
for / f %% s in ('% cygwinDir% \ cygpath.exe -a -u %% f') do (
REM ... and compile it into javascript in the destination folder!
% nodeDir% \ node% coffeePath% -c -o% outputPath% %% s
)
)
echo done!
compile.bat and get the compiled roast.js in the JavaScripts folder: C: \ Project
> compile.bat
Done!
C: \ Project
> type JavaScripts \ roast.js
(function () {
var roast;
roast = function (what) {
return "Roasted" + (what);
};
console.log (roast ('coffee!'));
}). call (this);
<? xml version = "1.0"?>
<project xmlns = "http://nant.sf.net/release/0.90-alpha1/nant.xsd" name = "Coffee test">
<! - Set the environment variables for the script. The path to cygwin is required to use the function $ {cygpath} ->
<setenv>
<variable name = "PATH" value = "Tools \ CygwinLite \ bin; Tools \ nodejs;% PATH%" />
</ setenv>
<foreach item = "File" property = "filename">
<in>
<items basedir = "CoffeeScripts">
<include name = "*. coffee" />
</ items>
</ in>
<do>
<exec program = "node">
<arg line = "$ {cygpath :: get-unix-path ('Tools \ CoffeeScript \ bin \ coffee')}" />
<arg line = "- c" />
<arg line = "- o $ {cygpath :: get-unix-path (path :: get-full-path ('JavaScripts'))}" />
<arg line = "$ {cygpath :: get-unix-path (path :: get-full-path (filename))}" />
</ exec>
</ do>
</ foreach>
</ project>
compile.build " and write a new " compile.bat " to run it:Tools \ Nant \ bin \ nant.exe -buildfile: compile.build
C: \ Project \ JavaScripts > node roast.js Roasted coffee!
Source: https://habr.com/ru/post/106811/
All Articles