closure compiler output on the same file not working [duplicate] - google-closure-compiler

This question already has answers here:
Use Closure Compiler Command Line Minify and Replace Original File
(2 answers)
Closed 8 years ago.
I try to override my source file with compiled version at build time.
java -jar compiler.jar --js test.js --js_output_file test.js
the above command succeed but the content of test.js gets wipped out.
If I output to a different file then it works.
What should i do to make it override the same file with minified
version?

try:
java -jar compiler.jar --js test.js > test2.js; mv test2.js test.js

Related

scss builder for cloud9 web editor

Hey there :) I'm trying to figure out how I can make a scss builder for cloud9. I could only find something for less here on stackoverflow.
I'm trying to get main.scss in my scss folder to be compiled into main.css in a css folder at the same level.
The builder:
{
"caption" : "SCSS",
"cmd": ["scss", "$file", "-x", "${file/\\.scss/\\.css/}"],
"selector": "source.scss"
}
Error:
OptionParser::InvalidOption: invalid option: -x
Use --trace for backtrace.
I think the way you're using the Cloud9 builder is correct, however, I couldn't find the -x option within scss. Here's what scss -h gives me:
Usage: scss [options] [INPUT] [OUTPUT]
Description:
Converts SCSS or Sass files to CSS.
Common Options:
-I, --load-path PATH Specify a Sass import path.
-r, --require LIB Require a Ruby library before running Sass.
--compass Make Compass imports available and load project configuration.
-t, --style NAME Output style. Can be nested (default), compact, compressed, or expanded.
-?, -h, --help Show this help message.
-v, --version Print the Sass version.
Watching and Updating:
--watch Watch files or directories for changes.
The location of the generated CSS can be set using a colon:
scss --watch input.scss:output.css
scss --watch input-dir:output-dir
--poll Check for file changes manually, rather than relying on the OS.
Only meaningful for --watch.
--update Compile files or directories to CSS.
Locations are set like --watch.
-f, --force Recompile every Sass file, even if the CSS file is newer.
Only meaningful for --update.
--stop-on-error If a file fails to compile, exit immediately.
Only meaningful for --watch and --update.
Input and Output:
--sass Use the indented Sass syntax.
--sourcemap=TYPE How to link generated output to the source files.
auto (default): relative paths where possible, file URIs elsewhere
file: always absolute file URIs
inline: include the source text in the sourcemap
none: no sourcemaps
-s, --stdin Read input from standard input instead of an input file.
This is the default if no input file is specified.
-E, --default-encoding ENCODING Specify the default encoding for input files.
--unix-newlines Use Unix-style newlines in written files.
Always true on Unix.
-g, --debug-info Emit output that can be used by the FireSass Firebug plugin.
-l, --line-numbers Emit comments in the generated CSS indicating the corresponding source line.
--line-comments
Miscellaneous:
-i, --interactive Run an interactive SassScript shell.
-c, --check Just check syntax, don't evaluate.
--precision NUMBER_OF_DIGITS How many digits of precision to use when outputting decimal numbers.
Defaults to 5.
--cache-location PATH The path to save parsed Sass files. Defaults to .sass-cache.
-C, --no-cache Don't cache parsed Sass files.
--trace Show a full Ruby stack trace on error.
-q, --quiet Silence warnings and status messages during compilation.
Here's something that should work for you:
{
"cmd" : ["scss", "$file", "$file_path/../css/$file_base_name.css"],
"info" : "Building $file_path/$file_name",
"selector": "source.scss"
}
Where $file is the full path, $file_path is the directory path, and $file_base_name is the name of your file without the extension. You can take a look at the other variables available to you here.

How to compile java file from windchill shell

