Skip to content

Commit 144b8b7

Browse files
committed
Use synchronous functions to build files
1 parent 3a902f7 commit 144b8b7

1 file changed

Lines changed: 11 additions & 22 deletions

File tree

src/abe-json-builder.js

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ var colors = require('colours'),
1616

1717
exports.jsonBuilder = function (options, callback) {
1818
lodash.merge(opt, options);
19+
var folderPath = path.join(process.cwd(), opt.build);
20+
21+
if (!fs.existsSync(folderPath)) {
22+
mkdirp.sync(folderPath);
23+
}
1924

2025
glob
2126
.sync(opt.location + '.json', {
2227
mark: true
2328
})
2429
.forEach(function (match) {
25-
var json = require(process.cwd() + '/' + match);
30+
var json = require(path.join(process.cwd(), match));
2631

2732
// Check that the JSON passed to the function has examples / matches
2833
// ABE Spec
@@ -31,34 +36,18 @@ exports.jsonBuilder = function (options, callback) {
3136
}
3237

3338
var folderArr = path.dirname(match).split('/'),
34-
filePath = process.cwd() + '/' + opt.build,
3539
buildName = folderArr[folderArr.length - 1] + '-',
3640
baseName = path.basename(match, '.json');
3741

38-
if (!fs.existsSync(filePath)) {
39-
mkdirp(filePath, function (err) {
40-
if (err) {
41-
console.log(err);
42-
} else if (opt.verbose) {
43-
console.log(opt.build.yellow, ' created.');
44-
}
45-
});
46-
}
47-
4842
// Loop through each example within the JSON to create it's own
4943
// JSON file
5044
lodash.forEach(json.examples, function (obj, key) {
51-
var bodyData = json.examples[key].response.body,
52-
fileData = JSON.stringify(bodyData, null, 4),
53-
file = buildName + baseName + '-' + key + '.json';
45+
var data = JSON.stringify(json
46+
.examples[key].response.body, null, 4)
47+
file = buildName + baseName + '-' + key + '.json',
48+
filePath = path.join(folderPath, file);
5449

55-
fs.writeFile(filePath + file, fileData, function (err) {
56-
if (err) {
57-
console.log(err);
58-
} else if (opt.verbose) {
59-
console.log(file.green, ' file was saved.');
60-
}
61-
});
50+
fs.writeFileSync(filePath, data);
6251
});
6352

6453
});

0 commit comments

Comments
 (0)