UNPKG

create-readme

Version:

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

70 lines (59 loc) 2.1 kB
// Generated by CoffeeScript 2.3.2 (function() { var LicenseParser, Promise, fs, logger; logger = require('../logger'); Promise = require('bluebird'); fs = Promise.promisifyAll(require('fs')); // Creates license information module.exports = LicenseParser = (function() { class LicenseParser { // Creates a new LicenseParser that checks whether a license file exists // and gives its url // @param (options) [Object] An optional set of options // @option options encoding [String] Encoding for reading the file ['utf-8'] // @option options licenseFile [String] Location of the license file ['LICENSE'] constructor(options) { var base, base1; this.options = options; if (this.options == null) { this.options = {}; } if ((base = this.options).encoding == null) { base.encoding = 'utf-8'; } if ((base1 = this.options).licenseFile == null) { base1.licenseFile = 'LICENSE'; } } // Create license information // @param pkg [Object] package.json data // @returns [Promise<Object>] License information {name: string, file: string} run(pkg) { var file; logger.info("Creating license info"); if (!pkg.license) { return Promise.resolve(null); } logger.debug(" Reading license file from " + this.options.licenseFile); file = fs.readFileAsync(this.options.licenseFile, { encoding: this.options.encoding }).then(() => { logger.debug(`License file ${this.options.licenseFile} found`); return this.options.licenseFile; }).catch({ code: 'ENOENT' }, function() { logger.debug("No license file found"); return ""; }); return Promise.resolve({ name: pkg.license, file: file }).props(); } }; // @property [String] The name of this component LicenseParser.name = "LicenseParser"; return LicenseParser; }).call(this); }).call(this);