I'm the developer of an NPM package, and am trying to normalize line endings. I'm on a Windows machine with VSCode, so most of my files are in CRLF format. However, minified and sourcemap files generated by my bundler, Rollup, are in LF format.
I personally prefer LF format, and would like to have my distributed builds in LF format, as well as the files in my personal editor. However, I don't want to mess other Windows users using different editors.
How should I configure .gitattributes, .editorconfig, my VSCode Settings, and my Git settings to best accomplish this? Thanks!
If is better to specifiy in a .gitattributes (as in here) a consistent eol policy for files with specific extensions: see this .gitattributes for instance, which uses LF.
VSCode has "auto" as its default file.eol, which should be enough: Git will do the conversion on checkout, and VSCode won't convert it.
Related
I'm developing an Electron app and would like the end-users to be able to import a Word document and convert it to a PDF. Is there a way to do this via the command-line with MS Word on Windows and macOS?
I've found solutions that covert using LibreOffice or do doc -> HTML -> pdf such as docx-pdf style conversion. Of course there are API solutions but this is a no-go due to sensitive documents.
The requirement is to convert without a change of formatting, so the thinking is using MS Word to covert would minimise chances of changes (unlike docx-pdf) but also something the end-users are more likely to have installed (LibreOffice is very niche in this sector).
Thanks.
You can use the docx2pdf tool to convert a docx file to pdf retaining all formatting. It works on macOS and Windows and requires Microsoft Word to be installed.
pip install docx2pdf
docx2pdf input.docx output.pdf
docx2pdf --help
If you don't want the python dependency, you can see the JXA (AppleScript for javascript) code that can be directly run on macOS with no dependencies. It also uses win32com on windows to directly talk to Microsoft Word.
Disclaimer: I wrote the docx2pdf to pdf tool. https://github.com/AlJohri/docx2pdf/
If you want to generate Microsoft word/excel/PowerPoint document dynamically .
Do check
https://www.npmjs.com/package/officegen
So gifify is a pretty awesome script that converts videos to gifs via command line: https://github.com/vvo/gifify
I'm keen to get this working on my Windows 10 machine. I'm pretty new to windows and relatively new to coding, but I was able to get a few things working, but ran into a problem.
Here is what I did:
Installed node.js + npm
Installed FFmpeg using npm
Installed ImageMagick using npm (i think i did this wrong, might have only installed the wrapper).
Downloaded giflossy. It needed to be built (?)
Installed Visual Studio 2015, tried to build it using nmake and got this error:
NMAKE : fatal error U1073: don't know how to make 'win32cfg.h'
The command I used was:
PS C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin> .\nmake -f "C:\Users\Robert's Workstation\.npm-global\node_modules\giflossy-lossy-1.82.1\src\Makefile.w32"
Would really appreciate some help with this :D
I think I f***ing did it!
I spent two hours wildly downloading binaries, googling like crazy and adding a quantum tonne of environment variables to the PATH, but I did it. Here's how:
ffmpeg: http://ffmpeg.zeranoe.com/builds/. Download the binaries, place them in your Programs folder (or anywhere), copy the path and add it to your PATH environment variable
Gifsickle with lossy. I tried to compile the source from GitHub, but both makefiles threw an error (I did not investigate that any further). Instead, I searched for an already compiled binary on the web (risky) and found: https://encode.ru/threads/2481-How-to-compile-giflossy. You need 7zip to extract the binaries, but once you've done this, place them in your Programs Folder, add the path to the binaries to your PATH environment variable and you're set.
ImageMagick with convert: https://www.imagemagick.org/script/download.php#windows
Make sure to check the following options:
This should add the ImageMagick binaries to the PATH env vars for you.
Battle any '[x] is not recognised as blah' errors with locating the binary and adding its path to the PATH env variable.
If there's only the source available and you have to compile it by yourself, search for compiled binaries online.
In my project, for example, I have this structure:
/public/js/src/ /* many jquery plugins there */
/public/css/src/ /* many css files there, that describe different things */
After changes have been made, I would like to type in command line something like:
root#hostname:/var/www/test/public# ./build
which would generate two files:
/public/css/build.css - all files from /public/css/src/ folder with minified source
/public/js/build.js - all files from /public/js/src folder with minified source
For the moment I am using less css, which is working on node. I would like to have one script that will do everything, for css as for javascript. Could you please advise the best way to "build" dev-source javascript & css files?
You can use YUI Compressor. I'm sure it's also available for Linux.
It works from the command line. Read here how it works.
Example:
java -jar yuicompressor-x.y.z.jar myfile.js -o myfile-min.js --charset utf-8
I'm sure you can setup a simple Bash script that executes two commands, one for CSS and one for JS by using parameters as input.
YUI-Compressor is available as a package in any Ubuntu version.
apt-get install yui-compressor
Hope it helps
You can use Apache ANT and YUI Compressor to set up your own build process. You can minify all your JS and CSS files with a single command.
EDIT: if you want a sample project try H5bp's ant build scripts http://html5boilerplate.com/
I know this is an old question, but for those getting here through Google. You can easily use Compass for this.
compass compile --output-style compressed --force
More info: http://compass-style.org/help/tutorials/production-css/
Use ACCSS for css compression, its compression rate is better than YUI-Compressors and its written in c with automake installation, so it is portable to almost every system.
Like above, you can use a shell script to combine less and accss. accss support reading from stdin, so you can combine them with
lessc styles.less | accss > out.css
It also has severeal compatibility options, especially for Internet Explorer.
https://github.com/acwtools/accss
I'm using NetBeans 6.5 and I have some javascript files that it claims are binary files and won't display annotations. svn propedit shows that the svn:mime-type is text/javascript and to display the annotations on the command line I have to run "svn annotate --force file.js".
from http://subversion.tigris.org/svn_1.4_releasenotes.html:
svn blame --force Displays the output
of blame, even if the file is binary.
It looks like this is not a NetBeans-specific problem, but something related to how svn handles Your .js files. It would be good to add a proper tag to this question.
from http://subversion.tigris.org/faq.html#binary-files:
Subversion just looks at the first
1024 bytes of the file; if any of the
bytes are zero, or if more than 15%
are not ASCII printing characters,
then Subversion calls the file binary.
(...) Subversion treats the following
files as text: (...) Files with a
svn:mime-type starting "text/"
If Your javascript file contains binary data, You might consider moving it to the end of the file.
There is a chance that the property is set to " text/javascript" or something that looks like text/javascript to human, but not to the svn.
There is a chance that the file used to be binary, but it's not anymore, however You have updated Your repository while not having write access to .svn/ directory (and svn still 'thinks' the file is binary).
There is a chance You have changed the property to the right one, but have not commited it yet.
Finally, the most powerfull solution to svn problems I have ever encountered was to copy the file, delete it the from svn, commit, add the file back (from the copy) and commit. Beware: You loose change history by doing so.
I wish You good luck on finding out what has caused this problem!
I am writing a batch script in order to beautify JavaScript code. It needs to work on both Windows and Linux.
How can I beautify JavaScript code using the command line tools?
First, pick your favorite Javascript based Pretty Print/Beautifier. I prefer the one at http://jsbeautifier.org/, because it's what I found first. Downloads its file https://github.com/beautify-web/js-beautify/blob/master/js/lib/beautify.js
Second, download and install The Mozilla group's Java based Javascript engine, Rhino. "Install" is a little bit misleading; Download the zip file, extract everything, place js.jar in your Java classpath (or Library/Java/Extensions on OS X). You can then run scripts with an invocation similar to this
java -cp js.jar org.mozilla.javascript.tools.shell.Main name-of-script.js
Use the Pretty Print/Beautifier from step 1 to write a small shell script that will read in your javascript file and run it through the Pretty Print/Beautifier from step one. For example
//original code
(function() { ... js_beautify code ... }());
//new code
print(global.js_beautify(readFile(arguments[0])));
Rhino gives javascript a few extra useful functions that don't necessarily make sense in a browser context, but do in a console context. The function print does what you'd expect, and prints out a string. The function readFile accepts a file path string as an argument and returns the contents of that file.
You'd invoke the above something like
java -cp js.jar org.mozilla.javascript.tools.shell.Main beautify.js file-to-pp.js
You can mix and match Java and Javascript in your Rhino run scripts, so if you know a little Java it shouldn't be too hard to get this running with text-streams as well.
UPDATE April 2014:
The beautifier has been rewritten since I answered this in 2010. There is now a python module in there, an npm Package for nodejs, and the jar file is gone. Please read the project page on github.com.
Python style:
$ pip install jsbeautifier
NPM style:
$ npm -g install js-beautify
to use it (this will return the beatified js file on the terminal, the main file remains unchanged):
$ js-beautify file.js
To make the changes take effect on the file, you should use this command:
$ js-beautify -r file.js
Original answer
Adding to Answer of #Alan Storm
the command line beautifier based on http://jsbeautifier.org/ has gotten a bit easier to use, because it is now (alternatively) based on the V8 javascript engine (c++ code) instead of rhino (java-based JS engine, packaged as "js.jar"). So you can use V8 instead of rhino.
How to use:
download jsbeautifier.org zip file from
http://github.com/einars/js-beautify/zipball/master
(this is a download URL linked to a zip file such as http://download.github.com/einars-js-beautify-10384df.zip)
old (no longer works, jar file is gone)
java -jar js.jar name-of-script.js
new (alternative)
install/compile v8 lib FROM svn, see v8/README.txt in above-mentioned zip file
./jsbeautify somefile.js
-has slightly different command line options than the rhino version,
-and works great in Eclipse when configured as an "External Tool"
If you're using nodejs then try uglify-js
On Linux or Mac, assuming you already have nodejs installed, you can install uglify with:
sudo npm install -g uglify-js
And then get the options:
uglifyjs -h
So if I have a source file foo.js which looks like this:
// foo.js -- minified
function foo(bar,baz){console.log("something something");return true;}
I can beautify it like so:
uglifyjs foo.js --beautify --output cutefoo.js
uglify uses spaces for indentation by default so if I want to convert the 4-space-indentation to tabs I can run it through unexpand which Ubuntu 12.04 comes with:
unexpand --tabs=4 cutefoo.js > cuterfoo.js
Or you can do it all in one go:
uglifyjs foo.js --beautify | unexpand --tabs=4 > cutestfoo.js
You can find out more about unexpand here
so after all this I wind up with a file that looks like so:
function foo(bar, baz) {
console.log("something something");
return true;
}
update 2016-06-07
It appears that the maintainer of uglify-js is now working on version 2 though installation is the same.
On Ubuntu LTS
$ sudo apt install jsbeautifier
$ js-beautify ugly.js > beautiful.js
For in place beautifying, any of the follwing commands:
$ js-beautify -r file.js
$ js-beautify --replace file.js
You have a few one liner choices. Use with npm or standalone with npx.
Semistandar
npx semistandard "js/**/*.js" --fix
Standard
npx standard "js/**/*.js" --fix
Prettier
npx prettier --single-quote --write --trailing-comma all "js/**/*.js"
In the console, you can use Artistic Style (a.k.a. AStyle) with --mode=java.
It works great and it's free, open-source and cross-platform (Linux, Mac OS X, Windows).
Use the modern JavaScript way:
Use Grunt in combination with the jsbeautifier plugin for Grunt
You can install everything easily into your dev environment using npm.
All you will need is set up a Gruntfile.js with the appropriate tasks, which can also involve file concatenation, lint, uglify, minify etc, and run the grunt command.
I'm not able to add a comment to the accepted answer so that's why you see a post that should have not existed in the first place.
Basically I also needed a javascript beautifier in a java code and to my surprise none is available as far as I could find. So I coded one myself entirely based on the accepted answer (it wraps the jsbeautifier.org beautifier .js script but is callable from java or the command line).
The code is located at https://github.com/belgampaul/JsBeautifier
I used rhino and beautifier.js
USAGE from console: java -jar jsbeautifier.jar script indentation
example: java -jar jsbeautifier.jar "function ff() {return;}" 2
USAGE from java code:
public static String jsBeautify(String jsCode, int indentSize)
You are welcome to extend the code. In my case I only needed the indentation so I could check the generated javascript while developing.
In the hope it'll save you some time in your project.
I've written an article explaining how to build a command-line JavaScript beautifier implemented in JavaScript in under 5 minutes. YMMV.
Download the latest stable Rhino and unpack it somewhere, e.g. ~/dev/javascript/rhino
Download beautify.js which is referenced from aforementioned jsbeautifier.org then copy it somewhere, e.g. ~/dev/javascript/bin/cli-beautifier.js
Add this at the end of beautify.js (using some additional top-level properties to JavaScript):
// Run the beautifier on the file passed as the first argument.
print( j23s_beautify( readFile( arguments[0] )));
Copy-paste the following code in an executable file, e.g. ~/dev/javascript/bin/jsbeautifier.sh:
#!/bin/sh
java -cp ~/dev/javascript/rhino/js.jar org.mozilla.javascript.tools.shell.Main ~/dev/web/javascript/bin/cli-beautifier.js $*
(optional) Add the folder with jsbeautifier.js to PATH or moving to some folder already there.
I believe when you asked about command line tool you just wanted to beautify all your js files in batch.
In this case Intellij IDEA (tested with 11.5) can do this.
You just need to select any of your project files and select "Code"->"Reformat code.." in main IDE menu. Then in the dialog select "all files in directory ..." and press "enter".
Just make sure you dedicated enough memory for the JVM.