Skip to content

Instantly share code, notes, and snippets.

@ethangardner
Created August 20, 2019 17:25
Show Gist options
  • Save ethangardner/d12c7eed37d8918d7f9ef975e03ba61e to your computer and use it in GitHub Desktop.
Save ethangardner/d12c7eed37d8918d7f9ef975e03ba61e to your computer and use it in GitHub Desktop.
Komodo userscript to format files with prettier.
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