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