Skip to content

Commit 16bdc38

Browse files
committed
Fix core logic for version 0.4.0 of source.
1 parent e79652e commit 16bdc38

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

core/index.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
var fs = require('fs');
2+
var path = require('path');
23

3-
var OUTPUT_SPEC_DEPENDENCIES_FILE = global.opts.core.specDependenciesTree.outputFile || 'data/spec_dependencies_tree.json';
4-
var specDepsIncludedDirs = global.opts.core.specDependenciesTree.includedDirs || [];
4+
var includedDirs = global.opts.core.specDependenciesTree.includedDirs || [];
55
var sourceRoot = global.opts.core.common.pathToUser;
6-
var INFO_FILE = "info.json";
6+
var infoFile = "info.json";
77

88
// configuration for function timeout
99
var CRON = global.opts.core.fileTree.cron;
@@ -14,14 +14,14 @@ var specDependenciesTree = function(dir) {
1414
var outputJSON = {},
1515
specsDirs = {};
1616

17-
specDepsIncludedDirs.forEach(function(includedDir) {
17+
includedDirs.forEach(function(includedDir) {
1818
specsDirs = fs.readdirSync(dir + '/' + includedDir);
1919

2020
specsDirs.forEach(function(specDir) {
2121
var pathToInfo = dir + '/' + includedDir + '/' + specDir;
2222

23-
if (fs.existsSync(pathToInfo + '/' + INFO_FILE)) {
24-
var fileJSON = JSON.parse(fs.readFileSync(pathToInfo + '/' + INFO_FILE, "utf8"));
23+
if (fs.existsSync(pathToInfo + '/' + infoFile)) {
24+
var fileJSON = JSON.parse(fs.readFileSync(pathToInfo + '/' + infoFile, "utf8"));
2525

2626
if (fileJSON['usedSpecs']) {
2727
fileJSON['usedSpecs'].forEach(function(usedSpec){
@@ -37,11 +37,18 @@ var specDependenciesTree = function(dir) {
3737
};
3838

3939
var SpecDependenciesWrite = function() {
40-
fs.writeFile(global.app.get('user') + "/" + OUTPUT_SPEC_DEPENDENCIES_FILE, JSON.stringify(specDependenciesTree(sourceRoot), null, 4), function (err) {
40+
var outputFile = global.app.get('user') + "/" + global.opts.core.specDependenciesTree.outputFile;
41+
var outputPath = path.dirname(outputFile);
42+
43+
if (!fs.existsSync(outputPath)) {
44+
fs.mkdirSync(outputPath);
45+
}
46+
47+
fs.writeFile(outputFile, JSON.stringify(specDependenciesTree(sourceRoot), null, 4), function (err) {
4148
if (err) {
42-
console.log(err);
49+
console.log('Error writing file tree of dependecies: ', err);
4350
} else {
44-
console.log("Spec dependencies JSON saved to " + global.opts.core.common.pathToUser+"/"+OUTPUT_SPEC_DEPENDENCIES_FILE);
51+
console.log("Spec dependencies JSON saved to " + outputFile);
4552
}
4653
});
4754
};
@@ -51,6 +58,6 @@ SpecDependenciesWrite();
5158
// setcron
5259
if (CRON || (global.MODE === 'production' && CRON_PROD)) {
5360
setInterval(function(){
54-
GlobalWrite();
61+
SpecDependenciesWrite();
5562
}, CRON_REPEAT_TIME);
5663
}

0 commit comments

Comments
 (0)