@thisismanta/semantic-version 6.0.0 → 7.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.js +12 -18
- package/lib/install-git-hooks.js +26 -47
- package/lib/run.d.ts +1 -0
- package/lib/run.js +44 -0
- package/package.json +3 -5
package/lib/auto-npm-version.js
CHANGED
|
@@ -27,9 +27,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
const semver_1 = __importDefault(require("semver"));
|
|
30
|
-
const execa_1 = require("execa");
|
|
31
30
|
const github = __importStar(require("@actions/github"));
|
|
32
31
|
const index_1 = require("./index");
|
|
32
|
+
const run_1 = require("./run");
|
|
33
33
|
const debug_1 = require("./debug");
|
|
34
34
|
main();
|
|
35
35
|
async function main() {
|
|
@@ -39,14 +39,14 @@ async function main() {
|
|
|
39
39
|
}
|
|
40
40
|
// Set up Git commit author for further use in "npm version" and "git push" command
|
|
41
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'}`);
|
|
42
|
+
if (!(await (0, run_1.run)(`git config user.name`).catch(() => ''))) {
|
|
43
|
+
await (0, run_1.run)(`git config user.name ${github.context.payload.pusher?.name || github.context.actor}`);
|
|
44
|
+
await (0, run_1.run)(`git config user.email ${github.context.payload.pusher?.email || 'github-actions@github.com'}`);
|
|
45
45
|
}
|
|
46
|
-
const remote = await run(`git remote`) || 'origin';
|
|
46
|
+
const remote = await (0, run_1.run)(`git remote`) || 'origin';
|
|
47
47
|
// Check if the given GITHUB_TOKEN has the permission to push to the repository
|
|
48
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}`);
|
|
49
|
+
await (0, run_1.run)(`git push --dry-run ${remote}`);
|
|
50
50
|
const lastVersion = await getLastVersion();
|
|
51
51
|
(0, debug_1.debug)('lastVersion »', JSON.stringify(lastVersion));
|
|
52
52
|
if (!lastVersion) {
|
|
@@ -61,8 +61,8 @@ async function main() {
|
|
|
61
61
|
console.log('Done without a new version');
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
|
-
await run(`npm version --git-tag-version ${releaseType}`);
|
|
65
|
-
await run(`git push --follow-tags ${remote}`);
|
|
64
|
+
await (0, run_1.run)(`npm version --git-tag-version ${releaseType}`);
|
|
65
|
+
await (0, run_1.run)(`git push --follow-tags ${remote}`);
|
|
66
66
|
const nextVersion = await getLastVersion();
|
|
67
67
|
(0, debug_1.debug)('nextVersion »', JSON.stringify(nextVersion));
|
|
68
68
|
console.log(`Created tag v${nextVersion}`);
|
|
@@ -82,19 +82,13 @@ async function main() {
|
|
|
82
82
|
(0, debug_1.debug)('releaseCreationRespond »', JSON.stringify(releaseCreationRespond, null, 2));
|
|
83
83
|
console.log('Done with a new release at', releaseCreationRespond.data.html_url);
|
|
84
84
|
}
|
|
85
|
-
async function run(command) {
|
|
86
|
-
(0, debug_1.debug)(command);
|
|
87
|
-
const { stdout } = await (0, execa_1.execaCommand)(command);
|
|
88
|
-
(0, debug_1.debug)(stdout);
|
|
89
|
-
return stdout;
|
|
90
|
-
}
|
|
91
85
|
async function getLastVersion() {
|
|
92
|
-
return (semver_1.default.valid(await run('git describe --tags --abbrev=0').catch(() => '')) ||
|
|
93
|
-
semver_1.default.valid(JSON.parse(await run('npm pkg get version'))));
|
|
86
|
+
return (semver_1.default.valid(await (0, run_1.run)('git describe --tags --abbrev=0').catch(() => '')) ||
|
|
87
|
+
semver_1.default.valid(JSON.parse(await (0, run_1.run)('npm pkg get version'))));
|
|
94
88
|
}
|
|
95
89
|
async function getGitHistory(version) {
|
|
96
|
-
const tagFound = !!(await run(`git tag --list v${version}`));
|
|
97
|
-
return await run(`git --no-pager log ${tagFound ? `v${version}..HEAD` : ''} --format=%H%s`);
|
|
90
|
+
const tagFound = !!(await (0, run_1.run)(`git tag --list v${version}`));
|
|
91
|
+
return await (0, run_1.run)(`git --no-pager log ${tagFound ? `v${version}..HEAD` : ''} --format=%H%s`);
|
|
98
92
|
}
|
|
99
93
|
function getCommits(gitLog) {
|
|
100
94
|
return gitLog
|
package/lib/install-git-hooks.js
CHANGED
|
@@ -25,65 +25,44 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const fs = __importStar(require("fs/promises"));
|
|
27
27
|
const fp = __importStar(require("path"));
|
|
28
|
-
const
|
|
28
|
+
const run_1 = require("./run");
|
|
29
29
|
const debug_1 = require("./debug");
|
|
30
30
|
main();
|
|
31
31
|
const packageName = require('../package.json').name;
|
|
32
32
|
async function main() {
|
|
33
|
-
const
|
|
34
|
-
(0, debug_1.debug)('
|
|
35
|
-
|
|
36
|
-
(0, debug_1.debug)('gitDirectoryPath »', gitDirectoryPath);
|
|
37
|
-
if (!gitDirectoryPath) {
|
|
33
|
+
const rootDirectoryPath = await (0, run_1.run)('git rev-parse --show-toplevel');
|
|
34
|
+
(0, debug_1.debug)('rootDirectoryPath »', rootDirectoryPath);
|
|
35
|
+
if (!rootDirectoryPath) {
|
|
38
36
|
throw new Error('Could not find a Git directory.');
|
|
39
37
|
}
|
|
40
|
-
const packageJSON = JSON.parse(await fs.readFile(fp.join(
|
|
38
|
+
const packageJSON = JSON.parse(await fs.readFile(fp.join(rootDirectoryPath, 'package.json'), 'utf-8'));
|
|
41
39
|
if (packageJSON.name === packageName) {
|
|
42
40
|
console.warn('Skip installing Git hooks as it is supposed to be done on a consumer repository.');
|
|
43
41
|
return;
|
|
44
42
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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) {
|
|
43
|
+
const hookDirectoryPath = await (0, run_1.run)('git config --get core.hooksPath').catch(() => '') || '.git/hooks';
|
|
44
|
+
const hookFilePath = fp.join(rootDirectoryPath, hookDirectoryPath, 'commit-msg');
|
|
45
|
+
(0, debug_1.debug)('hookFilePath »', hookFilePath);
|
|
72
46
|
try {
|
|
73
|
-
await fs.access(
|
|
74
|
-
|
|
47
|
+
await fs.access(hookFilePath, fs.constants.R_OK | fs.constants.W_OK);
|
|
48
|
+
(0, debug_1.debug)('Found', hookFilePath);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
await fs.mkdir(fp.dirname(hookFilePath), { recursive: true });
|
|
52
|
+
await fs.writeFile(hookFilePath, '#!/bin/sh\n', 'utf-8');
|
|
53
|
+
(0, debug_1.debug)('Created', hookFilePath);
|
|
75
54
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
console.log('Created', filePath);
|
|
55
|
+
const hookFileText = await fs.readFile(hookFilePath, 'utf-8');
|
|
56
|
+
if (/(^|\s|\/)lint-commit-message(\s|$)/m.test(hookFileText)) {
|
|
57
|
+
console.log('Skipped adding commit-msg Git hook.');
|
|
80
58
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
59
|
+
else {
|
|
60
|
+
await fs.appendFile(hookFilePath, [
|
|
61
|
+
'',
|
|
62
|
+
'dir="$(git rev-parse --show-toplevel)"',
|
|
63
|
+
'"$dir/node_modules/.bin/lint-commit-message" "$@"',
|
|
64
|
+
'',
|
|
65
|
+
].join('\n'), 'utf-8');
|
|
66
|
+
console.log('Done adding commit-msg Git hook.');
|
|
88
67
|
}
|
|
89
68
|
}
|
package/lib/run.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function run(command: string): Promise<string>;
|
package/lib/run.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
exports.run = void 0;
|
|
27
|
+
const cp = __importStar(require("child_process"));
|
|
28
|
+
const debug_1 = require("./debug");
|
|
29
|
+
function run(command) {
|
|
30
|
+
(0, debug_1.debug)(command);
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
cp.exec(command, (error, stdout, stderr) => {
|
|
33
|
+
if (error) {
|
|
34
|
+
reject(error);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const output = (stdout + stderr).trim();
|
|
38
|
+
(0, debug_1.debug)(output);
|
|
39
|
+
resolve(output);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
exports.run = run;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thisismanta/semantic-version",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"author": "Anantachai Saothong <thisismanta@gmail.com>",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": {
|
|
@@ -25,22 +25,20 @@
|
|
|
25
25
|
"build": "rm -rf lib && tsc",
|
|
26
26
|
"preversion": "npm run build",
|
|
27
27
|
"version": "npm publish --access public",
|
|
28
|
-
"postinstall": "node ./lib/install-git-hooks.js"
|
|
29
|
-
"prepare": "husky install"
|
|
28
|
+
"postinstall": "node ./lib/install-git-hooks.js"
|
|
30
29
|
},
|
|
31
30
|
"devDependencies": {
|
|
32
31
|
"@types/jest": "^29.5.11",
|
|
33
32
|
"@types/node": "^20.0.0",
|
|
34
33
|
"@types/semver": "^7.5.6",
|
|
35
34
|
"jest": "^29.7.0",
|
|
35
|
+
"lefthook": "^1.6.0",
|
|
36
36
|
"ts-jest": "^29.1.1",
|
|
37
37
|
"ts-node": "^10.9.2",
|
|
38
38
|
"typescript": "^5.3.3"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@actions/github": "^6.0.0",
|
|
42
|
-
"execa": "npm:@esm2cjs/execa@^6.1.1-cjs.1",
|
|
43
|
-
"husky": "^8.0.3",
|
|
44
42
|
"semver": "^7.5.4"
|
|
45
43
|
},
|
|
46
44
|
"jest": {
|