File tree 3 files changed +57
-14
lines changed
3 files changed +57
-14
lines changed Original file line number Diff line number Diff line change @@ -6,21 +6,24 @@ import Directory from '../entities/directory';
6
6
import repository from '../process/repository' ;
7
7
import isAllowed from '../utils/is-allowed' ;
8
8
import isInput from '../utils/is-input' ;
9
+ import getTrackedExtensions from '../utils/get-tracked-extensions' ;
9
10
10
11
function isAllowedChanges ( directories , file ) {
11
12
return directories
12
13
. every ( dir => isAllowed ( file ) && isInput ( dir , file ) ) ;
13
14
}
14
15
16
+ const trackedExtensions = getTrackedExtensions ( ) ;
17
+
15
18
function createPattern ( directories ) {
16
19
return directories . reduce ( ( acc , dir ) => {
17
20
const directory = new Directory ( dir ) ;
18
21
const directoryConfigs = directory . getConfigs ( ) ;
19
22
20
23
directoryConfigs . forEach ( ( currentConfig ) => {
21
- acc . push ( slash ( path . resolve ( currentConfig . context , '**/*.js' ) ) ) ;
22
- acc . push ( slash ( path . resolve ( currentConfig . context , ' **/*.css' ) ) ) ;
23
- acc . push ( slash ( path . resolve ( currentConfig . context , '**/*.scss' ) ) ) ;
24
+ trackedExtensions . forEach ( ( extName ) => {
25
+ acc . push ( slash ( path . resolve ( currentConfig . context , ` **/*${ extName } ` ) ) ) ;
26
+ } ) ;
24
27
} ) ;
25
28
26
29
return acc ;
Original file line number Diff line number Diff line change
1
+ import argv from '../process/argv' ;
2
+
3
+ const defaultExtensions = [
4
+ '.js' ,
5
+ '.jsx' ,
6
+ '.vue' ,
7
+ '.css' ,
8
+ '.scss' ,
9
+ ] ;
10
+
11
+ export default function getTrackedExtensions ( ) : Array < string >
12
+ {
13
+ if ( typeof argv . watch === 'string' && argv . watch . length > 0 )
14
+ {
15
+ return argv . watch
16
+ . split ( ',' )
17
+ . map ( ( extName ) => {
18
+ return String ( extName ) . trim ( ) ;
19
+ } )
20
+ . reduce ( ( acc , extName ) => {
21
+ if ( typeof extName === 'string' && extName . length > 0 )
22
+ {
23
+ if ( extName === 'defaults' )
24
+ {
25
+ return [ ...acc , ...defaultExtensions ] ;
26
+ }
27
+
28
+ const preparedName = ( ( ) => {
29
+ if ( ! extName . startsWith ( '.' ) )
30
+ {
31
+ return `.${ extName } ` ;
32
+ }
33
+
34
+ return extName ;
35
+ } ) ( ) ;
36
+
37
+ if ( ! acc . includes ( preparedName ) )
38
+ {
39
+ acc . push ( preparedName ) ;
40
+ }
41
+ }
42
+
43
+ return acc ;
44
+ } , [ ] ) ;
45
+ }
46
+
47
+ return [ ...defaultExtensions ] ;
48
+ }
Original file line number Diff line number Diff line change 1
1
import slash from 'slash' ;
2
2
import path from 'path' ;
3
+ import getTrackedExtensions from './get-tracked-extensions' ;
3
4
4
5
export default function isAllowed ( fileName ) {
5
6
if ( typeof fileName !== 'string' ) {
@@ -18,15 +19,6 @@ export default function isAllowed(fileName) {
18
19
return false ;
19
20
}
20
21
21
- const ext = path . extname ( normalizedFileName ) ;
22
-
23
- switch ( ext ) {
24
- case '.js' :
25
- case '.jsx' :
26
- case '.css' :
27
- case '.scss' :
28
- return true ;
29
- default :
30
- return false ;
31
- }
22
+ return getTrackedExtensions ( )
23
+ . includes ( path . extname ( normalizedFileName ) ) ;
32
24
}
You can’t perform that action at this time.
0 commit comments