UNPKG

6.65 kBJavaScriptView Raw
1const
2 fs = require('fs'),
3 fse = require('fs-extra'),
4 { green } = require('chalk')
5
6const
7 appPaths = require('./app-paths')
8
9module.exports = function legacyValidations (cfg) {
10 let file, content, error = false
11
12 file = appPaths.resolve.app(cfg.sourceFiles.indexHtmlTemplate)
13 if (!fs.existsSync(file)) {
14 console.log('⚠️ Missing /src/index.template.html file...')
15 console.log()
16 error = true
17 }
18 content = fs.readFileSync(file, 'utf-8')
19 if (content.indexOf('<base href') > -1) {
20 console.log(`⚠️ Your newer Quasar CLI requires a minor change to /src/index.template.html
21 Please remove this tag completely:
22 <base href="<%= htmlWebpackPlugin.options.appBase %>">
23 `)
24 console.log()
25 error = true
26 }
27
28 if (content.indexOf(`chunk.initial ? 'preload' : 'prefetch'`) > -1) {
29 console.log(`\n⚠️ Your newer Quasar CLI requires a minor change to /src/index.template.html
30 Please remove this section completely:
31
32 <!--
33 The following is optional if you DON'T build for PWA.
34 Preloads/prefetches chunks/assets.
35 -->
36 <% if (!['cordova', 'electron'].includes(htmlWebpackPlugin.options.ctx.modeName) && htmlWebpackPlugin.options.ctx.prod) {
37 for (var chunk of webpack.chunks) {
38 for (var file of chunk.files) {
39 if (file.match(/\.(js|css)$/)) { %>
40 <link rel="<%= chunk.initial ? 'preload' : 'prefetch' %>" href="<%= file %>" as="<%= file.match(/\.css$/)? 'style' : 'script' %>">
41 <% }}}} %>
42 `)
43 console.log()
44 error = true
45 }
46
47 if (content.indexOf('<link rel="manifest"') > -1) {
48 console.log(`\n⚠️ Your newer Quasar CLI requires a minor change to /src/index.template.html
49 Please remove this section completely:
50
51 <% if (htmlWebpackPlugin.options.ctx.mode.pwa) { %>
52 <!-- Add to home screen for Android and modern mobile browsers -->
53 .....
54 <% } %>
55 `)
56 console.log()
57 error = true
58 }
59
60 if (content.indexOf('htmlWebpackPlugin.options.headScripts') > -1) {
61 console.log(`\n⚠️ Your newer Quasar CLI requires a minor change to /src/index.template.html
62 Please remove this section completely:
63
64 <%= htmlWebpackPlugin.options.headScripts %>
65 `)
66 console.log()
67 error = true
68 }
69
70 if (content.indexOf('htmlWebpackPlugin.options.bodyScripts') > -1) {
71 console.log(`\n⚠️ Your newer Quasar CLI requires a minor change to /src/index.template.html
72 Please remove this section completely:
73
74 <%= htmlWebpackPlugin.options.bodyScripts %>
75 `)
76 console.log()
77 error = true
78 }
79
80 file = appPaths.resolve.app(cfg.sourceFiles.rootComponent)
81 content = fs.readFileSync(file, 'utf-8')
82 if (content.indexOf('q-app') === -1) {
83 console.log(`\n⚠️ Quasar CLI requires a minor change to the root component:
84 ${file}
85
86 Please add: id="q-app" (or write #q-app if using Pug)
87 to the outermost HTML element of the template.
88
89${green('Example:')}
90 <template>
91 <div id="q-app">
92 ...
93 </div>
94 </template>
95`)
96 error = true
97 }
98
99 if (error) {
100 process.exit(1)
101 }
102
103 file = appPaths.resolve.app(cfg.sourceFiles.router)
104 content = fs.readFileSync(file, 'utf-8')
105 if (cfg.ctx.mode.ssr && content.indexOf('export default function') === -1) {
106 console.log(`\n⚠️ In order to build with SSR mode you need a minor change to the ROUTER file
107 This won't break other build modes after you change it.
108
109 ${file}
110
111 You need to have a default export set to "function ({ store })" which returns a new
112 instance of Router instead of default exporting the Router instance itself.
113
114${green('OLD WAY:')}
115 import Vue from 'vue'
116 import VueRouter from 'vue-router'
117 import routes from './routes'
118 Vue.use(VueRouter)
119
120 // in the new way, we'll wrap the instantiation into:
121 // export default function ({ store }) --> store is optional
122 const Router = new VueRouter({
123 scrollBehavior: () => ({ y: 0 }),
124 routes,
125 // Leave these as they are and change from quasar.conf.js instead!
126 mode: process.env.VUE_ROUTER_MODE,
127 base: process.env.VUE_ROUTER_BASE,
128 })
129
130 // in the new way, this will be no more
131 export default Router
132
133${green('NEW WAY:')}
134 import Vue from 'vue'
135 import VueRouter from 'vue-router'
136 import routes from './routes'
137 Vue.use(VueRouter)
138
139 // DO NOT import the store here as you will receive it as
140 // parameter in the default exported function:
141
142 export default function (/* { store } */) {
143 // IMPORTANT! Instantiate Router inside this function
144
145 const Router = new VueRouter({
146 scrollBehavior: () => ({ y: 0 }),
147 routes,
148 // Leave these as they are and change from quasar.conf.js instead!
149 mode: process.env.VUE_ROUTER_MODE,
150 base: process.env.VUE_ROUTER_BASE,
151 })
152
153 return Router
154 }
155 `)
156 console.log()
157 process.exit(1)
158 }
159
160 if (cfg.store && cfg.ctx.mode.ssr) {
161 file = appPaths.resolve.app(cfg.sourceFiles.store)
162 content = fs.readFileSync(file, 'utf-8')
163 if (content.indexOf('export default function') === -1) {
164 console.log(`\n⚠️ In order to build with SSR mode you need a minor change to the STORE file
165 This won't break other build modes after you change it.
166
167 ${file}
168
169 You need to have a default export set to "function ()" which returns a new
170 instance of Vuex Store instead of default exporting the Store instance itself.
171
172${green('OLD WAY:')}
173 import Vue from 'vue'
174 import Vuex from 'vuex'
175 import example from './module-example'
176 Vue.use(Vuex)
177
178 // in the new way, we'll wrap the instantiation into:
179 // export default function ()
180 const store = new Vuex.Store({
181 modules: {
182 example
183 }
184 })
185
186 // in the new way, this will be no more
187 export default store
188
189${green('NEW WAY:')}
190 import Vue from 'vue'
191 import Vuex from 'vuex'
192 import example from './module-example'
193 Vue.use(Vuex)
194
195 export default function () {
196 // IMPORTANT! Instantiate Store inside this function
197
198 const Store = new Vuex.Store({
199 modules: {
200 example
201 }
202 })
203
204 return Store
205 }
206 `)
207 console.log()
208 process.exit(1)
209 }
210 }
211
212 file = appPaths.resolve.app('.babelrc')
213 if (!fs.existsSync(file)) {
214 console.log('⚠️ Missing .babelrc file...')
215 console.log()
216 process.exit(1)
217 }
218 content = fs.readFileSync(file, 'utf-8')
219 if (content.indexOf('"transform-runtime"') > -1) {
220 console.log()
221 console.log(' ⚠️ WARNING')
222 console.log(` Your newer Quasar CLI requires a change to .babelrc file.`)
223 console.log(` Doing it automatically. Please review the changes.`)
224 console.log()
225
226 fse.copySync(
227 appPaths.resolve.cli('templates/app/babelrc'),
228 appPaths.resolve.app('.babelrc')
229 )
230 }
231}