create-readme
Version:
Automatically creates README.md based on package.json and other existing files.
71 lines (59 loc) • 2.57 kB
JavaScript
// Generated by CoffeeScript 2.3.2
(function() {
var DocsParser, Promise, fs, logger, path;
logger = require('../logger');
Promise = require('bluebird');
fs = Promise.promisifyAll(require('fs'));
path = require('path');
// Creates a link to the documentation on the corresponding GitHub Pages page.
module.exports = DocsParser = (function() {
class DocsParser {
// Creates a new DocsParser
// @param (options) [Object] An optional set of options
// @option options encoding [String] Encoding for reading the file ['utf-8']
// @option options docFile [String] Documentation entry point ['index.html']
// @option options branch [String] The branch to use for the documentation ['master']
constructor(options) {
var base, base1, base2, ref, ref1;
this.options = options;
if (this.options == null) {
this.options = {};
}
if ((base = this.options).encoding == null) {
base.encoding = 'utf-8';
}
if ((base1 = this.options).branch == null) {
base1.branch = (ref = (ref1 = this.options.git) != null ? ref1.branch : void 0) != null ? ref : 'master';
}
if ((base2 = this.options).docFile == null) {
base2.docFile = 'index.html';
}
}
// Check whether a documentation exists, it is in /docs and the repo uses github.
// If all conditions are true, create a link to the documentation via GitHub Pages.
// @param pkg [Object] package.json data
// @returns [Promise<Object>] Documentation information [string]
run(pkg) {
var docDir, ref;
logger.info("Creating documentation info");
if (pkg.git == null) {
logger.debug(" Not adding documentation due to missing git repo info");
return Promise.resolve(null);
}
docDir = (ref = pkg.directories) != null ? ref.doc : void 0;
if (!docDir) {
logger.debug(" Not adding documentation due to missing directories/doc entry");
return Promise.resolve(null);
}
if (docDir !== 'docs') {
logger.debug(" Not adding documentation because it isn't in docs folder " + "and therefore incompatible with GitHub Pages");
return Promise.resolve(null);
}
return Promise.resolve("https://" + pkg.git.user + ".github.io/" + pkg.git.repo + "/");
}
};
// @property [String] The name of this component
DocsParser.name = "DocsParser";
return DocsParser;
}).call(this);
}).call(this);