@naturalcycles/dev-lib 13.25.10 → 13.26.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.
@@ -13,6 +13,6 @@ const git_util_1 = require("../util/git.util");
13
13
  const localConfig = `${cwd}/commitlint.config.js`;
14
14
  const sharedConfig = `${paths_cnst_1.cfgDir}/commitlint.config.js`;
15
15
  const config = fs.existsSync(localConfig) ? localConfig : sharedConfig;
16
- const env = { GIT_BRANCH: await (0, git_util_1.gitCurrentBranchName)() };
16
+ const env = { GIT_BRANCH: (0, git_util_1.gitCurrentBranchName)() };
17
17
  await (0, exec_1.execWithArgs)(`commitlint`, [`--edit`, editMsg, `--config`, config], { env });
18
18
  });
@@ -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 });
@@ -42,7 +42,7 @@ async function lintAllCommand() {
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
48
  await (0, git_util_1.gitPull)();
@@ -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,4 +1,5 @@
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
4
  export declare function gitHasUncommittedChanges(): Promise<boolean>;
4
5
  /**
@@ -11,7 +12,7 @@ export declare function gitCommitAll(msg: string): Promise<boolean>;
11
12
  export declare function gitIsAhead(): Promise<boolean>;
12
13
  export declare function gitPull(): Promise<void>;
13
14
  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>;
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,12 @@
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
6
  const exec_util_1 = require("@naturalcycles/nodejs-lib/dist/exec/exec.util");
6
7
  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;
8
+ function getLastGitCommitMsg() {
9
+ return execSync('git log -1 --pretty=%B');
13
10
  }
14
11
  exports.getLastGitCommitMsg = getLastGitCommitMsg;
15
12
  function commitMessageToTitleMessage(msg) {
@@ -72,7 +69,7 @@ async function gitPush() {
72
69
  const cmd = 'git';
73
70
  const args = ['push'];
74
71
  const { CIRCLE_BRANCH } = process.env;
75
- const branchName = CIRCLE_BRANCH || (await gitCurrentBranchName());
72
+ const branchName = CIRCLE_BRANCH || gitCurrentBranchName();
76
73
  if (branchName) {
77
74
  args.push('--set-upstream', 'origin', branchName);
78
75
  }
@@ -82,38 +79,24 @@ async function gitPush() {
82
79
  });
83
80
  }
84
81
  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);
82
+ function gitCurrentCommitSha(full = false) {
83
+ const sha = execSync('git rev-parse HEAD');
84
+ return full ? sha : sha.slice(0, 7);
91
85
  }
92
86
  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);
87
+ function gitCurrentCommitTimestamp() {
88
+ return Number(execSync('git log -1 --format=%ct'));
99
89
  }
100
90
  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();
91
+ function gitCurrentBranchName() {
92
+ return execSync('git rev-parse --abbrev-ref HEAD');
108
93
  }
109
94
  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;
95
+ function gitCurrentRepoName() {
96
+ const originUrl = execSync('git config --get remote.origin.url');
97
+ return path.basename(originUrl, '.git');
118
98
  }
119
99
  exports.gitCurrentRepoName = gitCurrentRepoName;
100
+ function execSync(cmd) {
101
+ return cp.execSync(cmd).toString().trim();
102
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
- "version": "13.25.10",
3
+ "version": "13.26.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "tsn-debug": "tsn testScript.ts",