1
1
var fs = require ( 'fs' ) ;
2
+ var path = require ( 'path' ) ;
2
3
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 || [ ] ;
5
5
var sourceRoot = global . opts . core . common . pathToUser ;
6
- var INFO_FILE = "info.json" ;
6
+ var infoFile = "info.json" ;
7
7
8
8
// configuration for function timeout
9
9
var CRON = global . opts . core . fileTree . cron ;
@@ -14,14 +14,14 @@ var specDependenciesTree = function(dir) {
14
14
var outputJSON = { } ,
15
15
specsDirs = { } ;
16
16
17
- specDepsIncludedDirs . forEach ( function ( includedDir ) {
17
+ includedDirs . forEach ( function ( includedDir ) {
18
18
specsDirs = fs . readdirSync ( dir + '/' + includedDir ) ;
19
19
20
20
specsDirs . forEach ( function ( specDir ) {
21
21
var pathToInfo = dir + '/' + includedDir + '/' + specDir ;
22
22
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" ) ) ;
25
25
26
26
if ( fileJSON [ 'usedSpecs' ] ) {
27
27
fileJSON [ 'usedSpecs' ] . forEach ( function ( usedSpec ) {
@@ -37,11 +37,18 @@ var specDependenciesTree = function(dir) {
37
37
} ;
38
38
39
39
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 ) {
41
48
if ( err ) {
42
- console . log ( err ) ;
49
+ console . log ( 'Error writing file tree of dependecies: ' , err ) ;
43
50
} 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 ) ;
45
52
}
46
53
} ) ;
47
54
} ;
@@ -51,6 +58,6 @@ SpecDependenciesWrite();
51
58
// setcron
52
59
if ( CRON || ( global . MODE === 'production' && CRON_PROD ) ) {
53
60
setInterval ( function ( ) {
54
- GlobalWrite ( ) ;
61
+ SpecDependenciesWrite ( ) ;
55
62
} , CRON_REPEAT_TIME ) ;
56
63
}
0 commit comments