Created
August 20, 2019 17:25
-
-
Save ethangardner/d12c7eed37d8918d7f9ef975e03ba61e to your computer and use it in GitHub Desktop.
Komodo userscript to format files with prettier.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var view = require("ko/views").current(); | |
var shell = require("ko/shell"); | |
var filename = view.title; | |
var filePath = view.filePath; | |
var types = [ | |
'scss', | |
'js', | |
'jsx' | |
]; | |
var pieces = filename.split("."); | |
if ( | |
pieces.length >= 2 && | |
pieces[pieces.length - 2] !== "min" && | |
types.indexOf(pieces[pieces.length - 1]) !== -1 | |
) { | |
shell.exec(`prettier ${filePath} --write`, {}, function(err, data) { | |
if (err) { | |
console.log(err.message); | |
} else { | |
console.log(data); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment