From d2b8b355fb5e304dd40dc03cad8b2e48e24adf87 Mon Sep 17 00:00:00 2001 From: Bucko Date: Tue, 3 Oct 2017 12:26:08 -0700 Subject: [PATCH] cleanup for PR and add more code documentation --- guide-generator.js | 21 +- guides-old.html | 484 --------------------------------------- guides/test.html | 405 -------------------------------- utils/createHTML.js | 11 +- utils/generateArchive.js | 14 +- utils/generatePages.js | 6 +- utils/helpers.js | 12 +- 7 files changed, 40 insertions(+), 913 deletions(-) delete mode 100644 guides-old.html delete mode 100644 guides/test.html diff --git a/guide-generator.js b/guide-generator.js index c490c3c..433d9fc 100644 --- a/guide-generator.js +++ b/guide-generator.js @@ -41,13 +41,14 @@ if ( args.indexOf('--help') > -1 || args.length === 0 ) { } generatePages(markdownDir, all, __dirname) - .then(() => { - console.log('Writing guides archive...'); - return generateArchive('guides', __dirname); - }) - .then((guidesArchive) => { - fs.writeFileSync('guides.html', guidesArchive); - console.log('Guides archive done'); - }) - .then(() => console.log('All files done!')) - .catch(e => console.log('There was a problem: ', e)); +.then((files) => { + console.log('Finished generating files: ', files); + console.log('Writing guides archive...'); + return generateArchive('guides', __dirname); +}) +.then((guidesArchive) => { + fs.writeFileSync('guides.html', guidesArchive); + console.log('Guides archive done'); +}) +.then(() => console.log('All files done!')) +.catch(e => console.log('There was a problem: ', e)); diff --git a/guides-old.html b/guides-old.html deleted file mode 100644 index bb2e963..0000000 --- a/guides-old.html +++ /dev/null @@ -1,484 +0,0 @@ - - - - - - - - - bcoin | Extending Bitcoin into Enterprise & Production - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
Loading... - - - - - - - - - - - - - - - - - - - - - - -
-
- - - -
-
- - - - - - - -
- -
- - - - -
-
- - - -
- - -
-
- -
-
- -

 Guides  and  Videos 

- -
-
- -
-
- - - -
-
- -
- - - - - - -
-
-
OS Installs
- - - - - -
-
Guides
- - -
-
-
- -
-
-

Generate a Bitcoin Address

- -

Follow along with the steps to build a transaction from scratch using built-in bcoin utilities. These steps are based on those outlined in the Bitcoin Wiki.

- Start › -
-
-
-
- - -
-
-
- -
-
-

Intro to Scripting

- -

Scripts are array-like objects with some helper functions. Learn the basics here.

- Start › -
-
-
-
- - -
-
-
- -
-
-

Create an OP_RETURN

- -

This example creates a transaction with output containing a null data script with our data.

- Start › -
-
-
-
- - -
- - -
- -
-
- - -
- - - - - - -
-
- -
-
-
-

Ready to start building? Read the docs!

- Documentation -
-
-
- -
-
- - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/guides/test.html b/guides/test.html deleted file mode 100644 index f68d94d..0000000 --- a/guides/test.html +++ /dev/null @@ -1,405 +0,0 @@ - - - - - - - - - bcoin | Extending Bitcoin into Enterprise & Production - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
Loading... - - - - - - - - - - - - - - - - - - - - - - -
-
- - - -
-
- - - - - - - -
- -
- - - - -
-
- - - -
- - -
-
- -
-
- -

 Guides  and  Videos 

- -
-
- -
-
- - - -
-
- -
- - - - - -
- -
-
- - - -
-
-
- -

Test a Guide

console.log('well whadya know it works!');

Pretty cool!

- - - -
-
-
-
-
- - -
- - - - -
- -
-
- - -
- - - - - - - -
-
- -
-
-
-

Ready to start building? Read the docs!