I am trying to compile a simple Hello World from windchill shell using command javac com.A.B.Test.
But it is displaying could not find main class error.
I think your problem is Java and not Windchill related.
Let's say your Java source file is stored in the following location:
/src/com/A/B/Test.java
To compile that file in shell (Linux for example):
cd /src
javac com/A/B/Test.java
To run that file (if it contains a main method):
java -cp /src com.A.B.Test
Try using the below command from the windchill Shell.
Hope you are following the default file structure provided by the Vendor i'm providing the same below otherwise just edit the path mentioned in the below command.
javac -d codebase -cp %CLASSPATH%;%WT_HOME%\srclib\tool\Annotations.jar src*.java
First Go to Windchill Shell then navigate to the folder where java file is present. At that location type javac Test.java and press enter.
Put the code into WT_HOME/src/com/package, than run from WT_HOME:
ant -f bin/tools.xml class -Dclass.includes=com/..path-to-package/*

Batch Ruby Sass Watch String

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

How to compile several files to the same ones

I know that Google Closure Compiler allows me to compile several files into a single one like the following:
java -jar compiler.jar --js assets/js/file1.js
assets/js/file2.js --js_output_file assets/js/file.min.js
But I need to compile files and put it to the same name in the same folder like this:
java -jar compiler.jar --js assets/js/file1.js
--js_output_file assets/js/file1.js
java -jar compiler.jar --js assets/js/file2.js
--js_output_file assets/js/file2.js
But it doesn't work. The files get corrupted. Can you help me?
First and most importantly, your compile script is set up to overwrite your source files. Are you really, absolutely positive that this is what you intend to do? Compilation is a lossy transformation: it destroys comments (including type annotations), renames everything, refactors aggressively, inlines everywhere, and generally purees your hard work into an unmaintainable mess.
java -jar compiler.jar --js assets/js/file1.js
--js_output_file assets/js/file1.js
java -jar compiler.jar --js assets/js/file2.js
--js_output_file assets/js/file2.js
If I am to take you at your word and you have actually done the above, this would unfortunately explain your "my files are now corrupted" question. I hope you have a backup.
More generally, grok the Compiler Manual. All of it, but especially the section on inconsistent property names. If the compiler is not informed about how your source files relate to eachother, it is impossible for closure to rename their contents consistently.
If you intend to create pre-compiled .dll style shared objects, this is not supported by closure because of the name-fragmentation issues documented in the manual. Also, there's no need to pre-compile, compilation is reasonably fast as-is. Share your source files instead.
Please, please make yourself a build directory and pipe your compiler output away from your source code. Code never builds perfectly on the first pass. Even if the code in question is a simple math utility, you'll want to build and test more than a few times.
In summary:
(1) read entire manual, (2) write Externs or try goog.require, (3) pre-compilation is overrated, (4) never ever ever overwrite source files ever, (5) keep frequent backups.
Simply use multiple "--js" params in command line:
java -jar compiler.jar --js 1.js --js 2.js --js 3.js --js_output_file all.js

Using the --module option in Closure Compiler to create multiple output files

I'm creating a fairly large library of JavaScript, using Closure Compiler for both its wonderful compression as well as the type-checking and warning systems.
I want to create multiple output files though, because the files are loaded asynchronously (and some files are only loaded on-demand).
Poking around the source code, I've found the --module flag, as well as some related flags. The source code says the following about the option:
A javascript module specification. The format is <name>:<num-js-files>[:[<dep>,...][:]]]. Module names must be unique. Each dep is the name of a module that this module depends on. Modules must be listed in dependency order, and js source files must be listed in the corresponding order. Where --module flags occur in relation to --js flags is unimportant
... and that's all I can find. I'd love to learn more about how to use this option, does anyone have any experience here? Alternatively, if there's another way to create multiple output files, I'm all ears.
java -jar compiler.jar ^
--chunk jq:1: --js jquery-1.6.2.js ^
--chunk t:1:jq: --js test.js ^
--compilation_level ADVANCED_OPTIMIZATIONS
This example will compile out 2 files for you:
jq.js
t.js
jq.js will be jquery 1.6.2 with advanced minification, and t.js will use that minified version of JQuery properly.
I wish there was a JavaFiddle I could post this to to demonstrate it.
Older version
This original answer was for an older version of Closure Compiler. I've left it intact below in case you're in an environment that needs to keep the older version in place.
How to handle multiple output files, aka modules:
http://groups.google.com/group/closure-compiler-discuss/browse_thread/thread/ec7f6809b19b019e/25a94f3994173840
Copy/pasting:
java -jar Build\Tools\compiler.jar ^
--compilation_level=ADVANCED_OPTIMIZATIONS ^
--externs Build\jQuery.externs.js ^
--js Build\Output\Compiling.js ^
--js Script/Themes.lang.js ^
--js Script/Themes.js ^
--module Core:3 ^
--js UI/ThemeChooser/ThemeChooser_en.htm.js ^
--js UI/ThemeChooser/ThemeChooser.js ^
--module UI_ThemeChooser:2:Core ^
--js UI/VerticalTabs/VerticalTabs_en.htm.js ^
--js UI/VerticalTabs/VerticalTabs.js ^
--module UI_VerticalTabs:2:Core ^
--js Pager/Pager_en.htm.js ^
--js Pager/jquery.Pager.js ^
--js Pager/Pager.js ^
--module Pager:3:VerticalTabs ^
--module_output_path_prefix .\Compiled\
And as he notes, --js_output_file is irrelevant when outputting modules.
Note: Apparently the Closure Compiler has changed the arg "--module" to "--chunk". An editor suggested the change; for the newer version I kept the change, for the older version I kept the older argument name, since there are always people out there using older versions of build tools, and that kind of small breaking change can really screw ya up.

Resources