Skip to content

Commit 972d4cd

Browse files
committedDec 17, 2017
use prettier at migrate
1 parent 88aaaa2 commit 972d4cd

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
 

‎lib/commands/migrate.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const inquirer = require("inquirer");
77
const PLazy = require("p-lazy");
88
const Listr = require("listr");
99

10+
const runPrettier = require("../utils/run-prettier");
11+
1012
module.exports = function transformFile(
1113
currentConfigPath,
1214
outputConfigPath,
@@ -78,7 +80,7 @@ module.exports = function transformFile(
7880
])
7981
.then(answers => {
8082
if (answers["confirmMigration"]) {
81-
fs.writeFile(outputConfigPath, result, "utf8", err => {
83+
runPrettier(outputConfigPath, result, err => {
8284
if (err) {
8385
throw err;
8486
} else {

‎lib/utils/run-prettier.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ const chalk = require("chalk");
1313
* @returns fs - Writes a file at given location and prints messages accordingly
1414
*/
1515

16-
module.exports = function runPrettier(outputPath, source) {
16+
module.exports = function runPrettier(outputPath, source, cb) {
1717
function validateConfig() {
1818
let prettySource;
19+
let error;
1920
try {
2021
prettySource = prettier.format(source, {
2122
singleQuote: true,
@@ -31,6 +32,10 @@ module.exports = function runPrettier(outputPath, source) {
3132
)
3233
);
3334
prettySource = source;
35+
error = err;
36+
}
37+
if (cb) {
38+
return cb(error);
3439
}
3540
return fs.writeFileSync(outputPath, prettySource, "utf8");
3641
}

0 commit comments

Comments
 (0)
Please sign in to comment.