Fetch Electron documentation as raw markdown strings
Перейти к файлу
Zeke Sikelianos 2e72513c83 remove leftover console log statement 2017-05-12 19:00:35 -07:00
test fetch all docs, not just API docs 2016-12-16 12:51:47 -08:00
.gitignore Add tests for reading structures 2016-10-05 12:38:15 +11:00
.travis.yml add travis config and badge 2016-06-16 15:38:17 -07:00
README.md always require a version, branch, SHA, or path 2016-11-10 14:47:19 -08:00
cli.js it works! 2016-06-16 15:32:27 -07:00
index.js remove leftover console log statement 2017-05-12 19:00:35 -07:00
package.json 3.0.0 2016-12-16 12:56:25 -08:00

README.md

electron-docs Build Status

This package consumes the electron/electron repo in search of markdown files, and returns an array of file objects with stringified file contents.

It is used by Electron's docs linter.

Installation

npm install electron-docs --save

Programmatic Usage

Require the function and call it with any of the following:

  • A remote branch name, like master
  • A version number, like 1.4.4
  • A commit SHA, like 76375a83eb3a97e7aed14d37d8bdc858c765e564
  • A local directory, like ~/my/path/to/electron/
const electronDocs = require('electron-docs')

electronDocs('master').then(function(docs) {
  // docs is an array of objects, one for each markdown file in /docs
})

Each object in the docs array looks like this:

{
 slug: "windows-store-guide",
 filename: "docs/tutorial/windows-store-guide.md",
 markdown_content: "# Windows Store Guide\n\n..."
}

When fetching docs from a local directory, be sure to use a full path:

const path = require('path')
const docsPath = path.join(__dirname, 'docs')
electronDocs(docsPath).then(function(docs) {
  // ...
})

If you prefer node-style callbacks instead of promises, those are supported too:

electronDocs('1.0.0', function(err, docs) {
  console.log(err, docs)
})

CLI Usage

Add this to your package.json file:

{
  "scripts": {
    "docs": "electron-docs > docs.json"
  }
}

When you run npm run docs, the module writes the stringified JSON object to stdout, and the output is piped into a file.

stdout ftw!

Tests

npm i && npm t

Dependencies

  • got: Simplified HTTP requests
  • gunzip-maybe: Transform stream that gunzips its input if it is gzipped and just echoes it if not
  • node-dir: asynchronous file and directory operations for Node.js
  • ora: Elegant terminal spinner
  • path-exists: Check if a path exists
  • pify: Promisify a callback-style function
  • semver: The semantic version parser used by npm.
  • tar-fs: filesystem bindings for tar-stream

Dev Dependencies

  • tap-spec: Formatted TAP output like Mocha's spec reporter
  • tape: tap-producing test harness for node and browsers

License

MIT