Implement Windows Terminal theme generator

This commit is contained in:
Matt Swensen 2020-05-07 06:57:36 -06:00
parent 615946af9a
commit e8e0980307
No known key found for this signature in database
GPG Key ID: 3F9E482BFC526F35
7 changed files with 237 additions and 0 deletions

@ -0,0 +1,2 @@
node_modules
LICENSE.md

@ -0,0 +1,2 @@
version-tag-prefix "@themer/windows-terminal-v"
version-git-message "@themer/windows-terminal-v%s"

@ -0,0 +1,15 @@
# @themer/windows-terminal
A [Windows Terminal](https://github.com/microsoft/terminal) template for [themer](https://github.com/mjswensen/themer).
## Installation & usage
Install this module wherever you have `themer` installed:
npm install @themer/windows-terminal
Then pass `@themer/windows-terminal` as a `-t` (`--template`) arg to `themer`:
themer -c my-colors.js -t @themer/windows-terminal -o gen
Installation instructions for the generated theme(s) will be included in `<output dir>/README.md`.

@ -0,0 +1,79 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`themer Windows Terminal theme generator should generate well-formatted themes 1`] = `
"{
\\"name\\": \\"Themer Dark\\",
\\"background\\": \\"#282629\\",
\\"foreground\\": \\"#E0DCE0\\",
\\"cursorColor\\": \\"#CC78FA\\",
\\"selectionBackground\\": \\"#66BFFF\\",
\\"black\\": \\"#656066\\",
\\"brightBlack\\": \\"#847E85\\",
\\"red\\": \\"#FF4050\\",
\\"brightRed\\": \\"#FF6673\\",
\\"green\\": \\"#A4CC35\\",
\\"brightGreen\\": \\"#B6D65D\\",
\\"brightYellow\\": \\"#FFDA6E\\",
\\"blue\\": \\"#66BFFF\\",
\\"brightBlue\\": \\"#85CBFF\\",
\\"purple\\": \\"#CC78FA\\",
\\"brightPurple\\": \\"#D692FB\\",
\\"cyan\\": \\"#26C99E\\",
\\"brightCyan\\": \\"#51D3B1\\",
\\"white\\": \\"#E0DCE0\\",
\\"brightWhite\\": \\"#FFFCFF\\"
}"
`;
exports[`themer Windows Terminal theme generator should generate well-formatted themes 2`] = `
"{
\\"name\\": \\"Themer Light\\",
\\"background\\": \\"#FFFCFF\\",
\\"foreground\\": \\"#474247\\",
\\"cursorColor\\": \\"#BF65F0\\",
\\"selectionBackground\\": \\"#53A6E1\\",
\\"black\\": \\"#474247\\",
\\"brightBlack\\": \\"#656066\\",
\\"red\\": \\"#F03E4D\\",
\\"brightRed\\": \\"#F36471\\",
\\"green\\": \\"#97BD2D\\",
\\"brightGreen\\": \\"#ACCA57\\",
\\"brightYellow\\": \\"#F1C74D\\",
\\"blue\\": \\"#53A6E1\\",
\\"brightBlue\\": \\"#75B7E7\\",
\\"purple\\": \\"#BF65F0\\",
\\"brightPurple\\": \\"#CC83F3\\",
\\"cyan\\": \\"#1FC598\\",
\\"brightCyan\\": \\"#4CD0AD\\",
\\"white\\": \\"#C1BCC2\\",
\\"brightWhite\\": \\"#E0DCE0\\"
}"
`;
exports[`themer Windows Terminal theme generator should provide installation instructions 1`] = `
"
1. Open the Windows Terminal settings (\`Ctrl\`-\`,\`)
2. Add the contents of 'themer-dark.json' and 'themer-light.json' to the \`schemes\` array in \`profile.json\`
3. Set the \`colorScheme\` property to the desired scheme name (\\"Themer Dark\\" or \\"Themer Light\\") in the profiles section of \`profile.json\`, e.g.:
\\"profiles\\": {
\\"defaults\\": {
\\"colorScheme\\": \\"Themer Dark\\"
}
}
"
`;
exports[`themer Windows Terminal theme generator should provide installation instructions 2`] = `
"
1. Open the Windows Terminal settings (\`Ctrl\`-\`,\`)
2. Add the contents of 'themer-light.json' to the \`schemes\` array in \`profile.json\`
3. Set the \`colorScheme\` property to the desired scheme name (\\"Themer Light\\") in the profiles section of \`profile.json\`, e.g.:
\\"profiles\\": {
\\"defaults\\": {
\\"colorScheme\\": \\"Themer Light\\"
}
}
"
`;

