This repository has been archived by the owner on Apr 29, 2022. It is now read-only.
forked from dracula/visual-studio-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
48 lines (40 loc) · 1.33 KB
/
build.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
const fs = require('fs');
const path = require('path');
const tinycolor = require('tinycolor2');
const yaml = require('js-yaml');
const THEME_DIR = path.join(__dirname, 'theme');
const THEME_YAML_FILE = path.join(__dirname, 'src', 'golden-dracula.yml');
if (!fs.existsSync(THEME_DIR)) {
fs.mkdirSync(THEME_DIR);
}
const withAlphaType = new yaml.Type('!alpha', {
kind: 'sequence',
construct: data => {
return data[0] + data[1];
},
represent: data => {
return [data[0], data[1]];
},
});
const schema = yaml.Schema.create([withAlphaType]);
const standard = fs.readFileSync(THEME_YAML_FILE, 'utf8');
yamlObj = yaml.load(standard, { schema });
yamlObj.colors = Object.keys(yamlObj.colors).reduce((obj, key) => {
if (yamlObj.colors[key] === null) {
return obj;
}
return Object.assign({}, obj, { [key]: yamlObj.colors[key] });
}, {});
const brightColors = [...yamlObj.dracula.ansi, ...yamlObj.dracula.brightOther];
const soft = standard.replace(/'(#[0-9A-Z]{6})/g, (match, hex) => {
if (brightColors.indexOf(hex) > -1) {
return `'${tinycolor(hex)
.desaturate(20)
.toHexString()}`;
}
return `'${tinycolor(hex).toHexString()}`;
});
fs.writeFileSync(
path.join(THEME_DIR, 'golden-dracula.json'),
JSON.stringify(yaml.load(standard, { schema }), null, 4)
);