Rewrite Notes - agnoster/literapi GitHub Wiki

In order to modularize Literapi, I'll be generalizing and breaking it into middleware components.

Base components:

  • markdown - parses a markdown document (given by a stream)
  • http - takes code blocks from the markdown step and makes HTTP calls and tests assertions
  • markdown-writer - serializes the markdown document again
  • reporter - write information to console about the run (success/fail/what went wrong)

What do they need to work?

  • Stream -> markdown -> Document
  • Block -> http -> ??? Assertions?
  • Document, Stream -> markdown-writer
Run {
  Documents {
    filename: string
    title: string (from markdown?)
    stream (?)
    Examples {
      ok: true/false
      pending: true/false
      errors: [] (strings?)
      text: string
    }
  }
}

Q: Three levels... three types of plugin? A: NO!

Maybe: a plugin is an object with elements (like "run", "document", "example") mapped to functions.

// plugins/noisy.js
module.exports = {
  "run": function(run, next) {
     console.log("Run: ", run); next()
  },
  "document": function(doc, next) {
     console.log("Document: ", doc); next()
  },
  "example": function(example, next) {
     console.log("Example: ", example); next()
  }
}

Then they simply get chained like so:

literapi().use(literapi.noisy)

The default setup would look something like this:

var literapi = require('literapi')()
  .use(literapi.readfile)
  .use(literapi.markdown)
  .use(literapi.http({ root: options.root })
  .use(literapi.default_reporter)

if (options.write) literapi.use(literapi.markdown_output)

literapi.runWithFiles(options.files)

Which could be quickly run as:

require('literapi').withDefaultPlugins(options).runWithFiles(options.files)