UNPKG

changelog-reminder

Version:

```bash $ npm install changelog-reminder ```

535 lines (516 loc) 22.3 kB
#!/usr/bin/env node (function(FuseBox){FuseBox.$fuse$=FuseBox; FuseBox.pkg("default", {}, function(___scope___){ ___scope___.file("cli.js", function(exports, require, module, __filename, __dirname){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var yargs = require("yargs"); var reminder_1 = require("./reminder"); var config_1 = require("./config"); var argv = yargs .usage("Usage: $0 [options]") .options({ config: { description: "<path> config file relative path", alias: "c", requiresArg: true, required: false, default: config_1.defaultConfigPath, string: true } }) .alias("help", "h") .alias("version", "v").argv; var config = new config_1.Config(argv); var changelogger = new reminder_1.Reminder(config); changelogger.run(); }); ___scope___.file("reminder.js", function(exports, require, module, __filename, __dirname){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var logger_1 = require("./logger"); var parser_1 = require("./parser"); var Reminder = /** @class */ (function () { function Reminder(config) { this.config = config; this.store = new parser_1.Store(); this.parser = new parser_1.Parser(config, this.store); this.logger = new logger_1.Logger(config, this.store); } Reminder.prototype.run = function () { this.parser.parse(); this.logger.log(); }; return Reminder; }()); exports.Reminder = Reminder; }); ___scope___.file("logger.js", function(exports, require, module, __filename, __dirname){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var fs = require("fs"); var output_1 = require("./output"); var readline = require("readline"); var o = new output_1.Output(); var log = console.log; var Logger = /** @class */ (function () { function Logger(config, store) { this.config = config; this.store = store; } Logger.prototype.getFreshVersions = function () { var title = this.findLoggerFile() ? fs.readFileSync(this.config.logger).toString() : ""; return this.store.getFreshVersions(title); }; Logger.prototype.findLoggerFile = function () { return fs.existsSync(this.config.logger); }; Logger.prototype.wrtieLoggerFile = function () { var latestVersion = this.store.getLatestVersion(); fs.writeFileSync(this.config.logger, latestVersion.title); }; Logger.prototype.log = function () { var _this = this; var freshVersions = this.getFreshVersions(); // If no fresh versions, it's unnecessary to enquire. if (freshVersions.length === 0) { o.showNochange(); } this.config.showIntro && this.displayIntro(); freshVersions.forEach(function (version) { _this.displayVersion(version); }); if (freshVersions.length === 0) return; if (this.config.confirm) { this.inquiry(); } else { this.wrtieLoggerFile(); } }; Logger.prototype.displayIntro = function () { o.showIntro(this.store.intro); }; Logger.prototype.inquiry = function () { var _this = this; var rl = readline.createInterface({ input: process.stdin, output: process.stdout }); rl.question("Changes acknowledged. (Y/n) ", function (answer) { if (answer != "Y") { _this.log(); } else { _this.wrtieLoggerFile(); rl.close(); } }); }; Logger.prototype.displayVersion = function (version) { o.addVersion(version.title); version.changes.forEach(function (change) { o.addChange(change.type, change.items); }); o.show(); }; return Logger; }()); exports.Logger = Logger; }); ___scope___.file("output.js", function(exports, require, module, __filename, __dirname){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var chalk = require("chalk"); var Table = require("cli-table-redemption"); var CHARS = { top: "═", "top-mid": "╤", "top-left": "╔", "top-right": "╗", bottom: "═", "bottom-mid": "╧", "bottom-left": "╚", "bottom-right": "╝", left: "║", "left-mid": "╟", mid: "─", "mid-mid": "┼", right: "║", "right-mid": "╢", middle: "│" }; var log = console.log; var Output = /** @class */ (function () { function Output(options) { this.options = { versionTitleColor: chalk.default.bold.magentaBright, changeTypeColor: chalk.default.bold.cyanBright }; // this.options = this.options } Output.prototype.addVersion = function (title) { title = this.options.versionTitleColor(title); this.table = new Table({ chars: CHARS }); this.table.push(["Version: " + title]); }; Output.prototype.addChange = function (type, items) { type = this.options.changeTypeColor(type); this.table.push(["Change: " + type]); this.table.push([this.orderChangeItems(items)]); }; Output.prototype.showIntro = function (intro, show) { if (show === void 0) { show = true; } this.table = this.table || new Table({ chars: CHARS }); var introTitle = chalk.default.bold.blue("CHANGELOG NOTE"); this.table.push([introTitle], [intro]); show && this.show(); }; Output.prototype.showNochange = function (show) { if (show === void 0) { show = true; } this.table = new Table({ chars: CHARS }); var statusText = chalk.default.bold.blue("Status"); this.table.push([statusText], ["No changes found."]); }; Output.prototype.show = function () { log(this.table.toString()); }; Output.prototype.orderChangeItems = function (items) { return items .map(function (item, i) { var order = chalk.default.bold.gray("" + (i + 1)); return order + ". " + item; }) .join("\n"); }; return Output; }()); exports.Output = Output; }); ___scope___.file("parser/index.js", function(exports, require, module, __filename, __dirname){ "use strict"; function __export(m) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } Object.defineProperty(exports, "__esModule", { value: true }); __export(require("./parser")); __export(require("./store")); }); ___scope___.file("parser/parser.js", function(exports, require, module, __filename, __dirname){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var marked = require("marked"); var cheerio = require("cheerio"); var fs = require("fs"); var store_1 = require("./store"); var error_1 = require("./error"); var INTRO_FLAG = "h1"; var VERSION_FLAG = "h2"; var CHANGE_FLAG = "h3"; var LIST_FLAG = "ul"; var INTRO_TEXT_FLAG = "p"; var ParserStatus; (function (ParserStatus) { ParserStatus["INTRO"] = "introduction"; ParserStatus["VERSION"] = "version"; ParserStatus["CHANGE"] = "change"; ParserStatus["LIST"] = "change list"; ParserStatus["END"] = "end"; })(ParserStatus = exports.ParserStatus || (exports.ParserStatus = {})); var Parser = /** @class */ (function () { function Parser(config, store) { this.config = config; this.store = store; this.status = ParserStatus.INTRO; this.introText = []; var marked_ = marked; if (!this.changelogExist()) { console.error(config.changelog + " is not existed."); process.exit(1); } var content = fs.readFileSync(config.changelog).toString(); var html = marked_(content); this.$ = cheerio.load(html); this.currentElement = this.$("h1"); } Parser.prototype.changelogExist = function () { return fs.existsSync(this.config.changelog); }; Parser.prototype.parseError = function (err) { console.log(err.message); process.exit(1); }; Parser.prototype.parse = function () { var el = this.currentElement.first()[0]; if (!el) { // Push the last version this.pushChange(); this.pushVersion(); return; } var name = el.tagName; var stop = false; switch (this.status) { case ParserStatus.INTRO: if (name == VERSION_FLAG) { this.pushIntroText(); this.status = ParserStatus.VERSION; stop = true; break; } // Do not add changlog title into introduction text name !== INTRO_FLAG && this.addIntroText(); break; case ParserStatus.VERSION: if (name == CHANGE_FLAG) { this.status = ParserStatus.CHANGE; stop = true; break; } if (this.currentVersion) { this.pushVersion(); } this.addVersion(); break; case ParserStatus.CHANGE: this.addChange(); this.status = ParserStatus.LIST; break; case ParserStatus.LIST: if (name == VERSION_FLAG) { this.status = ParserStatus.VERSION; this.pushChange(); stop = true; break; } else if (name == CHANGE_FLAG) { this.status = ParserStatus.CHANGE; this.pushChange(); stop = true; break; } this.addList(); break; default: break; } if (!stop) { this.currentElement = this.currentElement.next(); } this.parse(); }; Parser.prototype.pushVersion = function () { this.store.addVersion(this.currentVersion); }; Parser.prototype.pushChange = function () { this.currentVersion.changes.push(this.currentChange); }; Parser.prototype.addIntroText = function () { var el = this.currentElement.first(); this.introText.push(el.text()); }; Parser.prototype.pushIntroText = function () { var intro = this.introText.join("\n"); this.store.setIntro(intro); this.introText = []; }; Parser.prototype.addVersion = function () { var el = this.currentElement.first(); var name = el[0].tagName; if (name !== VERSION_FLAG) { this.parseError(new error_1.ParseError(ParserStatus.VERSION)); } this.currentVersion = new store_1.Version(el.text()); }; Parser.prototype.addChange = function () { var name = this.currentElement.first()[0].tagName; if (name !== CHANGE_FLAG) { this.parseError(new error_1.ParseError(ParserStatus.CHANGE)); } this.currentChange = new store_1.Change(); var text = this.currentElement[0].children[0].data; if (!this.currentChange.setType(text)) { this.parseError(new error_1.ParseError(ParserStatus.LIST, store_1.ChangeTypes, text)); } }; Parser.prototype.addList = function () { var _this = this; var name = this.currentElement.first()[0].tagName; if (name !== LIST_FLAG) { this.parseError(new error_1.ParseError(ParserStatus.LIST)); } var list = this.currentElement.first().children("li"); list.each(function (i, el) { _this.currentChange.items.push(_this.getLiText(el)); }); }; Parser.prototype.getLiText = function (li) { return li.children[0].data; }; return Parser; }()); exports.Parser = Parser; }); ___scope___.file("parser/store.js", function(exports, require, module, __filename, __dirname){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var ChangeTypes; (function (ChangeTypes) { ChangeTypes["Added"] = "Added"; ChangeTypes["Changed"] = "Changed"; ChangeTypes["Deprecated"] = "Deprecated"; ChangeTypes["Removed"] = "Removed"; ChangeTypes["Fixed"] = "Fixed"; ChangeTypes["Security"] = "Security"; })(ChangeTypes = exports.ChangeTypes || (exports.ChangeTypes = {})); var Change = /** @class */ (function () { function Change() { this.items = []; } Change.prototype.setType = function (text) { if (!(text in ChangeTypes)) { return false; } this.type = ChangeTypes[text]; return true; }; return Change; }()); exports.Change = Change; var Version = /** @class */ (function () { function Version(title) { this.changes = []; this.title = title; } return Version; }()); exports.Version = Version; var Store = /** @class */ (function () { function Store() { this._versions = []; } Store.prototype.addVersion = function (v) { this._versions.push(v); }; Object.defineProperty(Store.prototype, "versions", { get: function () { return this._versions; }, enumerable: true, configurable: true }); Object.defineProperty(Store.prototype, "intro", { get: function () { return this._intro; }, enumerable: true, configurable: true }); Store.prototype.setIntro = function (intro) { this._intro = intro; }; Store.prototype.getFreshVersions = function (title) { var freshVersions = []; for (var i = 0; i < this._versions.length; ++i) { if (this._versions[i].title === title) { return freshVersions; } freshVersions.push(this._versions[i]); } return freshVersions; }; Store.prototype.getLatestVersion = function () { return this._versions[0]; }; return Store; }()); exports.Store = Store; }); ___scope___.file("parser/error.js", function(exports, require, module, __filename, __dirname){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var chalk = require("chalk"); var ParseError = /** @class */ (function (_super) { __extends(ParseError, _super); function ParseError(status, expect, actual) { var _this = _super.call(this) || this; var messagePrefix = chalk.default.bold.red("Parsing error") + ": "; if (expect && actual) { expect = expect instanceof Object ? Object.keys(expect).join(", ") : expect; _this.message = "expect " + expect + ", but got '" + chalk.default.bold(actual) + "' "; } _this.message = messagePrefix + _this.message + ("while parsing " + chalk.default.bold(status) + "."); return _this; } return ParseError; }(Error)); exports.ParseError = ParseError; }); ___scope___.file("config.js", function(exports, require, module, __filename, __dirname){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var path = require("path"); var fs = require("fs"); var defaultChangelogPath = "CHANGELOG"; var defaultLoggerPath = ".changelog-reminder"; exports.defaultConfigPath = "changelog-reminder.js"; var Config = /** @class */ (function () { function Config(argv) { if (argv === void 0) { argv = { config: exports.defaultConfigPath }; } this.confirm = false; this.showIntro = true; this.logger = defaultLoggerPath; this.changelog = defaultChangelogPath; var cwd = process.cwd(); var configPath = path.resolve(cwd, argv.config); this.loadConfig(configPath); this.changelog = path.resolve(cwd, this.changelog); this.logger = path.resolve(cwd, this.logger); } Config.prototype.loadConfig = function (configPath) { if (fs.existsSync(configPath)) { var configFile = require(configPath); this.mergeOptions(configFile); } }; Config.prototype.mergeOptions = function (configFile) { var _this = this; Object.keys(configFile).map(function (key) { _this[key] = configFile[key] === undefined ? _this[key] : configFile[key]; }); }; return Config; }()); exports.Config = Config; }); return ___scope___.entry = "cli.ts"; }); FuseBox.target = "server" FuseBox.import("default/cli.js"); FuseBox.main("default/cli.js"); }) (function(e){function r(e){var r=e.charCodeAt(0),n=e.charCodeAt(1);if((p||58!==n)&&(r>=97&&r<=122||64===r)){if(64===r){var t=e.split("/"),i=t.splice(2,t.length).join("/");return[t[0]+"/"+t[1],i||void 0]}var o=e.indexOf("/");if(o===-1)return[e];var a=e.substring(0,o),u=e.substring(o+1);return[a,u]}}function n(e){return e.substring(0,e.lastIndexOf("/"))||"./"}function t(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];for(var n=[],t=0,i=arguments.length;t<i;t++)n=n.concat(arguments[t].split("/"));for(var o=[],t=0,i=n.length;t<i;t++){var a=n[t];a&&"."!==a&&(".."===a?o.pop():o.push(a))}return""===n[0]&&o.unshift(""),o.join("/")||(o.length?"/":".")}function i(e){var r=e.match(/\.(\w{1,})$/);return r&&r[1]?e:e+".js"}function o(e){if(p){var r,n=document,t=n.getElementsByTagName("head")[0];/\.css$/.test(e)?(r=n.createElement("link"),r.rel="stylesheet",r.type="text/css",r.href=e):(r=n.createElement("script"),r.type="text/javascript",r.src=e,r.async=!0),t.insertBefore(r,t.firstChild)}}function a(e,r){for(var n in e)e.hasOwnProperty(n)&&r(n,e[n])}function u(e){return{server:require(e)}}function f(e,n){var o=n.path||"./",a=n.pkg||"default",f=r(e);if(f&&(o="./",a=f[0],n.v&&n.v[a]&&(a=a+"@"+n.v[a]),e=f[1]),e)if(126===e.charCodeAt(0))e=e.slice(2,e.length),o="./";else if(!p&&(47===e.charCodeAt(0)||58===e.charCodeAt(1)))return u(e);var s=g[a];if(!s){if(p&&"electron"!==x.target)throw"Package not found "+a;return u(a+(e?"/"+e:""))}e=e?e:"./"+s.s.entry;var l,c=t(o,e),d=i(c),v=s.f[d];return!v&&d.indexOf("*")>-1&&(l=d),v||l||(d=t(c,"/","index.js"),v=s.f[d],v||"."!==c||(d=s.s&&s.s.entry||"index.js",v=s.f[d]),v||(d=c+".js",v=s.f[d]),v||(v=s.f[c+".jsx"]),v||(d=c+"/index.jsx",v=s.f[d])),{file:v,wildcard:l,pkgName:a,versions:s.v,filePath:c,validPath:d}}function s(e,r,n){if(void 0===n&&(n={}),!p)return r(/\.(js|json)$/.test(e)?v.require(e):"");if(n&&n.ajaxed===e)return console.error(e,"does not provide a module");var i=new XMLHttpRequest;i.onreadystatechange=function(){if(4==i.readyState)if(200==i.status){var n=i.getResponseHeader("Content-Type"),o=i.responseText;/json/.test(n)?o="module.exports = "+o:/javascript/.test(n)||(o="module.exports = "+JSON.stringify(o));var a=t("./",e);x.dynamic(a,o),r(x.import(e,{ajaxed:e}))}else console.error(e,"not found on request"),r(void 0)},i.open("GET",e,!0),i.send()}function l(e,r){var n=h[e];if(n)for(var t in n){var i=n[t].apply(null,r);if(i===!1)return!1}}function c(e,r){if(void 0===r&&(r={}),58===e.charCodeAt(4)||58===e.charCodeAt(5))return o(e);var t=f(e,r);if(t.server)return t.server;var i=t.file;if(t.wildcard){var a=new RegExp(t.wildcard.replace(/\*/g,"@").replace(/[.?*+^$[\]\\(){}|-]/g,"\\$&").replace(/@@/g,".*").replace(/@/g,"[a-z0-9$_-]+"),"i"),u=g[t.pkgName];if(u){var d={};for(var m in u.f)a.test(m)&&(d[m]=c(t.pkgName+"/"+m));return d}}if(!i){var h="function"==typeof r,x=l("async",[e,r]);if(x===!1)return;return s(e,function(e){return h?r(e):null},r)}var _=t.pkgName;if(i.locals&&i.locals.module)return i.locals.module.exports;var y=i.locals={},w=n(t.validPath);y.exports={},y.module={exports:y.exports},y.require=function(e,r){return c(e,{pkg:_,path:w,v:t.versions})},p||!v.require.main?y.require.main={filename:"./",paths:[]}:y.require.main=v.require.main;var j=[y.module.exports,y.require,y.module,t.validPath,w,_];return l("before-import",j),i.fn.apply(0,j),l("after-import",j),y.module.exports}if(e.FuseBox)return e.FuseBox;var d="undefined"!=typeof WorkerGlobalScope,p="undefined"!=typeof window&&window.navigator||d,v=p?d?{}:window:global;p&&(v.global=d?{}:window),e=p&&"undefined"==typeof __fbx__dnm__?e:module.exports;var m=p?d?{}:window.__fsbx__=window.__fsbx__||{}:v.$fsbx=v.$fsbx||{};p||(v.require=require);var g=m.p=m.p||{},h=m.e=m.e||{},x=function(){function r(){}return r.global=function(e,r){return void 0===r?v[e]:void(v[e]=r)},r.import=function(e,r){return c(e,r)},r.on=function(e,r){h[e]=h[e]||[],h[e].push(r)},r.exists=function(e){try{var r=f(e,{});return void 0!==r.file}catch(e){return!1}},r.remove=function(e){var r=f(e,{}),n=g[r.pkgName];n&&n.f[r.validPath]&&delete n.f[r.validPath]},r.main=function(e){return this.mainFile=e,r.import(e,{})},r.expose=function(r){var n=function(n){var t=r[n].alias,i=c(r[n].pkg);"*"===t?a(i,function(r,n){return e[r]=n}):"object"==typeof t?a(t,function(r,n){return e[n]=i[r]}):e[t]=i};for(var t in r)n(t)},r.dynamic=function(r,n,t){this.pkg(t&&t.pkg||"default",{},function(t){t.file(r,function(r,t,i,o,a){var u=new Function("__fbx__dnm__","exports","require","module","__filename","__dirname","__root__",n);u(!0,r,t,i,o,a,e)})})},r.flush=function(e){var r=g.default;for(var n in r.f)e&&!e(n)||delete r.f[n].locals},r.pkg=function(e,r,n){if(g[e])return n(g[e].s);var t=g[e]={};return t.f={},t.v=r,t.s={file:function(e,r){return t.f[e]={fn:r}}},n(t.s)},r.addPlugin=function(e){this.plugins.push(e)},r.packages=g,r.isBrowser=p,r.isServer=!p,r.plugins=[],r}();return p||(v.FuseBox=x),e.FuseBox=x}(this))