keep-a-changelog 2.0.0-beta → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/CHANGELOG.md +23 -1
  2. package/README.md +5 -2
  3. package/esm/_dnt.polyfills.js +15 -0
  4. package/esm/_dnt.shims.js +62 -0
  5. package/esm/bin.js +18 -16
  6. package/esm/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/_util/assert.js +0 -0
  7. package/esm/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/_util/os.js +5 -3
  8. package/esm/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/flags/mod.js +0 -0
  9. package/esm/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/path/_constants.js +0 -0
  10. package/esm/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/path/_interface.js +0 -0
  11. package/esm/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/path/_util.js +0 -0
  12. package/esm/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/path/common.js +0 -0
  13. package/esm/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/path/glob.js +1 -1
  14. package/esm/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/path/mod.js +0 -0
  15. package/esm/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/path/posix.js +5 -2
  16. package/esm/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/path/separator.js +0 -0
  17. package/esm/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/path/win32.js +5 -2
  18. package/esm/deps/{deno_land/std_0.51.0 → deno.land/std@0.51.0}/fs/eol.js +0 -0
  19. package/esm/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/ini.js +3 -3
  20. package/esm/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/mod.js +0 -0
  21. package/esm/deps/{deno_land/x/semver_v1.4.0 → deno.land/x/semver@v1.4.0}/mod.js +0 -0
  22. package/esm/mod.js +1 -0
  23. package/esm/src/Release.js +11 -4
  24. package/esm/src/deps.js +1 -1
  25. package/esm/src/parser.js +16 -3
  26. package/esm/test/changelog.expected.md +3 -3
  27. package/esm/test/changelog.md +9 -6
  28. package/package.json +6 -6
  29. package/script/_dnt.polyfills.js +16 -0
  30. package/script/_dnt.shims.js +66 -0
  31. package/script/bin.js +140 -0
  32. package/script/deps/deno.land/std@0.120.0/_util/assert.js +18 -0
  33. package/script/deps/deno.land/std@0.120.0/_util/os.js +43 -0
  34. package/script/deps/deno.land/std@0.120.0/flags/mod.js +259 -0
  35. package/script/deps/deno.land/std@0.120.0/path/_constants.js +48 -0
  36. package/script/deps/deno.land/std@0.120.0/path/_interface.js +4 -0
  37. package/script/deps/deno.land/std@0.120.0/path/_util.js +124 -0
  38. package/script/deps/deno.land/std@0.120.0/path/common.js +40 -0
  39. package/script/deps/deno.land/std@0.120.0/path/glob.js +391 -0
  40. package/script/deps/deno.land/std@0.120.0/path/mod.js +45 -0
  41. package/script/deps/deno.land/std@0.120.0/path/posix.js +535 -0
  42. package/script/deps/deno.land/std@0.120.0/path/separator.js +8 -0
  43. package/script/deps/deno.land/std@0.120.0/path/win32.js +1005 -0
  44. package/script/deps/deno.land/std@0.51.0/fs/eol.js +34 -0
  45. package/script/deps/deno.land/x/ini@v2.1.0/ini.js +256 -0
  46. package/script/deps/deno.land/x/ini@v2.1.0/mod.js +17 -0
  47. package/script/deps/deno.land/x/semver@v1.4.0/mod.js +1568 -0
  48. package/script/mod.js +15 -0
  49. package/{umd → script}/package.json +0 -0
  50. package/script/src/Change.js +51 -0
  51. package/script/src/Changelog.js +140 -0
  52. package/script/src/Release.js +217 -0
  53. package/script/src/deps.js +9 -0
  54. package/script/src/parser.js +168 -0
  55. package/{umd → script}/test/changelog.custom.type.md +0 -0
  56. package/{umd → script}/test/changelog.expected.md +3 -3
  57. package/{umd → script}/test/changelog.md +9 -6
  58. package/{umd → script}/test/empty.expected.md +0 -0
  59. package/types/_dnt.polyfills.d.ts +11 -0
  60. package/types/_dnt.shims.d.ts +5 -0
  61. package/types/bin.d.ts +1 -1
  62. package/types/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/_util/assert.d.ts +0 -0
  63. package/types/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/_util/os.d.ts +0 -0
  64. package/types/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/flags/mod.d.ts +0 -0
  65. package/types/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/path/_constants.d.ts +0 -0
  66. package/types/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/path/_interface.d.ts +0 -0
  67. package/types/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/path/_util.d.ts +0 -0
  68. package/types/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/path/common.d.ts +0 -0
  69. package/types/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/path/glob.d.ts +0 -0
  70. package/types/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/path/mod.d.ts +0 -0
  71. package/types/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/path/posix.d.ts +0 -0
  72. package/types/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/path/separator.d.ts +0 -0
  73. package/types/deps/{deno_land/std_0.113.0 → deno.land/std@0.120.0}/path/win32.d.ts +0 -0
  74. package/types/deps/{deno_land/std_0.51.0 → deno.land/std@0.51.0}/fs/eol.d.ts +0 -0
  75. package/types/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/ini.d.ts +0 -0
  76. package/types/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/mod.d.ts +0 -0
  77. package/types/deps/{deno_land/x/semver_v1.4.0 → deno.land/x/semver@v1.4.0}/mod.d.ts +0 -0
  78. package/types/mod.d.ts +1 -0
  79. package/types/src/Release.d.ts +3 -2
  80. package/types/src/deps.d.ts +1 -1
  81. package/types/deps/deno_land/std_0.115.1/fmt/colors.d.ts +0 -270
  82. package/types/deps/deno_land/std_0.115.1/testing/_diff.d.ts +0 -23
  83. package/types/deps/deno_land/std_0.115.1/testing/asserts.d.ts +0 -151
  84. package/types/test/Change.test.d.ts +0 -1
  85. package/types/test/fixture/CustomRelease.d.ts +0 -7
  86. package/types/test/parser.test.d.ts +0 -1
  87. package/types/test/test.d.ts +0 -1
  88. package/umd/bin.js +0 -143
  89. package/umd/deps/deno_land/std_0.113.0/_util/assert.js +0 -27
  90. package/umd/deps/deno_land/std_0.113.0/_util/os.js +0 -46
  91. package/umd/deps/deno_land/std_0.113.0/flags/mod.js +0 -268
  92. package/umd/deps/deno_land/std_0.113.0/path/_constants.js +0 -57
  93. package/umd/deps/deno_land/std_0.113.0/path/_interface.js +0 -13
  94. package/umd/deps/deno_land/std_0.113.0/path/_util.js +0 -133
  95. package/umd/deps/deno_land/std_0.113.0/path/common.js +0 -49
  96. package/umd/deps/deno_land/std_0.113.0/path/glob.js +0 -396
  97. package/umd/deps/deno_land/std_0.113.0/path/mod.js +0 -50
  98. package/umd/deps/deno_land/std_0.113.0/path/posix.js +0 -537
  99. package/umd/deps/deno_land/std_0.113.0/path/separator.js +0 -17
  100. package/umd/deps/deno_land/std_0.113.0/path/win32.js +0 -1007
  101. package/umd/deps/deno_land/std_0.51.0/fs/eol.js +0 -43
  102. package/umd/deps/deno_land/x/ini_v2.1.0/ini.js +0 -261
  103. package/umd/deps/deno_land/x/ini_v2.1.0/mod.js +0 -22
  104. package/umd/deps/deno_land/x/semver_v1.4.0/mod.js +0 -1577
  105. package/umd/mod.js +0 -23
  106. package/umd/src/Change.js +0 -60
  107. package/umd/src/Changelog.js +0 -149
  108. package/umd/src/Release.js +0 -219
  109. package/umd/src/deps.js +0 -18
  110. package/umd/src/parser.js +0 -164