- Documentation -
-
-
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/utils/createHTML.js b/utils/createHTML.js index c144e14..5d04968 100644 --- a/utils/createHTML.js +++ b/utils/createHTML.js @@ -82,8 +82,13 @@ const createHTML = async function createHTML(markdownFile, htmlFile, author, pos template = insertToTemplate(template, GUIDE_START, blogText); // create the html file for final output - fs.writeFileSync(htmlFile, template); - console.log(`Finished ${path.basename(htmlFile)}`); + return new Promise((resolve, reject) => { + fs.writeFile(htmlFile, template, {flags: 'w+'}, (err) => { + if (err) reject(err); + resolve(htmlFile) + }); + }) + .then((htmlFile) => console.log(`Finished ${path.basename(htmlFile)}!`)); } -module.exports = createHTML; \ No newline at end of file +module.exports = createHTML; diff --git a/utils/generateArchive.js b/utils/generateArchive.js index 13a0db7..400a27a 100644 --- a/utils/generateArchive.js +++ b/utils/generateArchive.js @@ -24,19 +24,31 @@ const generateArchive = async function(archiveName, rootDirectory) { archiveTemplate = insertToTemplate(archiveTemplate, SIDEBAR_START, sidebarText); + // collect post information of guides to add in archive + // `posts` returns an array of objects storing the info for each post const posts = await getPostInfo(markdownDir); let archiveItemTemplate = fs.readFileSync(itemTemplatePath).toString(); + + // Use the underscore templating engine for filling in post info in our template html archiveItemTemplate = _.template(archiveItemTemplate); + + // Let's start building out the text for the archives list let archives = '
'; archives += '
Guides
'; archives += '\n'; + + // Add each post to the list _.each(posts, (post) => { - // need to get the relative file path + // need to get the relative file path and convert to html since that's what we're linking to const filePath = post.fileName.replace(/\.[^/.]+$/, ".html"); post.filePath = archiveName.concat('/', filePath); + + // Add archive item from template archives += archiveItemTemplate(post); archives += '\n'; }); + + // Once our archives are ready, add the list into the archive page template archiveTemplate = insertToTemplate(archiveTemplate, ARCHIVES_START, archives); return archiveTemplate; diff --git a/utils/generatePages.js b/utils/generatePages.js index b0857ae..7f9ceb8 100644 --- a/utils/generatePages.js +++ b/utils/generatePages.js @@ -16,7 +16,7 @@ const generatePages = async (markdownDir, all, rootDir) => { // since the `fs.readdir` is an async callback that we'd like to `await` on return new Promise ((resolve, reject) => { fs.readdir(markdownDir, async (err, files) => { - if (err) throw err; + if (err) reject(err); for (let i=0; i < files.length; i++) { const file = files[i]; const ext = path.extname(file); @@ -33,7 +33,7 @@ const generatePages = async (markdownDir, all, rootDir) => { } // once we've converted all markdown files in the folder // we can resolve our promise and continue in our promise/await chain - resolve(); + resolve(files); }); }) } else { @@ -43,4 +43,4 @@ const generatePages = async (markdownDir, all, rootDir) => { } } -module.exports = generatePages; \ No newline at end of file +module.exports = generatePages; diff --git a/utils/helpers.js b/utils/helpers.js index 022f889..68e2287 100644 --- a/utils/helpers.js +++ b/utils/helpers.js @@ -4,6 +4,10 @@ const assert = require('assert'); const marked = require('marked'); +const getPostMeta = (author='bcoin-org') => ''; + const insertToTemplate = (template, targetText, customText) => { assert(typeof template === 'string', 'template must be a string'); assert(typeof customText === 'string', 'customText must be a string'); @@ -79,14 +83,8 @@ const getPostInfo = function getPostInfo(pathToFiles, postMeta) { }); } -const getPostMeta = (author='bcoin-org') => ''; - - - module.exports = { insertToTemplate, getPostMeta, getPostInfo -}; \ No newline at end of file +};