Implement renderInstructions in themer-hyper

This commit is contained in:
Matt Swensen 2020-03-10 06:40:31 -06:00
parent e5a31ef886
commit 467ae4c600
No known key found for this signature in database
GPG Key ID: 3F9E482BFC526F35
4 changed files with 43 additions and 16 deletions

@ -12,18 +12,4 @@ Then pass `themer-hyper` as a `-t` (`--template`) arg to `themer`:
themer -c my-colors.js -t themer-hyper -o gen
## Output
`themer-hyper` will generate a `themer-hyper-dark/` or `themer-hyper-light/` directory (or both), depending on which color set you passed to `themer`, which will contain the files for a Hyper theme plugin package.
To install your generated plugin, first symlink the outputted package directory to the Hyper local plugins directory:
ln -s <full path to themer output directory>/themer-hyper/themer-hyper-dark ~/.hyper_plugins/local/
Finally, edit `~/.hyper.js` and add the package to the `localPlugins` array:
...
localPlugins: [
'themer-hyper-dark'
],
...
Installation instructions for the generated theme(s) will be included in `<output dir>/README.md`.

@ -1,5 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Hyper.app theme generator should provide installation instructions 1`] = `
"
First, copy (or symlink) the outputted package directories to the Hyper local plugins directory:
cp themer-hyper-dark ~/.hyper_plugins/local/
cp themer-hyper-light ~/.hyper_plugins/local/
Then edit \`~/.hyper.js\` and add the package to the \`localPlugins\` array:
...
localPlugins: [
'themer-hyper-dark' // or 'themer-hyper-light'
],
...
"
`;
exports[`Hyper.app theme generator should render valid JSON to package.json files 1`] = `
Object {
"description": "dark theme for Hyper.app, generated by themer",

@ -63,6 +63,24 @@ const renderIndexFiles = colorSets => colorSets.map(colorSet => Promise.resolve(
`),
}));
const renderInstructions = paths => {
const directories = [...(new Set(paths.map(path.dirname)))];
return `
First, copy (or symlink) the outputted package ${directories.length > 1 ? 'directories' : 'directory'} to the Hyper local plugins directory:
${directories.map(dir => ` cp ${dir} ~/.hyper_plugins/local/`).join('\n')}
Then edit \`~/.hyper.js\` and add the package to the \`localPlugins\` array:
...
localPlugins: [
${directories.map(dir => dir.split(path.sep)).map(dirs => dirs[dirs.length - 1]).map(dir => `'${dir}'`).join(' // or ')}
],
...
`;
}
module.exports = {
render,
renderInstructions,
};

@ -1,4 +1,4 @@
const { render } = require('./index'),
const { render, renderInstructions } = require('./index'),
{ colors } = require('../../themer-colors-default'),
path = require('path');
@ -35,4 +35,10 @@ describe('Hyper.app theme generator', () => {
files.forEach(file => expect(file.contents).toBeInstanceOf(Buffer));
});
it('should provide installation instructions', async () => {
const files = await Promise.all(render(colors));
const instructions = renderInstructions(files.map(({ name }) => name));
expect(instructions).toMatchSnapshot();
});
});