package/umd/mod.js DELETED
@@ -1,23 +0,0 @@
1
- var __importDefault = (this && this.__importDefault) || function (mod) {
2
- return (mod && mod.__esModule) ? mod : { "default": mod };
3
- };
4
- (function (factory) {
5
- if (typeof module === "object" && typeof module.exports === "object") {
6
- var v = factory(require, exports);
7
- if (v !== undefined) module.exports = v;
8
- }
9
- else if (typeof define === "function" && define.amd) {
10
- define(["require", "exports", "./src/parser.js", "./src/Change.js", "./src/Changelog.js", "./src/Release.js"], factory);
11
- }
12
- })(function (require, exports) {
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.Release = exports.parser = exports.Changelog = exports.Change = void 0;
15
- const parser_js_1 = __importDefault(require("./src/parser.js"));
16
- exports.parser = parser_js_1.default;
17
- const Change_js_1 = __importDefault(require("./src/Change.js"));
18
- exports.Change = Change_js_1.default;
19
- const Changelog_js_1 = __importDefault(require("./src/Changelog.js"));
20
- exports.Changelog = Changelog_js_1.default;
21
- const Release_js_1 = __importDefault(require("./src/Release.js"));
22
- exports.Release = Release_js_1.default;
23
- });
package/umd/src/Change.js DELETED
@@ -1,60 +0,0 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
5
- }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports"], factory);
8
- }
9
- })(function (require, exports) {
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- class Change {
12
- constructor(title, description = "") {
13
- Object.defineProperty(this, "title", {
14
- enumerable: true,
15
- configurable: true,
16
- writable: true,
17
- value: void 0
18
- });
19
- Object.defineProperty(this, "description", {
20
- enumerable: true,
21
- configurable: true,
22
- writable: true,
23
- value: void 0
24
- });
25
- Object.defineProperty(this, "issues", {
26
- enumerable: true,
27
- configurable: true,
28
- writable: true,
29
- value: []
30
- });
31
- this.title = Change.extractIssues(title, this.issues);
32
- this.description = Change.extractIssues(description, this.issues);
33
- }
34
- static extractIssues(text, issues) {
35
- return text
36
- .replace(/(^|[^\\])\[#(\d+)\](?=[^\(]|$)/g, (_, start, index) => {
37
- if (!issues.includes(index)) {
38
- issues.push(index);
39
- }
40
- return `${start}[#${index}]`;
41
- })
42
- .replace(/(^|[\s,])#(\d+)(?=[\s,\.]|$)/g, (_, start, index) => {
43
- if (!issues.includes(index)) {
44
- issues.push(index);
45
- }
46
- return `${start}[#${index}]`;
47
- });
48
- }
49
- toString() {
50
- let t = this.title.split("\n").map((line) => ` ${line}`.trimEnd());
51
- t[0] = "-" + t[0].substr(1);
52
- if (this.description) {
53
- t.push("");
54
- t = t.concat(this.description.split("\n").map((line) => ` ${line}`.trimEnd()));
55
- }
56
- return t.join("\n").trim();
57
- }
58
- }
59
- exports.default = Change;
60
- });
@@ -1,149 +0,0 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
5
- }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./deps.js"], factory);
8
- }
9
- })(function (require, exports) {
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- const deps_js_1 = require("./deps.js");
12
- class Changelog {
13
- constructor(title, description = "") {
14
- Object.defineProperty(this, "flag", {
15
- enumerable: true,
16
- configurable: true,
17
- writable: true,
18
- value: void 0
19
- });
20
- Object.defineProperty(this, "title", {
21
- enumerable: true,
22
- configurable: true,
23
- writable: true,
24
- value: void 0
25
- });
26
- Object.defineProperty(this, "description", {
27
- enumerable: true,
28
- configurable: true,
29
- writable: true,
30
- value: void 0
31
- });
32
- Object.defineProperty(this, "head", {
33
- enumerable: true,
34
- configurable: true,
35
- writable: true,
36
- value: "HEAD"
37
- });
38
- Object.defineProperty(this, "footer", {
39
- enumerable: true,
40
- configurable: true,
41
- writable: true,
42
- value: void 0
43
- });
44
- Object.defineProperty(this, "url", {
45
- enumerable: true,
46
- configurable: true,
47
- writable: true,
48
- value: void 0
49
- });
50
- Object.defineProperty(this, "releases", {
51
- enumerable: true,
52
- configurable: true,
53
- writable: true,
54
- value: []
55
- });
56
- Object.defineProperty(this, "tagNameBuilder", {
57
- enumerable: true,
58
- configurable: true,
59
- writable: true,
60
- value: void 0
61
- });
62
- this.title = title;
63
- this.description = description;
64
- }
65
- addRelease(release) {
66
- this.releases.push(release);
67
- this.sortReleases();
68
- release.changelog = this;
69
- return this;
70
- }
71
- findRelease(version) {
72
- if (!version) {
73
- return this.releases.find((release) => !release.version);
74
- }
75
- return this.releases.find((release) => release.version && (0, deps_js_1.eq)(release.version, version));
76
- }
77
- sortReleases() {
78
- this.releases.sort((a, b) => a.compare(b));
79
- }
80
- tagName(release) {
81
- if (this.tagNameBuilder) {
82
- return this.tagNameBuilder(release);
83
- }
84
- return `v${release.version}`;
85
- }
86
- toString() {
87
- const t = [];
88
- if (this.flag) {
89
- t.push(`<!-- ${this.flag} -->`);
90
- t.push("");
91
- }
92
- t.push(`# ${this.title}`);
93
- const links = [];
94
- const compareLinks = [];
95
- const description = this.description.trim() ||
96
- `All notable changes to this project will be documented in this file.
97
-
98
- The format is based on [Keep a Changelog](http://keepachangelog.com/)
99
- and this project adheres to [Semantic Versioning](http://semver.org/).`;
100
- if (description) {
101
- t.push("");
102
- t.push(description);
103
- }
104
- this.releases.forEach((release) => {
105
- t.push("");
106
- t.push(release.toString(this));
107
- release.getLinks(this).forEach((link) => {
108
- if (!links.includes(link)) {
109
- links.push(link);
110
- }
111
- });
112
- const compareLink = release.getCompareLink(this);
113
- if (compareLink) {
114
- compareLinks.push(compareLink);
115
- }
116
- });
117
- if (links.length) {
118
- t.push("");
119
- links.sort(compare);
120
- links.forEach((link) => t.push(link));
121
- }
122
- if (compareLinks.length) {
123
- t.push("");
124
- compareLinks.forEach((link) => t.push(link));
125
- }
126
- t.push("");
127
- if (this.footer) {
128
- t.push("---");
129
- t.push("");
130
- t.push(this.footer);
131
- t.push("");
132
- }
133
- return t.join("\n");
134
- }
135
- }
136
- exports.default = Changelog;
137
- function compare(a, b) {
138
- if (a === b) {
139
- return 0;
140
- }
141
- const reg = /^\[#(\d+)\]:/;
142
- const aNumber = a.match(reg);
143
- const bNumber = b.match(reg);
144
- if (aNumber && bNumber) {
145
- return parseInt(aNumber[1]) - parseInt(bNumber[1]);
146
- }
147
- return a < b ? -1 : 1;
148
- }
149
- });
@@ -1,219 +0,0 @@
1
- var __importDefault = (this && this.__importDefault) || function (mod) {
2
- return (mod && mod.__esModule) ? mod : { "default": mod };
3
- };
4
- (function (factory) {
5
- if (typeof module === "object" && typeof module.exports === "object") {
6
- var v = factory(require, exports);
7
- if (v !== undefined) module.exports = v;
8
- }
9
- else if (typeof define === "function" && define.amd) {
10
- define(["require", "exports", "./deps.js", "./Change.js"], factory);
11
- }
12
- })(function (require, exports) {
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- const deps_js_1 = require("./deps.js");
15
- const Change_js_1 = __importDefault(require("./Change.js"));
16
- class Release {
17
- constructor(version, date, description = "") {
18
- Object.defineProperty(this, "changelog", {
19
- enumerable: true,
20
- configurable: true,
21
- writable: true,
22
- value: void 0
23
- });
24
- Object.defineProperty(this, "version", {
25
- enumerable: true,
26
- configurable: true,
27
- writable: true,
28
- value: void 0
29
- });
30
- Object.defineProperty(this, "date", {
31
- enumerable: true,
32
- configurable: true,
33
- writable: true,
34
- value: void 0
35
- });
36
- Object.defineProperty(this, "description", {
37
- enumerable: true,
38
- configurable: true,
39
- writable: true,
40
- value: void 0
41
- });
42
- Object.defineProperty(this, "changes", {
43
- enumerable: true,
44
- configurable: true,
45
- writable: true,
46
- value: void 0
47
- });
48
- this.setVersion(version);
49
- this.setDate(date);
50
- this.description = description;
51
- this.changes = new Map([
52
- ["added", []],
53
- ["changed", []],
54
- ["deprecated", []],
55
- ["removed", []],
56
- ["fixed", []],
57
- ["security", []],
58
- ]);
59
- }
60
- compare(release) {
61
- if (!this.version && release.version) {
62
- return -1;
63
- }
64
- if (!release.version) {
65
- return 1;
66
- }
67
- if (!this.date && release.date) {
68
- return -1;
69
- }
70
- if (!release.date) {
71
- return 1;
72
- }
73
- if (this.version && release.version) {
74
- return -this.version.compare(release.version);
75
- }
76
- return 0;
77
- }
78
- isEmpty() {
79
- if (this.description.trim()) {
80
- return false;
81
- }
82
- return Array.from(this.changes.values()).every((change) => !change.length);
83
- }
84
- setVersion(version) {
85
- if (typeof version === "string") {
86
- version = new deps_js_1.Semver(version);
87
- }
88
- this.version = version;
89
- //Re-sort the releases of the parent changelog
90
- if (this.changelog) {
91
- this.changelog.sortReleases();
92
- }
93
- }
94
- setDate(date) {
95
- if (typeof date === "string") {
96
- date = new Date(date);
97
- }
98
- this.date = date;
99
- }
100
- addChange(type, change) {
101
- if (!(change instanceof Change_js_1.default)) {
102
- change = new Change_js_1.default(change);
103
- }
104
- if (!this.changes.has(type)) {
105
- throw new Error("Invalid change type");
106
- }
107
- this.changes.get(type).push(change);
108
- return this;
109
- }
110
- added(change) {
111
- return this.addChange("added", change);
112
- }
113
- changed(change) {
114
- return this.addChange("changed", change);
115
- }
116
- deprecated(change) {
117
- return this.addChange("deprecated", change);
118
- }
119
- removed(change) {
120
- return this.addChange("removed", change);
121
- }
122
- fixed(change) {
123
- return this.addChange("fixed", change);
124
- }
125
- security(change) {
126
- return this.addChange("security", change);
127
- }
128
- toString(changelog) {
129
- let t = [];
130
- const hasCompareLink = this.getCompareLink(changelog) !== undefined;
131
- if (this.version) {
132
- if (hasCompareLink) {
133
- t.push(`## [${this.version}] - ${formatDate(this.date)}`);
134
- }
135
- else {
136
- t.push(`## ${this.version} - ${formatDate(this.date)}`);
137
- }
138
- }
139
- else {
140
- if (hasCompareLink) {
141
- t.push("## [Unreleased]");
142
- }
143
- else {
144
- t.push("## Unreleased");
145
- }
146
- }
147
- if (this.description.trim()) {
148
- t.push(this.description.trim());
149
- t.push("");
150
- }
151
- this.changes.forEach((changes, type) => {
152
- if (changes.length) {
153
- t.push(`### ${type[0].toUpperCase()}${type.substring(1)}`);
154
- t = t.concat(changes.map((change) => change.toString()));
155
- t.push("");
156
- }
157
- });
158
- return t.join("\n").trim();
159
- }
160
- getCompareLink(changelog) {
161
- if (!changelog?.url) {
162
- return;
163
- }
164
- const index = changelog.releases.indexOf(this);
165
- if (index === -1) {
166
- return;
167
- }
168
- let offset = 1;
169
- let previous = changelog.releases[index + offset];
170
- while (previous && !previous.date) {
171
- ++offset;
172
- previous = changelog.releases[index + offset];
173
- }
174
- if (!previous) {
175
- if (!this.version || !this.date) {
176
- return;
177
- }
178
- return `[${this.version}]: ${changelog.url}/releases/tag/${changelog.tagName(this)}`;
179
- }
180
- if (!this.version) {
181
- return `[Unreleased]: ${changelog.url}/compare/${changelog.tagName(previous)}...${changelog.head}`;
182
- }
183
- if (!this.date) {
184
- return `[${this.version}]: ${changelog.url}/compare/${changelog.tagName(previous)}...${changelog.head}`;
185
- }
186
- return `[${this.version}]: ${changelog.url}/compare/${changelog.tagName(previous)}...${changelog.tagName(this)}`;
187
- }
188
- getLinks(changelog) {
189
- const links = [];
190
- if (!changelog.url) {
191
- return links;
192
- }
193
- this.changes.forEach((changes) => changes.forEach((change) => {
194
- change.issues.forEach((issue) => {
195
- if (!links.includes(issue)) {
196
- links.push(`[#${issue}]: ${changelog.url}/issues/${issue}`);
197
- }
198
- });
199
- }));
200
- return links;
201
- }
202
- }
203
- exports.default = Release;
204
- function formatDate(date) {
205
- if (!date) {
206
- return "Unreleased";
207
- }
208
- const year = date.getUTCFullYear();
209
- let month = date.getUTCMonth() + 1;
210
- let day = date.getUTCDate();
211
- if (month < 10) {
212
- month = "0" + month;
213
- }
214
- if (day < 10) {
215
- day = "0" + day;
216
- }
217
- return `${year}-${month}-${day}`;
218
- }
219
- });
package/umd/src/deps.js DELETED
@@ -1,18 +0,0 @@
1
- var __importDefault = (this && this.__importDefault) || function (mod) {
2
- return (mod && mod.__esModule) ? mod : { "default": mod };
3
- };
4
- (function (factory) {
5
- if (typeof module === "object" && typeof module.exports === "object") {
6
- var v = factory(require, exports);
7
- if (v !== undefined) module.exports = v;
8
- }
9
- else if (typeof define === "function" && define.amd) {
10
- define(["require", "exports", "../deps/deno_land/x/semver_v1.4.0/mod.js"], factory);
11
- }
12
- })(function (require, exports) {
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.eq = exports.Semver = void 0;
15
- var mod_js_1 = require("../deps/deno_land/x/semver_v1.4.0/mod.js");
16
- Object.defineProperty(exports, "Semver", { enumerable: true, get: function () { return __importDefault(mod_js_1).default; } });
17
- Object.defineProperty(exports, "eq", { enumerable: true, get: function () { return mod_js_1.eq; } });
18
- });
package/umd/src/parser.js DELETED
@@ -1,164 +0,0 @@
1
- var __importDefault = (this && this.__importDefault) || function (mod) {
2
- return (mod && mod.__esModule) ? mod : { "default": mod };
3
- };
4
- (function (factory) {
5
- if (typeof module === "object" && typeof module.exports === "object") {
6
- var v = factory(require, exports);
7
- if (v !== undefined) module.exports = v;
8
- }
9
- else if (typeof define === "function" && define.amd) {
10
- define(["require", "exports", "./Changelog.js", "./Release.js"], factory);
11
- }
12
- })(function (require, exports) {
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- const Changelog_js_1 = __importDefault(require("./Changelog.js"));
15
- const Release_js_1 = __importDefault(require("./Release.js"));
16
- const defaultOptions = {
17
- releaseCreator: (version, date, description) => new Release_js_1.default(version, date, description),
18
- };
19
- /** Parse a markdown string */
20
- function parser(markdown, options) {
21
- const opts = Object.assign({}, defaultOptions, options);
22
- const tokens = tokenize(markdown);
23
- try {
24
- return processTokens(tokens, opts);
25
- }
26
- catch (error) {
27
- throw new Error(`Parse error in the line ${tokens[0][0]}: ${error.message}`);
28
- }
29
- }
30
- exports.default = parser;
31
- /** Process an array of tokens to build the Changelog */
32
- function processTokens(tokens, opts) {
33
- const changelog = new Changelog_js_1.default("");
34
- changelog.flag = getContent(tokens, "flag");
35
- changelog.title = getContent(tokens, "h1", true);
36
- changelog.description = getContent(tokens, "p");
37
- //Releases
38
- let release;
39
- while ((release = getContent(tokens, "h2").toLowerCase())) {
40
- const matches = release.match(/\[?([^\]]+)\]?\s*-\s*([\d]{4}-[\d]{1,2}-[\d]{1,2})$/);
41
- if (matches) {
42
- release = opts.releaseCreator(matches[1], matches[2]);
43
- }
44
- else if (release.includes("unreleased")) {
45
- const matches = release.match(/\[?([^\]]+)\]?\s*-\s*unreleased$/);
46
- release = matches
47
- ? opts.releaseCreator(matches[1])
48
- : opts.releaseCreator();
49
- }
50
- else {
51
- throw new Error(`Syntax error in the release title`);
52
- }
53
- changelog.addRelease(release);
54
- release.description = getContent(tokens, "p");
55
- let type;
56
- while ((type = getContent(tokens, "h3").toLowerCase())) {
57
- let change;
58
- while ((change = getContent(tokens, "li"))) {
59
- release.addChange(type, change);
60
- }
61
- }
62
- }
63
- //Skip release links
64
- let link = getContent(tokens, "link");
65
- while (link) {
66
- if (!changelog.url) {
67
- const matches = link.match(/^\[.*\]\:\s*(http.*)\/compare\/.*$/);
68
- if (matches) {
69
- changelog.url = matches[1];
70
- }
71
- }
72
- link = getContent(tokens, "link");
73
- }
74
- //Footer
75
- if (getContent(tokens, "hr")) {
76
- changelog.footer = getContent(tokens, "p");
77
- }
78
- if (tokens.length) {
79
- throw new Error(`Unexpected content ${JSON.stringify(tokens)}`);
80
- }
81
- return changelog;
82
- }
83
- /** Returns the content of a token */
84
- function getContent(tokens, type, required = false) {
85
- if (!tokens[0] || tokens[0][1] !== type) {
86
- if (required) {
87
- throw new Error(`Required token missing in: "${tokens[0][0]}"`);
88
- }
89
- return "";
90
- }
91
- return tokens.shift()[2].join("\n");
92
- }
93
- /** Tokenize a markdown string */
94
- function tokenize(markdown) {
95
- const tokens = [];
96
- markdown
97
- .trim()
98
- .split("\n")
99
- .map((line, index) => {
100
- const lineNumber = index + 1;
101
- if (line.startsWith("---")) {
102
- return [lineNumber, "hr", ["-"]];
103
- }
104
- if (line.startsWith("# ")) {
105
- return [lineNumber, "h1", [line.substr(1).trim()]];
106
- }
107
- if (line.startsWith("## ")) {
108
- return [lineNumber, "h2", [line.substr(2).trim()]];
109
- }
110
- if (line.startsWith("### ")) {
111
- return [lineNumber, "h3", [line.substr(3).trim()]];
112
- }
113
- if (line.startsWith("-")) {
114
- return [lineNumber, "li", [line.substr(1).trim()]];
115
- }
116
- if (line.startsWith("*")) {
117
- return [lineNumber, "li", [line.substr(1).trim()]];
118
- }
119
- if (line.match(/^\[.*\]\:\s*http.*$/)) {
120
- return [lineNumber, "link", [line.trim()]];
121
- }
122
- const result = line.match(/^<!--(.*)-->$/);
123
- if (result) {
124
- return [lineNumber, "flag", [result[1].trim()]];
125
- }
126
- return [lineNumber, "p", [line.trimEnd()]];
127
- })
128
- .forEach((line, index) => {
129
- const [lineNumber, type, [content]] = line;
130
- if (index > 0) {
131
- const prevType = tokens[0][1];
132
- if (type === "p") {
133
- if (prevType === "p") {
134
- return tokens[0][2].push(content);
135
- }
136
- if (prevType === "li") {
137
- return tokens[0][2].push(content.replace(/^\s\s/, ""));
138
- }
139
- }
140
- }
141
- tokens.unshift([lineNumber, type, [content]]);
142
- });
143
- return tokens
144
- .filter((token) => !isEmpty(token[2]))
145
- .map((token) => {
146
- const content = token[2];
147
- while (isEmpty(content[content.length - 1])) {
148
- content.pop();
149
- }
150
- while (isEmpty(content[0])) {
151
- content.shift();
152
- }
153
- return token;
154
- })
155
- .reverse();
156
- }
157
- /** Check if a string or array is empty */
158
- function isEmpty(val) {
159
- if (Array.isArray(val)) {
160
- val = val.join("");
161
- }
162
- return !val || val.trim() === "";
163
- }
164
- });