11var fs = require ( 'fs' ) ;
2+ var deepExtend = require ( 'deep-extend' ) ;
23var path = require ( 'path' ) ;
34
4- var includedDirs = global . opts . core . specDependenciesTree . includedDirs || [ ] ;
5- var sourceRoot = global . opts . core . common . pathToUser ;
6- var infoFile = "info.json" ;
5+ var config = {
6+ includedDirs : [ ] ,
7+ outputFile : "data/spec_dependencies_tree.json" ,
8+
9+ // cron
10+ cron : false ,
11+ cronProd : true ,
12+ cronRepeatTime : 60000 ,
13+
14+ // file from parser get info
15+ infoFile : "info.json" ,
16+ sourceRoot : global . opts . core . common . pathToUser
17+ } ;
18+ // Overwriting base options
19+ deepExtend ( config , global . opts . core . specDependenciesTree ) ;
720
8- // configuration for function timeout
9- var CRON = global . opts . core . fileTree . cron ;
10- var CRON_PROD = global . opts . core . fileTree . cronProd ;
11- var CRON_REPEAT_TIME = global . opts . core . fileTree . cronRepeatTime ;
1221
1322var specDependenciesTree = function ( dir ) {
1423 var outputJSON = { } ,
1524 specsDirs = { } ;
1625
17- includedDirs . forEach ( function ( includedDir ) {
26+ config . includedDirs . forEach ( function ( includedDir ) {
1827 specsDirs = fs . readdirSync ( dir + '/' + includedDir ) ;
1928
2029 specsDirs . forEach ( function ( specDir ) {
2130 var pathToInfo = dir + '/' + includedDir + '/' + specDir ;
2231
23- if ( fs . existsSync ( pathToInfo + '/' + infoFile ) ) {
24- var fileJSON = JSON . parse ( fs . readFileSync ( pathToInfo + '/' + infoFile , "utf8" ) ) ;
32+ if ( fs . existsSync ( pathToInfo + '/' + config . infoFile ) ) {
33+ var fileJSON = JSON . parse ( fs . readFileSync ( pathToInfo + '/' + config . infoFile , "utf8" ) ) ;
2534
2635 if ( fileJSON [ 'usedSpecs' ] ) {
2736 fileJSON [ 'usedSpecs' ] . forEach ( function ( usedSpec ) {
@@ -37,14 +46,14 @@ var specDependenciesTree = function(dir) {
3746} ;
3847
3948var SpecDependenciesWrite = function ( ) {
40- var outputFile = global . app . get ( 'user' ) + "/" + global . opts . core . specDependenciesTree . outputFile ;
49+ var outputFile = global . app . get ( 'user' ) + "/" + config . outputFile ;
4150 var outputPath = path . dirname ( outputFile ) ;
4251
4352 if ( ! fs . existsSync ( outputPath ) ) {
4453 fs . mkdirSync ( outputPath ) ;
4554 }
4655
47- fs . writeFile ( outputFile , JSON . stringify ( specDependenciesTree ( sourceRoot ) , null , 4 ) , function ( err ) {
56+ fs . writeFile ( outputFile , JSON . stringify ( specDependenciesTree ( config . sourceRoot ) , null , 4 ) , function ( err ) {
4857 if ( err ) {
4958 console . log ( 'Error writing file tree of dependecies: ' , err ) ;
5059 } else {
@@ -55,9 +64,9 @@ var SpecDependenciesWrite = function() {
5564
5665SpecDependenciesWrite ( ) ;
5766
58- // setcron
59- if ( CRON || ( global . MODE === 'production' && CRON_PROD ) ) {
60- setInterval ( function ( ) {
61- SpecDependenciesWrite ( ) ;
62- } , CRON_REPEAT_TIME ) ;
67+ // Running by cron
68+ if ( config . cron || ( global . MODE === 'production' && config . cronProd ) ) {
69+ setInterval ( function ( ) {
70+ writeDataFile ( ) ;
71+ } , config . cronRepeatTime ) ;
6372}
0 commit comments