Add APIs for path separator and README header

This commit is contained in:
Matt Swensen 2020-03-21 08:09:15 -06:00
parent 08cb1b72e4
commit 6ffcbeb354
No known key found for this signature in database
GPG Key ID: 3F9E482BFC526F35
3 changed files with 20 additions and 5 deletions

@ -47,7 +47,13 @@ const path = require('path'),
),
);
console.log('rendering templates...');
const outputs = await themer(colors, templates, args);
const outputs = await themer(
colors,
templates,
args,
path.sep,
'# themer - theme installation instructions',
);
console.log('writing files...');
for (const output of outputs) {
const outputFilePath = path.resolve(args.out, output.name);

@ -1,11 +1,17 @@
module.exports = async function themer (colors, templates, extraArgs) {
module.exports = async function themer(
colors,
templates,
extraArgs,
pathSeparator,
instructionsHead,
) {
const files = [];
const instructions = [];
for (const template of templates) {
const outputs = (await Promise.all(template.render(colors, extraArgs)))
.map(file => ({
...file,
name: `${template.name}/${file.name}`,
name: `${template.name}${pathSeparator}${file.name}`,
}));
files.push(...outputs);
if (template.renderInstructions) {
@ -18,7 +24,7 @@ module.exports = async function themer (colors, templates, extraArgs) {
files.push({
name: 'README.md',
contents: Buffer.from(
`# themer - theme installation instructions\n\n${instructions.join('\n\n')}`,
`${instructionsHead}\n\n${instructions.join('\n\n')}`,
'utf8'
)
})

@ -1,4 +1,5 @@
const themer = require('./themer');
const themer = require('./themer'),
path = require('path');
describe('themer core', () => {
it('should produce a list of files from colors + templates', async () => {
@ -34,6 +35,8 @@ describe('themer core', () => {
},
],
{},
path.sep,
'# test',
);
expect(outputs.length).toBe(2);
});