Makefile to combine js files and make a compressed version - javascript

I am trying to write a basic makefile that combines multiple js files into a single one and then does the same but compresses them.
So far I have this one that can make the compressed version fine.
# Set the source directory
srcdir = src/
# Create the list of modules
modules = ${srcdir}core.js\
${srcdir}sizzle.js\
${srcdir}json2.js\
${srcdir}ajax.js\
${srcdir}attribute.js\
${srcdir}content.js\
${srcdir}cookie.js\
${srcdir}css.js\
${srcdir}event.js\
${srcdir}json.js\
${srcdir}location.js\
${srcdir}opacity.js\
${srcdir}ready.js\
${srcdir}size.js\
${srcdir}init.js
# Compress all of the modules into spark.js
spark.js: ${modules}
java -jar yuicompressor.jar -o $# $^
Does anyone know how I would go about adding an uncompressed version called spark-dev.js? I have been trying to use cat but I didn't get very far. This is my first makefile I have ever written.
EDIT
I tried this code with cat
spark-dev.js: ${modules}
cat $# $^

You were almost there :-) This should work:
spark-dev.js: ${modules}
cat > $# $^
Background: The function of cat is to (try to) open all the files listed on its command line, and dump the contents to stdout. The > $# syntax is understood by the shell to mean "create the file $#, and connect this command's stdout to it", so now we end up with the contents of $^ combined together into $#.

Related

copy a file from drive F to all folders in C:\program files

I've been reading through a lot of stuff on this site and I cannot seem to find an answer to my need.... to the point:
I need to copy 1 file to all folder in C:\program files dir, however I'm trying to find a way that I wont need to specify the full path...for a rough example I can
REN F:\source\*.bat *.exe
(or .mp3 or .jpg or .vbs etc etc)
the above commands will rename all *.bat files to *.exe files, without specifying a path
so I'm looking for a similar command line in a batch to move 1 specific file to multiple folders in a dir without specific paths...
I have tried %~d0\ and %programfiles% but nothing seems to work for me....
I still do not fully understand the use case for this, but here is something that will copy a file into each subdirectory below the user's "Program Files" directory. Once you are sure that the copies you expect would be done, remove the -WhatIf from the Copy-Item cmdlet.
Get-ChildItem -Directory -Path $Env:ProgramFiles |
ForEach-Object {
Copy-Item -Path 'C:\src\t t t.txt' -Destination $_.FullName -WhatIf
}
If you must run it from a cmd.exe shell, put the code above into a file named with a .ps1 extension and run:
powershell -NoProfile -File copyit.ps1
Notes:
It is important to use the environment variable ProgramFiles because the actual directory name may be in a language you do not know.
There may be permission issues with writing to these directories. Try using Run as Administrator.
Yes, there are certainly .bat file script ways to do this. The future Microsoft direction is PowerShell. Might as well start grocking it now.

Output minified javascript file to a different directory with YUI Compressor File Watcher in IntelliJ

I'm using YUI Compressor JS as my file watcher in intellij to minify my javascript files. The compressor works fine when i set 'Arguments' and 'Output path to refresh' parameters like below:
Arguments = $FileName$ -o $FileNameWithoutExtension$.min.js
Output path to refresh = $FileNameWithoutExtension$.min.js
It then produces the minified file in the original file's folder. What I can not achieve here is that I want minified files to be placed in some other directory.
So far I tried to set the two aforementioned parameters with values below:
Arguments= $FileName$ -o $FileParentDir$-min\$FileDirName$\$FileNameWithoutExtension$.min.js
Output paths to refresh = $FileNameWithoutExtension$.min.js
But it then generates the minified version of the javascript file and overwrites it to the original file; prompting me with 'File Cache Conflict' dialoge like below.
File Cache Conflict Dialoge Image
My original javascript files reside in 'webapp/resources/js' folder, but I want minified files to be generated in 'webapp/resources/js-min' folder with the same structure as in 'webapp/resources/js' folder.
n the Arguments text box, type:
$FileName -o /your_custom_directory/
the Arguments pass to compresssor and it put your out put file in your_custom_directory then in "out put path to refresh" insert your_custom_directory too,this pass to phpstorm for indexing file
for me its like this
js>my_js_file
js>min>result
Arguments: $FileName$ -o $FileDir$/min/$FileNameWithoutExtension$.min.js
output paths to refresh:/min
Have you tried $FileParentDir$/js-min/$FileNameWithoutExtension$.min.js?
Are you on Windows? YUI Compressor doesn't seem to accept Windows absolute path as a -o value... When I run java -jar yuicompressor-2.4.8.jar -v -o C:\WebstormProjects\untitled3\webapp\resources\js-min\sub\subsub\f3.min.js f3.js, no f3.min.js is produced, the original file is modified instead:(
As far as I can see from the last comment in https://github.com/yui/yuicompressor/issues/78 thread, the bug should be fixed in yuicompressor-2.4.9. But this version is not available at https://github.com/yui/yuicompressor/releases, and the link to jar provided in comment seems to be outdated...
In general, I'd strongly recommend using a different JS minifier, as YUI Compressor looks dead - no updates since 2013

