@thisismanta/semantic-version 2.0.0 → 5.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/auto-npm-version.d.ts +1 -1
- package/lib/auto-npm-version.js +147 -127
- package/lib/debug.d.ts +1 -1
- package/lib/debug.js +9 -9
- package/lib/index.d.ts +8 -7
- package/lib/index.js +40 -40
- package/lib/install-git-hooks.d.ts +1 -1
- package/lib/install-git-hooks.js +89 -89
- package/lib/lint-commit-message.d.ts +1 -1
- package/lib/lint-commit-message.js +42 -42
- package/package.json +5 -4
- package/lib/index.test.d.ts +0 -1
- package/lib/index.test.js +0 -84
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/lib/auto-npm-version.js
CHANGED
|
@@ -1,127 +1,147 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const semver_1 = __importDefault(require("semver"));
|
|
30
|
-
const execa_1 = require("execa");
|
|
31
|
-
const github = __importStar(require("@actions/github"));
|
|
32
|
-
const index_1 = require("./index");
|
|
33
|
-
const debug_1 = require("./debug");
|
|
34
|
-
main();
|
|
35
|
-
async function main() {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
(0, debug_1.debug)('
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
})
|
|
118
|
-
(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const semver_1 = __importDefault(require("semver"));
|
|
30
|
+
const execa_1 = require("execa");
|
|
31
|
+
const github = __importStar(require("@actions/github"));
|
|
32
|
+
const index_1 = require("./index");
|
|
33
|
+
const debug_1 = require("./debug");
|
|
34
|
+
main();
|
|
35
|
+
async function main() {
|
|
36
|
+
(0, debug_1.debug)('process.env.GITHUB_TOKEN »', process.env.GITHUB_TOKEN);
|
|
37
|
+
if (!process.env.GITHUB_TOKEN) {
|
|
38
|
+
throw new Error('Expected "GITHUB_TOKEN" env to be provided.');
|
|
39
|
+
}
|
|
40
|
+
// Set up Git commit author for further use in "npm version" and "git push" command
|
|
41
|
+
// See https://github.com/actions/checkout#push-a-commit-using-the-built-in-token
|
|
42
|
+
if (!(await run(`git config user.name`).catch(() => ''))) {
|
|
43
|
+
await run(`git config user.name ${github.context.payload.pusher?.name || github.context.actor}`);
|
|
44
|
+
await run(`git config user.email ${github.context.payload.pusher?.email || 'github-actions@github.com'}`);
|
|
45
|
+
}
|
|
46
|
+
const remote = await run(`git remote`) || 'origin';
|
|
47
|
+
// Check if the given GITHUB_TOKEN has the permission to push to the repository
|
|
48
|
+
// See https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#configuring-the-default-github_token-permissions
|
|
49
|
+
await run(`git push --dry-run ${remote}`);
|
|
50
|
+
const lastVersion = await getLastVersion();
|
|
51
|
+
(0, debug_1.debug)('lastVersion »', JSON.stringify(lastVersion));
|
|
52
|
+
if (!lastVersion) {
|
|
53
|
+
throw new Error('Expected "version" field to exist in package.json.');
|
|
54
|
+
}
|
|
55
|
+
const commits = getCommits(await getGitHistory(lastVersion));
|
|
56
|
+
console.log(`Found ${commits.length} qualified commits since v${lastVersion}`);
|
|
57
|
+
(0, debug_1.debug)('commits »', JSON.stringify(commits, null, 2));
|
|
58
|
+
const releaseType = getReleaseType(commits);
|
|
59
|
+
(0, debug_1.debug)('releaseType »', JSON.stringify(releaseType));
|
|
60
|
+
if (!releaseType) {
|
|
61
|
+
console.log('Done without releasing a new version');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
await run(`npm version --git-tag-version ${releaseType}`);
|
|
65
|
+
await run(`git push --follow-tags ${remote}`);
|
|
66
|
+
const nextVersion = await getLastVersion();
|
|
67
|
+
(0, debug_1.debug)('nextVersion »', JSON.stringify(nextVersion));
|
|
68
|
+
console.log(`Created tag v${nextVersion}`);
|
|
69
|
+
if (!nextVersion) {
|
|
70
|
+
throw new Error(`Expected "${nextVersion}" returned from "npm version" to be a valid semantic version.`);
|
|
71
|
+
}
|
|
72
|
+
const releaseNote = getReleaseNote(commits);
|
|
73
|
+
(0, debug_1.debug)('releaseNote »', releaseNote);
|
|
74
|
+
const octokit = github.getOctokit(process.env.GITHUB_TOKEN);
|
|
75
|
+
// See https://octokit.github.io/rest.js/v19#repos-create-release
|
|
76
|
+
const releaseRespond = await octokit.rest.repos.createRelease({
|
|
77
|
+
...github.context.repo,
|
|
78
|
+
tag_name: 'v' + nextVersion,
|
|
79
|
+
body: releaseNote,
|
|
80
|
+
make_latest: true, // TODO: compare with the latest release
|
|
81
|
+
});
|
|
82
|
+
(0, debug_1.debug)('releaseRespond »', JSON.stringify(releaseRespond, null, 2));
|
|
83
|
+
if (releaseRespond.status >= 200 && releaseRespond.status < 300) {
|
|
84
|
+
console.log('Created', releaseRespond.data.url);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async function run(command) {
|
|
88
|
+
(0, debug_1.debug)(command);
|
|
89
|
+
const { stdout } = await (0, execa_1.execaCommand)(command);
|
|
90
|
+
(0, debug_1.debug)(stdout);
|
|
91
|
+
return stdout;
|
|
92
|
+
}
|
|
93
|
+
async function getLastVersion() {
|
|
94
|
+
return (semver_1.default.valid(await run('git describe --tags --abbrev=0').catch(() => '')) ||
|
|
95
|
+
semver_1.default.valid(JSON.parse(await run('npm pkg get version'))));
|
|
96
|
+
}
|
|
97
|
+
async function getGitHistory(version) {
|
|
98
|
+
const tagFound = !!(await run(`git tag --list v${version}`));
|
|
99
|
+
return await run(`git --no-pager log ${tagFound ? `v${version}..HEAD` : ''} --format=%H%s`);
|
|
100
|
+
}
|
|
101
|
+
function getCommits(gitLog) {
|
|
102
|
+
return gitLog
|
|
103
|
+
.split('\n')
|
|
104
|
+
.filter(line => line.length > 0)
|
|
105
|
+
.map(line => ({
|
|
106
|
+
hash: line.substring(0, 40),
|
|
107
|
+
message: line.substring(40),
|
|
108
|
+
}))
|
|
109
|
+
.filter(({ message }) => semver_1.default.valid(message) === null)
|
|
110
|
+
.map(({ hash, message }) => {
|
|
111
|
+
const { type, breaking, subject } = (0, index_1.checkConventionalMessage)(message, { debug: () => { } });
|
|
112
|
+
return { hash, type, breaking, subject };
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function getReleaseType(commits) {
|
|
116
|
+
return (commits.find(({ breaking }) => breaking) && 'major' ||
|
|
117
|
+
commits.find(({ type }) => type === 'feat') && 'minor' ||
|
|
118
|
+
commits.find(({ type }) => type === 'fix' || type === 'build') && 'patch' ||
|
|
119
|
+
null);
|
|
120
|
+
}
|
|
121
|
+
function getReleaseNote(commits) {
|
|
122
|
+
const groups = {
|
|
123
|
+
'BREAKING CHANGES': [],
|
|
124
|
+
'Features': [],
|
|
125
|
+
'Bug Fixes': [],
|
|
126
|
+
'Others': [],
|
|
127
|
+
};
|
|
128
|
+
for (const commit of commits) {
|
|
129
|
+
if (commit.breaking) {
|
|
130
|
+
groups['BREAKING CHANGES'].push(commit);
|
|
131
|
+
}
|
|
132
|
+
else if (commit.type === 'feat') {
|
|
133
|
+
groups['Features'].push(commit);
|
|
134
|
+
}
|
|
135
|
+
else if (commit.type === 'fix') {
|
|
136
|
+
groups['Bug Fixes'].push(commit);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
groups['Others'].push(commit);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return Object.entries(groups)
|
|
143
|
+
.filter(([title, commits]) => commits.length > 0)
|
|
144
|
+
.map(([title, commits]) => `### ${title}\n\n` +
|
|
145
|
+
commits.map(({ subject, hash }) => `- ${subject} (${hash})`).join('\n'))
|
|
146
|
+
.join('\n\n');
|
|
147
|
+
}
|
package/lib/debug.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function debug(...args: Array<any>): void;
|
|
1
|
+
export declare function debug(...args: Array<any>): void;
|
package/lib/debug.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.debug = void 0;
|
|
4
|
-
function debug(...args) {
|
|
5
|
-
if (process.env.DEBUG) {
|
|
6
|
-
console.log(...args);
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
exports.debug = debug;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.debug = void 0;
|
|
4
|
+
function debug(...args) {
|
|
5
|
+
if (process.env.DEBUG) {
|
|
6
|
+
console.log(...args);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.debug = debug;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export declare const allowedTypes:
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export declare const allowedTypes: readonly ["feat", "fix", "build", "chore"];
|
|
2
|
+
export type SemanticType = typeof allowedTypes[number];
|
|
3
|
+
export declare function checkConventionalMessage(message: string, { debug }: Pick<Console, 'debug'>): {
|
|
4
|
+
type: "feat" | "fix" | "build" | "chore" | undefined;
|
|
5
|
+
breaking: boolean;
|
|
6
|
+
subject: string;
|
|
7
|
+
errors: string[];
|
|
8
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkConventionalMessage = exports.allowedTypes = void 0;
|
|
4
|
-
const titlePattern = /^(?<type>\w+)(?<scope>\(.*?\))?(?<breaking>\!)?:(?<subject>.+)/;
|
|
5
|
-
exports.allowedTypes = ['feat', 'fix', '
|
|
6
|
-
function checkConventionalMessage(message, { debug }) {
|
|
7
|
-
const pattern = (message.match(titlePattern)?.groups || {});
|
|
8
|
-
const { type, scope, breaking, subject } = pattern;
|
|
9
|
-
debug('type »', type);
|
|
10
|
-
debug('scope »', scope);
|
|
11
|
-
debug('breaking »', breaking);
|
|
12
|
-
debug('subject »', subject?.trim());
|
|
13
|
-
const errors = [
|
|
14
|
-
!type &&
|
|
15
|
-
'The pull request title must match the pattern of "<type>[!]: <subject>" which is a reduced set of https://www.conventionalcommits.org/en/v1.0.0/',
|
|
16
|
-
typeof type === 'string' && exports.allowedTypes.includes(type.toLowerCase()) === false &&
|
|
17
|
-
'The type in a pull request title must be one of ' + exports.allowedTypes.map(name => '"' + name + '"').join(', ') + '.',
|
|
18
|
-
typeof type === 'string' && /^[a-z]+$/.test(type) === false &&
|
|
19
|
-
'The type in a pull request title must be in lower case only.',
|
|
20
|
-
scope &&
|
|
21
|
-
'A scope in a pull request title is never allowed.',
|
|
22
|
-
typeof type === 'string' && typeof subject !== 'string' &&
|
|
23
|
-
'The subject in a pull request title must be provided.',
|
|
24
|
-
typeof subject === 'string' && (subject.match(/^ +/)?.[0].length || 0) !== 1 &&
|
|
25
|
-
'A single space must be after ":" symbol.',
|
|
26
|
-
typeof subject === 'string' && /^[a-z]/.test(subject.trim()) === false &&
|
|
27
|
-
'The subject must start with a lower case latin alphabet.',
|
|
28
|
-
typeof subject === 'string' && /[\s\.]+$/.test(subject) && /\.{3}$/.test(subject.trim()) === false &&
|
|
29
|
-
'The subject must not end with a period or a space.',
|
|
30
|
-
].filter((error) => typeof error === 'string');
|
|
31
|
-
return {
|
|
32
|
-
type,
|
|
33
|
-
breaking: !!breaking,
|
|
34
|
-
subject: typeof subject === 'string'
|
|
35
|
-
? subject.trim().replace(/[\s\.]+$/, '') + (/\.{3}$/.test(subject.trim()) ? '...' : '')
|
|
36
|
-
: message,
|
|
37
|
-
errors
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
exports.checkConventionalMessage = checkConventionalMessage;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkConventionalMessage = exports.allowedTypes = void 0;
|
|
4
|
+
const titlePattern = /^(?<type>\w+)(?<scope>\(.*?\))?(?<breaking>\!)?:(?<subject>.+)/;
|
|
5
|
+
exports.allowedTypes = ['feat', 'fix', 'build', 'chore'];
|
|
6
|
+
function checkConventionalMessage(message, { debug }) {
|
|
7
|
+
const pattern = (message.match(titlePattern)?.groups || {});
|
|
8
|
+
const { type, scope, breaking, subject } = pattern;
|
|
9
|
+
debug('type »', type);
|
|
10
|
+
debug('scope »', scope);
|
|
11
|
+
debug('breaking »', breaking);
|
|
12
|
+
debug('subject »', subject?.trim());
|
|
13
|
+
const errors = [
|
|
14
|
+
!type &&
|
|
15
|
+
'The pull request title must match the pattern of "<type>[!]: <subject>" which is a reduced set of https://www.conventionalcommits.org/en/v1.0.0/',
|
|
16
|
+
typeof type === 'string' && exports.allowedTypes.includes(type.toLowerCase()) === false &&
|
|
17
|
+
'The type in a pull request title must be one of ' + exports.allowedTypes.map(name => '"' + name + '"').join(', ') + '.',
|
|
18
|
+
typeof type === 'string' && /^[a-z]+$/.test(type) === false &&
|
|
19
|
+
'The type in a pull request title must be in lower case only.',
|
|
20
|
+
scope &&
|
|
21
|
+
'A scope in a pull request title is never allowed.',
|
|
22
|
+
typeof type === 'string' && typeof subject !== 'string' &&
|
|
23
|
+
'The subject in a pull request title must be provided.',
|
|
24
|
+
typeof subject === 'string' && (subject.match(/^ +/)?.[0].length || 0) !== 1 &&
|
|
25
|
+
'A single space must be after ":" symbol.',
|
|
26
|
+
typeof subject === 'string' && /^[a-z]/.test(subject.trim()) === false &&
|
|
27
|
+
'The subject must start with a lower case latin alphabet.',
|
|
28
|
+
typeof subject === 'string' && /[\s\.]+$/.test(subject) && /\.{3}$/.test(subject.trim()) === false &&
|
|
29
|
+
'The subject must not end with a period or a space.',
|
|
30
|
+
].filter((error) => typeof error === 'string');
|
|
31
|
+
return {
|
|
32
|
+
type: exports.allowedTypes.includes(type) ? type : undefined,
|
|
33
|
+
breaking: !!breaking,
|
|
34
|
+
subject: typeof subject === 'string'
|
|
35
|
+
? subject.trim().replace(/[\s\.]+$/, '') + (/\.{3}$/.test(subject.trim()) ? '...' : '')
|
|
36
|
+
: message,
|
|
37
|
+
errors
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
exports.checkConventionalMessage = checkConventionalMessage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/lib/install-git-hooks.js
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const fs = __importStar(require("fs/promises"));
|
|
27
|
-
const fp = __importStar(require("path"));
|
|
28
|
-
const execa_1 = require("execa");
|
|
29
|
-
const debug_1 = require("./debug");
|
|
30
|
-
main();
|
|
31
|
-
const packageName = require('../package.json').name;
|
|
32
|
-
async function main() {
|
|
33
|
-
const currentDirectoryPath = process.cwd();
|
|
34
|
-
(0, debug_1.debug)('currentDirectoryPath »', currentDirectoryPath);
|
|
35
|
-
const gitDirectoryPath = await findGitDirectoryPath(currentDirectoryPath);
|
|
36
|
-
(0, debug_1.debug)('gitDirectoryPath »', gitDirectoryPath);
|
|
37
|
-
if (!gitDirectoryPath) {
|
|
38
|
-
throw new Error('Could not find a Git directory.');
|
|
39
|
-
}
|
|
40
|
-
const packageJSON = JSON.parse(await fs.readFile(fp.join(gitDirectoryPath, 'package.json'), 'utf-8'));
|
|
41
|
-
if (packageJSON.name === packageName) {
|
|
42
|
-
console.warn('Skip installing Git hooks as it is supposed to be done on a consumer repository.');
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
console.log('Installing Husky');
|
|
46
|
-
await (0, execa_1.execaCommand)('npx husky install', { cwd: gitDirectoryPath });
|
|
47
|
-
const huskyDirectoryPath = fp.resolve(gitDirectoryPath, '.husky');
|
|
48
|
-
(0, debug_1.debug)('huskyDirectoryPath »', huskyDirectoryPath);
|
|
49
|
-
await fs.access(huskyDirectoryPath);
|
|
50
|
-
await upsert(fp.join(huskyDirectoryPath, 'commit-msg'), 'npx lint-commit-message ${1}');
|
|
51
|
-
console.log('Done adding Git hooks.');
|
|
52
|
-
}
|
|
53
|
-
async function findGitDirectoryPath(path) {
|
|
54
|
-
const pathList = path.split(fp.sep);
|
|
55
|
-
while (pathList.length > 1) {
|
|
56
|
-
const testPath = fp.join(pathList.join(fp.sep), '.git');
|
|
57
|
-
try {
|
|
58
|
-
await fs.access(testPath);
|
|
59
|
-
const stat = await fs.lstat(testPath);
|
|
60
|
-
if (stat.isDirectory()) {
|
|
61
|
-
return pathList.join(fp.sep);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
// Do nothing
|
|
66
|
-
}
|
|
67
|
-
pathList.pop();
|
|
68
|
-
}
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
async function upsert(filePath, text) {
|
|
72
|
-
try {
|
|
73
|
-
await fs.access(filePath);
|
|
74
|
-
console.log('Found', filePath);
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
await fs.writeFile(filePath, '#!/usr/bin/env sh' + '\n' +
|
|
78
|
-
'. "$(dirname -- "$0")/_/husky.sh"' + '\n', 'utf-8');
|
|
79
|
-
console.log('Created', filePath);
|
|
80
|
-
}
|
|
81
|
-
const fileText = await fs.readFile(filePath, 'utf-8');
|
|
82
|
-
const lines = fileText.trim().split('\n');
|
|
83
|
-
const index = lines
|
|
84
|
-
.findIndex(line => line.trim().includes(text));
|
|
85
|
-
if (index === -1) {
|
|
86
|
-
await fs.appendFile(filePath, '\n' + text + '\n', 'utf-8');
|
|
87
|
-
console.log(`Added "${text}" to ${filePath}`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const fs = __importStar(require("fs/promises"));
|
|
27
|
+
const fp = __importStar(require("path"));
|
|
28
|
+
const execa_1 = require("execa");
|
|
29
|
+
const debug_1 = require("./debug");
|
|
30
|
+
main();
|
|
31
|
+
const packageName = require('../package.json').name;
|
|
32
|
+
async function main() {
|
|
33
|
+
const currentDirectoryPath = process.cwd();
|
|
34
|
+
(0, debug_1.debug)('currentDirectoryPath »', currentDirectoryPath);
|
|
35
|
+
const gitDirectoryPath = await findGitDirectoryPath(currentDirectoryPath);
|
|
36
|
+
(0, debug_1.debug)('gitDirectoryPath »', gitDirectoryPath);
|
|
37
|
+
if (!gitDirectoryPath) {
|
|
38
|
+
throw new Error('Could not find a Git directory.');
|
|
39
|
+
}
|
|
40
|
+
const packageJSON = JSON.parse(await fs.readFile(fp.join(gitDirectoryPath, 'package.json'), 'utf-8'));
|
|
41
|
+
if (packageJSON.name === packageName) {
|
|
42
|
+
console.warn('Skip installing Git hooks as it is supposed to be done on a consumer repository.');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
console.log('Installing Husky');
|
|
46
|
+
await (0, execa_1.execaCommand)('npx husky install', { cwd: gitDirectoryPath });
|
|
47
|
+
const huskyDirectoryPath = fp.resolve(gitDirectoryPath, '.husky');
|
|
48
|
+
(0, debug_1.debug)('huskyDirectoryPath »', huskyDirectoryPath);
|
|
49
|
+
await fs.access(huskyDirectoryPath);
|
|
50
|
+
await upsert(fp.join(huskyDirectoryPath, 'commit-msg'), 'npx lint-commit-message ${1}');
|
|
51
|
+
console.log('Done adding Git hooks.');
|
|
52
|
+
}
|
|
53
|
+
async function findGitDirectoryPath(path) {
|
|
54
|
+
const pathList = path.split(fp.sep);
|
|
55
|
+
while (pathList.length > 1) {
|
|
56
|
+
const testPath = fp.join(pathList.join(fp.sep), '.git');
|
|
57
|
+
try {
|
|
58
|
+
await fs.access(testPath);
|
|
59
|
+
const stat = await fs.lstat(testPath);
|
|
60
|
+
if (stat.isDirectory()) {
|
|
61
|
+
return pathList.join(fp.sep);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// Do nothing
|
|
66
|
+
}
|
|
67
|
+
pathList.pop();
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
async function upsert(filePath, text) {
|
|
72
|
+
try {
|
|
73
|
+
await fs.access(filePath);
|
|
74
|
+
console.log('Found', filePath);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
await fs.writeFile(filePath, '#!/usr/bin/env sh' + '\n' +
|
|
78
|
+
'. "$(dirname -- "$0")/_/husky.sh"' + '\n', 'utf-8');
|
|
79
|
+
console.log('Created', filePath);
|
|
80
|
+
}
|
|
81
|
+
const fileText = await fs.readFile(filePath, 'utf-8');
|
|
82
|
+
const lines = fileText.trim().split('\n');
|
|
83
|
+
const index = lines
|
|
84
|
+
.findIndex(line => line.trim().includes(text));
|
|
85
|
+
if (index === -1) {
|
|
86
|
+
await fs.appendFile(filePath, '\n' + text + '\n', 'utf-8');
|
|
87
|
+
console.log(`Added "${text}" to ${filePath}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const fs = __importStar(require("fs/promises"));
|
|
27
|
-
const index_1 = require("./index");
|
|
28
|
-
const debug_1 = require("./debug");
|
|
29
|
-
main();
|
|
30
|
-
async function main() {
|
|
31
|
-
const [messageFilePath] = process.argv.slice(2);
|
|
32
|
-
(0, debug_1.debug)('messageFilePath »', messageFilePath);
|
|
33
|
-
const message = (await fs.readFile(messageFilePath, 'utf-8')).trim();
|
|
34
|
-
(0, debug_1.debug)('message »', message);
|
|
35
|
-
const { errors } = (0, index_1.checkConventionalMessage)(message, { debug: debug_1.debug });
|
|
36
|
-
if (errors.length > 0) {
|
|
37
|
-
for (const error of errors) {
|
|
38
|
-
console.error(error);
|
|
39
|
-
}
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const fs = __importStar(require("fs/promises"));
|
|
27
|
+
const index_1 = require("./index");
|
|
28
|
+
const debug_1 = require("./debug");
|
|
29
|
+
main();
|
|
30
|
+
async function main() {
|
|
31
|
+
const [messageFilePath] = process.argv.slice(2);
|
|
32
|
+
(0, debug_1.debug)('messageFilePath »', messageFilePath);
|
|
33
|
+
const message = (await fs.readFile(messageFilePath, 'utf-8')).trim();
|
|
34
|
+
(0, debug_1.debug)('message »', message);
|
|
35
|
+
const { errors } = (0, index_1.checkConventionalMessage)(message, { debug: debug_1.debug });
|
|
36
|
+
if (errors.length > 0) {
|
|
37
|
+
for (const error of errors) {
|
|
38
|
+
console.error(error);
|
|
39
|
+
}
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thisismanta/semantic-version",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"author": "Anantachai Saothong <thisismanta@gmail.com>",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"engines": {
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"test": "jest",
|
|
21
21
|
"build": "rm -rf lib && tsc",
|
|
22
|
-
"preversion": "npm run
|
|
22
|
+
"preversion": "npm run build",
|
|
23
23
|
"version": "npm publish --access public",
|
|
24
|
-
"
|
|
25
|
-
"
|
|
24
|
+
"postinstall": "node ./lib/install-git-hooks.js",
|
|
25
|
+
"prepare": "husky install"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/jest": "^29.4.0",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"@types/semver": "^7.3.13",
|
|
31
31
|
"jest": "^29.4.3",
|
|
32
32
|
"ts-jest": "^29.0.5",
|
|
33
|
+
"ts-node": "^10.9.1",
|
|
33
34
|
"typescript": "^4.9.5"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
package/lib/index.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/index.test.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const index_1 = require("./index");
|
|
4
|
-
const debug = jest.fn();
|
|
5
|
-
it('does not return any error, given a valid pattern', () => {
|
|
6
|
-
for (const type of index_1.allowedTypes) {
|
|
7
|
-
expect((0, index_1.checkConventionalMessage)(type + ': xxx', { debug })).toEqual({
|
|
8
|
-
type: type,
|
|
9
|
-
breaking: false,
|
|
10
|
-
subject: 'xxx',
|
|
11
|
-
errors: []
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
expect((0, index_1.checkConventionalMessage)('chore!: xxx', { debug })).toEqual({
|
|
15
|
-
type: 'chore',
|
|
16
|
-
breaking: true,
|
|
17
|
-
subject: 'xxx',
|
|
18
|
-
errors: []
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
it('returns the error, given an invalid pattern', () => {
|
|
22
|
-
expect((0, index_1.checkConventionalMessage)('xxx', { debug })).toMatchObject({
|
|
23
|
-
errors: [
|
|
24
|
-
'The pull request title must match the pattern of "<type>[!]: <subject>" which is a reduced set of https://www.conventionalcommits.org/en/v1.0.0/'
|
|
25
|
-
]
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
it('returns the error, given an unknown type', () => {
|
|
29
|
-
expect((0, index_1.checkConventionalMessage)('unknown: xxx', { debug })).toMatchObject({
|
|
30
|
-
type: 'unknown',
|
|
31
|
-
errors: [
|
|
32
|
-
'The type in a pull request title must be one of \"feat\", \"fix\", \"test\", \"refactor\", \"chore\".'
|
|
33
|
-
]
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
it('returns the error, given a non-lower-case type', () => {
|
|
37
|
-
expect((0, index_1.checkConventionalMessage)('CHORE: xxx', { debug })).toMatchObject({
|
|
38
|
-
errors: [
|
|
39
|
-
'The type in a pull request title must be in lower case only.'
|
|
40
|
-
]
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
it('returns the error, given a scope', () => {
|
|
44
|
-
expect((0, index_1.checkConventionalMessage)('chore(scope): xxx', { debug })).toMatchObject({
|
|
45
|
-
errors: [
|
|
46
|
-
'A scope in a pull request title is never allowed.'
|
|
47
|
-
]
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
it('returns the error, given zero or more-than-one spaces after ":" symbol', () => {
|
|
51
|
-
expect((0, index_1.checkConventionalMessage)('chore:xxx', { debug })).toMatchObject({
|
|
52
|
-
subject: 'xxx',
|
|
53
|
-
errors: [
|
|
54
|
-
'A single space must be after ":" symbol.'
|
|
55
|
-
]
|
|
56
|
-
});
|
|
57
|
-
expect((0, index_1.checkConventionalMessage)('chore: xxx', { debug })).toMatchObject({
|
|
58
|
-
subject: 'xxx',
|
|
59
|
-
errors: [
|
|
60
|
-
'A single space must be after ":" symbol.'
|
|
61
|
-
]
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
it('returns the error, given the first word in non-lower-case for the subject', () => {
|
|
65
|
-
expect((0, index_1.checkConventionalMessage)('chore: Xxx', { debug })).toMatchObject({
|
|
66
|
-
errors: [
|
|
67
|
-
'The subject must start with a lower case latin alphabet.'
|
|
68
|
-
]
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
it('returns the error, given a period after the subject', () => {
|
|
72
|
-
expect((0, index_1.checkConventionalMessage)('chore: xxx.', { debug })).toMatchObject({
|
|
73
|
-
subject: 'xxx',
|
|
74
|
-
errors: [
|
|
75
|
-
'The subject must not end with a period or a space.'
|
|
76
|
-
]
|
|
77
|
-
});
|
|
78
|
-
expect((0, index_1.checkConventionalMessage)('chore: xxx ...', { debug })).toEqual({
|
|
79
|
-
type: 'chore',
|
|
80
|
-
breaking: false,
|
|
81
|
-
subject: 'xxx...',
|
|
82
|
-
errors: []
|
|
83
|
-
});
|
|
84
|
-
});
|