keep-a-changelog 0.10.4 → 2.0.0-beta

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 (96) hide show
  1. package/CHANGELOG.md +5 -196
  2. package/LICENSE +1 -1
  3. package/README.md +93 -63
  4. package/esm/bin.js +113 -0
  5. package/esm/deps/deno_land/std_0.113.0/_util/assert.js +13 -0
  6. package/esm/deps/deno_land/std_0.113.0/_util/os.js +15 -0
  7. package/esm/deps/deno_land/std_0.113.0/flags/mod.js +255 -0
  8. package/esm/deps/deno_land/std_0.113.0/path/_constants.js +45 -0
  9. package/esm/deps/deno_land/std_0.113.0/path/_interface.js +3 -0
  10. package/esm/deps/deno_land/std_0.113.0/path/_util.js +114 -0
  11. package/esm/deps/deno_land/std_0.113.0/path/common.js +36 -0
  12. package/esm/deps/deno_land/std_0.113.0/path/glob.js +361 -0
  13. package/esm/deps/deno_land/std_0.113.0/path/mod.js +14 -0
  14. package/esm/deps/deno_land/std_0.113.0/path/posix.js +493 -0
  15. package/esm/deps/deno_land/std_0.113.0/path/separator.js +5 -0
  16. package/esm/deps/deno_land/std_0.113.0/path/win32.js +963 -0
  17. package/esm/deps/deno_land/std_0.51.0/fs/eol.js +29 -0
  18. package/esm/deps/deno_land/x/ini_v2.1.0/ini.js +226 -0
  19. package/esm/deps/deno_land/x/ini_v2.1.0/mod.js +1 -0
  20. package/esm/deps/deno_land/x/semver_v1.4.0/mod.js +1527 -0
  21. package/esm/mod.js +5 -0
  22. package/esm/package.json +3 -0
  23. package/esm/src/Change.js +48 -0
  24. package/esm/src/Changelog.js +137 -0
  25. package/esm/src/Release.js +204 -0
  26. package/esm/src/deps.js +1 -0
  27. package/esm/src/parser.js +149 -0
  28. package/esm/test/changelog.custom.type.md +24 -0
  29. package/esm/test/changelog.expected.md +169 -0
  30. package/esm/test/changelog.md +197 -0
  31. package/esm/test/empty.expected.md +6 -0
  32. package/package.json +26 -24
  33. package/types/bin.d.ts +2 -0
  34. package/types/deps/deno_land/std_0.113.0/_util/assert.d.ts +5 -0
  35. package/types/deps/deno_land/std_0.113.0/_util/os.d.ts +3 -0
  36. package/types/deps/deno_land/std_0.113.0/flags/mod.d.ts +50 -0
  37. package/types/deps/deno_land/std_0.113.0/path/_constants.d.ts +39 -0
  38. package/types/deps/deno_land/std_0.113.0/path/_interface.d.ts +26 -0
  39. package/types/deps/deno_land/std_0.113.0/path/_util.d.ts +8 -0
  40. package/types/deps/deno_land/std_0.113.0/path/common.d.ts +13 -0
  41. package/types/deps/deno_land/std_0.113.0/path/glob.d.ts +78 -0
  42. package/types/deps/deno_land/std_0.113.0/path/mod.d.ts +9 -0
  43. package/types/deps/deno_land/std_0.113.0/path/posix.d.ts +80 -0
  44. package/types/deps/deno_land/std_0.113.0/path/separator.d.ts +2 -0
  45. package/types/deps/deno_land/std_0.113.0/path/win32.d.ts +87 -0
  46. package/types/deps/deno_land/std_0.115.1/fmt/colors.d.ts +270 -0
  47. package/types/deps/deno_land/std_0.115.1/testing/_diff.d.ts +23 -0
  48. package/types/deps/deno_land/std_0.115.1/testing/asserts.d.ts +151 -0
  49. package/types/deps/deno_land/std_0.51.0/fs/eol.d.ts +12 -0
  50. package/types/deps/deno_land/x/ini_v2.1.0/ini.d.ts +53 -0
  51. package/types/deps/deno_land/x/ini_v2.1.0/mod.d.ts +1 -0
  52. package/types/deps/deno_land/x/semver_v1.4.0/mod.d.ts +116 -0
  53. package/types/mod.d.ts +5 -0
  54. package/types/src/Change.d.ts +8 -0
  55. package/types/src/Changelog.d.ts +18 -0
  56. package/types/src/Release.d.ts +25 -0
  57. package/types/src/deps.d.ts +1 -0
  58. package/types/src/parser.d.ts +11 -0
  59. package/types/test/Change.test.d.ts +1 -0
  60. package/types/test/fixture/CustomRelease.d.ts +7 -0
  61. package/types/test/parser.test.d.ts +1 -0
  62. package/types/test/test.d.ts +1 -0
  63. package/umd/bin.js +143 -0
  64. package/umd/deps/deno_land/std_0.113.0/_util/assert.js +27 -0
  65. package/umd/deps/deno_land/std_0.113.0/_util/os.js +46 -0
  66. package/umd/deps/deno_land/std_0.113.0/flags/mod.js +268 -0
  67. package/umd/deps/deno_land/std_0.113.0/path/_constants.js +57 -0
  68. package/umd/deps/deno_land/std_0.113.0/path/_interface.js +13 -0
  69. package/umd/deps/deno_land/std_0.113.0/path/_util.js +133 -0
  70. package/umd/deps/deno_land/std_0.113.0/path/common.js +49 -0
  71. package/umd/deps/deno_land/std_0.113.0/path/glob.js +396 -0
  72. package/umd/deps/deno_land/std_0.113.0/path/mod.js +50 -0
  73. package/umd/deps/deno_land/std_0.113.0/path/posix.js +537 -0
  74. package/umd/deps/deno_land/std_0.113.0/path/separator.js +17 -0
  75. package/umd/deps/deno_land/std_0.113.0/path/win32.js +1007 -0
  76. package/umd/deps/deno_land/std_0.51.0/fs/eol.js +43 -0
  77. package/umd/deps/deno_land/x/ini_v2.1.0/ini.js +261 -0
  78. package/umd/deps/deno_land/x/ini_v2.1.0/mod.js +22 -0
  79. package/umd/deps/deno_land/x/semver_v1.4.0/mod.js +1577 -0
  80. package/umd/mod.js +23 -0
  81. package/umd/package.json +3 -0
  82. package/umd/src/Change.js +60 -0
  83. package/umd/src/Changelog.js +149 -0
  84. package/umd/src/Release.js +219 -0
  85. package/umd/src/deps.js +18 -0
  86. package/umd/src/parser.js +164 -0
  87. package/umd/test/changelog.custom.type.md +24 -0
  88. package/umd/test/changelog.expected.md +169 -0
  89. package/umd/test/changelog.md +197 -0
  90. package/umd/test/empty.expected.md +6 -0
  91. package/bin.js +0 -128
  92. package/src/Change.js +0 -40
  93. package/src/Changelog.js +0 -121
  94. package/src/Release.js +0 -220
  95. package/src/index.js +0 -6
  96. package/src/parser.js +0 -182