How to combine multiple Javascript files from different folder in a single file?

i have lots of JavaScript files in different folders and want to add them to a master.js together. I have the following project structure:
/dist/js/master.js <-- Output file
/src/bootstrap-untouched/js <-- Bootstrap Plugins (alert.js, button.js etc.)
/src/js/plugins.js
/src/js/script.js
It would be good if I could activate and deactivate the individual bootstrap plugins. I do not want to use Grunt and Gulp. I use only the NPM.
I think that would have to somehow work with browserify and uglifyjs.
In the source folder execute:
find . -name \*.js -type f -exec cat {} \; > ~/master.js
That is all.
I'm assuming you've got some starter file (like entry.js - you can call it whatever you want actually).
In that case, this code should work:
var b = require('browserify')();
b.add('your entry js');
b.transform('uglifyify');
var indexjs = fs.createWriteStream('build/bundle.js');
b.bundle().pipe(indexjs);

Closure Compiler combine files

I have the following setup in my phpstorm, and I would like to combine my javascript files located in the /js/app and /js/lib folder.
now it's only minifying a single jar, I would like to combine them
One simple way to do it:
Create a closure.command file (or whatever you want to name it) in the same directory as your js files. Put Closure command line options in it like so:
--js file1.js
--js file2.js
--js_output_file all.min.js
Edit the Closure file watcher arguments to include "--flagfile closure.command". You will probably want to uncheck the "Create output file from stdout" option.
** Since you want it to operate on js files from different directories you may have to modify the file paths and "Working Directory" option for it to work properly.

merging my CSS and JS files breaks code (working on mac, not on my server)

I'm merging (and afterwards minify with YUI compressor) my CSS and JS files.
My web application works fine when just linking the separate files.
Now I want to merge the files as one CSS file, so I just basically do the following:
find /myapp/js/ -type f -name "incl_*.js" -exec cat {} + > ./temporary/js_backend_merged.js
That merges all my javascript files perfectly. When I do this on my mac, all goes well and I can use the merged file in my application with no problems
When I merge the same files with the same command on my CentOS server, this doesn't work, my JS start throwing errors. I have the same problem when merging CSS files, the CSS doesn't render correctly on my Centos box when merged. It does when I merge them on my MAC.
Also, I did the same process before on my previous centos server, with no problems at all.
I'm thinking in the direct of a character set problem on the server maybe?
Who can solve this little mistery that took 2 complete days of my time already with no luck at all...
UPDATE: the problem is that the command: find /myapp/js/ -type f -name "incl_*.js" -exec cat {} + > ./temporary/js_backend_merged.js orders files from incl_01 to incl_02, ... correctly on the mac, but the same command orders these files differently on the server
I see that I can use sort -n to sort results, but I cant get the above command working correctly with the sort option added to it.
(find /myapp/js/ -type f -name "incl_*.js" | sort | xargs cat) > ./temporary/js_backend_merged.js
That'll use find the list of files, sort them, then pipe to xargs, takes the list of files from stdin, and applies the 'cat' command to them.
Then the whole thing is redirected to js_backend_merged.js

Categories