Created
August 10, 2017 02:14
-
-
Save jackysee/0238e1a0a2afe71ccd223ad16f77a0d5 to your computer and use it in GitHub Desktop.
Run prettier on vue file
This file contains hidden or 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
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