@naturalcycles/dev-lib 13.25.10 → 13.27.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/bin/commitlint-def.js +23 -11
- package/dist/cmd/generate-build-info.command.js +1 -1
- package/dist/cmd/lint-all.command.js +6 -6
- package/dist/util/buildInfo.util.d.ts +1 -1
- package/dist/util/buildInfo.util.js +5 -9
- package/dist/util/git.util.d.ts +11 -10
- package/dist/util/git.util.js +61 -72
- package/package.json +1 -2
|
@@ -1,18 +1,30 @@
|
|
|
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 = { GIT_BRANCH: (0, git_util_1.gitCurrentBranchName)() };
|
|
15
|
+
// await execWithArgs(`commitlint`, [`--edit`, editMsg, `--config`, config], { env })
|
|
16
|
+
execSync(`node ./node_modules/.bin/commitlint --edit ${editMsg} --config ${config}`, {
|
|
17
|
+
env,
|
|
18
18
|
});
|
|
19
|
+
function execSync(cmd, opt) {
|
|
20
|
+
try {
|
|
21
|
+
cp.execSync(cmd, {
|
|
22
|
+
...opt,
|
|
23
|
+
encoding: 'utf8',
|
|
24
|
+
stdio: 'inherit',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -12,7 +12,7 @@ async function generateBuildInfoCommand() {
|
|
|
12
12
|
desc: 'Output directory',
|
|
13
13
|
},
|
|
14
14
|
}).argv;
|
|
15
|
-
const buildInfo =
|
|
15
|
+
const buildInfo = (0, __1.generateBuildInfo)();
|
|
16
16
|
console.log(buildInfo);
|
|
17
17
|
if (dir)
|
|
18
18
|
fs.mkdirSync(dir, { recursive: true });
|
|
@@ -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,19 +35,19 @@ 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`);
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
44
|
const msg = 'style(ci): ' +
|
|
45
|
-
(0, js_lib_1._truncate)((0, git_util_1.commitMessageToTitleMessage)(
|
|
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) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { BuildInfo } from './buildInfo.model';
|
|
2
|
-
export declare function generateBuildInfo(dev?: boolean):
|
|
2
|
+
export declare function generateBuildInfo(dev?: boolean): BuildInfo;
|
|
@@ -3,18 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateBuildInfo = void 0;
|
|
4
4
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
5
|
const git_util_1 = require("./git.util");
|
|
6
|
-
|
|
6
|
+
function generateBuildInfo(dev = false) {
|
|
7
7
|
const now = (0, js_lib_1.localTime)();
|
|
8
|
-
const [rev, branchName, repoName, tsCommit] = dev
|
|
9
|
-
? ['devRev', 'devBranch', 'devRepo', now.unix()]
|
|
10
|
-
: await Promise.all([
|
|
11
|
-
(0, git_util_1.gitCurrentCommitSha)(),
|
|
12
|
-
(0, git_util_1.gitCurrentBranchName)(),
|
|
13
|
-
(0, git_util_1.gitCurrentRepoName)(),
|
|
14
|
-
(0, git_util_1.gitCurrentCommitTimestamp)(),
|
|
15
|
-
]);
|
|
16
8
|
const ts = now.unix();
|
|
17
9
|
const tsStr = now.toPretty();
|
|
10
|
+
const rev = dev ? 'devRev' : (0, git_util_1.gitCurrentCommitSha)();
|
|
11
|
+
const branchName = dev ? 'devBranch' : (0, git_util_1.gitCurrentBranchName)();
|
|
12
|
+
const repoName = dev ? 'devRepo' : (0, git_util_1.gitCurrentRepoName)();
|
|
13
|
+
const tsCommit = dev ? now.unix() : (0, git_util_1.gitCurrentCommitTimestamp)();
|
|
18
14
|
const ver = [now.toStringCompact(), repoName, branchName, rev].join('_');
|
|
19
15
|
return {
|
|
20
16
|
ts,
|
package/dist/util/git.util.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import type { UnixTimestampNumber } from '@naturalcycles/js-lib';
|
|
2
|
+
export declare function getLastGitCommitMsg(): string;
|
|
2
3
|
export declare function commitMessageToTitleMessage(msg: string): string;
|
|
3
|
-
export declare function gitHasUncommittedChanges():
|
|
4
|
+
export declare function gitHasUncommittedChanges(): boolean;
|
|
4
5
|
/**
|
|
5
6
|
* @returns true if there were changes
|
|
6
7
|
*/
|
|
7
|
-
export declare function gitCommitAll(msg: string):
|
|
8
|
+
export declare function gitCommitAll(msg: string): boolean;
|
|
8
9
|
/**
|
|
9
10
|
* @returns true if there are not pushed commits.
|
|
10
11
|
*/
|
|
11
|
-
export declare function gitIsAhead():
|
|
12
|
-
export declare function gitPull():
|
|
13
|
-
export declare function gitPush():
|
|
14
|
-
export declare function gitCurrentCommitSha(full?: boolean):
|
|
15
|
-
export declare function gitCurrentCommitTimestamp():
|
|
16
|
-
export declare function gitCurrentBranchName():
|
|
17
|
-
export declare function gitCurrentRepoName():
|
|
12
|
+
export declare function gitIsAhead(): boolean;
|
|
13
|
+
export declare function gitPull(): void;
|
|
14
|
+
export declare function gitPush(): void;
|
|
15
|
+
export declare function gitCurrentCommitSha(full?: boolean): string;
|
|
16
|
+
export declare function gitCurrentCommitTimestamp(): UnixTimestampNumber;
|
|
17
|
+
export declare function gitCurrentBranchName(): string;
|
|
18
|
+
export declare function gitCurrentRepoName(): string;
|
package/dist/util/git.util.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
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
|
+
const cp = require("node:child_process");
|
|
4
5
|
const path = require("node:path");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// git log -1 --pretty=%B
|
|
9
|
-
const cmd = 'git';
|
|
10
|
-
const args = ['log', '-1', '--pretty=%B'];
|
|
11
|
-
const { stdout: msg } = await execa(cmd, args);
|
|
12
|
-
return msg;
|
|
6
|
+
const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
|
|
7
|
+
function getLastGitCommitMsg() {
|
|
8
|
+
return execSync('git log -1 --pretty=%B');
|
|
13
9
|
}
|
|
14
10
|
exports.getLastGitCommitMsg = getLastGitCommitMsg;
|
|
15
11
|
function commitMessageToTitleMessage(msg) {
|
|
@@ -18,102 +14,95 @@ function commitMessageToTitleMessage(msg) {
|
|
|
18
14
|
return title || preTitle;
|
|
19
15
|
}
|
|
20
16
|
exports.commitMessageToTitleMessage = commitMessageToTitleMessage;
|
|
21
|
-
|
|
17
|
+
function gitHasUncommittedChanges() {
|
|
22
18
|
// git diff-index --quiet HEAD -- || echo "untracked"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
try {
|
|
20
|
+
cp.execSync('git diff-index --quiet HEAD --', {
|
|
21
|
+
encoding: 'utf8',
|
|
22
|
+
});
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
30
28
|
}
|
|
31
29
|
exports.gitHasUncommittedChanges = gitHasUncommittedChanges;
|
|
32
30
|
/**
|
|
33
31
|
* @returns true if there were changes
|
|
34
32
|
*/
|
|
35
|
-
|
|
33
|
+
function gitCommitAll(msg) {
|
|
36
34
|
// git commit -a -m "style(lint-all): $GIT_MSG" || true
|
|
37
|
-
|
|
38
|
-
const cmd = `git
|
|
39
|
-
const args = ['commit', '-a', '--no-verify', '-m', msg]
|
|
40
|
-
(0,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
+
}
|
|
48
48
|
}
|
|
49
49
|
exports.gitCommitAll = gitCommitAll;
|
|
50
50
|
/**
|
|
51
51
|
* @returns true if there are not pushed commits.
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
function gitIsAhead() {
|
|
54
54
|
// ahead=`git rev-list HEAD --not --remotes | wc -l | awk '{print $1}'`
|
|
55
55
|
const cmd = `git rev-list HEAD --not --remotes | wc -l | awk '{print $1}'`;
|
|
56
|
-
const
|
|
56
|
+
const stdout = execSync(cmd);
|
|
57
57
|
// console.log(`gitIsAhead: ${stdout}`)
|
|
58
58
|
return Number(stdout) > 0;
|
|
59
59
|
}
|
|
60
60
|
exports.gitIsAhead = gitIsAhead;
|
|
61
|
-
|
|
62
|
-
const cmd = 'git';
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
61
|
+
function gitPull() {
|
|
62
|
+
const cmd = 'git pull';
|
|
63
|
+
try {
|
|
64
|
+
cp.execSync(cmd, {
|
|
65
|
+
stdio: 'inherit',
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
catch { }
|
|
68
69
|
}
|
|
69
70
|
exports.gitPull = gitPull;
|
|
70
|
-
|
|
71
|
+
function gitPush() {
|
|
71
72
|
// git push --set-upstream origin $CIRCLE_BRANCH && echo "pushed, exiting" && exit 0
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
const { CIRCLE_BRANCH } = process.env;
|
|
75
|
-
const branchName = CIRCLE_BRANCH || (await gitCurrentBranchName());
|
|
73
|
+
let cmd = 'git push';
|
|
74
|
+
const branchName = gitCurrentBranchName();
|
|
76
75
|
if (branchName) {
|
|
77
|
-
|
|
76
|
+
cmd += ` --set-upstream origin ${branchName}`;
|
|
78
77
|
}
|
|
79
|
-
(0,
|
|
80
|
-
|
|
78
|
+
console.log((0, colors_1.grey)(cmd));
|
|
79
|
+
cp.execSync(cmd, {
|
|
81
80
|
stdio: 'inherit',
|
|
82
81
|
});
|
|
83
82
|
}
|
|
84
83
|
exports.gitPush = gitPush;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const args = ['rev-parse', 'HEAD'];
|
|
89
|
-
const { stdout: commitSha } = await execa(cmd, args);
|
|
90
|
-
return full ? commitSha.trim() : commitSha.trim().slice(0, 7);
|
|
84
|
+
function gitCurrentCommitSha(full = false) {
|
|
85
|
+
const sha = execSync('git rev-parse HEAD');
|
|
86
|
+
return full ? sha : sha.slice(0, 7);
|
|
91
87
|
}
|
|
92
88
|
exports.gitCurrentCommitSha = gitCurrentCommitSha;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const cmd = 'git';
|
|
96
|
-
const args = ['log', '-1', '--format=%ct'];
|
|
97
|
-
const { stdout: ts } = await execa(cmd, args);
|
|
98
|
-
return Number(ts);
|
|
89
|
+
function gitCurrentCommitTimestamp() {
|
|
90
|
+
return Number(execSync('git log -1 --format=%ct'));
|
|
99
91
|
}
|
|
100
92
|
exports.gitCurrentCommitTimestamp = gitCurrentCommitTimestamp;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const cmd = 'git';
|
|
104
|
-
const args = ['rev-parse', '--abbrev-ref', 'HEAD'];
|
|
105
|
-
const { stdout: branchName } = await execa(cmd, args);
|
|
106
|
-
// console.log(`gitCurrentBranchName: ${branchName}`)
|
|
107
|
-
return branchName.trim();
|
|
93
|
+
function gitCurrentBranchName() {
|
|
94
|
+
return execSync('git rev-parse --abbrev-ref HEAD');
|
|
108
95
|
}
|
|
109
96
|
exports.gitCurrentBranchName = gitCurrentBranchName;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const args = ['config', '--get', 'remote.origin.url'];
|
|
114
|
-
const { stdout: originUrl } = await execa(cmd, args);
|
|
115
|
-
const repoName = path.basename(originUrl, '.git');
|
|
116
|
-
// console.log(`gitCurrentRepoName: ${repoName}`)
|
|
117
|
-
return repoName;
|
|
97
|
+
function gitCurrentRepoName() {
|
|
98
|
+
const originUrl = execSync('git config --get remote.origin.url');
|
|
99
|
+
return path.basename(originUrl, '.git');
|
|
118
100
|
}
|
|
119
101
|
exports.gitCurrentRepoName = gitCurrentRepoName;
|
|
102
|
+
function execSync(cmd) {
|
|
103
|
+
return cp
|
|
104
|
+
.execSync(cmd, {
|
|
105
|
+
encoding: 'utf8',
|
|
106
|
+
})
|
|
107
|
+
.trim();
|
|
108
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/dev-lib",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.27.0",
|
|
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",
|