Skip to content

Commit 4f53314

Browse files
committed
feat: Polishing auto import feature
1 parent 3d89947 commit 4f53314

File tree

3 files changed

+46
-25
lines changed

3 files changed

+46
-25
lines changed

generator/index.js

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ const iconMap = {
2424
mdi: 'mdi-v4'
2525
}
2626

27-
module.exports = (api, opts) => {
28-
const components = []
29-
const directives = []
30-
const plugins = []
27+
const components = []
28+
const directives = []
29+
const plugins = []
3130

31+
module.exports = (api, opts) => {
3232
const
3333
quasarPath = api.resolve('./src/quasar.js'),
3434
tsPath = api.resolve('./src/main.ts'),
@@ -97,6 +97,7 @@ module.exports = (api, opts) => {
9797
let lines = `import Vue from 'vue'\n`
9898

9999
const
100+
autoImport = opts.quasar.importStrategy !== 'manual',
100101
hasIconSet = opts.quasar.iconSet !== 'material-icons',
101102
hasLang = opts.quasar.lang !== 'en-us'
102103

@@ -127,32 +128,46 @@ module.exports = (api, opts) => {
127128
})
128129

129130
// build import
130-
lines += `\nimport `
131-
lines += `{\n Quasar, `
132-
components
133-
.concat(directives)
134-
.concat(plugins)
135-
.forEach(part => {
136-
lines += `\n ${part},`
137-
})
138-
lines += `\n}`
139-
lines += ` from 'quasar'`
131+
if (autoImport) {
132+
lines += `\nimport { Quasar } from 'quasar'`
133+
}
134+
else {
135+
lines += `\nimport {\n Quasar, `
136+
components
137+
.concat(directives)
138+
.concat(plugins)
139+
.forEach(part => {
140+
lines += `\n ${part},`
141+
})
142+
lines += `\n}`
143+
lines += ` from 'quasar'`
144+
}
140145

141146
// build Vue.use()
142147
lines += `\n\nVue.use(Quasar, {`
143148
lines += `\n config: {}`
144149

145150
lines += ',\n components: {'
146-
components.forEach(part => {
147-
lines += `\n ${part},`
148-
})
149-
lines += `\n }`
151+
if (autoImport) {
152+
lines += ` /* not needed if importStrategy is not 'manual' */ }`
153+
}
154+
else {
155+
components.forEach(part => {
156+
lines += `\n ${part},`
157+
})
158+
lines += `\n }`
159+
}
150160

151161
lines += ',\n directives: {'
152-
directives.forEach(part => {
153-
lines += `\n ${part},`
154-
})
155-
lines += `\n }`
162+
if (autoImport) {
163+
lines += ` /* not needed if importStrategy is not 'manual' */ }`
164+
}
165+
else {
166+
directives.forEach(part => {
167+
lines += `\n ${part},`
168+
})
169+
lines += `\n }`
170+
}
156171

157172
lines += ',\n plugins: {'
158173
plugins.forEach(part => {

index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,11 @@ module.exports = (api, options) => {
3535
.options(strategy)
3636
.before('cache-loader')
3737
}
38+
else if (![void 0, 'manual'].includes(strategy)) {
39+
console.error(`Incorrect setting for quasar > importStrategy (${strategy})`)
40+
console.error(`Use one of: 'kebab', 'pascal', 'combined', 'manual'.`)
41+
console.log()
42+
process.exit(1)
43+
}
3844
})
3945
}

prompts.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ module.exports = [
1414
message: 'Pick a Quasar components & directives import strategy: (can be changed later)',
1515
choices: [
1616
{
17-
name: '* Auto-import in-use Quasar components & directives (kebab-case, can be later changed to \'pascal\' or \'combined\')',
17+
name: `Auto-import in-use Quasar components & directives (kebab-case, can be later changed to 'pascal' or 'combined')`,
1818
value: 'kebab',
1919
short: 'Auto import (kebab-case)',
2020
checked: true
2121
},
2222
{
23-
name: '* Manually specify what to import',
24-
value: '\'manual\'',
23+
name: 'Manually specify what to import',
24+
value: 'manual',
2525
short: 'Manual'
2626
}
2727
]

0 commit comments

Comments
 (0)