@@ -28,38 +28,33 @@ function updateHeadersInSrcAndLibFiles() {
28
28
throw new Error ( file + ' : has no header information.' ) ;
29
29
}
30
30
31
- // if header and license are the same, do nothing
32
- if ( isCorrect ( header ) ) return ;
33
-
34
- // if header and license only differ by date, update header
35
- else if ( hasWrongDate ( header ) ) {
31
+ // if header and license are the same remove the header!
32
+ if ( isRedundant ( header ) ) {
36
33
var codeLines = code . split ( '\n' ) ;
37
34
38
35
codeLines . splice ( header . loc . start . line - 1 , header . loc . end . line ) ;
39
36
40
- var newCode = licenseSrc + '\n' + codeLines . join ( '\n' ) ;
37
+ var i ;
38
+ for ( i = 0 ; i < codeLines . length ; i ++ ) {
39
+ if ( codeLines [ i ] ) {
40
+ break ;
41
+ }
42
+ }
43
+
44
+ var newCode = codeLines . splice ( i ) . join ( '\n' ) ;
41
45
42
46
common . writeFile ( file , newCode ) ;
43
- } else {
44
- // otherwise, throw an error
45
- throw new Error ( file + ' : has wrong header information.' ) ;
46
47
}
47
48
} ) ;
48
49
} ) ;
49
50
} ) ;
50
51
51
- function isCorrect ( header ) {
52
+ function isRedundant ( header ) {
52
53
return (
53
54
header . value . replace ( / \s + $ / gm, '' ) ===
54
55
licenseStr . replace ( / \s + $ / gm, '' )
55
56
) ;
56
57
}
57
-
58
- function hasWrongDate ( header ) {
59
- var regex = / C o p y r i g h t 2 0 [ 0 - 9 ] [ 0 - 9 ] - 2 0 [ 0 - 9 ] [ 0 - 9 ] / g;
60
-
61
- return ( header . value . replace ( regex , '' ) === licenseStr . replace ( regex , '' ) ) ;
62
- }
63
58
}
64
59
65
60
updateHeadersInSrcAndLibFiles ( ) ;
0 commit comments