1
+ var fs = require ( 'fs' ) ;
2
+
3
+ var OUTPUT_SPEC_DEPENDENCIES_FILE = global . opts . core . specDependenciesTree . outputFile || 'data/spec_dependencies_tree.json' ;
4
+ var specDepsIncludedDirs = global . opts . core . specDependenciesTree . includedDirs || [ ] ;
5
+ var sourceRoot = global . opts . core . common . pathToUser ;
6
+ var INFO_FILE = "info.json" ;
7
+
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 ;
12
+
13
+ var specDependenciesTree = function ( dir ) {
14
+ var outputJSON = { } ,
15
+ specsDirs = { } ;
16
+
17
+ specDepsIncludedDirs . forEach ( function ( includedDir ) {
18
+ specsDirs = fs . readdirSync ( dir + '/' + includedDir ) ;
19
+
20
+ specsDirs . forEach ( function ( specDir ) {
21
+ var pathToInfo = dir + '/' + includedDir + '/' + specDir ;
22
+
23
+ if ( fs . existsSync ( pathToInfo + '/' + INFO_FILE ) ) {
24
+ var fileJSON = JSON . parse ( fs . readFileSync ( pathToInfo + '/' + INFO_FILE , "utf8" ) ) ;
25
+
26
+ if ( fileJSON [ 'usedSpecs' ] ) {
27
+ fileJSON [ 'usedSpecs' ] . forEach ( function ( usedSpec ) {
28
+ outputJSON [ usedSpec ] = outputJSON [ usedSpec ] || [ ] ;
29
+ outputJSON [ usedSpec ] . push ( '/' + includedDir + '/' + specDir ) ;
30
+ } ) ;
31
+ }
32
+ }
33
+ } ) ;
34
+ } ) ;
35
+
36
+ return outputJSON ;
37
+ } ;
38
+
39
+ var SpecDependenciesWrite = function ( ) {
40
+ fs . writeFile ( global . app . get ( 'user' ) + "/" + OUTPUT_SPEC_DEPENDENCIES_FILE , JSON . stringify ( specDependenciesTree ( sourceRoot ) , null , 4 ) , function ( err ) {
41
+ if ( err ) {
42
+ console . log ( err ) ;
43
+ } else {
44
+ console . log ( "Spec dependencies JSON saved to " + global . opts . core . common . pathToUser + "/" + OUTPUT_SPEC_DEPENDENCIES_FILE ) ;
45
+ }
46
+ } ) ;
47
+ } ;
48
+
49
+ SpecDependenciesWrite ( ) ;
50
+
51
+ // setcron
52
+ if ( CRON || ( global . MODE === 'production' && CRON_PROD ) ) {
53
+ setInterval ( function ( ) {
54
+ GlobalWrite ( ) ;
55
+ } , CRON_REPEAT_TIME ) ;
56
+ }
0 commit comments