Add APIs for path separator and README header
This commit is contained in:
parent
08cb1b72e4
commit
6ffcbeb354
@ -47,7 +47,13 @@ const path = require('path'),
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
console.log('rendering templates...');
|
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...');
|
console.log('writing files...');
|
||||||
for (const output of outputs) {
|
for (const output of outputs) {
|
||||||
const outputFilePath = path.resolve(args.out, output.name);
|
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 files = [];
|
||||||
const instructions = [];
|
const instructions = [];
|
||||||
for (const template of templates) {
|
for (const template of templates) {
|
||||||
const outputs = (await Promise.all(template.render(colors, extraArgs)))
|
const outputs = (await Promise.all(template.render(colors, extraArgs)))
|
||||||
.map(file => ({
|
.map(file => ({
|
||||||
...file,
|
...file,
|
||||||
name: `${template.name}/${file.name}`,
|
name: `${template.name}${pathSeparator}${file.name}`,
|
||||||
}));
|
}));
|
||||||
files.push(...outputs);
|
files.push(...outputs);
|
||||||
if (template.renderInstructions) {
|
if (template.renderInstructions) {
|
||||||
@ -18,7 +24,7 @@ module.exports = async function themer (colors, templates, extraArgs) {
|
|||||||
files.push({
|
files.push({
|
||||||
name: 'README.md',
|
name: 'README.md',
|
||||||
contents: Buffer.from(
|
contents: Buffer.from(
|
||||||
`# themer - theme installation instructions\n\n${instructions.join('\n\n')}`,
|
`${instructionsHead}\n\n${instructions.join('\n\n')}`,
|
||||||
'utf8'
|
'utf8'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
const themer = require('./themer');
|
const themer = require('./themer'),
|
||||||
|
path = require('path');
|
||||||
|
|
||||||
describe('themer core', () => {
|
describe('themer core', () => {
|
||||||
it('should produce a list of files from colors + templates', async () => {
|
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);
|
expect(outputs.length).toBe(2);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user