awesome-docker/build.js

52 lines
1.3 KiB
Markdown
Raw Normal View History

2018-07-21 09:12:59 -04:00
const fs = require('fs-extra');
2018-03-17 11:27:41 -04:00
const cheerio = require('cheerio');
2018-07-21 09:12:59 -04:00
const showdown = require('showdown');
2018-03-17 11:27:41 -04:00
process.env.NODE_ENV = 'production';
2018-07-21 09:12:59 -04:00
const LOG = {
error: (...args) => console.error('❌ ERROR', { ...args }),
debug: (...args) => {
if (process.env.DEBUG) console.log('💡 DEBUG: ', { ...args });
},
};
2020-04-13 10:15:18 -04:00
const handleFailure = (err) => {
2018-07-21 09:12:59 -04:00
LOG.error(err);
process.exit(1);
};
process.on('unhandledRejection', handleFailure);
// --- FILES
const README = 'README.md';
const WEBSITE_FOLDER = 'website';
const indexTemplate = `${WEBSITE_FOLDER}/index.tmpl.html`;
const indexDestination = `${WEBSITE_FOLDER}/index.html`;
async function processIndex() {
2020-04-13 12:12:42 -04:00
const converter = new showdown.Converter();
converter.setFlavor('github');
2018-03-18 09:37:19 -04:00
2018-07-21 09:12:59 -04:00
try {
LOG.debug('Loading files...', { indexTemplate, README });
const template = await fs.readFile(indexTemplate, 'utf8');
const markdown = await fs.readFile(README, 'utf8');
2018-03-18 09:37:19 -04:00
2018-07-21 09:12:59 -04:00
LOG.debug('Merging files...');
const $ = cheerio.load(template);
$('#md').append(converter.makeHtml(markdown));
2018-03-18 09:37:19 -04:00
2018-07-21 09:12:59 -04:00
LOG.debug('Writing index.html');
await fs.outputFile(indexDestination, $.html(), 'utf8');
LOG.debug('DONE 👍');
} catch (err) {
handleFailure(err);
}
}
2018-03-18 10:01:47 -04:00
2018-07-21 09:12:59 -04:00
async function main() {
await processIndex();
}
2018-03-18 09:37:19 -04:00
main();