-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathgen-vars.js
More file actions
33 lines (28 loc) · 1020 Bytes
/
gen-vars.js
File metadata and controls
33 lines (28 loc) · 1020 Bytes
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
const path = require('path')
const fs = require('fs')
const ora = require('ora')
const config = require('./config')
const varsPath = path.resolve(config.themePath, './src/common/var.scss')
const varsStorePath = path.resolve(config.themePath, './src/common/var-store.scss')
exports.check = function () {
if (!fs.existsSync(varsPath)) {
ora('please install `' + config.themeName + '`').fail()
process.exit(1)
}
}
exports.init = function (_file) {
const spinner = ora('Generator variables file').start()
const filePath = path.resolve(process.cwd(), _file ? _file : config.config)
if (fs.existsSync(filePath)) {
spinner.text = 'Variables file already exists.'
spinner.fail()
} else {
// Some exceptions may cause the compilation to fail to recover normally
if (fs.existsSync(varsStorePath)) {
fs.writeFileSync(filePath, fs.readFileSync(varsStorePath), 'utf-8')
} else {
fs.writeFileSync(filePath, fs.readFileSync(varsPath), 'utf-8')
}
spinner.succeed()
}
}