@@ -7,6 +7,7 @@ var glob = require('glob');
7
7
8
8
var constants = require ( './util/constants' ) ;
9
9
10
+ updateHeadersInSrcFiles ( ) ;
10
11
11
12
// add headers to dist files
12
13
@@ -30,61 +31,61 @@ function headerLicense(path) {
30
31
} ) ;
31
32
}
32
33
34
+ // add or update header to src/ lib/ files
35
+ function updateHeadersInSrcFiles ( ) {
36
+ var srcGlob = path . join ( constants . pathToSrc , '**/*.js' ) ;
37
+ var libGlob = path . join ( constants . pathToLib , '**/*.js' ) ;
33
38
pathsDist . forEach ( headerLicense ) ;
34
39
40
+ // remove leading '/*' and trailing '*/' for comparison with falafel output
41
+ var licenseSrc = constants . licenseSrc ;
42
+ var licenseStr = licenseSrc . substring ( 2 , licenseSrc . length - 2 ) ;
35
43
36
- // add or update header to src files
44
+ glob ( '{' + srcGlob + ',' + libGlob + '}' , function ( err , files ) {
45
+ files . forEach ( function ( file ) {
46
+ fs . readFile ( file , 'utf-8' , function ( err , code ) {
37
47
38
- // remove leading '/*' and trailing '*/' for comparison with falafel output
39
- var licenseSrc = constants . licenseSrc ;
40
- var licenseStr = licenseSrc . substring ( 2 , licenseSrc . length - 2 ) ;
48
+ // parse through code string while keeping track of comments
49
+ var comments = [ ] ;
50
+ falafel ( code , { onComment : comments , locations : true } , function ( ) { } ) ;
41
51
42
- var srcGlob = path . join ( constants . pathToSrc , '**/*.js' ) ;
43
- var libGlob = path . join ( constants . pathToLib , '**/*.js' ) ;
44
- glob ( '{' + srcGlob + ',' + libGlob + '}' , function ( err , files ) {
45
- files . forEach ( function ( file ) {
46
- fs . readFile ( file , 'utf-8' , function ( err , code ) {
52
+ var header = comments [ 0 ] ;
47
53
48
- // parse through code string while keeping track of comments
49
- var comments = [ ] ;
50
- falafel ( code , { onComment : comments , locations : true } , function ( ) { } ) ;
54
+ // error out if no header is found
55
+ if ( ! header || header . loc . start . line > 1 ) {
56
+ throw new Error ( file + ' : has no header information.' ) ;
57
+ }
51
58
52
- var header = comments [ 0 ] ;
59
+ // if header and license are the same, do nothing
60
+ if ( isCorrect ( header ) ) return ;
53
61
54
- // error out if no header is found
55
- if ( ! header || header . loc . start . line > 1 ) {
56
- throw new Error ( file + ' : has no header information.' ) ;
57
- }
62
+ // if header and license only differ by date, update header
63
+ else if ( hasWrongDate ( header ) ) {
64
+ var codeLines = code . split ( '\n' ) ;
58
65
59
- // if header and license are the same, do nothing
60
- if ( isCorrect ( header ) ) return ;
66
+ codeLines . splice ( header . loc . start . line - 1 , header . loc . end . line ) ;
61
67
62
- // if header and license only differ by date, update header
63
- else if ( hasWrongDate ( header ) ) {
64
- var codeLines = code . split ( '\n' ) ;
68
+ var newCode = licenseSrc + '\n' + codeLines . join ( '\n' ) ;
65
69
66
- codeLines . splice ( header . loc . start . line - 1 , header . loc . end . line ) ;
67
-
68
- var newCode = licenseSrc + '\n' + codeLines . join ( '\n' ) ;
69
-
70
- fs . writeFile ( file , newCode , function ( err ) {
71
- if ( err ) throw err ;
72
- } ) ;
73
- }
74
- else {
75
- // otherwise, throw an error
76
- throw new Error ( file + ' : has wrong header information.' ) ;
77
- }
70
+ fs . writeFile ( file , newCode , function ( err ) {
71
+ if ( err ) throw err ;
72
+ } ) ;
73
+ }
74
+ else {
75
+ // otherwise, throw an error
76
+ throw new Error ( file + ' : has wrong header information.' ) ;
77
+ }
78
+ } ) ;
78
79
} ) ;
79
80
} ) ;
80
- } ) ;
81
81
82
- function isCorrect ( header ) {
83
- return ( header . value === licenseStr ) ;
84
- }
82
+ function isCorrect ( header ) {
83
+ return ( header . value === licenseStr ) ;
84
+ }
85
85
86
- function hasWrongDate ( header ) {
87
- var regex = / C o p y r i g h t 2 0 [ 0 - 9 ] [ 0 - 9 ] - 2 0 [ 0 - 9 ] [ 0 - 9 ] / g;
86
+ function hasWrongDate ( header ) {
87
+ var regex = / C o p y r i g h t 2 0 [ 0 - 9 ] [ 0 - 9 ] - 2 0 [ 0 - 9 ] [ 0 - 9 ] / g;
88
88
89
- return ( header . value . replace ( regex , '' ) === licenseStr . replace ( regex , '' ) ) ;
89
+ return ( header . value . replace ( regex , '' ) === licenseStr . replace ( regex , '' ) ) ;
90
+ }
90
91
}
0 commit comments