@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.
@@ -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
- (0, script_1.runScript)(async () => {
10
- const editMsg = process.argv[process.argv.length - 1] || '.git/COMMIT_EDITMSG';
11
- console.log(editMsg);
12
- const cwd = process.cwd();
13
- const localConfig = `${cwd}/commitlint.config.js`;
14
- const sharedConfig = `${paths_cnst_1.cfgDir}/commitlint.config.js`;
15
- const config = fs.existsSync(localConfig) ? localConfig : sharedConfig;
16
- const env = { GIT_BRANCH: await (0, git_util_1.gitCurrentBranchName)() };
17
- await (0, exec_1.execWithArgs)(`commitlint`, [`--edit`, editMsg, `--config`, config], { env });
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 = await (0, __1.generateBuildInfo)();
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 = await (0, git_util_1.gitHasUncommittedChanges)();
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 = await (0, git_util_1.gitHasUncommittedChanges)();
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)(await (0, git_util_1.getLastGitCommitMsg)()), 60) +
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
- await (0, git_util_1.gitPull)();
49
- await (0, git_util_1.gitCommitAll)(msg);
50
- await (0, git_util_1.gitPush)();
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): Promise<BuildInfo>;
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
- async function generateBuildInfo(dev = false) {
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,
@@ -1,17 +1,18 @@
1
- export declare function getLastGitCommitMsg(): Promise<string>;
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(): Promise<boolean>;
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): Promise<boolean>;
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(): Promise<boolean>;
12
- export declare function gitPull(): Promise<void>;
13
- export declare function gitPush(): Promise<void>;
14
- export declare function gitCurrentCommitSha(full?: boolean): Promise<string>;
15
- export declare function gitCurrentCommitTimestamp(): Promise<number>;
16
- export declare function gitCurrentBranchName(): Promise<string>;
17
- export declare function gitCurrentRepoName(): Promise<string>;
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;
@@ -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 exec_util_1 = require("@naturalcycles/nodejs-lib/dist/exec/exec.util");
6
- const execa = require("execa");
7
- async function getLastGitCommitMsg() {
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
- async function gitHasUncommittedChanges() {
17
+ function gitHasUncommittedChanges() {
22
18
  // git diff-index --quiet HEAD -- || echo "untracked"
23
- const cmd = 'git diff-index --quiet HEAD --';
24
- const { exitCode } = await execa(cmd, {
25
- shell: true,
26
- reject: false,
27
- });
28
- // console.log(code)
29
- return !!exitCode;
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
- async function gitCommitAll(msg) {
33
+ function gitCommitAll(msg) {
36
34
  // git commit -a -m "style(lint-all): $GIT_MSG" || true
37
- // const cmd = `git commit -a --no-verify -m "${msg}"`
38
- const cmd = `git`;
39
- const args = ['commit', '-a', '--no-verify', '-m', msg];
40
- (0, exec_util_1.logExec)(cmd, args);
41
- const { exitCode } = await execa(cmd, args, {
42
- // shell: true,
43
- stdio: 'inherit',
44
- reject: false,
45
- });
46
- // console.log(`gitCommitAll code: ${code}`)
47
- return !exitCode;
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
- async function gitIsAhead() {
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 { stdout } = await execa(cmd, { shell: true });
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
- async function gitPull() {
62
- const cmd = 'git';
63
- const args = ['pull'];
64
- await execa(cmd, args, {
65
- reject: false,
66
- stdio: 'inherit',
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
- async function gitPush() {
71
+ function gitPush() {
71
72
  // git push --set-upstream origin $CIRCLE_BRANCH && echo "pushed, exiting" && exit 0
72
- const cmd = 'git';
73
- const args = ['push'];
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
- args.push('--set-upstream', 'origin', branchName);
76
+ cmd += ` --set-upstream origin ${branchName}`;
78
77
  }
79
- (0, exec_util_1.logExec)(cmd, args);
80
- await execa(cmd, args, {
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
- async function gitCurrentCommitSha(full = false) {
86
- // git rev-parse HEAD
87
- const cmd = 'git';
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
- async function gitCurrentCommitTimestamp() {
94
- // git log -1 --format=%ct
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
- async function gitCurrentBranchName() {
102
- // git rev-parse --abbrev-ref HEAD
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
- async function gitCurrentRepoName() {
111
- // basename -s .git `git config --get remote.origin.url`
112
- const cmd = 'git';
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.25.10",
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",