@ -0,0 +1,82 @@
const path = require('path'),
Color = require('color');
const MIX = 0.2;
const brightMix = (colors, key, isDark) =>
Color(colors[key])
.mix(isDark ? Color(colors.shade7) : Color(colors.shade0), MIX)
.hex();
const renderTheme = ([firstLetter, ...letters], colors, isDark) => JSON.stringify(
{
name: `Themer ${[firstLetter.toUpperCase(), ...letters].join('')}`,
background: colors.shade0,
foreground: colors.shade6,
cursorColor: colors.accent6,
selectionBackground: colors.accent5,
black: isDark ? colors.shade2 : colors.shade6,
brightBlack: isDark ? colors.shade3 : colors.shade5,
red: colors.accent0,
brightRed: brightMix(colors, 'accent0', isDark),
green: colors.accent3,
brightGreen: brightMix(colors, 'accent3', isDark),
yellow: colors.accen2,
brightYellow: brightMix(colors, 'accent2', isDark),
blue: colors.accent5,
brightBlue: brightMix(colors, 'accent5', isDark),
purple: colors.accent6,
brightPurple: brightMix(colors, 'accent6', isDark),
cyan: colors.accent4,
brightCyan: brightMix(colors, 'accent4', isDark),
white: isDark ? colors.shade6 : colors.shade2,
brightWhite: isDark ? colors.shade7 : colors.shade1,
},
null,
2,
);
const render = colors => Object.entries(colors)
.map(async ([name, colors]) => ({
name: `themer-${name}.json`,
contents: Buffer.from(renderTheme(name, colors, name === 'dark')),
}));
const pathsToThemeNames = paths =>
paths
.map(p => path.basename(p, '.json'))
.map(basename =>
basename
.split('-')
.map(([firstLetter, ...tail]) =>
[firstLetter.toUpperCase(), ...tail].join(''),
)
.join(' '),
);
const renderInstructions = paths => `
1. Open the Windows Terminal settings (\`Ctrl\`-\`,\`)
2. Add the contents of ${paths.map(p => `'${p}'`).join(' and ')} to the \`schemes\` array in \`profile.json\`
3. Set the \`colorScheme\` property to the desired scheme name (${pathsToThemeNames(paths).map(name => `"${name}"`).join(' or ')}) in the profiles section of \`profile.json\`, e.g.:
"profiles": {
"defaults": {
"colorScheme": "${pathsToThemeNames(paths)[0]}"
}
}
`;
module.exports = {
render,
renderInstructions,
};

@ -0,0 +1,22 @@
const { render, renderInstructions } = require('./index');
const { colors } = require('../../colors-default');
describe('themer Windows Terminal theme generator', () => {
const promisedFiles = Promise.all(render(colors));
it('should generate well-formatted themes', async () => {
const files = await promisedFiles;
for (const file of files) {
expect(file.contents.toString('utf8')).toMatchSnapshot();
}
});
it('should provide installation instructions', async () => {
const files = await promisedFiles;
const instructions = renderInstructions(files.map(({ name }) => name));
expect(instructions).toMatchSnapshot();
const singleThemeInstructions = renderInstructions([files[1].name]);
expect(singleThemeInstructions).toMatchSnapshot();
});
});

@ -0,0 +1,35 @@
{
"name": "@themer/windows-terminal",
"version": "1.0.0",
"description": "TODO",
"main": "lib/index.js",
"engines": {
"node": ">=8.11.4"
},
"scripts": {
"prepublishOnly": "cp ../../../LICENSE.md ./"
},
"author": "mjswensen",
"license": "MIT",
"files": [
"/lib/index.js"
],
"repository": {
"type": "git",
"url": "git+https://github.com/mjswensen/themer.git"
},
"bugs": {
"url": "https://github.com/mjswensen/themer/issues"
},
"homepage": "https://github.com/mjswensen/themer/tree/master/cli/packages/windows-terminal#readme",
"peerDependencies": {
"themer": "^3"
},
"keywords": [
"themer",
"windows terminal"
],
"dependencies": {
"color": "^3.1.2"
}
}