@@ -7,6 +7,10 @@ var extract = require('../extract');
7
7
var command = require ( './command' ) ;
8
8
var chalk = require ( 'chalk' ) ;
9
9
var isChildProcess = typeof process . send == 'function' ; // child process has send method
10
+ var collectUsed = {
11
+ files : require ( './collectUsed/files' ) ,
12
+ l10n : require ( './collectUsed/l10n' )
13
+ } ;
10
14
11
15
if ( isChildProcess )
12
16
process . on ( 'uncaughtException' , function ( error ) {
@@ -91,69 +95,10 @@ function lint(config){
91
95
l10nInfo : true
92
96
} ) . concat ( [
93
97
function ( flow ) {
94
- function isTarget ( basePath , collectPath , file ) {
95
- return file . filename && ( basePath + file . filename ) . indexOf ( collectPath + '/' ) === 0 ;
96
- }
97
-
98
98
if ( options . warnUnusedFiles )
99
- {
100
- var basePath = flow . options . base ;
101
- var collectPath = flow . files . abspath ( basePath , options . warnUnusedFiles ) ;
102
- var stack = [ flow . files . queue [ 0 ] ] ;
103
- var usedFiles = { } ;
104
- var handled = { } ;
105
- var cursor ;
106
-
107
- while ( cursor = stack . pop ( ) )
108
- {
109
- // mark file as handled
110
- handled [ cursor . uniqueId ] = true ;
111
-
112
- if ( isTarget ( basePath , collectPath , cursor ) )
113
- usedFiles [ cursor . filename ] = true ;
114
-
115
- if ( cursor . type == 'template' )
116
- {
117
- if ( cursor . decl . deps )
118
- {
119
- cursor . decl . deps . forEach ( function ( resource ) {
120
- if ( ! resource . virtual && isTarget ( basePath , collectPath , { filename : resource . url } ) )
121
- usedFiles [ resource . url ] = true ;
122
- } ) ;
123
- }
124
- if ( cursor . decl . l10n )
125
- {
126
- cursor . decl . l10n . forEach ( function ( item ) {
127
- var l10nInfo = item . split ( '@' ) ;
128
- var dictFilename = l10nInfo [ 1 ] || l10nInfo [ 0 ] ;
129
-
130
- if ( isTarget ( basePath , collectPath , { filename : dictFilename } ) )
131
- usedFiles [ dictFilename ] = true ;
132
- } ) ;
133
- }
134
- if ( cursor . decl . styles )
135
- {
136
- cursor . decl . styles . forEach ( function ( style ) {
137
- if ( ! style . resource && isTarget ( basePath , collectPath , { filename : style . sourceUrl } ) )
138
- usedFiles [ style . sourceUrl ] = true ;
139
- } ) ;
140
- }
141
- }
142
-
143
- cursor . linkTo . forEach ( function ( link ) {
144
- // prevent to handling files that already handled
145
- if ( link [ 0 ] && ! handled [ link [ 0 ] . uniqueId ] ) {
146
- stack . push ( link [ 0 ] ) ;
147
- }
148
- } ) ;
149
- }
150
-
151
- flow . usedFiles = {
152
- basePath : basePath ,
153
- collectPath : collectPath ,
154
- items : Object . keys ( usedFiles )
155
- } ;
156
- }
99
+ collectUsed . files ( flow ) ;
100
+ if ( options . warnUnusedL10n )
101
+ collectUsed . l10n ( flow ) ;
157
102
} ,
158
103
function ( flow ) {
159
104
flow . result = require ( './reporter/process-warns' ) ( flow , options ) ;
@@ -214,6 +159,7 @@ function lint(config){
214
159
success : ! flow . warns . length ,
215
160
warnings : flow . warns ,
216
161
usedFiles : flow . usedFiles ,
162
+ usedL10nTokens : flow . usedL10nTokens ,
217
163
result : flow . result
218
164
} ) ;
219
165
} ) ;
0 commit comments