Implement renderInstructions for themer-sketch-palettes

This commit is contained in:
Matt Swensen 2020-03-13 07:16:09 -06:00
parent cf843d63c4
commit 321ebbc50c
No known key found for this signature in database
GPG Key ID: 3F9E482BFC526F35
4 changed files with 25 additions and 4 deletions

@ -12,6 +12,4 @@ Then pass `themer-sketch-palettes` as a `-t` (`--template`) arg to `themer`:
themer -c my-colors.js -t themer-sketch-palettes -o gen
## Output
`themer-sketch-palettes` will generate a `themer-sketch-palettes-dark.sketchpalette` / `themer-sketch-palettes-light.sketchpalette` (or both) in your output directory, which may then be loaded into Sketch through the [sketch-palettes](https://github.com/andrewfiorillo/sketch-palettes) plugin.
Installation instructions for the generated theme file(s) will be included in `<output dir>/README.md`.

@ -3,3 +3,12 @@
exports[`render should render properly formatted .sketchpalette files 1`] = `"{\\"compatibleVersion\\":\\"2.0\\",\\"pluginVersion\\":\\"2.13\\",\\"colors\\":[{\\"red\\":1,\\"green\\":0.25098039215686274,\\"blue\\":0.3137254901960784,\\"alpha\\":1},{\\"red\\":0.9490196078431372,\\"green\\":0.5058823529411764,\\"blue\\":0.26666666666666666,\\"alpha\\":1},{\\"red\\":1,\\"green\\":0.8235294117647058,\\"blue\\":0.2901960784313726,\\"alpha\\":1},{\\"red\\":0.6431372549019608,\\"green\\":0.8,\\"blue\\":0.20784313725490197,\\"alpha\\":1},{\\"red\\":0.14901960784313725,\\"green\\":0.788235294117647,\\"blue\\":0.6196078431372549,\\"alpha\\":1},{\\"red\\":0.4,\\"green\\":0.7490196078431373,\\"blue\\":1,\\"alpha\\":1},{\\"red\\":0.8,\\"green\\":0.47058823529411764,\\"blue\\":0.9803921568627451,\\"alpha\\":1},{\\"red\\":0.9607843137254902,\\"green\\":0.3254901960784314,\\"blue\\":0.7490196078431373,\\"alpha\\":1},{\\"red\\":0.1568627450980392,\\"green\\":0.14901960784313725,\\"blue\\":0.1607843137254902,\\"alpha\\":1},{\\"red\\":0.2784313725490196,\\"green\\":0.25882352941176473,\\"blue\\":0.2784313725490196,\\"alpha\\":1},{\\"red\\":0.396078431372549,\\"green\\":0.3764705882352941,\\"blue\\":0.4,\\"alpha\\":1},{\\"red\\":0.5176470588235295,\\"green\\":0.49411764705882355,\\"blue\\":0.5215686274509804,\\"alpha\\":1},{\\"red\\":0.6352941176470588,\\"green\\":0.615686274509804,\\"blue\\":0.6392156862745098,\\"alpha\\":1},{\\"red\\":0.7568627450980392,\\"green\\":0.7372549019607844,\\"blue\\":0.7607843137254902,\\"alpha\\":1},{\\"red\\":0.8784313725490196,\\"green\\":0.8627450980392157,\\"blue\\":0.8784313725490196,\\"alpha\\":1},{\\"red\\":1,\\"green\\":0.9882352941176471,\\"blue\\":1,\\"alpha\\":1}],\\"gradients\\":[],\\"images\\":[]}"`;
exports[`render should render properly formatted .sketchpalette files 2`] = `"{\\"compatibleVersion\\":\\"2.0\\",\\"pluginVersion\\":\\"2.13\\",\\"colors\\":[{\\"red\\":0.9411764705882353,\\"green\\":0.24313725490196078,\\"blue\\":0.30196078431372547,\\"alpha\\":1},{\\"red\\":0.9529411764705882,\\"green\\":0.4666666666666667,\\"blue\\":0.20784313725490197,\\"alpha\\":1},{\\"red\\":0.9333333333333333,\\"green\\":0.7294117647058823,\\"blue\\":0.12941176470588237,\\"alpha\\":1},{\\"red\\":0.592156862745098,\\"green\\":0.7411764705882353,\\"blue\\":0.17647058823529413,\\"alpha\\":1},{\\"red\\":0.12156862745098039,\\"green\\":0.7725490196078432,\\"blue\\":0.596078431372549,\\"alpha\\":1},{\\"red\\":0.3254901960784314,\\"green\\":0.6509803921568628,\\"blue\\":0.8823529411764706,\\"alpha\\":1},{\\"red\\":0.7490196078431373,\\"green\\":0.396078431372549,\\"blue\\":0.9411764705882353,\\"alpha\\":1},{\\"red\\":0.9333333333333333,\\"green\\":0.3058823529411765,\\"blue\\":0.7215686274509804,\\"alpha\\":1},{\\"red\\":1,\\"green\\":0.9882352941176471,\\"blue\\":1,\\"alpha\\":1},{\\"red\\":0.8784313725490196,\\"green\\":0.8627450980392157,\\"blue\\":0.8784313725490196,\\"alpha\\":1},{\\"red\\":0.7568627450980392,\\"green\\":0.7372549019607844,\\"blue\\":0.7607843137254902,\\"alpha\\":1},{\\"red\\":0.6352941176470588,\\"green\\":0.615686274509804,\\"blue\\":0.6392156862745098,\\"alpha\\":1},{\\"red\\":0.5176470588235295,\\"green\\":0.49411764705882355,\\"blue\\":0.5215686274509804,\\"alpha\\":1},{\\"red\\":0.396078431372549,\\"green\\":0.3764705882352941,\\"blue\\":0.4,\\"alpha\\":1},{\\"red\\":0.2784313725490196,\\"green\\":0.25882352941176473,\\"blue\\":0.2784313725490196,\\"alpha\\":1},{\\"red\\":0.1568627450980392,\\"green\\":0.14901960784313725,\\"blue\\":0.1607843137254902,\\"alpha\\":1}],\\"gradients\\":[],\\"images\\":[]}"`;
exports[`renderInstructions should provide installation instructions 1`] = `
"
Load the generated theme files into Sketch through the [sketch-palettes](https://github.com/andrewfiorillo/sketch-palettes) plugin.
* \`themer-sketch-palettes-dark.sketchpalette\`
* \`themer-sketch-palettes-light.sketchpalette\`
"
`;

@ -21,3 +21,9 @@ module.exports.render = colors =>
),
})
);
module.exports.renderInstructions = paths => `
Load the generated theme ${paths.length > 1 ? 'files' : 'file'} into Sketch through the [sketch-palettes](https://github.com/andrewfiorillo/sketch-palettes) plugin.
${paths.map(p => `* \`${p}\``).join('\n')}
`;

@ -1,4 +1,4 @@
const { render } = require('./index');
const { render, renderInstructions } = require('./index');
const { colors } = require('../../themer-colors-default');
describe('render', () => {
@ -12,3 +12,11 @@ describe('render', () => {
});
});
});
describe('renderInstructions', () => {
it('should provide installation instructions', async () => {
const files = await Promise.all(render(colors));
const instructions = renderInstructions(files.map(({ name }) => name));
expect(instructions).toMatchSnapshot();
});
})