package/src/Release.js DELETED
@@ -1,220 +0,0 @@
1
- const Semver = require('semver/classes/semver');
2
- const Change = require('./Change');
3
-
4
- class Release {
5
- constructor(version, date, description = '') {
6
- this.setVersion(version);
7
- this.setDate(date);
8
-
9
- this.description = description;
10
- this.changes = new Map([
11
- ['added', []],
12
- ['changed', []],
13
- ['deprecated', []],
14
- ['removed', []],
15
- ['fixed', []],
16
- ['security', []],
17
- ]);
18
- }
19
-
20
- compare(release) {
21
- if (!this.version && release.version) {
22
- return -1;
23
- }
24
-
25
- if (!release.version) {
26
- return 1;
27
- }
28
-
29
- if (!this.date && release.date) {
30
- return -1;
31
- }
32
-
33
- if (!release.date) {
34
- return 1;
35
- }
36
-
37
- return -this.version.compare(release.version);
38
- }
39
-
40
- isEmpty() {
41
- if (this.description.trim()) {
42
- return false;
43
- }
44
-
45
- return Array.from(this.changes.values()).every((change) => !change.length);
46
- }
47
-
48
- setVersion(version) {
49
- if (typeof version === 'string') {
50
- version = new Semver(version);
51
- }
52
- this.version = version;
53
- //Re-sort the releases of the parent changelog
54
- if (this.changelog) {
55
- this.changelog.sortReleases();
56
- }
57
- }
58
-
59
- setDate(date) {
60
- if (typeof date === 'string') {
61
- date = new Date(date);
62
- }
63
- this.date = date;
64
- }
65
-
66
- addChange(type, change) {
67
- if (!(change instanceof Change)) {
68
- change = new Change(change);
69
- }
70
-
71
- if (!this.changes.has(type)) {
72
- throw new Error('Invalid change type');
73
- }
74
-
75
- this.changes.get(type).push(change);
76
-
77
- return this;
78
- }
79
-
80
- added(change) {
81
- return this.addChange('added', change);
82
- }
83
-
84
- changed(change) {
85
- return this.addChange('changed', change);
86
- }
87
-
88
- deprecated(change) {
89
- return this.addChange('deprecated', change);
90
- }
91
-
92
- removed(change) {
93
- return this.addChange('removed', change);
94
- }
95
-
96
- fixed(change) {
97
- return this.addChange('fixed', change);
98
- }
99
-
100
- security(change) {
101
- return this.addChange('security', change);
102
- }
103
-
104
- toString(changelog) {
105
- let t = [];
106
-
107
- if (this.version) {
108
- if (this.hasCompareLink(changelog)) {
109
- t.push(`## [${this.version}] - ${formatDate(this.date)}`);
110
- } else {
111
- t.push(`## ${this.version} - ${formatDate(this.date)}`);
112
- }
113
- } else {
114
- if (this.hasCompareLink(changelog)) {
115
- t.push('## [Unreleased]');
116
- } else {
117
- t.push('## Unreleased');
118
- }
119
- }
120
-
121
- if (this.description.trim()) {
122
- t.push(this.description.trim());
123
- t.push('');
124
- }
125
-
126
- this.changes.forEach((changes, type) => {
127
- if (changes.length) {
128
- t.push(`### ${type[0].toUpperCase()}${type.substring(1)}`);
129
- t = t.concat(changes.map((change) => change.toString()));
130
- t.push('');
131
- }
132
- });
133
-
134
- return t.join('\n').trim();
135
- }
136
-
137
- getCompareLink(changelog) {
138
- if (!this.hasCompareLink(changelog)) {
139
- return;
140
- }
141
-
142
- const index = changelog.releases.indexOf(this);
143
-
144
- let offset = 1;
145
- let previous = changelog.releases[index + offset];
146
-
147
- while (!previous.date) {
148
- ++offset;
149
- previous = changelog.releases[index + offset];
150
- }
151
-
152
- if (!this.version) {
153
- return `[Unreleased]: ${changelog.url}/compare/${changelog.tagName(previous)}...${
154
- changelog.head
155
- }`;
156
- }
157
-
158
- if (!this.date) {
159
- return `[${this.version}]: ${changelog.url}/compare/${changelog.tagName(previous)}...${
160
- changelog.head
161
- }`;
162
- }
163
-
164
- return `[${this.version}]: ${changelog.url}/compare/${changelog.tagName(
165
- previous
166
- )}...${changelog.tagName(this)}`;
167
- }
168
-
169
- getLinks(changelog) {
170
- const links = [];
171
-
172
- if (!changelog.url) {
173
- return links;
174
- }
175
-
176
- this.changes.forEach((changes) =>
177
- changes.forEach((change) => {
178
- change.issues.forEach((issue) => {
179
- if (!links.includes(issue)) {
180
- links.push(`[#${issue}]: ${changelog.url}/issues/${issue}`);
181
- }
182
- });
183
- })
184
- );
185
-
186
- return links;
187
- }
188
-
189
- hasCompareLink(changelog) {
190
- if (!changelog || !changelog.url || !changelog.releases.length) {
191
- return false;
192
- }
193
-
194
- const index = changelog.releases.indexOf(this);
195
- const next = changelog.releases[index + 1];
196
-
197
- return next && next.version && next.date;
198
- }
199
- }
200
-
201
- module.exports = Release;
202
-
203
- function formatDate(date) {
204
- if (!date) {
205
- return 'Unreleased';
206
- }
207
-
208
- let year = date.getUTCFullYear(),
209
- month = date.getUTCMonth() + 1,
210
- day = date.getUTCDate();
211
-
212
- if (month < 10) {
213
- month = '0' + month;
214
- }
215
- if (day < 10) {
216
- day = '0' + day;
217
- }
218
-
219
- return `${year}-${month}-${day}`;
220
- }
package/src/index.js DELETED
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- parser: require('./parser'),
3
- Change: require('./Change'),
4
- Changelog: require('./Changelog'),
5
- Release: require('./Release'),
6
- };
package/src/parser.js DELETED
@@ -1,182 +0,0 @@
1
- const Changelog = require('./Changelog');
2
- const Release = require('./Release');
3
-
4
- const defaultOptions = {
5
- releaseCreator: (version, date, description) => new Release(version, date, description),
6
- };
7
-
8
- module.exports = function parser(markdown, options) {
9
- const opts = Object.assign({}, defaultOptions, options);
10
- const tokens = tokenize(markdown);
11
-
12
- try {
13
- return parseTokens(tokens, opts);
14
- } catch (error) {
15
- throw new Error(`Parse error in the line ${tokens[0][0]}: ${error.message}`);
16
- }
17
- };
18
-
19
- function parseTokens(tokens, opts) {
20
- const changelog = new Changelog();
21
-
22
- changelog.title = getContent(tokens, 'h1', true);
23
- changelog.description = getContent(tokens, 'p');
24
-
25
- //Releases
26
- let release;
27
-
28
- while ((release = getContent(tokens, 'h2').toLowerCase())) {
29
- const matches = release.match(/\[?([^\]]+)\]?\s*-\s*([\d]{4}-[\d]{1,2}-[\d]{1,2})$/);
30
-
31
- if (matches) {
32
- release = opts.releaseCreator(matches[1], matches[2]);
33
- } else if (release.includes('unreleased')) {
34
- const matches = release.match(/\[?([^\]]+)\]?\s*-\s*unreleased$/);
35
- release = matches ? opts.releaseCreator(matches[1]) : opts.releaseCreator();
36
- } else {
37
- throw new Error(`Syntax error in the release title`);
38
- }
39
-
40
- changelog.addRelease(release);
41
- release.description = getContent(tokens, 'p');
42
-
43
- let type;
44
-
45
- while ((type = getContent(tokens, 'h3').toLowerCase())) {
46
- let change;
47
-
48
- while ((change = getContent(tokens, 'li'))) {
49
- release.addChange(type, change);
50
- }
51
- }
52
- }
53
-
54
- //Skip release links
55
- let link = getContent(tokens, 'link');
56
-
57
- while (link) {
58
- if (!changelog.url) {
59
- const matches = link.match(/^\[.*\]\:\s*(http.*)\/compare\/.*$/);
60
-
61
- if (matches) {
62
- changelog.url = matches[1];
63
- }
64
- }
65
-
66
- link = getContent(tokens, 'link');
67
- }
68
-
69
- //Footer
70
- if (getContent(tokens, 'hr')) {
71
- changelog.footer = getContent(tokens, 'p');
72
- }
73
-
74
- if (tokens.length) {
75
- throw new Error(`Unexpected content ${JSON.stringify(tokens)}`);
76
- }
77
-
78
- return changelog;
79
- }
80
-
81
- function getContent(tokens, type, required = false) {
82
- if (!tokens[0] || tokens[0][1] !== type) {
83
- if (required) {
84
- throw new Error(`Required token missing in: "${tokens[0][0]}"`);
85
- }
86
-
87
- return '';
88
- }
89
-
90
- return tokens.shift()[2].join('\n');
91
- }
92
-
93
- function tokenize(markdown) {
94
- const tokens = [];
95
-
96
- markdown
97
- .trim()
98
- .split('\n')
99
- .map((line, index, allLines) => {
100
- if (line.startsWith('---')) {
101
- return ['hr', ['-']];
102
- }
103
-
104
- if (line.startsWith('# ')) {
105
- return ['h1', [line.substr(1).trim()]];
106
- }
107
-
108
- if (line.startsWith('## ')) {
109
- return ['h2', [line.substr(2).trim()]];
110
- }
111
-
112
- if (line.startsWith('### ')) {
113
- return ['h3', [line.substr(3).trim()]];
114
- }
115
-
116
- if (line.startsWith('-')) {
117
- return ['li', [line.substr(1).trim()]];
118
- }
119
-
120
- if (line.startsWith('*')) {
121
- return ['li', [line.substr(1).trim()]];
122
- }
123
-
124
- if (line.match(/^\[.*\]\:\s*http.*$/)) {
125
- return ['link', [line.trim()]];
126
- }
127
- if (line.match(/^\[.*\]\:$/)) {
128
- const nextLine = allLines[index + 1];
129
- if (nextLine && nextLine.match(/\s+http.*$/)) {
130
- // We found a multi-line link: treat it like a single line
131
- allLines[index + 1] = '';
132
- return ['link', [line.trim() + '\n' + nextLine.trimEnd()]];
133
- }
134
- }
135
-
136
- return ['p', [line.trimEnd()]];
137
- })
138
- .forEach((line, index) => {
139
- const [type, [content]] = line;
140
-
141
- if (index > 0) {
142
- const prevType = tokens[0][1];
143
-
144
- if (type === 'p') {
145
- if (prevType === 'p') {
146
- return tokens[0][2].push(content);
147
- }
148
-
149
- if (prevType === 'li') {
150
- return tokens[0][2].push(content.replace(/^\s\s/, ''));
151
- }
152
- }
153
- }
154
-
155
- tokens.unshift([index + 1, type, [content]]);
156
- });
157
-
158
- return tokens
159
- .filter((token) => !isEmpty(token[2]))
160
- .map((token) => {
161
- const content = token[2];
162
-
163
- while (isEmpty(content[content.length - 1])) {
164
- content.pop();
165
- }
166
-
167
- while (isEmpty(content[0])) {
168
- content.shift();
169
- }
170
-
171
- return token;
172
- })
173
- .reverse();
174
- }
175
-
176
- function isEmpty(val) {
177
- if (Array.isArray(val)) {
178
- val = val.join('');
179
- }
180
-
181
- return !val || val.trim() === '';
182
- }