@naturalcycles/dev-lib 13.26.0 → 13.27.1
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/bin/commitlint-def.js +26 -11
- package/dist/cmd/lint-all.command.js +5 -5
- package/dist/util/git.util.d.ts +5 -5
- package/dist/util/git.util.js +46 -40
- package/package.json +1 -2
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const cp = require("node:child_process");
|
|
4
5
|
const fs = require("node:fs");
|
|
5
|
-
const exec_1 = require("@naturalcycles/nodejs-lib/dist/exec");
|
|
6
|
-
const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
|
|
7
6
|
const paths_cnst_1 = require("../cnst/paths.cnst");
|
|
8
7
|
const git_util_1 = require("../util/git.util");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
const editMsg = process.argv[process.argv.length - 1] || '.git/COMMIT_EDITMSG';
|
|
9
|
+
// console.log(editMsg)
|
|
10
|
+
const cwd = process.cwd();
|
|
11
|
+
const localConfig = `${cwd}/commitlint.config.js`;
|
|
12
|
+
const sharedConfig = `${paths_cnst_1.cfgDir}/commitlint.config.js`;
|
|
13
|
+
const config = fs.existsSync(localConfig) ? localConfig : sharedConfig;
|
|
14
|
+
const env = {
|
|
15
|
+
...process.env,
|
|
16
|
+
GIT_BRANCH: (0, git_util_1.gitCurrentBranchName)(),
|
|
17
|
+
};
|
|
18
|
+
// await execWithArgs(`commitlint`, [`--edit`, editMsg, `--config`, config], { env })
|
|
19
|
+
execSync(`node ./node_modules/.bin/commitlint --edit ${editMsg} --config ${config}`, {
|
|
20
|
+
env,
|
|
18
21
|
});
|
|
22
|
+
function execSync(cmd, opt) {
|
|
23
|
+
try {
|
|
24
|
+
cp.execSync(cmd, {
|
|
25
|
+
...opt,
|
|
26
|
+
encoding: 'utf8',
|
|
27
|
+
stdio: 'inherit',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -22,7 +22,7 @@ async function lintAllCommand() {
|
|
|
22
22
|
default: false,
|
|
23
23
|
},
|
|
24
24
|
}).argv;
|
|
25
|
-
const hadChangesBefore =
|
|
25
|
+
const hadChangesBefore = (0, git_util_1.gitHasUncommittedChanges)();
|
|
26
26
|
await (0, eslint_all_command_1.eslintAllCommand)();
|
|
27
27
|
if (fs.existsSync(`node_modules/stylelint`) &&
|
|
28
28
|
fs.existsSync(`node_modules/stylelint-config-standard-scss`)) {
|
|
@@ -35,7 +35,7 @@ async function lintAllCommand() {
|
|
|
35
35
|
}
|
|
36
36
|
if (commitOnChanges || failOnChanges) {
|
|
37
37
|
// detect changes
|
|
38
|
-
const hasChanges =
|
|
38
|
+
const hasChanges = (0, git_util_1.gitHasUncommittedChanges)();
|
|
39
39
|
if (hasChanges) {
|
|
40
40
|
if (hadChangesBefore) {
|
|
41
41
|
console.log(`lint-all: there are changes before running lint-all, will not commit`);
|
|
@@ -45,9 +45,9 @@ async function lintAllCommand() {
|
|
|
45
45
|
(0, js_lib_1._truncate)((0, git_util_1.commitMessageToTitleMessage)((0, git_util_1.getLastGitCommitMsg)()), 60) +
|
|
46
46
|
'\n\n[skip ci]';
|
|
47
47
|
// pull, commit, push changes
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
(0, git_util_1.gitPull)();
|
|
49
|
+
(0, git_util_1.gitCommitAll)(msg);
|
|
50
|
+
(0, git_util_1.gitPush)();
|
|
51
51
|
}
|
|
52
52
|
// fail on changes
|
|
53
53
|
if (failOnChanges) {
|
package/dist/util/git.util.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { UnixTimestampNumber } from '@naturalcycles/js-lib';
|
|
2
2
|
export declare function getLastGitCommitMsg(): string;
|
|
3
3
|
export declare function commitMessageToTitleMessage(msg: string): string;
|
|
4
|
-
export declare function gitHasUncommittedChanges():
|
|
4
|
+
export declare function gitHasUncommittedChanges(): boolean;
|
|
5
5
|
/**
|
|
6
6
|
* @returns true if there were changes
|
|
7
7
|
*/
|
|
8
|
-
export declare function gitCommitAll(msg: string):
|
|
8
|
+
export declare function gitCommitAll(msg: string): boolean;
|
|
9
9
|
/**
|
|
10
10
|
* @returns true if there are not pushed commits.
|
|
11
11
|
*/
|
|
12
|
-
export declare function gitIsAhead():
|
|
13
|
-
export declare function gitPull():
|
|
14
|
-
export declare function gitPush():
|
|
12
|
+
export declare function gitIsAhead(): boolean;
|
|
13
|
+
export declare function gitPull(): void;
|
|
14
|
+
export declare function gitPush(): void;
|
|
15
15
|
export declare function gitCurrentCommitSha(full?: boolean): string;
|
|
16
16
|
export declare function gitCurrentCommitTimestamp(): UnixTimestampNumber;
|
|
17
17
|
export declare function gitCurrentBranchName(): string;
|
package/dist/util/git.util.js
CHANGED
|
@@ -3,8 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.gitCurrentRepoName = exports.gitCurrentBranchName = exports.gitCurrentCommitTimestamp = exports.gitCurrentCommitSha = exports.gitPush = exports.gitPull = exports.gitIsAhead = exports.gitCommitAll = exports.gitHasUncommittedChanges = exports.commitMessageToTitleMessage = exports.getLastGitCommitMsg = void 0;
|
|
4
4
|
const cp = require("node:child_process");
|
|
5
5
|
const path = require("node:path");
|
|
6
|
-
const
|
|
7
|
-
const execa = require("execa");
|
|
6
|
+
const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
|
|
8
7
|
function getLastGitCommitMsg() {
|
|
9
8
|
return execSync('git log -1 --pretty=%B');
|
|
10
9
|
}
|
|
@@ -15,66 +14,69 @@ function commitMessageToTitleMessage(msg) {
|
|
|
15
14
|
return title || preTitle;
|
|
16
15
|
}
|
|
17
16
|
exports.commitMessageToTitleMessage = commitMessageToTitleMessage;
|
|
18
|
-
|
|
17
|
+
function gitHasUncommittedChanges() {
|
|
19
18
|
// git diff-index --quiet HEAD -- || echo "untracked"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
try {
|
|
20
|
+
cp.execSync('git diff-index --quiet HEAD --', {
|
|
21
|
+
encoding: 'utf8',
|
|
22
|
+
});
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
27
28
|
}
|
|
28
29
|
exports.gitHasUncommittedChanges = gitHasUncommittedChanges;
|
|
29
30
|
/**
|
|
30
31
|
* @returns true if there were changes
|
|
31
32
|
*/
|
|
32
|
-
|
|
33
|
+
function gitCommitAll(msg) {
|
|
33
34
|
// git commit -a -m "style(lint-all): $GIT_MSG" || true
|
|
34
|
-
|
|
35
|
-
const cmd = `git
|
|
36
|
-
const args = ['commit', '-a', '--no-verify', '-m', msg]
|
|
37
|
-
(0,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
const cmd = `git commit -a --no-verify -m "${msg}"`;
|
|
36
|
+
// const cmd = `git`
|
|
37
|
+
// const args = ['commit', '-a', '--no-verify', '-m', msg]
|
|
38
|
+
console.log((0, colors_1.grey)(cmd));
|
|
39
|
+
try {
|
|
40
|
+
cp.execSync(cmd, {
|
|
41
|
+
stdio: 'inherit',
|
|
42
|
+
});
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
45
48
|
}
|
|
46
49
|
exports.gitCommitAll = gitCommitAll;
|
|
47
50
|
/**
|
|
48
51
|
* @returns true if there are not pushed commits.
|
|
49
52
|
*/
|
|
50
|
-
|
|
53
|
+
function gitIsAhead() {
|
|
51
54
|
// ahead=`git rev-list HEAD --not --remotes | wc -l | awk '{print $1}'`
|
|
52
55
|
const cmd = `git rev-list HEAD --not --remotes | wc -l | awk '{print $1}'`;
|
|
53
|
-
const
|
|
56
|
+
const stdout = execSync(cmd);
|
|
54
57
|
// console.log(`gitIsAhead: ${stdout}`)
|
|
55
58
|
return Number(stdout) > 0;
|
|
56
59
|
}
|
|
57
60
|
exports.gitIsAhead = gitIsAhead;
|
|
58
|
-
|
|
59
|
-
const cmd = 'git';
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
61
|
+
function gitPull() {
|
|
62
|
+
const cmd = 'git pull';
|
|
63
|
+
try {
|
|
64
|
+
cp.execSync(cmd, {
|
|
65
|
+
stdio: 'inherit',
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
catch { }
|
|
65
69
|
}
|
|
66
70
|
exports.gitPull = gitPull;
|
|
67
|
-
|
|
71
|
+
function gitPush() {
|
|
68
72
|
// git push --set-upstream origin $CIRCLE_BRANCH && echo "pushed, exiting" && exit 0
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
const { CIRCLE_BRANCH } = process.env;
|
|
72
|
-
const branchName = CIRCLE_BRANCH || gitCurrentBranchName();
|
|
73
|
+
let cmd = 'git push';
|
|
74
|
+
const branchName = gitCurrentBranchName();
|
|
73
75
|
if (branchName) {
|
|
74
|
-
|
|
76
|
+
cmd += ` --set-upstream origin ${branchName}`;
|
|
75
77
|
}
|
|
76
|
-
(0,
|
|
77
|
-
|
|
78
|
+
console.log((0, colors_1.grey)(cmd));
|
|
79
|
+
cp.execSync(cmd, {
|
|
78
80
|
stdio: 'inherit',
|
|
79
81
|
});
|
|
80
82
|
}
|
|
@@ -98,5 +100,9 @@ function gitCurrentRepoName() {
|
|
|
98
100
|
}
|
|
99
101
|
exports.gitCurrentRepoName = gitCurrentRepoName;
|
|
100
102
|
function execSync(cmd) {
|
|
101
|
-
return cp
|
|
103
|
+
return cp
|
|
104
|
+
.execSync(cmd, {
|
|
105
|
+
encoding: 'utf8',
|
|
106
|
+
})
|
|
107
|
+
.trim();
|
|
102
108
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/dev-lib",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.27.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky install",
|
|
6
6
|
"tsn-debug": "tsn testScript.ts",
|
|
@@ -47,7 +47,6 @@
|
|
|
47
47
|
"eslint-plugin-unicorn": "^47.0.0",
|
|
48
48
|
"eslint-plugin-unused-imports": "^2.0.0",
|
|
49
49
|
"eslint-plugin-vue": "^9.0.0",
|
|
50
|
-
"execa": "^5.0.0",
|
|
51
50
|
"expect-type": "^0.16.0",
|
|
52
51
|
"husky": "^8.0.1",
|
|
53
52
|
"jest-junit": "^16.0.0",
|