commit
5cb5148876
|
@ -12,10 +12,10 @@ const argv = minimist(process.argv.slice(2), {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const filename = argv["_"][0];
|
const filenames = argv["_"];
|
||||||
const write = argv['write'];
|
const write = argv["write"];
|
||||||
|
|
||||||
if(!filename || !filename.match(/\S/)) {
|
if (!filenames.length) {
|
||||||
console.log(
|
console.log(
|
||||||
"Usage: prettier [opts] [filename]\n\n" +
|
"Usage: prettier [opts] [filename]\n\n" +
|
||||||
"Available options:\n" +
|
"Available options:\n" +
|
||||||
|
@ -30,27 +30,34 @@ if(!filename || !filename.match(/\S/)) {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let input;
|
filenames.forEach(filename => {
|
||||||
try {
|
fs.readFile(filename, "utf8", (err, input) => {
|
||||||
input = fs.readFileSync(filename, "utf8")
|
if (err) {
|
||||||
}
|
console.error("Unable to read file: " + filename + "\n" + err);
|
||||||
catch(e) {
|
// Don't exit the process if one file failed
|
||||||
console.log("Unable to read file: " + filename);
|
process.exitCode = 2;
|
||||||
process.exit(2);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const output = jscodefmt.format(input, {
|
const output = jscodefmt.format(input, {
|
||||||
printWidth: argv['print-width'],
|
printWidth: argv["print-width"],
|
||||||
tabWidth: argv['tab-width'],
|
tabWidth: argv["tab-width"],
|
||||||
bracketSpacing: argv['bracket-spacing'],
|
bracketSpacing: argv["bracket-spacing"],
|
||||||
useFlowParser: argv['flow-parser'],
|
useFlowParser: argv["flow-parser"],
|
||||||
singleQuote: argv["single-quote"],
|
singleQuote: argv["single-quote"],
|
||||||
trailingComma: argv["trailing-comma"]
|
trailingComma: argv["trailing-comma"]
|
||||||
});
|
});
|
||||||
|
|
||||||
if (write) {
|
if (write) {
|
||||||
fs.writeFileSync(filename, output, "utf8");
|
fs.writeFile(filename, output, "utf8", err => {
|
||||||
|
if (err) {
|
||||||
|
console.error("Unable to write file: " + filename + "\n" + err);
|
||||||
|
// Don't exit the process if one file failed
|
||||||
|
process.exitCode = 2;
|
||||||
}
|
}
|
||||||
else {
|
});
|
||||||
|
} else {
|
||||||
console.log(output);
|
console.log(output);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -2,7 +2,7 @@
|
||||||
"name": "prettier",
|
"name": "prettier",
|
||||||
"version": "0.0.3",
|
"version": "0.0.3",
|
||||||
"bin": {
|
"bin": {
|
||||||
"prettier": "./bin/prettier"
|
"prettier": "./bin/prettier.js"
|
||||||
},
|
},
|
||||||
"main": "./index.js",
|
"main": "./index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -19,7 +19,9 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"format": "./bin/prettier --write src/printer.js"
|
"format": "./bin/prettier.js --write",
|
||||||
|
"format:single": "npm run format -- src/printer.js",
|
||||||
|
"format:all": "npm run format -- src/*.js bin/*.js"
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
"setupFiles": [
|
"setupFiles": [
|
||||||
|
|
Loading…
Reference in New Issue