forked from primer/github-syntax-theme-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codemirror.js
37 lines (31 loc) · 1.11 KB
/
codemirror.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
const mkdirp = require("mkdirp")
const fs = require("fs")
const sass = require("node-sass")
const utils = require("../utils")
module.exports = (theme) => {
mkdirp.sync(`build/codemirror`)
let template = fs.readFileSync("./lib/templates/codemirror.scss").toString()
let output = utils.header(theme)
template = template.replace(new RegExp("\\${theme}", "g"), theme.filename)
theme.settings.forEach((setting) => {
const settings = setting.settings
const scope = setting.scope
// Editor settings
if (!scope) {
Object.keys(settings).forEach((key) => {
template = template.replace(new RegExp("\\${" + key + "}", "g"), settings[key])
})
output += template
} else {
const singleScope = scope.split(", ")[0]
if (singleScope && !singleScope.match(/[\.\s\-]/)) {
output += `\n.cm-s-${theme.filename} .cm-${singleScope} { ${utils.declarations(settings)} }`
}
}
})
const result = sass.renderSync({
data: output,
includePaths: ["./node_modules"]
})
fs.writeFileSync(`./build/codemirror/codemirror-${theme.filename}-theme.css`, result.css)
}