conventional-commits-parser 5.0.0 → 6.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.
package/dist/regex.js ADDED
@@ -0,0 +1,50 @@
1
+ const nomatchRegex = /(?!.*)/;
2
+ function join(parts, joiner) {
3
+ return parts
4
+ .map(val => val.trim())
5
+ .filter(Boolean)
6
+ .join(joiner);
7
+ }
8
+ function getNotesRegex(noteKeywords, notesPattern) {
9
+ if (!noteKeywords) {
10
+ return nomatchRegex;
11
+ }
12
+ const noteKeywordsSelection = join(noteKeywords, '|');
13
+ if (!notesPattern) {
14
+ return new RegExp(`^[\\s|*]*(${noteKeywordsSelection})[:\\s]+(.*)`, 'i');
15
+ }
16
+ return notesPattern(noteKeywordsSelection);
17
+ }
18
+ function getReferencePartsRegex(issuePrefixes, issuePrefixesCaseSensitive) {
19
+ if (!issuePrefixes) {
20
+ return nomatchRegex;
21
+ }
22
+ const flags = issuePrefixesCaseSensitive ? 'g' : 'gi';
23
+ return new RegExp(`(?:.*?)??\\s*([\\w-\\.\\/]*?)??(${join(issuePrefixes, '|')})([\\w-]*\\d+)`, flags);
24
+ }
25
+ function getReferencesRegex(referenceActions) {
26
+ if (!referenceActions) {
27
+ // matches everything
28
+ return /()(.+)/gi;
29
+ }
30
+ const joinedKeywords = join(referenceActions, '|');
31
+ return new RegExp(`(${joinedKeywords})(?:\\s+(.*?))(?=(?:${joinedKeywords})|$)`, 'gi');
32
+ }
33
+ /**
34
+ * Make the regexes used to parse a commit.
35
+ * @param options
36
+ * @returns Regexes.
37
+ */
38
+ export function getParserRegexes(options = {}) {
39
+ const notes = getNotesRegex(options.noteKeywords, options.notesPattern);
40
+ const referenceParts = getReferencePartsRegex(options.issuePrefixes, options.issuePrefixesCaseSensitive);
41
+ const references = getReferencesRegex(options.referenceActions);
42
+ return {
43
+ notes,
44
+ referenceParts,
45
+ references,
46
+ mentions: /@([\w-]+)/g,
47
+ url: /\b(?:https?):\/\/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reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
3
+ /// <reference types="node" resolution-mode="require"/>
4
+ import type { ParserStreamOptions } from './types.js';
5
+ /**
6
+ * Create async generator function to parse async iterable of raw commits.
7
+ * @param options - CommitParser options.
8
+ * @returns Async generator function to parse async iterable of raw commits.
9
+ */
10
+ export declare function parseCommits(options?: ParserStreamOptions): (rawCommits: Iterable<string | Buffer> | AsyncIterable<string | Buffer>) => AsyncGenerator<import("./types.js").Commit, void, unknown>;
11
+ /**
12
+ * Create stream to parse commits.
13
+ * @param options - CommitParser options.
14
+ * @returns Stream of parsed commits.
15
+ */
16
+ export declare function parseCommitsStream(options?: ParserStreamOptions): import("stream").Duplex;
17
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":";;;AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAGrD;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,OAAO,GAAE,mBAAwB,gBAYnB,SAAS,MAAM,GAAG,MAAM,CAAC,GAAG,cAAc,MAAM,GAAG,MAAM,CAAC,gEAazE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,mBAAwB,2BAEnE"}
package/dist/stream.js ADDED
@@ -0,0 +1,38 @@
1
+ import { Transform } from 'stream';
2
+ import { CommitParser } from './CommitParser.js';
3
+ /**
4
+ * Create async generator function to parse async iterable of raw commits.
5
+ * @param options - CommitParser options.
6
+ * @returns Async generator function to parse async iterable of raw commits.
7
+ */
8
+ export function parseCommits(options = {}) {
9
+ const warnOption = options.warn;
10
+ const warn = warnOption === true
11
+ ? (err) => {
12
+ throw err;
13
+ }
14
+ : warnOption
15
+ ? (err) => warnOption(err.toString())
16
+ : () => { };
17
+ return async function* parse(rawCommits) {
18
+ const parser = new CommitParser(options);
19
+ let rawCommit;
20
+ for await (rawCommit of rawCommits) {
21
+ try {
22
+ yield parser.parse(rawCommit.toString());
23
+ }
24
+ catch (err) {
25
+ warn(err);
26
+ }
27
+ }
28
+ };
29
+ }
30
+ /**
31
+ * Create stream to parse commits.
32
+ * @param options - CommitParser options.
33
+ * @returns Stream of parsed commits.
34
+ */
35
+ export function parseCommitsStream(options = {}) {
36
+ return Transform.from(parseCommits(options));
37
+ }
38
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RyZWFtLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3N0cmVhbS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsU0FBUyxFQUFFLE1BQU0sUUFBUSxDQUFBO0FBRWxDLE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQTtBQUVoRDs7OztHQUlHO0FBQ0gsTUFBTSxVQUFVLFlBQVksQ0FDMUIsVUFBK0IsRUFBRTtJQUVqQyxNQUFNLFVBQVUsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFBO0lBQy9CLE1BQU0sSUFBSSxHQUFHLFVBQVUsS0FBSyxJQUFJO1FBQzlCLENBQUMsQ0FBQyxDQUFDLEdBQVUsRUFBRSxFQUFFO1lBQ2YsTUFBTSxHQUFHLENBQUE7UUFDWCxDQUFDO1FBQ0QsQ0FBQyxDQUFDLFVBQVU7WUFDVixDQUFDLENBQUMsQ0FBQyxHQUFVLEVBQUUsRUFBRSxDQUFDLFVBQVUsQ0FBQyxHQUFHLENBQUMsUUFBUSxFQUFFLENBQUM7WUFDNUMsQ0FBQyxDQUFDLEdBQUcsRUFBRSxHQUFjLENBQUMsQ0FBQTtJQUUxQixPQUFPLEtBQUssU0FBUyxDQUFDLENBQUMsS0FBSyxDQUMxQixVQUFzRTtRQUV0RSxNQUFNLE1BQU0sR0FBRyxJQUFJLFlBQVksQ0FBQyxPQUFPLENBQUMsQ0FBQTtRQUN4QyxJQUFJLFNBQTBCLENBQUE7UUFFOUIsSUFBSSxLQUFLLEVBQUUsU0FBUyxJQUFJLFVBQVUsRUFBRTtZQUNsQyxJQUFJO2dCQUNGLE1BQU0sTUFBTSxDQUFDLEtBQUssQ0FBQyxTQUFTLENBQUMsUUFBUSxFQUFFLENBQUMsQ0FBQTthQUN6QztZQUFDLE9BQU8sR0FBRyxFQUFFO2dCQUNaLElBQUksQ0FBQyxHQUFZLENBQUMsQ0FBQTthQUNuQjtTQUNGO0lBQ0gsQ0FBQyxDQUFBO0FBQ0gsQ0FBQztBQUVEOzs7O0dBSUc7QUFDSCxNQUFNLFVBQVUsa0JBQWtCLENBQUMsVUFBK0IsRUFBRTtJQUNsRSxPQUFPLFNBQVMsQ0FBQyxJQUFJLENBQUMsWUFBWSxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUE7QUFDOUMsQ0FBQyJ9
@@ -0,0 +1,99 @@
1
+ export interface ParserOptions {
2
+ /**
3
+ * Character used to comment out a line.
4
+ */
5
+ commentChar?: string;
6
+ /**
7
+ * Pattern to match merge headers. EG: branch merge, GitHub or GitLab like pull requests headers.
8
+ * When a merge header is parsed, the next line is used for conventional header parsing.
9
+ */
10
+ mergePattern?: RegExp;
11
+ /**
12
+ * Used to define what capturing group of `mergePattern`.
13
+ */
14
+ mergeCorrespondence?: string[];
15
+ /**
16
+ * Used to match header pattern.
17
+ */
18
+ headerPattern?: RegExp;
19
+ /**
20
+ * Breaking changes header pattern.
21
+ */
22
+ breakingHeaderPattern?: RegExp;
23
+ /**
24
+ * Used to define what capturing group of `headerPattern` captures what header part.
25
+ * The order of the array should correspond to the order of `headerPattern`'s capturing group.
26
+ */
27
+ headerCorrespondence?: string[];
28
+ /**
29
+ * Pattern to match what this commit reverts.
30
+ */
31
+ revertPattern?: RegExp;
32
+ /**
33
+ * Used to define what capturing group of `revertPattern` captures what reverted commit fields.
34
+ * The order of the array should correspond to the order of `revertPattern`'s capturing group.
35
+ */
36
+ revertCorrespondence?: string[];
37
+ /**
38
+ * Pattern to match other fields.
39
+ */
40
+ fieldPattern?: RegExp;
41
+ /**
42
+ * Keywords for important notes. This value is case **insensitive**.
43
+ */
44
+ noteKeywords?: string[];
45
+ /**
46
+ * A function that takes `noteKeywordsSelection` and returns a `RegExp` to be matched against the notes.
47
+ */
48
+ notesPattern?(text: string): RegExp;
49
+ /**
50
+ * The prefixes of an issue. EG: In `gh-123` `gh-` is the prefix.
51
+ */
52
+ issuePrefixes?: string[];
53
+ /**
54
+ * Used to define if `issuePrefixes` should be considered case sensitive.
55
+ */
56
+ issuePrefixesCaseSensitive?: boolean;
57
+ /**
58
+ * Keywords to reference an issue. This value is case **insensitive**.
59
+ */
60
+ referenceActions?: string[];
61
+ }
62
+ export interface ParserStreamOptions extends ParserOptions {
63
+ /**
64
+ * What warn function to use. For example, `console.warn.bind(console)`. By default, it's a noop. If it is `true`, it will error if commit cannot be parsed (strict).
65
+ */
66
+ warn?: boolean | ((message: string) => void);
67
+ }
68
+ export interface ParserRegexes {
69
+ notes: RegExp;
70
+ referenceParts: RegExp;
71
+ references: RegExp;
72
+ mentions: RegExp;
73
+ url: RegExp;
74
+ }
75
+ export interface CommitReference {
76
+ raw: string;
77
+ action: string | null;
78
+ owner: string | null;
79
+ repository: string | null;
80
+ issue: string;
81
+ prefix: string;
82
+ }
83
+ export interface CommitNote {
84
+ title: string;
85
+ text: string;
86
+ }
87
+ export type CommitMeta = Record<string, string | null>;
88
+ export interface CommitBase {
89
+ merge: string | null;
90
+ revert: CommitMeta | null;
91
+ header: string | null;
92
+ body: string | null;
93
+ footer: string | null;
94
+ notes: CommitNote[];
95
+ mentions: string[];
96
+ references: CommitReference[];
97
+ }
98
+ export type Commit = CommitBase & CommitMeta;
99
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW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CAAA;IACpB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAA;AAEtD,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,MAAM,EAAE,UAAU,GAAG,IAAI,CAAA;IACzB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,KAAK,EAAE,UAAU,EAAE,CAAA;IACnB,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,UAAU,EAAE,eAAe,EAAE,CAAA;CAC9B;AAED,MAAM,MAAM,MAAM,GAAG,UAAU,GAAG,UAAU,CAAA"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvdHlwZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Remove leading and trailing newlines.
3
+ * @param input
4
+ * @returns String without leading and trailing newlines.
5
+ */
6
+ export declare function trimNewLines(input: string): string;
7
+ /**
8
+ * Append a newline to a string.
9
+ * @param src
10
+ * @param line
11
+ * @returns String with appended newline.
12
+ */
13
+ export declare function appendLine(src: string | null, line: string | undefined): string;
14
+ /**
15
+ * Creates a function that filters out comments lines.
16
+ * @param char
17
+ * @returns Comment filter function.
18
+ */
19
+ export declare function getCommentFilter(char: string | undefined): (line: string) => boolean;
20
+ /**
21
+ * Select lines before the scissor.
22
+ * @param lines
23
+ * @returns Lines before the scissor.
24
+ */
25
+ export declare function truncateToScissor(lines: string[]): string[];
26
+ /**
27
+ * Filter out GPG sign lines.
28
+ * @param line
29
+ * @returns True if the line is not a GPG sign line.
30
+ */
31
+ export declare function gpgFilter(line: string): boolean;
32
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,UAiBzC;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,UAEtE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,UAE5C,MAAM,aAElB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,YAQhD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,WAErC"}
package/dist/utils.js ADDED
@@ -0,0 +1,59 @@
1
+ const SCISSOR = '# ------------------------ >8 ------------------------';
2
+ /**
3
+ * Remove leading and trailing newlines.
4
+ * @param input
5
+ * @returns String without leading and trailing newlines.
6
+ */
7
+ export function trimNewLines(input) {
8
+ // To escape ReDos we should escape String#replace with regex.
9
+ const matches = input.match(/[^\r\n]/);
10
+ if (typeof matches?.index !== 'number') {
11
+ return '';
12
+ }
13
+ const firstIndex = matches.index;
14
+ let lastIndex = input.length - 1;
15
+ while (input[lastIndex] === '\r' || input[lastIndex] === '\n') {
16
+ lastIndex--;
17
+ }
18
+ return input.substring(firstIndex, lastIndex + 1);
19
+ }
20
+ /**
21
+ * Append a newline to a string.
22
+ * @param src
23
+ * @param line
24
+ * @returns String with appended newline.
25
+ */
26
+ export function appendLine(src, line) {
27
+ return src ? `${src}\n${line || ''}` : line || '';
28
+ }
29
+ /**
30
+ * Creates a function that filters out comments lines.
31
+ * @param char
32
+ * @returns Comment filter function.
33
+ */
34
+ export function getCommentFilter(char) {
35
+ return char
36
+ ? (line) => !line.startsWith(char)
37
+ : () => true;
38
+ }
39
+ /**
40
+ * Select lines before the scissor.
41
+ * @param lines
42
+ * @returns Lines before the scissor.
43
+ */
44
+ export function truncateToScissor(lines) {
45
+ const scissorIndex = lines.indexOf(SCISSOR);
46
+ if (scissorIndex === -1) {
47
+ return lines;
48
+ }
49
+ return lines.slice(0, scissorIndex);
50
+ }
51
+ /**
52
+ * Filter out GPG sign lines.
53
+ * @param line
54
+ * @returns True if the line is not a GPG sign line.
55
+ */
56
+ export function gpgFilter(line) {
57
+ return !line.match(/^\s*gpg:/);
58
+ }
59
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvdXRpbHMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsTUFBTSxPQUFPLEdBQUcsd0RBQXdELENBQUE7QUFFeEU7Ozs7R0FJRztBQUNILE1BQU0sVUFBVSxZQUFZLENBQUMsS0FBYTtJQUN4Qyw4REFBOEQ7SUFFOUQsTUFBTSxPQUFPLEdBQUcsS0FBSyxDQUFDLEtBQUssQ0FBQyxTQUFTLENBQUMsQ0FBQTtJQUV0QyxJQUFJLE9BQU8sT0FBTyxFQUFFLEtBQUssS0FBSyxRQUFRLEVBQUU7UUFDdEMsT0FBTyxFQUFFLENBQUE7S0FDVjtJQUVELE1BQU0sVUFBVSxHQUFHLE9BQU8sQ0FBQyxLQUFLLENBQUE7SUFDaEMsSUFBSSxTQUFTLEdBQUcsS0FBSyxDQUFDLE1BQU0sR0FBRyxDQUFDLENBQUE7SUFFaEMsT0FBTyx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QUFTLENBQUMsSUFBWTtJQUNwQyxPQUFPLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxVQUFVLENBQUMsQ0FBQTtBQUNoQyxDQUFDIn0=
package/package.json CHANGED
@@ -1,29 +1,23 @@
1
1
  {
2
2
  "name": "conventional-commits-parser",
3
- "version": "5.0.0",
4
- "description": "Parse raw conventional commits",
5
- "bugs": {
6
- "url": "https://github.com/conventional-changelog/conventional-changelog/issues"
7
- },
8
- "homepage": "https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser#readme",
3
+ "type": "module",
4
+ "version": "6.1.0",
5
+ "description": "Parse raw conventional commits.",
9
6
  "author": {
10
7
  "name": "Steve Mao",
11
8
  "email": "maochenyan@gmail.com",
12
9
  "url": "https://github.com/stevemao"
13
10
  },
11
+ "license": "MIT",
12
+ "homepage": "https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser#readme",
14
13
  "repository": {
15
14
  "type": "git",
16
- "url": "https://github.com/conventional-changelog/conventional-changelog.git"
15
+ "url": "https://github.com/conventional-changelog/conventional-changelog.git",
16
+ "directory": "packages/conventional-commits-parser"
17
17
  },
18
- "license": "MIT",
19
- "engines": {
20
- "node": ">=16"
18
+ "bugs": {
19
+ "url": "https://github.com/conventional-changelog/conventional-changelog/issues"
21
20
  },
22
- "files": [
23
- "index.js",
24
- "cli.mjs",
25
- "lib"
26
- ],
27
21
  "keywords": [
28
22
  "conventional-commits-parser",
29
23
  "changelog",
@@ -32,16 +26,20 @@
32
26
  "parsing",
33
27
  "logs"
34
28
  ],
29
+ "engines": {
30
+ "node": ">=18"
31
+ },
32
+ "exports": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/index.js"
35
+ },
36
+ "files": [
37
+ "dist"
38
+ ],
35
39
  "dependencies": {
36
- "JSONStream": "^1.3.5",
37
- "is-text-path": "^2.0.0",
38
- "meow": "^12.0.1",
39
- "split2": "^4.0.0"
40
+ "meow": "^13.0.0"
40
41
  },
41
42
  "bin": {
42
- "conventional-commits-parser": "cli.mjs"
43
- },
44
- "devDependencies": {
45
- "forceable-tty": "^0.1.0"
43
+ "conventional-commits-parser": "./dist/cli/index.js"
46
44
  }
47
45
  }
package/cli.mjs DELETED
@@ -1,170 +0,0 @@
1
- #!/usr/bin/env node
2
- import fs from 'fs'
3
- import readline from 'readline'
4
- import { Transform } from 'stream'
5
- import isTextPath from 'is-text-path'
6
- import JSONStream from 'JSONStream'
7
- import split from 'split2'
8
- import meow from 'meow'
9
- import conventionalCommitsParser from './index.js'
10
-
11
- const cli = meow(`
12
- Practice writing commit messages or parse messages from files.
13
- If used without specifying a text file path, you will enter an interactive shell.
14
- Otherwise the commit messages in the files are parsed and printed
15
- By default, commits will be split by three newlines ('\\n\\n\\n') or you can specify a separator.
16
-
17
- Usage
18
- conventional-commits-parser [<commit-separator>]
19
- conventional-commits-parser [<commit-separator>] <path> [<path> ...]
20
- cat <path> | conventional-commits-parser [<commit-separator>]
21
-
22
- Example
23
- conventional-commits-parser
24
- conventional-commits-parser log.txt
25
- cat log.txt | conventional-commits-parser
26
- conventional-commits-parser log2.txt '===' >> parsed.txt
27
-
28
- Options
29
- -p, --header-pattern Regex to match header pattern
30
- -c, --header-correspondence Comma separated parts used to define what capturing group of 'headerPattern' captures what
31
- -r, --reference-actions Comma separated keywords that used to reference issues
32
- -i, --issue-prefixes Comma separated prefixes of an issue
33
- --issue-prefixes-case-sensitive Treat issue prefixes as case sensitive
34
- -n, --note-keywords Comma separated keywords for important notes
35
- -f, --field-pattern Regex to match other fields
36
- --revert-pattern Regex to match revert pattern
37
- --revert-correspondence Comma separated fields used to define what the commit reverts
38
- -v, --verbose Verbose output
39
- `, {
40
- importMeta: import.meta,
41
- flags: {
42
- headerPattern: {
43
- shortFlag: 'p',
44
- type: 'string'
45
- },
46
- headerCorrespondence: {
47
- shortFlag: 'c',
48
- type: 'string'
49
- },
50
- referenceActions: {
51
- shortFlag: 'r',
52
- type: 'string'
53
- },
54
- issuePrefixes: {
55
- shortFlag: 'i',
56
- type: 'string'
57
- },
58
- issuePrefixesCaseSensitive: {
59
- type: 'boolean'
60
- },
61
- noteKeywords: {
62
- shortFlag: 'n',
63
- type: 'string'
64
- },
65
- fieldPattern: {
66
- shortFlag: 'f',
67
- type: 'string'
68
- },
69
- revertPattern: {
70
- type: 'string'
71
- },
72
- revertCorrespondence: {
73
- type: 'string'
74
- },
75
- verbose: {
76
- shortFlag: 'v',
77
- type: 'boolean'
78
- }
79
- }
80
- })
81
-
82
- const filePaths = []
83
- let separator = '\n\n\n'
84
-
85
- cli.input.forEach((arg) => {
86
- if (isTextPath(arg)) {
87
- filePaths.push(arg)
88
- } else {
89
- separator = arg
90
- }
91
- })
92
-
93
- const length = filePaths.length
94
- const options = cli.flags
95
-
96
- if (options.verbose) {
97
- options.warn = console.log.bind(console)
98
- }
99
-
100
- function processFile (fileIndex) {
101
- const filePath = filePaths[fileIndex]
102
- fs.createReadStream(filePath)
103
- .on('error', (err) => {
104
- console.warn('Failed to read file ' + filePath + '\n' + err)
105
- if (++fileIndex < length) {
106
- processFile(fileIndex)
107
- }
108
- })
109
- .pipe(split(separator))
110
- .pipe(conventionalCommitsParser(options))
111
- .pipe(JSONStream.stringify())
112
- .on('end', () => {
113
- if (++fileIndex < length) {
114
- processFile(fileIndex)
115
- }
116
- })
117
- .pipe(process.stdout)
118
- }
119
-
120
- if (process.stdin.isTTY) {
121
- if (length > 0) {
122
- processFile(0)
123
- } else {
124
- let commit = ''
125
- const stream = new Transform({
126
- transform: (chunk, enc, cb) => cb(null, chunk)
127
- })
128
- const rl = readline.createInterface({
129
- input: process.stdin,
130
- output: process.stdout,
131
- terminal: true
132
- })
133
-
134
- stream.pipe(conventionalCommitsParser(options))
135
- .pipe(JSONStream.stringify('', '', ''))
136
- .pipe(
137
- new Transform({
138
- transform (chunk, enc, cb) {
139
- if (chunk.toString() === '""') {
140
- cb(null, 'Commit cannot be parsed\n')
141
- } else {
142
- cb(null, chunk + '\n')
143
- }
144
- }
145
- })
146
- )
147
- .pipe(process.stdout)
148
-
149
- rl.on('line', (line) => {
150
- commit += line + '\n'
151
- if (commit.indexOf(separator) === -1) {
152
- return
153
- }
154
-
155
- stream.write(commit)
156
- commit = ''
157
- })
158
- }
159
- } else {
160
- options.warn = true
161
- process.stdin
162
- .pipe(split(separator))
163
- .pipe(conventionalCommitsParser(options))
164
- .on('error', (err) => {
165
- console.error(err.toString())
166
- process.exit(1)
167
- })
168
- .pipe(JSONStream.stringify())
169
- .pipe(process.stdout)
170
- }
package/index.js DELETED
@@ -1,105 +0,0 @@
1
- 'use strict'
2
-
3
- const { Transform } = require('stream')
4
- const parser = require('./lib/parser')
5
- const regex = require('./lib/regex')
6
-
7
- function assignOpts (options) {
8
- options = {
9
- headerPattern: /^(\w*)(?:\(([\w$.\-*/ ]*)\))?: (.*)$/,
10
- headerCorrespondence: ['type', 'scope', 'subject'],
11
- referenceActions: [
12
- 'close',
13
- 'closes',
14
- 'closed',
15
- 'fix',
16
- 'fixes',
17
- 'fixed',
18
- 'resolve',
19
- 'resolves',
20
- 'resolved'
21
- ],
22
- issuePrefixes: ['#'],
23
- noteKeywords: ['BREAKING CHANGE', 'BREAKING-CHANGE'],
24
- fieldPattern: /^-(.*?)-$/,
25
- revertPattern: /^Revert\s"([\s\S]*)"\s*This reverts commit (\w*)\./,
26
- revertCorrespondence: ['header', 'hash'],
27
- warn: function () {},
28
- mergePattern: null,
29
- mergeCorrespondence: null,
30
- ...options
31
- }
32
-
33
- if (typeof options.headerPattern === 'string') {
34
- options.headerPattern = new RegExp(options.headerPattern)
35
- }
36
-
37
- if (typeof options.headerCorrespondence === 'string') {
38
- options.headerCorrespondence = options.headerCorrespondence.split(',')
39
- }
40
-
41
- if (typeof options.referenceActions === 'string') {
42
- options.referenceActions = options.referenceActions.split(',')
43
- }
44
-
45
- if (typeof options.issuePrefixes === 'string') {
46
- options.issuePrefixes = options.issuePrefixes.split(',')
47
- }
48
-
49
- if (typeof options.noteKeywords === 'string') {
50
- options.noteKeywords = options.noteKeywords.split(',')
51
- }
52
-
53
- if (typeof options.fieldPattern === 'string') {
54
- options.fieldPattern = new RegExp(options.fieldPattern)
55
- }
56
-
57
- if (typeof options.revertPattern === 'string') {
58
- options.revertPattern = new RegExp(options.revertPattern)
59
- }
60
-
61
- if (typeof options.revertCorrespondence === 'string') {
62
- options.revertCorrespondence = options.revertCorrespondence.split(',')
63
- }
64
-
65
- if (typeof options.mergePattern === 'string') {
66
- options.mergePattern = new RegExp(options.mergePattern)
67
- }
68
-
69
- return options
70
- }
71
-
72
- function conventionalCommitsParser (options) {
73
- options = assignOpts(options)
74
- const reg = regex(options)
75
-
76
- return new Transform({
77
- objectMode: true,
78
- highWaterMark: 16,
79
- transform (data, enc, cb) {
80
- let commit
81
-
82
- try {
83
- commit = parser(data.toString(), options, reg)
84
- cb(null, commit)
85
- } catch (err) {
86
- if (options.warn === true) {
87
- cb(err)
88
- } else {
89
- options.warn(err.toString())
90
- cb(null, '')
91
- }
92
- }
93
- }
94
- })
95
- }
96
-
97
- function sync (commit, options) {
98
- options = assignOpts(options)
99
- const reg = regex(options)
100
-
101
- return parser(commit, options, reg)
102
- }
103
-
104
- module.exports = conventionalCommitsParser
105
- module.exports.sync = sync