@monoweave/changelog 0.0.5 → 1.0.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.
- package/lib/changelog.d.ts +1 -2
- package/lib/changelog.js +12 -7
- package/lib/defaultChangelogWriter.d.ts +10 -0
- package/lib/defaultChangelogWriter.js +56 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -2
- package/lib/types.d.ts +11 -0
- package/lib/types.js +2 -0
- package/package.json +8 -8
package/lib/changelog.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CommitMessage, MonoweaveConfiguration, YarnContext } from '@monoweave/types';
|
|
2
|
-
declare const generateChangelogEntry: ({ config, context, packageName, previousVersion, newVersion, commits, }: {
|
|
2
|
+
export declare const generateChangelogEntry: ({ config, context, packageName, previousVersion, newVersion, commits, }: {
|
|
3
3
|
config: MonoweaveConfiguration;
|
|
4
4
|
context: YarnContext;
|
|
5
5
|
packageName: string;
|
|
@@ -7,4 +7,3 @@ declare const generateChangelogEntry: ({ config, context, packageName, previousV
|
|
|
7
7
|
newVersion: string;
|
|
8
8
|
commits: CommitMessage[];
|
|
9
9
|
}) => Promise<string | null>;
|
|
10
|
-
export default generateChangelogEntry;
|
package/lib/changelog.js
CHANGED
|
@@ -3,25 +3,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateChangelogEntry = void 0;
|
|
6
7
|
const stream_1 = require("stream");
|
|
7
8
|
const git_1 = require("@monoweave/git");
|
|
8
9
|
const io_1 = require("@monoweave/io");
|
|
9
10
|
const core_1 = require("@yarnpkg/core");
|
|
10
11
|
const conventional_changelog_writer_1 = __importDefault(require("conventional-changelog-writer"));
|
|
11
12
|
const conventional_commits_parser_1 = __importDefault(require("conventional-commits-parser"));
|
|
13
|
+
const defaultChangelogWriter_1 = require("./defaultChangelogWriter");
|
|
12
14
|
const resolveConventionalConfig_1 = __importDefault(require("./resolveConventionalConfig"));
|
|
13
15
|
const generateChangelogEntry = async ({ config, context, packageName, previousVersion, newVersion, commits, }) => {
|
|
14
|
-
if (!config.conventionalChangelogConfig) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
16
|
if (!commits.length) {
|
|
18
17
|
return null;
|
|
19
18
|
}
|
|
20
19
|
const ident = core_1.structUtils.parseIdent(packageName);
|
|
21
20
|
const workspace = context.project.getWorkspaceByIdent(ident);
|
|
22
|
-
const conventionalConfig = await (0, resolveConventionalConfig_1.default)({ config });
|
|
23
|
-
const commitsStream = stream_1.Readable.from(commits.map((commit) => `${commit.body}\n-hash-\n${commit.sha}`)).pipe((0, conventional_commits_parser_1.default)(conventionalConfig.parserOpts));
|
|
24
|
-
const conventionalCommits = await (0, io_1.readStream)(commitsStream);
|
|
25
21
|
const { host, owner, repository, repoUrl } = await (0, git_1.parseRepositoryProperty)(workspace);
|
|
26
22
|
const templateContext = {
|
|
27
23
|
version: newVersion,
|
|
@@ -34,6 +30,15 @@ const generateChangelogEntry = async ({ config, context, packageName, previousVe
|
|
|
34
30
|
previousTag: previousVersion ? `${packageName}@${previousVersion}` : undefined,
|
|
35
31
|
linkCompare: Boolean(previousVersion),
|
|
36
32
|
};
|
|
33
|
+
if (!config.conventionalChangelogConfig) {
|
|
34
|
+
return await (0, defaultChangelogWriter_1.defaultChangelogWriter)({
|
|
35
|
+
commits,
|
|
36
|
+
templateContext,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const conventionalConfig = await (0, resolveConventionalConfig_1.default)({ config });
|
|
40
|
+
const commitsStream = stream_1.Readable.from(commits.map((commit) => `${commit.body}\n-hash-\n${commit.sha}`)).pipe((0, conventional_commits_parser_1.default)(conventionalConfig.parserOpts));
|
|
41
|
+
const conventionalCommits = await (0, io_1.readStream)(commitsStream);
|
|
37
42
|
const changelogWriter = (0, conventional_changelog_writer_1.default)(templateContext, conventionalConfig.writerOpts);
|
|
38
43
|
async function* transformedCommits() {
|
|
39
44
|
for (const commit of conventionalCommits) {
|
|
@@ -48,4 +53,4 @@ const generateChangelogEntry = async ({ config, context, packageName, previousVe
|
|
|
48
53
|
const pipeline = stream_1.Readable.from(transformedCommits()).pipe(changelogWriter);
|
|
49
54
|
return (0, io_1.readStreamString)(pipeline);
|
|
50
55
|
};
|
|
51
|
-
exports.
|
|
56
|
+
exports.generateChangelogEntry = generateChangelogEntry;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { CommitMessage } from '@monoweave/types';
|
|
2
|
+
import { type TemplateContext } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Simple changelog entry writer if no conventional changelog config is provided.
|
|
5
|
+
* It is recommended to use a conventional changelog where possible (they'll handle more edge cases).
|
|
6
|
+
*/
|
|
7
|
+
export declare function defaultChangelogWriter({ commits, templateContext: { currentTag, host, owner, previousTag, repoUrl, repository, title, version }, }: {
|
|
8
|
+
commits: CommitMessage[];
|
|
9
|
+
templateContext: TemplateContext;
|
|
10
|
+
}): Promise<string | null>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultChangelogWriter = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Simple changelog entry writer if no conventional changelog config is provided.
|
|
6
|
+
* It is recommended to use a conventional changelog where possible (they'll handle more edge cases).
|
|
7
|
+
*/
|
|
8
|
+
async function defaultChangelogWriter({ commits, templateContext: { currentTag, host, owner, previousTag, repoUrl, repository, title, version }, }) {
|
|
9
|
+
const headerPattern = /^(\w*)(?:\((.*)\))?: (.*)$/;
|
|
10
|
+
const notePattern = /^(revert|note|breaking change):\s/i;
|
|
11
|
+
const dateString = new Date().toLocaleDateString();
|
|
12
|
+
const url = repoUrl || `${repository || `${host}/${owner}`}`;
|
|
13
|
+
const lines = [];
|
|
14
|
+
const commitMessages = [];
|
|
15
|
+
const notes = [];
|
|
16
|
+
const commitsByLine = commits
|
|
17
|
+
.map(({ sha, body }) => body.split('\n').map((b) => ({ sha, body: b })))
|
|
18
|
+
.flat();
|
|
19
|
+
for (const commit of commitsByLine) {
|
|
20
|
+
const shortSha = commit.sha.substring(0, 8);
|
|
21
|
+
const shaUrl = url ? `[${shortSha}](${url}/commits/${shortSha})` : `[${shortSha}]`;
|
|
22
|
+
const headerMatch = commit.body.match(headerPattern);
|
|
23
|
+
if (headerMatch) {
|
|
24
|
+
const [_, commitType] = headerMatch;
|
|
25
|
+
if (!commitType || commitType.toLowerCase() === 'wip') {
|
|
26
|
+
continue; // ignore wip commits
|
|
27
|
+
}
|
|
28
|
+
commitMessages.push(`* ${commit.body} (${shaUrl})`);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const noteMatch = commit.body.match(notePattern);
|
|
32
|
+
if (noteMatch) {
|
|
33
|
+
notes.push(`* ${commit.body} (${shaUrl})`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (commitMessages.length) {
|
|
37
|
+
lines.push('### Changes', '', ...commitMessages);
|
|
38
|
+
if (notes.length)
|
|
39
|
+
lines.push('');
|
|
40
|
+
}
|
|
41
|
+
if (notes.length) {
|
|
42
|
+
lines.push('### Notes', '', ...notes);
|
|
43
|
+
}
|
|
44
|
+
if (lines.length) {
|
|
45
|
+
const diffUrl = url && previousTag
|
|
46
|
+
? `[${version}](${url}/compare/${previousTag}...${currentTag})`
|
|
47
|
+
: `[${version}]`;
|
|
48
|
+
return [
|
|
49
|
+
`## ${diffUrl} "${title}" (${dateString}) <a name="${version}"></a>`,
|
|
50
|
+
'',
|
|
51
|
+
...lines,
|
|
52
|
+
].join('\n');
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
exports.defaultChangelogWriter = defaultChangelogWriter;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import generateChangelogEntry from './changelog';
|
|
1
|
+
import { generateChangelogEntry } from './changelog';
|
|
2
2
|
import prependChangelogFile from './prependChangelogFile';
|
|
3
3
|
import resolveConventionalConfig from './resolveConventionalConfig';
|
|
4
4
|
export { prependChangelogFile, resolveConventionalConfig, generateChangelogEntry };
|
package/lib/index.js
CHANGED
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.generateChangelogEntry = exports.resolveConventionalConfig = exports.prependChangelogFile = void 0;
|
|
7
|
-
const changelog_1 =
|
|
8
|
-
exports
|
|
7
|
+
const changelog_1 = require("./changelog");
|
|
8
|
+
Object.defineProperty(exports, "generateChangelogEntry", { enumerable: true, get: function () { return changelog_1.generateChangelogEntry; } });
|
|
9
9
|
const prependChangelogFile_1 = __importDefault(require("./prependChangelogFile"));
|
|
10
10
|
exports.prependChangelogFile = prependChangelogFile_1.default;
|
|
11
11
|
const resolveConventionalConfig_1 = __importDefault(require("./resolveConventionalConfig"));
|
package/lib/types.d.ts
ADDED
package/lib/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monoweave/changelog",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/monoweave/monoweave.git",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"author": {
|
|
10
10
|
"name": "noahnu",
|
|
11
|
-
"url": "https://monoweave.github.io"
|
|
11
|
+
"url": "https://monoweave.github.io/monoweave/"
|
|
12
12
|
},
|
|
13
13
|
"license": "BSD-3",
|
|
14
14
|
"publishConfig": {
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"prepack": "run workspace:build \"$(pwd)\""
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@monoweave/git": "^0.0
|
|
34
|
-
"@monoweave/io": "^0.0
|
|
33
|
+
"@monoweave/git": "^1.0.0",
|
|
34
|
+
"@monoweave/io": "^1.0.0",
|
|
35
35
|
"@monoweave/logging": "^0.0.4",
|
|
36
|
-
"@monoweave/types": "^0.0
|
|
36
|
+
"@monoweave/types": "^1.0.0",
|
|
37
37
|
"@yarnpkg/core": "^4.0.3",
|
|
38
38
|
"@yarnpkg/fslib": "^3.0.2"
|
|
39
39
|
},
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"p-limit": "^3.1.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@monoweave/git": "0.0
|
|
47
|
-
"@monoweave/io": "0.0
|
|
46
|
+
"@monoweave/git": "1.0.0",
|
|
47
|
+
"@monoweave/io": "1.0.0",
|
|
48
48
|
"@monoweave/logging": "0.0.4",
|
|
49
49
|
"@monoweave/test-utils": "link:../../testUtils",
|
|
50
|
-
"@monoweave/types": "0.0
|
|
50
|
+
"@monoweave/types": "1.0.0",
|
|
51
51
|
"@types/conventional-changelog-writer": "^4.0.7",
|
|
52
52
|
"@types/conventional-commits-parser": "^3.0.5",
|
|
53
53
|
"@types/jest": "^29.5.6",
|