-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.js
191 lines (150 loc) · 4.77 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
const fs = require('fs'),
extendPluginOptions = require('../lib/extendPluginOptions')
const message = `
Documentation can be found at: https://quasar.dev
Quasar is relying on donations to evolve. We'd be very grateful
if you can read our manifest on "Why donations are important":
https://quasar.dev/why-donate
Donation campaign: https://donate.quasar.dev Any amount is very
welcomed. If invoices are required, please first contact
Please give us a star on Github if you appreciate our work:
https://github.com/quasarframework/quasar
Enjoy! - Quasar Team
`
const iconMap = {
ionicons: 'ionicons-v4',
fontawesome: 'fontawesome-v5',
mdi: 'mdi-v4'
}
const plugins = []
module.exports = (api, opts) => {
const
quasarPath = api.resolve('./src/quasar.js'),
tsPath = api.resolve('./src/main.ts'),
jsPath = api.resolve('./src/main.js'),
hasTS = fs.existsSync(tsPath)
const dependencies = {
quasar: '^1.0.0',
'@quasar/extras': '^1.0.0'
}
const deps = {
dependencies,
devDependencies: {}
}
if (opts.quasar.cssPreprocessor === 'styl') {
Object.assign(deps.devDependencies, {
stylus: '^0.54.5',
'stylus-loader': '^3.0.2'
})
}
else if (['sass', 'scss'].includes(opts.quasar.cssPreprocessor)) {
Object.assign(deps.devDependencies, {
'sass': '^1.29.0',
'sass-loader': '^8.0.0'
})
}
if (opts.quasar.rtlSupport) {
deps.devDependencies['postcss-rtl'] = '^1.2.3'
}
api.extendPackage(deps)
// modify plugin options
extendPluginOptions(api, (pluginOptions, transpileDependencies) => {
pluginOptions.quasar = Object.assign(
pluginOptions.quasar || {},
{
importStrategy: 'kebab',
rtlSupport: opts.quasar.rtlSupport
}
)
transpileDependencies.push('quasar')
return { pluginOptions, transpileDependencies }
})
api.render('./templates/common')
if (opts.quasar.rtlSupport) {
api.render('./templates/rtl')
}
if (opts.quasar.cssPreprocessor !== 'none') {
api.render(`./templates/${opts.quasar.cssPreprocessor}`)
}
if (opts.quasar.replaceComponents) {
const extension = hasTS ? 'ts' : 'js',
routerFile = api.resolve(`src/router.${extension}`),
hasRouter = fs.existsSync(routerFile)
api.render(`./templates/with${hasRouter ? '' : 'out'}-router-base`, opts)
api.render(
`./templates/with${hasRouter ? '' : 'out'}-router`,
opts
)
if (hasRouter) {
api.render(`./templates/with-router-${extension}`)
}
}
api.onCreateComplete(() => {
let lines = `import Vue from 'vue'\n`
const
hasIconSet = opts.quasar.iconSet !== 'material-icons',
hasLang = opts.quasar.lang !== 'en-us'
if (!opts.quasar.features.includes(opts.quasar.iconSet)) {
opts.quasar.features.push(opts.quasar.iconSet)
}
if (opts.quasar.cssPreprocessor !== 'none') {
lines += `\nimport './styles/quasar.${opts.quasar.cssPreprocessor}'`
}
else {
lines += `\nimport 'quasar/dist/quasar.css'`
}
if (opts.quasar.features.includes('ie')) {
lines += `\nimport 'quasar/dist/quasar.ie.polyfills'`
}
if (hasIconSet) {
const set = iconMap[opts.quasar.iconSet] || opts.quasar.iconSet
lines += `\nimport iconSet from 'quasar/icon-set/${set}.js'`
}
if (hasLang) {
lines += `\nimport lang from 'quasar/lang/${opts.quasar.lang}.js'`
}
opts.quasar.features
.filter(feat => feat !== 'ie')
.forEach(feat => {
feat = iconMap[feat] || feat
lines += `\nimport '@quasar/extras/${feat}/${feat}.css'`
})
// build import
lines += `\nimport { Quasar } from 'quasar'`
// build Vue.use()
lines += `\n\nVue.use(Quasar, {`
lines += `\n config: {}`
lines += ',\n plugins: {'
plugins.forEach(part => {
lines += `\n ${part},`
})
lines += `\n }`
if (hasLang) {
lines += `,\n lang: lang`
}
if (hasIconSet) {
lines += `,\n iconSet: iconSet`
}
lines += `\n })`
// Now inject additions to main.[js|ts]
{
const mainPath = fs.existsSync(tsPath) ? tsPath : jsPath
let content = fs.readFileSync(mainPath, { encoding: 'utf8' })
const mainLines = content.split(/\r?\n/g).reverse()
const index = mainLines.findIndex(line => line.match(/^import/))
mainLines[index] += `\nimport './quasar'`
content = mainLines.reverse().join('\n')
fs.writeFileSync(mainPath, content, { encoding: 'utf8' })
fs.writeFileSync(quasarPath, lines, { encoding: 'utf8' })
}
if (api.generator.hasPlugin('@vue/cli-plugin-eslint')) {
const { spawnSync } = require('child_process')
spawnSync('node', [
'node_modules/@vue/cli-service/bin/vue-cli-service.js',
'lint'
])
}
api.exitLog(message, 'info')
})
}