87 lines
3.0 KiB
JavaScript
87 lines
3.0 KiB
JavaScript
const Color = require('color'),
|
|
path = require('path'),
|
|
{ version } = require('../package.json');
|
|
|
|
const getPackageName = theme => `themer-hyper-${theme}`;
|
|
const getFilePath = (theme, filename) => path.join(getPackageName(theme), filename);
|
|
const getIndexFilePath = theme => getFilePath(theme, 'index.js');
|
|
|
|
const render = (colors) => {
|
|
const colorSets = Object.entries(colors).map(([theme, colors]) => ({ theme: theme, colors: colors }));
|
|
return [
|
|
...renderPackageJsonFiles(colorSets),
|
|
...renderIndexFiles(colorSets),
|
|
];
|
|
};
|
|
|
|
const renderPackageJsonFiles = colorSets => colorSets.map(colorSet => Promise.resolve({
|
|
name: getFilePath(colorSet.theme, 'package.json'),
|
|
contents: Buffer.from(JSON.stringify({
|
|
name: getPackageName(colorSet.theme),
|
|
version,
|
|
description: `${colorSet.theme} theme for Hyper.app, generated by themer`,
|
|
keywords: [
|
|
'themer',
|
|
colorSet.theme,
|
|
'hyper',
|
|
],
|
|
main: getIndexFilePath(colorSet.theme),
|
|
}, null, 2)),
|
|
}));
|
|
|
|
const renderIndexFiles = colorSets => colorSets.map(colorSet => Promise.resolve({
|
|
name: getIndexFilePath(colorSet.theme),
|
|
contents: Buffer.from(`
|
|
module.exports.decorateConfig = config => {
|
|
return Object.assign({}, config, {
|
|
cursorColor: '${Color(colorSet.colors.accent6).fade(0.5).rgb().string()}',
|
|
cursorAccentColor: '${colorSet.colors.shade0}',
|
|
foregroundColor: '${colorSet.colors.shade6}',
|
|
backgroundColor: '${colorSet.colors.shade0}',
|
|
selectionColor: '${Color(colorSet.colors.accent5).fade(0.9).rgb().string()}',
|
|
borderColor: '${colorSet.colors.accent4}',
|
|
colors: {
|
|
black: '${colorSet.colors.shade0}',
|
|
red: '${colorSet.colors.accent0}',
|
|
green: '${colorSet.colors.accent3}',
|
|
yellow: '${colorSet.colors.accent2}',
|
|
blue: '${colorSet.colors.accent5}',
|
|
magenta: '${colorSet.colors.accent7}',
|
|
cyan: '${colorSet.colors.accent4}',
|
|
white: '${colorSet.colors.shade6}',
|
|
lightBlack: '${colorSet.colors.shade1}',
|
|
lightRed: '${colorSet.colors.accent1}',
|
|
lightGreen: '${colorSet.colors.accent3}',
|
|
lightYellow: '${colorSet.colors.accent2}',
|
|
lightBlue: '${colorSet.colors.accent5}',
|
|
lightMagenta: '${colorSet.colors.accent7}',
|
|
lightCyan: '${colorSet.colors.accent4}',
|
|
lightWhite: '${colorSet.colors.shade7}',
|
|
},
|
|
});
|
|
};
|
|
`),
|
|
}));
|
|
|
|
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 -R '${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,
|
|
};
|