@@ -15,7 +15,13 @@ module.exports = api => {
15
15
json : [ 'public/manifest.json' ]
16
16
}
17
17
} ,
18
- onRead : ( { data, cwd } ) => {
18
+ onRead : ( { data } ) => {
19
+ // Dirty hack here: only in onRead can we delete files from the original data.
20
+ // Remove (or, don't create the file) manifest.json if no actual content in it.
21
+ if ( ! data . manifest || ! Object . keys ( data . manifest ) . length ) {
22
+ delete data . manifest
23
+ }
24
+
19
25
return {
20
26
prompts : [
21
27
{
@@ -58,7 +64,12 @@ module.exports = api => {
58
64
message : 'org.vue.pwa.config.pwa.backgroundColor.message' ,
59
65
description : 'org.vue.pwa.config.pwa.backgroundColor.description' ,
60
66
default : '#000000' ,
61
- value : data . manifest && data . manifest . background_color ,
67
+ value :
68
+ ( data . vue &&
69
+ data . vue . pwa &&
70
+ data . vue . pwa . manifestOptions &&
71
+ data . vue . pwa . manifestOptions . background_color ) ||
72
+ ( data . manifest && data . manifest . background_color ) ,
62
73
skipSave : true
63
74
} ,
64
75
{
@@ -82,12 +93,12 @@ module.exports = api => {
82
93
type : 'list' ,
83
94
message : 'org.vue.pwa.config.pwa.manifestCrossorigin.message' ,
84
95
description : 'org.vue.pwa.config.pwa.manifestCrossorigin.description' ,
85
- default : undefined ,
96
+ default : null ,
86
97
value : data . vue && data . vue . pwa && data . vue . pwa . manifestCrossorigin ,
87
98
choices : [
88
99
{
89
100
name : 'none' ,
90
- value : undefined
101
+ value : null
91
102
} ,
92
103
{
93
104
name : 'anonymous' ,
@@ -102,35 +113,42 @@ module.exports = api => {
102
113
]
103
114
}
104
115
} ,
105
- onWrite : async ( { onWriteApi, prompts , cwd } ) => {
116
+ onWrite : async ( { api : onWriteApi , data , prompts } ) => {
106
117
const result = { }
107
118
for ( const prompt of prompts . filter ( p => ! p . raw . skipSave ) ) {
108
119
result [ `pwa.${ prompt . id } ` ] = await onWriteApi . getAnswer ( prompt . id )
109
120
}
110
- onWriteApi . setData ( 'vue' , result )
111
-
112
- // Update app manifest
113
121
114
- const name = result [ 'name' ]
115
- if ( name ) {
116
- onWriteApi . setData ( 'manifest' , {
117
- name,
118
- short_name : name
119
- } )
122
+ const backgroundColor = await onWriteApi . getAnswer ( 'backgroundColor' )
123
+ if ( ! data . manifest && backgroundColor ) {
124
+ result [ 'pwa.manifestOptions.background_color' ] = backgroundColor
120
125
}
121
126
122
- const themeColor = result [ 'themeColor' ]
123
- if ( themeColor ) {
124
- onWriteApi . setData ( 'manifest' , {
125
- theme_color : themeColor
126
- } )
127
- }
127
+ onWriteApi . setData ( 'vue' , result )
128
128
129
- const backgroundColor = await onWriteApi . getAnswer ( 'backgroundColor' )
130
- if ( backgroundColor ) {
131
- onWriteApi . setData ( 'manifest' , {
132
- background_color : backgroundColor
133
- } )
129
+ // Update app manifest (only when there's a manifest.json file,
130
+ // otherwise it will be inferred from options in vue.config.js)
131
+ if ( data . manifest ) {
132
+ const name = result [ 'name' ]
133
+ if ( name ) {
134
+ onWriteApi . setData ( 'manifest' , {
135
+ name,
136
+ short_name : name
137
+ } )
138
+ }
139
+
140
+ const themeColor = result [ 'themeColor' ]
141
+ if ( themeColor ) {
142
+ onWriteApi . setData ( 'manifest' , {
143
+ theme_color : themeColor
144
+ } )
145
+ }
146
+
147
+ if ( backgroundColor ) {
148
+ onWriteApi . setData ( 'manifest' , {
149
+ background_color : backgroundColor
150
+ } )
151
+ }
134
152
}
135
153
}
136
154
} )
0 commit comments