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