@@ -14,6 +14,7 @@ var path = require('path');
14
14
var rootdir = process . argv [ 2 ] ;
15
15
16
16
function addPlatformBodyTag ( indexPath , platform ) {
17
+
17
18
// add the platform class to the body tag
18
19
try {
19
20
var platformClass = 'platform-' + platform ;
@@ -22,21 +23,23 @@ function addPlatformBodyTag(indexPath, platform) {
22
23
var html = fs . readFileSync ( indexPath , 'utf8' ) ;
23
24
24
25
var bodyTag = findBodyTag ( html ) ;
25
- if ( ! bodyTag ) return ; // no opening body tag, something's wrong
26
+ if ( ! bodyTag ) return ; // no opening body tag, something's wrong
26
27
27
- if ( bodyTag . indexOf ( platformClass ) > - 1 ) return ; // already added
28
+ if ( bodyTag . indexOf ( platformClass ) > - 1 ) return ; // already added
28
29
29
30
var newBodyTag = bodyTag ;
30
31
31
32
var classAttr = findClassAttr ( bodyTag ) ;
32
- if ( classAttr ) {
33
+ if ( classAttr ) {
34
+
33
35
// body tag has existing class attribute, add the classname
34
- var endingQuote = classAttr . substring ( classAttr . length - 1 ) ;
35
- var newClassAttr = classAttr . substring ( 0 , classAttr . length - 1 ) ;
36
+ var endingQuote = classAttr . substring ( classAttr . length - 1 ) ;
37
+ var newClassAttr = classAttr . substring ( 0 , classAttr . length - 1 ) ;
36
38
newClassAttr += ' ' + platformClass + ' ' + cordovaClass + endingQuote ;
37
39
newBodyTag = bodyTag . replace ( classAttr , newClassAttr ) ;
38
40
39
41
} else {
42
+
40
43
// add class attribute to the body tag
41
44
newBodyTag = bodyTag . replace ( '>' , ' class="' + platformClass + ' ' + cordovaClass + '">' ) ;
42
45
}
@@ -46,49 +49,51 @@ function addPlatformBodyTag(indexPath, platform) {
46
49
fs . writeFileSync ( indexPath , html , 'utf8' ) ;
47
50
48
51
process . stdout . write ( 'add to body class: ' + platformClass + '\n' ) ;
49
- } catch ( e ) {
52
+ } catch ( e ) {
50
53
process . stdout . write ( e ) ;
51
54
}
52
55
}
53
56
54
57
function findBodyTag ( html ) {
58
+
55
59
// get the body tag
56
- try {
60
+ try {
57
61
return html . match ( / < b o d y (? = [ \s > ] ) ( .* ?) > / gi) [ 0 ] ;
58
- } catch ( e ) { }
62
+ } catch ( e ) { } // eslint-disable-line no-empty
59
63
}
60
64
61
65
function findClassAttr ( bodyTag ) {
66
+
62
67
// get the body tag's class attribute
63
- try {
68
+ try {
64
69
return bodyTag . match ( / c l a s s = [ " | ' ] ( .* ?) [ " | ' ] / gi) [ 0 ] ;
65
- } catch ( e ) { }
70
+ } catch ( e ) { } // eslint-disable-line no-empty
66
71
}
67
72
68
73
if ( rootdir ) {
69
74
70
75
// go through each of the platform directories that have been prepared
71
76
var platforms = ( process . env . CORDOVA_PLATFORMS ? process . env . CORDOVA_PLATFORMS . split ( ',' ) : [ ] ) ;
72
77
73
- for ( var x = 0 ; x < platforms . length ; x ++ ) {
78
+ for ( var x = 0 ; x < platforms . length ; x += 1 ) {
79
+
74
80
// open up the index.html file at the www root
75
81
try {
76
82
var platform = platforms [ x ] . trim ( ) . toLowerCase ( ) ;
77
83
var indexPath ;
78
84
79
- if ( platform == 'android' ) {
85
+ if ( platform = == 'android' ) {
80
86
indexPath = path . join ( 'platforms' , platform , 'assets' , 'www' , 'index.html' ) ;
81
87
} else {
82
88
indexPath = path . join ( 'platforms' , platform , 'www' , 'index.html' ) ;
83
89
}
84
90
85
- if ( fs . existsSync ( indexPath ) ) {
91
+ if ( fs . existsSync ( indexPath ) ) {
86
92
addPlatformBodyTag ( indexPath , platform ) ;
87
93
}
88
94
89
- } catch ( e ) {
95
+ } catch ( e ) {
90
96
process . stdout . write ( e ) ;
91
97
}
92
98
}
93
-
94
99
}
0 commit comments