Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow themes to copy assets to the output directory #387

Merged
merged 1 commit into from
Apr 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 21 additions & 9 deletions bin/raml2html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

'use strict';

const yargs = require('yargs');
const fs = require('fs');
const yargs = require('yargs');
const raml2html = require('..');
const pjson = require('../package.json');

Expand Down Expand Up @@ -56,19 +56,31 @@ if (argv.template) {
config = raml2html.getConfigForTheme(argv.theme, argv);
}

// Start the rendering process
raml2html
.render(input, config, argv)
.then(result => {
function writeOutput(result, config, argv) {
return new Promise((resolve, reject) => {
if (argv.output) {
fs.writeFileSync(argv.output, result);
fs.writeFile(argv.output, result, err => {
if (err) {
reject(err);
} else {
resolve();
}
});
} else {
// Simply output to console
process.stdout.write(result, () => {
process.exit(0);
});
process.stdout.write(result);
resolve();
}
});
}

// Start the rendering process
raml2html
.render(input, config, argv)
.then(result => {
return (config.writeOutput || writeOutput)(result, config, argv);
})
.then(() => process.exit(0))
.catch(error => {
if (error.message) {
console.error(error.message);
Expand Down