forked from dracula/visual-studio-code
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor build script and improve lint script (dracula#90)
* Refactor build script and read theme from source * Fix 'soft' typo * Reduce complexity at getSoftThemeYAML function * Fix imports order. Remove catch from build
- Loading branch information
1 parent
afa9d81
commit bf3c10d
Showing
7 changed files
with
100 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const fsp = require('./fsp'); | ||
const loadThemes = require('./loadThemes'); | ||
|
||
const THEME_DIR = path.join(__dirname, '..', 'theme'); | ||
const THEME_YAML_FILE = path.join(__dirname, '..', 'src', 'dracula.yml'); | ||
|
||
function toJSON(theme) { | ||
return JSON.stringify(theme, null, 4); | ||
} | ||
|
||
(async () => { | ||
if (!(await fsp.exists(THEME_DIR))) { | ||
await fsp.mkdir(THEME_DIR); | ||
} | ||
|
||
const { standardTheme, softTheme } = await loadThemes(THEME_YAML_FILE); | ||
const standardThemePath = path.join(THEME_DIR, 'dracula.json'); | ||
const softThemePath = path.join(THEME_DIR, 'dracula-soft.json'); | ||
|
||
await Promise.all([ | ||
fsp.writeFile(standardThemePath, toJSON(standardTheme)), | ||
fsp.writeFile(softThemePath, toJSON(softTheme)), | ||
]); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const util = require('util'); | ||
|
||
module.exports = { | ||
exists: util.promisify(fs.exists), | ||
mkdir: util.promisify(fs.mkdir), | ||
readFile: util.promisify(fs.readFile), | ||
writeFile: util.promisify(fs.writeFile), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
const tinycolor = require('tinycolor2'); | ||
const fsp = require('./fsp'); | ||
const { loadYAML } = require('./yaml'); | ||
|
||
async function loadTheme(yamlFilePath) { | ||
const standardThemeYAML = await fsp.readFile(yamlFilePath, 'utf8'); | ||
const standardTheme = await loadYAML(standardThemeYAML); | ||
|
||
const softThemeYAML = getSoftThemeYAML(standardThemeYAML, standardTheme); | ||
const softTheme = await loadYAML(softThemeYAML); | ||
|
||
return { standardTheme, softTheme }; | ||
} | ||
|
||
function getSoftThemeYAML(fileContent, standardTheme) { | ||
const brightColors = [ | ||
...standardTheme.dracula.ansi, | ||
...standardTheme.dracula.brightOther, | ||
]; | ||
|
||
return fileContent.replace(/#[0-9A-F]{6}/g, color => { | ||
if (brightColors.includes(color)) { | ||
return tinycolor(color) | ||
.desaturate(20) | ||
.toHexString(); | ||
} | ||
return color; | ||
}); | ||
} | ||
|
||
module.exports = loadTheme; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
const { Type, Schema, load } = require('js-yaml'); | ||
|
||
const withAlphaType = new Type('!alpha', { | ||
kind: 'sequence', | ||
construct: ([hexRGB, alpha]) => hexRGB + alpha, | ||
represent: ([hexRGB, alpha]) => hexRGB + alpha, | ||
}); | ||
|
||
const schema = Schema.create([withAlphaType]); | ||
|
||
async function loadYAML(file) { | ||
return load(file, { schema }); | ||
} | ||
|
||
module.exports = { | ||
loadYAML, | ||
}; |