mirror of
https://github.com/beautifier/js-beautify.git
synced 2024-11-27 14:40:23 +00:00
In the event output is destined for a recognized file type that differs from the configured type, do the right thing. closes #2 (for real)
This commit is contained in:
parent
21cb51b2b3
commit
3a1abe2fec
10
cli.js
10
cli.js
@ -205,7 +205,8 @@ function processInputSync(filepath) {
|
||||
|
||||
function makePretty(code, config, outfile, callback) {
|
||||
try {
|
||||
var pretty = beautify[config.type](code, config);
|
||||
var fileType = getOutputType(outfile, config.type);
|
||||
var pretty = beautify[fileType](code, config);
|
||||
|
||||
// ensure newline at end of beautified output
|
||||
pretty += '\n';
|
||||
@ -276,6 +277,13 @@ function dasherizeShorthands(hash) {
|
||||
return hash;
|
||||
}
|
||||
|
||||
function getOutputType(outfile, configType) {
|
||||
if (outfile && /\.(js|css|html)$/.test(outfile)) {
|
||||
return outfile.split('.').pop();
|
||||
}
|
||||
return configType;
|
||||
}
|
||||
|
||||
function getScriptName() {
|
||||
return path.basename(process.argv[1]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user