@@ -21,122 +21,105 @@ function printHostingInstructions(
21
21
buildFolder ,
22
22
useYarn
23
23
) {
24
- const publicPathname = url . parse ( publicPath ) . pathname ;
25
- if ( publicUrl && publicUrl . indexOf ( '.github.io/' ) !== - 1 ) {
24
+ if ( publicUrl && publicUrl . includes ( '.github.io/' ) ) {
26
25
// "homepage": "http://user.github.io/project"
27
- console . log (
28
- `The project was built assuming it is hosted at ${ chalk . green (
29
- publicPathname
30
- ) } .`
31
- ) ;
32
- console . log (
33
- `You can control this with the ${ chalk . green (
34
- 'homepage'
35
- ) } field in your ${ chalk . cyan ( 'package.json' ) } .`
36
- ) ;
37
- console . log ( ) ;
38
- console . log (
39
- `The ${ chalk . cyan ( buildFolder ) } folder is ready to be deployed.`
40
- ) ;
41
- console . log ( `To publish it at ${ chalk . green ( publicUrl ) } , run:` ) ;
42
- // If script deploy has been added to package.json, skip the instructions
43
- if ( typeof appPackage . scripts . deploy === 'undefined' ) {
44
- console . log ( ) ;
45
- if ( useYarn ) {
46
- console . log ( ` ${ chalk . cyan ( 'yarn' ) } add --dev gh-pages` ) ;
47
- } else {
48
- console . log ( ` ${ chalk . cyan ( 'npm' ) } install --save-dev gh-pages` ) ;
49
- }
50
- console . log ( ) ;
51
- console . log (
52
- `Add the following script in your ${ chalk . cyan ( 'package.json' ) } .`
53
- ) ;
54
- console . log ( ) ;
55
- console . log ( ` ${ chalk . dim ( '// ...' ) } ` ) ;
56
- console . log ( ` ${ chalk . yellow ( '"scripts"' ) } : {` ) ;
57
- console . log ( ` ${ chalk . dim ( '// ...' ) } ` ) ;
58
- console . log (
59
- ` ${ chalk . yellow ( '"predeploy"' ) } : ${ chalk . yellow (
60
- '"npm run build",'
61
- ) } `
62
- ) ;
63
- console . log (
64
- ` ${ chalk . yellow ( '"deploy"' ) } : ${ chalk . yellow (
65
- '"gh-pages -d build"'
66
- ) } `
67
- ) ;
68
- console . log ( ' }' ) ;
69
- console . log ( ) ;
70
- console . log ( 'Then run:' ) ;
71
- }
72
- console . log ( ) ;
73
- console . log ( ` ${ chalk . cyan ( useYarn ? 'yarn' : 'npm' ) } run deploy` ) ;
74
- console . log ( ) ;
26
+ const publicPathname = url . parse ( publicPath ) . pathname ;
27
+ const hasDeployScript = typeof appPackage . scripts . deploy !== 'undefined' ;
28
+ printBaseMessage ( buildFolder , publicPathname ) ;
29
+
30
+ printDeployInstructions ( publicUrl , hasDeployScript , useYarn ) ;
31
+
75
32
} else if ( publicPath !== '/' ) {
76
33
// "homepage": "http://mywebsite.com/project"
34
+ printBaseMessage ( buildFolder , publicPath ) ;
35
+
36
+ } else {
37
+ // "homepage": "http://mywebsite.com"
38
+ // or no homepage
39
+ printBaseMessage ( buildFolder , publicUrl ) ;
40
+
41
+ printStaticServerInstructions ( useYarn ) ;
42
+ }
43
+ console . log ( ) ;
44
+ }
45
+
46
+ function printBaseMessage ( buildFolder , hostingLocation ) {
77
47
console . log (
78
48
`The project was built assuming it is hosted at ${ chalk . green (
79
- publicPath
49
+ hostingLocation || 'the server root'
80
50
) } .`
81
51
) ;
82
52
console . log (
83
53
`You can control this with the ${ chalk . green (
84
54
'homepage'
85
55
) } field in your ${ chalk . cyan ( 'package.json' ) } .`
86
56
) ;
87
- console . log ( ) ;
88
- console . log (
89
- `The ${ chalk . cyan ( buildFolder ) } folder is ready to be deployed.`
90
- ) ;
91
- console . log ( ) ;
92
- } else {
93
- if ( publicUrl ) {
94
- // "homepage": "http://mywebsite.com"
95
- console . log (
96
- `The project was built assuming it is hosted at ${ chalk . green (
97
- publicUrl
98
- ) } .`
99
- ) ;
100
- console . log (
101
- `You can control this with the ${ chalk . green (
102
- 'homepage'
103
- ) } field in your ${ chalk . cyan ( 'package.json' ) } .`
104
- ) ;
105
- console . log ( ) ;
106
- } else {
107
- // no homepage
108
- console . log (
109
- 'The project was built assuming it is hosted at the server root.'
110
- ) ;
111
- console . log (
112
- `To override this, specify the ${ chalk . green (
113
- 'homepage'
114
- ) } in your ${ chalk . cyan ( 'package.json' ) } .`
115
- ) ;
57
+
58
+ if ( ! hostingLocation ) {
116
59
console . log ( 'For example, add this to build it for GitHub Pages:' ) ;
117
60
console . log ( ) ;
61
+
118
62
console . log (
119
63
` ${ chalk . green ( '"homepage"' ) } ${ chalk . cyan ( ':' ) } ${ chalk . green (
120
64
'"http://myname.github.io/myapp"'
121
65
) } ${ chalk . cyan ( ',' ) } `
122
66
) ;
123
- console . log ( ) ;
124
67
}
68
+ console . log ( ) ;
69
+
125
70
console . log (
126
71
`The ${ chalk . cyan ( buildFolder ) } folder is ready to be deployed.`
127
72
) ;
128
- console . log ( 'You may serve it with a static server:' ) ;
129
- console . log ( ) ;
130
- if ( ! fs . existsSync ( `${ globalModules } /serve` ) ) {
131
- if ( useYarn ) {
132
- console . log ( ` ${ chalk . cyan ( 'yarn' ) } global add serve` ) ;
133
- } else {
134
- console . log ( ` ${ chalk . cyan ( 'npm' ) } install -g serve` ) ;
135
- }
73
+ }
74
+
75
+ function printDeployInstructions ( publicUrl , hasDeployScript , useYarn ) {
76
+ console . log ( `To publish it at ${ chalk . green ( publicUrl ) } , run:` ) ;
77
+ console . log ( ) ;
78
+
79
+ // If script deploy has been added to package.json, skip the instructions
80
+ if ( ! hasDeployScript ) {
81
+ if ( useYarn ) {
82
+ console . log ( ` ${ chalk . cyan ( 'yarn' ) } add --dev gh-pages` ) ;
83
+ } else {
84
+ console . log ( ` ${ chalk . cyan ( 'npm' ) } install --save-dev gh-pages` ) ;
136
85
}
137
- console . log ( ` ${ chalk . cyan ( 'serve' ) } -s ${ buildFolder } ` ) ;
138
86
console . log ( ) ;
87
+
88
+ console . log ( `Add the following script in your ${ chalk . cyan (
89
+ 'package.json'
90
+ ) } .`) ;
91
+ console . log ( ) ;
92
+
93
+ console . log ( ` ${ chalk . dim ( '// ...' ) } ` ) ;
94
+ console . log ( ` ${ chalk . yellow ( '"scripts"' ) } : {` ) ;
95
+ console . log ( ` ${ chalk . dim ( '// ...' ) } ` ) ;
96
+ console . log ( ` ${ chalk . yellow ( '"predeploy"' ) } : ${ chalk . yellow (
97
+ '"npm run build",'
98
+ ) } `) ;
99
+ console . log ( ` ${ chalk . yellow ( '"deploy"' ) } : ${ chalk . yellow (
100
+ '"gh-pages -d build"'
101
+ ) } `) ;
102
+ console . log ( ' }' ) ;
103
+ console . log ( ) ;
104
+
105
+ console . log ( 'Then run:' ) ;
106
+ console . log ( ) ;
107
+ }
108
+ console . log ( ` ${ chalk . cyan ( useYarn ? 'yarn' : 'npm' ) } run deploy` ) ;
109
+ }
110
+
111
+ function printStaticServerInstructions ( useYarn ) {
112
+ console . log ( 'You may serve it with a static server:' ) ;
113
+ console . log ( ) ;
114
+
115
+ if ( ! fs . existsSync ( `${ globalModules } /serve` ) ) {
116
+ if ( useYarn ) {
117
+ console . log ( ` ${ chalk . cyan ( 'yarn' ) } global add serve` ) ;
118
+ } else {
119
+ console . log ( ` ${ chalk . cyan ( 'npm' ) } install -g serve` ) ;
120
+ }
139
121
}
122
+ console . log ( ` ${ chalk . cyan ( 'serve' ) } -s ${ buildFolder } ` ) ;
140
123
}
141
124
142
125
module . exports = printHostingInstructions ;
0 commit comments