UNPKG

create-readme

Version:

Automatically creates README.md based on package.json and other existing files.

77 lines (63 loc) 2.59 kB
// Generated by CoffeeScript 2.3.2 (function() { var DependencyParser, Promise, githubUrl2Obj, logger, path; logger = require('../logger'); Promise = require('bluebird'); path = require('path'); githubUrl2Obj = require('github-url-to-object'); // Creates a list of dependencies and devDependencies module.exports = DependencyParser = (function() { var getDepData; class DependencyParser { // Creates a new DependencyParser that creates lists of dependencies. // @param (options) [Object] An optional set of options // @option options addDescription [String] Additional text for the description [''] constructor(options) { this.options = options; if (this.options == null) { this.options = {}; } } // Create license information by concatenating options.addDescription to // pkg.description, separated by two line breaks. // @param pkg [Object] package.json data // @returns [Promise<String>] The description run(pkg) { logger.info("Parsing dependencies"); logger.debug(" Loading dependencies: " + Object.keys(pkg.dependencies)); logger.debug(" Loading devDependencies: " + Object.keys(pkg.devDependencies)); return Promise.resolve({ dep: Object.keys(pkg.dependencies).map(getDepData), dev: Object.keys(pkg.devDependencies).map(getDepData) }); } }; // @property [String] The name of this component DependencyParser.name = "DependencyParser"; // Find the github repo URL for a dependency and return it together with the name // @param dep [String] The name of an installed dependency // @returns [String] An object withthe github repo url or null { name: string, url: string } getDepData = function(dep) { var pkg, pkgPath, ref, ref1; pkgPath = path.join(process.cwd(), "node_modules", dep, "package.json"); logger.debug(" Reading " + pkgPath); pkg = require(pkgPath); if (((ref = pkg.repository) != null ? ref.url : void 0) && githubUrl2Obj(pkg.repository.url)) { logger.debug(" Adding dependency " + dep); return { name: dep, // coffeelint: disable=camel_case_vars url: githubUrl2Obj(pkg.repository.url).https_url, // coffeelint: enable=camel_case_vars desc: (ref1 = pkg.description) != null ? ref1 : "" }; } else { return { name: dep, url: null }; } }; return DependencyParser; }).call(this); }).call(this);