forked from vuetifyjs/vue-cli-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
72 lines (57 loc) · 1.71 KB
/
helpers.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
// Imports
const semver = require('semver')
const fs = require('fs')
// Check for existence of file and add import
function addImport (api, file, data, folder, end) {
// sass & scss file types
for (const ext of ['sass', 'scss']) {
const path = `${folder}/${file}.${ext}`
// If file doesn't exist in user
// project, continue to next
if (!fileExists(api, `src/${path}`)) continue
// If file exists, push it into
// the import statement
data.push(`@import '@/${path}${end}`)
}
}
// Go through each folder and add available imports
function addImports (api, file, data, end) {
// supported folders that can contain
// a variables or lists file
for (const folder of ['sass', 'scss', 'styles']) {
addImport(api, file, data, folder, end)
}
}
// Check if file exists in user project
function fileExists (api, file) {
return fs.existsSync(api.resolve(file))
}
// Create an import statement
// to bootstrap a users variables
function mergeRules (api, opt, ext) {
const data = []
const end = ext === 'sass' ? "'" : "';"
addImports(api, 'variables', data, end)
// Inject Vuetify styles at the end of user supplied
data.push(`@import '~vuetify/src/styles/styles.sass${end}`)
addImports(api, 'lists', data, end)
let sassLoaderVersion
try {
sassLoaderVersion = semver.major(require('sass-loader/package.json').version)
} catch (e) {}
// Merge with user-defined loader data config
if (sassLoaderVersion < 8) {
if (opt.data) data.unshift(opt.data)
opt.data = data.join('\n')
} else {
if (opt.prependData) data.unshift(opt.prependData)
opt.prependData = data.join('\n')
}
return opt
}
module.exports = {
addImport,
addImports,
fileExists,
mergeRules,
}