I'm building a web site and have multiple js files all in one directory. When I save any one of the js files I want a script to run that will compile and compress all files using the google closure compiler jar.
Example from Google Closure Compiler README:
java -jar compiler.jar --js=in1.js --js=in2.js ... --js_output_file=out.js
Is there a shell script or app that does this? I'm looking for something similar to how http://incident57.com/less/ works for CSS.
In linux you can use the inotifywait command to listen for changes in a specific folder.
This script can you give an idea:
#!/bin/bash
directory=$1
inotifywait -q -m --format '%f' -e modify -e move -e create -e delete ${directory} | while read line
do
echo "doing something with: $line";
# for example:
# java -jar compiler.jar --js=in1.js --js=in2.js ... --js_output_file=out.js
done
You can invoke this script specifying the "monitor" directory, in this way
./inotify.sh ~/Desktop/
Linux and Mac OSX have application interfaces that let you monitor filesystem changes.
I'm myself using linux so I'm familiar with inotify. Doing a script that compresses your files would be easy enough that I could do it for you from a feasible price.
For Mac OSX you can use FSEvents to get a same effect. Though you'll need to do it yourself.
If you wonder how to do this on windows.. Well nobody in his full senses would be using that system for software development.
If you use some eclipse-like IDE, you can create and set builder for this.
But your project should also has "Build Automatically" checkbox.
Fileconveyor is a Python script that watches and processes files, and can even upload them automatically.
I'd recommend checking out the website to see if it's something that might help you: http://fileconveyor.org/
Related
Would like to try this Rhino Debugger however having problems
I downloaded latest from here according to doc it says just simply run:
java org.mozilla.javascript.tools.debugger.Main [options] [filename.js] [script-arguments]
however..it's source code, so I probably need to build it first...(unless there are precompiled download out there?). Assuming I need to build it to get the jar file for debugger, I assume just build the build.gradle file at the root dir. Or run gradle tasks build ? When I do that I get error:
Execution failed for task ':checkstyleMain'.Unable to create a Checker: configLocation {C:\rhino\rhino-1.7.8\checkstyle.xml}, classpath {C:\rhino\rhino-1.7.8\buil
dGradle\classes\java\main;C:\rhino\rhino-1.7.8\buildGradle\resources\main}.
So..I'm a bit lost. Been ten years since I've worked with Java, but hopefully I'm missing something simple.
Any experienced Rhino JavaScript devs out there that can point me in the right direction? Should I just stick with using Eclipse? (Had that working, but I'm still curious about this debugger)
Download the latest rhino from the link you provided, at this time it is "rhino-1.7.8.zip". Unzip that and change directory to "rhino1.7.8/lib"; you need the "rhino-1.7.8.jar" in your CLASSPATH. Assuming you are in "rhino1.7.8/lib" that should be in your current folder, and you can then do
java -cp rhino-1.7.8.jar org.mozilla.javascript.tools.debugger.Main
Which should render like
I am trying to compile CoffeeScript but it fails. I have Node.JS installed, set $NODE_PATH to /home//bin (with my username, of course). That directory contains these files:
browserify coffee#1.1.3 uglifyjs
browserify#1.10.8 coffee#1.3.1 uglifyjs#1.0.6
cake sharejs uglifyjs#1.0.7
cake#1.1.3 sharejs#0.5.0-pre uglifyjs#1.2.6
cake#1.3.1 sharejs-exampleserver
coffee sharejs-exampleserver#0.5.0-pre
But I get this error:
Error: Command failed: /bin/sh: node_modules/.bin/browserify: not found
How to solve it? Not sure why it checks that directory.
I used "cake webclient" to compile it using the Cakefile.
I am using Ubuntu 11.10 x64, compiled ndm from source.
EDITED as requested:
I have got a project downloaded from github, which is written in CoffeeScript. I want to run to so I need to compile (build or whatever it is called) it to JavaScript. There is a Cakefile in trunk directory of the project. I got there and executed cake. It said there are 3 options available to build, one of them was cake webclient, so I executed this command. It started converting CoffeeScript files to JavaScript files but then I got that error on one of the files. That is all I know about the situation :D
EDITED (PATH and NODE_PATH values):
pius#pius-laptop:~$ echo $PATH
/home/pius/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/node/bin:/usr/local/share/npm/bin
pius#pius-laptop:~$ echo $NODE_PATH
/home/pius/bin
pius#pius-laptop:~$
I would guess you haven't set $NODE_PATH correctly because it's looking in the default directory. It should be done like this:
export NODE_PATH="/home/$USER/bin"
And check it with
echo $NODE_PATH
EDIT:
Perhaps something needs access to npm. You can try adding that to your path.
export PATH="$PATH:/usr/local/share/npm/bin"
Also, add these things to your .bashrc file and then they'll be available for every terminal. You will need to restart the terminal or execute
source ~/.bashrc
for the changes to take effect.
Try to download a pre-made package for ndm & CoffeeScript in Ubuntu 11.10 x64. If those work, then the issue is with the way you compile. If it does not work, then the issue is with your OS install (missing libs, different folders, etc).
I want to use Google Closure Compiler(GCC further) for joining my js-files and compressing before deploy. It's ok, if I will need to run some script. But how can I write a file with options for GCC? I can only write a *.sh file with task.
Help me please. Also it will be great, if there is some tool, that can watch for changes in my local js folder and run that task.
Thanks.
There are lots of "make" systems that provide a command to rebuild your software according to a set of rules when one of the source files changes. GNU/Linux has make, Java has ant, CoffeeScript has cake, Ruby has rake, etc. Any of these can spawn a task that will compile your .js files. They all have fiddly syntax.
A system that detects file changes and automatically rebuilds, tests, and deploys everything when files change is called a "continuous build", "continuous integration", or "continuous deployment" system. The big one is Jenkins developed for Java.
It sounds like you want a fairly simple single-user combination of 1 and 2.
node.js is well-suited to running a job that watches for file changes and spawns build commands. It doesn't have a "standard" JavaScript build system or continuous integration system. But there are lots of projects out there, such as
ready.js
drip for node.js got a lot of coverage but I'm not sure its status.
the CoffeeScript language (that compiles into JavaScript) has a Cakefile system that can watch for script changes and run commands
I'm trying to decide between ready.js and Cakefile myself.
check out plovr. http://plovr.com/
You need to get node.js so you can write make files in javascript , that's the best way to do it.
I use two different IDE's based on what I'm doing. My primary IDE is Visual Studio, whereby I use Chirpy to mash and minify my code. It works flawlessly and I love it. Problem is that when I'm not on my Windows box, I don't have access to it.
When not using Visual Studio, I'm usually writing Javascript apps in Webstorm on my Macbook Pro. Here in lies the problem. I haven't found a Webstorm plugin or any other app that I can configure to watch my scripts and mash/minify them.
How do you Mac users mash/minify your JS and CSS at design time with minimal effort?
For those who have now updated to WebStorm 6, this functionality is in-built. Simply go to File (or whatever the Mac equivalent is) -> Settings -> File Watchers and define a file watcher for the type of file you need to watch.
The relevant help documentation is here - http://www.jetbrains.com/webstorm/webhelp/using-file-watchers.html
You could use YUI Compressor without Command Line with these little Apps:
http://www.webmaster-source.com/minimus/ – free
http://www.matmartinez.net/delivery/ – free
I'm neither a Mac nor Webstorm user, but this might still be relevant.
For javascript I use the closure compiler as part of an upload script to minify. It doesn't monitor the files, it runs when I run the upload (a bash file).
If you wanted to keep it all in the IDE, it looks like Webstorm has an Ant plugin http://plugins.intellij.net/plugin/?webide&id=4526 that you could use to execute the closure compiler.
If you can find a command line css minifier then you could put that in the Ant script as well.
I use lessc and uglifyjs to concatenate and minify my css and js files. Here's a makefile from Twitter Bootstrap that I used a modified version of:
https://github.com/twitter/bootstrap/blob/master/Makefile
It's simple since all I do is type make in the command line whenever I want to compile.
I use Minify. It's on the Mac App Store.
I developed it to support my own workflow. minifyapp.com
Is it possible to compile a JS application and the NodeJS interpreter into a single executable for distribution?
you need a linux box with git and python, then ugly solution:
$ git clone git://github.com/ry/node.git
$ cd node
$ vim src/node.js # add your code to end before "process.loop();"
$ ./configure
$ make
$ sudo make install
$ node
Is it possible to compile a JS application and the NodeJS interpreter into a single executable for distribution?
This might sound obvious, but here's my take on it.
A "single executable for distribution" sounds a lot like an installer...
An installer would contain or be able to fetch online your js scripts and a compiled node.js. It would unpack everything and create a script in /etc/init.d/ to start and stop the server.
If all your clients are on the same distro (e.g. Debian), I'd just make a package for the appropriate packaging tool (e.g. apt) and let the package tool handle everything.
It the clients all have different distros, you could look into autopackage.
If your goal is to execute javascript, you might be able to create a simple C or C++ wrapper program which would spawn an interpreter and evaluate your JS. If you want a single file, the js source could be included as a string constant.
When you compiled the wrapper program, you'd want to statically link it to node and the rest of its dependency tree. Rather than depending on shared libraries on the system, static linking will copy the routines your project depends on into the compiled binary.
How you do this will depend on your environment