Skip to content

Instantly share code, notes, and snippets.

@jackysee
Created August 10, 2017 02:14
Show Gist options
  • Save jackysee/0238e1a0a2afe71ccd223ad16f77a0d5 to your computer and use it in GitHub Desktop.
Save jackysee/0238e1a0a2afe71ccd223ad16f77a0d5 to your computer and use it in GitHub Desktop.
Run prettier on vue file
const prettier = require('prettier');
const options = require('./package.json').prettier || {};
const fs = require('fs');
const parser = require('html-script-hook');
const file = process.argv[2];
const source = fs.readFileSync(file, 'utf8');
const result = parser(source, {
scriptCallback: function(code) {
return `\n\n${prettier.format(code, options)}\n`;
},
padLineNo: true
});
fs.writeFileSync(file, result, { encoding: 'utf8' });
console.log(`run prettier on ${file}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment