@naturalcycles/nodejs-lib 13.32.0 → 13.33.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.
Files changed (37) hide show
  1. package/dist/csv/csvReader.js +2 -2
  2. package/dist/fs/fs2.js +6 -3
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.js +2 -2
  5. package/dist/slack/slack.service.js +2 -4
  6. package/dist/stream/ndjson/transformJsonParse.js +1 -1
  7. package/dist/stream/transform/transformSplit.js +2 -2
  8. package/dist/stream/transform/worker/workerClassProxy.js +2 -2
  9. package/dist/stream/writable/writableLimit.js +1 -1
  10. package/dist/stream/writable/writableVoid.js +1 -1
  11. package/dist/util/buildInfo.util.js +5 -5
  12. package/dist/util/exec2.d.ts +167 -0
  13. package/dist/util/exec2.js +204 -0
  14. package/dist/util/git2.d.ts +25 -0
  15. package/dist/util/git2.js +95 -0
  16. package/package.json +2 -1
  17. package/src/csv/csvReader.ts +2 -7
  18. package/src/fs/fs2.ts +11 -7
  19. package/src/index.ts +2 -2
  20. package/src/secret/secrets-decrypt.util.ts +1 -1
  21. package/src/secret/secrets-encrypt.util.ts +1 -1
  22. package/src/slack/slack.service.ts +2 -3
  23. package/src/stream/ndjson/transformJsonParse.ts +1 -1
  24. package/src/stream/stream.model.ts +2 -2
  25. package/src/stream/transform/transformSplit.ts +3 -3
  26. package/src/stream/transform/worker/workerClassProxy.js +2 -2
  27. package/src/stream/writable/writableLimit.ts +1 -1
  28. package/src/stream/writable/writableVoid.ts +1 -1
  29. package/src/util/buildInfo.util.ts +5 -10
  30. package/src/util/exec2.ts +326 -0
  31. package/src/util/git2.ts +105 -0
  32. package/dist/util/exec.util.d.ts +0 -10
  33. package/dist/util/exec.util.js +0 -58
  34. package/dist/util/git.util.d.ts +0 -18
  35. package/dist/util/git.util.js +0 -109
  36. package/src/util/exec.util.ts +0 -79
  37. package/src/util/git.util.ts +0 -113
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.execVoidCommand = execVoidCommand;
4
- exports.execVoidCommandSync = execVoidCommandSync;
5
- const tslib_1 = require("tslib");
6
- const node_child_process_1 = tslib_1.__importDefault(require("node:child_process"));
7
- async function execVoidCommand(cmd, args = [], opt = {}) {
8
- logExec(cmd, args, opt);
9
- await new Promise(resolve => {
10
- const p = node_child_process_1.default.spawn(cmd, [...args], {
11
- stdio: 'inherit',
12
- // shell: true,
13
- ...opt,
14
- env: {
15
- ...process.env,
16
- ...opt.env,
17
- },
18
- });
19
- p.on('close', code => {
20
- if (code) {
21
- console.log(`${cmd} exited with code ${code}`);
22
- process.exit(code);
23
- }
24
- resolve();
25
- });
26
- });
27
- }
28
- function execVoidCommandSync(cmd, args = [], opt = {}) {
29
- logExec(cmd, args, opt);
30
- const r = node_child_process_1.default.spawnSync(cmd, [...args], {
31
- encoding: 'utf8',
32
- stdio: 'inherit',
33
- // shell: true, // removing shell breaks executing `tsc`
34
- ...opt,
35
- env: {
36
- ...process.env,
37
- ...opt.env,
38
- },
39
- });
40
- if (r.status) {
41
- console.log(`${cmd} exited with code ${r.status}`);
42
- process.exit(r.status);
43
- }
44
- if (r.error) {
45
- console.log(r.error);
46
- process.exit(r.error.errno || 1);
47
- }
48
- }
49
- function logExec(cmd, args = [], opt = {}) {
50
- if (opt.log === false)
51
- return;
52
- const cmdline = [
53
- ...Object.entries(opt.env || {}).map(([k, v]) => [k, v].join('=')),
54
- cmd,
55
- ...args,
56
- ].join(' ');
57
- console.log(cmdline);
58
- }
@@ -1,18 +0,0 @@
1
- import type { UnixTimestampNumber } from '@naturalcycles/js-lib';
2
- export declare function getLastGitCommitMsg(): string;
3
- export declare function commitMessageToTitleMessage(msg: string): string;
4
- export declare function gitHasUncommittedChanges(): boolean;
5
- /**
6
- * @returns true if there were changes
7
- */
8
- export declare function gitCommitAll(msg: string): boolean;
9
- /**
10
- * @returns true if there are not pushed commits.
11
- */
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,109 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLastGitCommitMsg = getLastGitCommitMsg;
4
- exports.commitMessageToTitleMessage = commitMessageToTitleMessage;
5
- exports.gitHasUncommittedChanges = gitHasUncommittedChanges;
6
- exports.gitCommitAll = gitCommitAll;
7
- exports.gitIsAhead = gitIsAhead;
8
- exports.gitPull = gitPull;
9
- exports.gitPush = gitPush;
10
- exports.gitCurrentCommitSha = gitCurrentCommitSha;
11
- exports.gitCurrentCommitTimestamp = gitCurrentCommitTimestamp;
12
- exports.gitCurrentBranchName = gitCurrentBranchName;
13
- exports.gitCurrentRepoName = gitCurrentRepoName;
14
- const tslib_1 = require("tslib");
15
- const node_child_process_1 = tslib_1.__importDefault(require("node:child_process"));
16
- const node_path_1 = tslib_1.__importDefault(require("node:path"));
17
- const colors_1 = require("../colors/colors");
18
- function getLastGitCommitMsg() {
19
- return execSync('git log -1 --pretty=%B');
20
- }
21
- function commitMessageToTitleMessage(msg) {
22
- const firstLine = msg.split('\n')[0];
23
- const [preTitle, title] = firstLine.split(': ');
24
- return title || preTitle;
25
- }
26
- function gitHasUncommittedChanges() {
27
- // git diff-index --quiet HEAD -- || echo "untracked"
28
- try {
29
- node_child_process_1.default.execSync('git diff-index --quiet HEAD --', {
30
- encoding: 'utf8',
31
- });
32
- return false;
33
- }
34
- catch {
35
- return true;
36
- }
37
- }
38
- /**
39
- * @returns true if there were changes
40
- */
41
- function gitCommitAll(msg) {
42
- // git commit -a -m "style(lint-all): $GIT_MSG" || true
43
- const cmd = `git commit -a --no-verify -m "${msg}"`;
44
- // const cmd = `git`
45
- // const args = ['commit', '-a', '--no-verify', '-m', msg]
46
- console.log((0, colors_1.grey)(cmd));
47
- try {
48
- node_child_process_1.default.execSync(cmd, {
49
- stdio: 'inherit',
50
- });
51
- return true;
52
- }
53
- catch {
54
- return false;
55
- }
56
- }
57
- /**
58
- * @returns true if there are not pushed commits.
59
- */
60
- function gitIsAhead() {
61
- // ahead=`git rev-list HEAD --not --remotes | wc -l | awk '{print $1}'`
62
- const cmd = `git rev-list HEAD --not --remotes | wc -l | awk '{print $1}'`;
63
- const stdout = execSync(cmd);
64
- // console.log(`gitIsAhead: ${stdout}`)
65
- return Number(stdout) > 0;
66
- }
67
- function gitPull() {
68
- const cmd = 'git pull';
69
- try {
70
- node_child_process_1.default.execSync(cmd, {
71
- stdio: 'inherit',
72
- });
73
- }
74
- catch { }
75
- }
76
- function gitPush() {
77
- // git push --set-upstream origin $CIRCLE_BRANCH && echo "pushed, exiting" && exit 0
78
- let cmd = 'git push';
79
- const branchName = gitCurrentBranchName();
80
- if (branchName) {
81
- cmd += ` --set-upstream origin ${branchName}`;
82
- }
83
- console.log((0, colors_1.grey)(cmd));
84
- node_child_process_1.default.execSync(cmd, {
85
- stdio: 'inherit',
86
- });
87
- }
88
- function gitCurrentCommitSha(full = false) {
89
- const sha = execSync('git rev-parse HEAD');
90
- return full ? sha : sha.slice(0, 7);
91
- }
92
- function gitCurrentCommitTimestamp() {
93
- return Number(execSync('git log -1 --format=%ct'));
94
- }
95
- function gitCurrentBranchName() {
96
- return execSync('git rev-parse --abbrev-ref HEAD');
97
- }
98
- function gitCurrentRepoName() {
99
- const originUrl = execSync('git config --get remote.origin.url');
100
- return node_path_1.default.basename(originUrl, '.git');
101
- }
102
- function execSync(cmd) {
103
- return node_child_process_1.default
104
- .execSync(cmd, {
105
- encoding: 'utf8',
106
- // stdio: 'inherit', // no, otherwise we don't get the output returned
107
- })
108
- .trim();
109
- }
@@ -1,79 +0,0 @@
1
- import type { ProcessEnvOptions, SpawnOptions } from 'node:child_process'
2
- import cp from 'node:child_process'
3
-
4
- export interface ExecOptions extends SpawnOptions {
5
- /**
6
- * Defaults to true.
7
- * Set to false to skip logging.
8
- */
9
- log?: boolean
10
- }
11
-
12
- export async function execVoidCommand(
13
- cmd: string,
14
- args: string[] = [],
15
- opt: ExecOptions = {},
16
- ): Promise<void> {
17
- logExec(cmd, args, opt)
18
-
19
- await new Promise<void>(resolve => {
20
- const p = cp.spawn(cmd, [...args], {
21
- stdio: 'inherit',
22
- // shell: true,
23
- ...opt,
24
- env: {
25
- ...process.env,
26
- ...opt.env,
27
- },
28
- })
29
-
30
- p.on('close', code => {
31
- if (code) {
32
- console.log(`${cmd} exited with code ${code}`)
33
- process.exit(code)
34
- }
35
- resolve()
36
- })
37
- })
38
- }
39
-
40
- export function execVoidCommandSync(cmd: string, args: string[] = [], opt: ExecOptions = {}): void {
41
- logExec(cmd, args, opt)
42
-
43
- const r = cp.spawnSync(cmd, [...args], {
44
- encoding: 'utf8',
45
- stdio: 'inherit',
46
- // shell: true, // removing shell breaks executing `tsc`
47
- ...opt,
48
- env: {
49
- ...process.env,
50
- ...opt.env,
51
- },
52
- })
53
-
54
- if (r.status) {
55
- console.log(`${cmd} exited with code ${r.status}`)
56
- process.exit(r.status)
57
- }
58
-
59
- if (r.error) {
60
- console.log(r.error)
61
- process.exit((r.error as NodeJS.ErrnoException).errno || 1)
62
- }
63
- }
64
-
65
- function logExec(
66
- cmd: string,
67
- args: string[] = [],
68
- opt: ProcessEnvOptions & ExecOptions = {},
69
- ): void {
70
- if (opt.log === false) return
71
-
72
- const cmdline = [
73
- ...Object.entries(opt.env || {}).map(([k, v]) => [k, v].join('=')),
74
- cmd,
75
- ...args,
76
- ].join(' ')
77
-
78
- console.log(cmdline)
79
- }
@@ -1,113 +0,0 @@
1
- import cp from 'node:child_process'
2
- import path from 'node:path'
3
- import type { UnixTimestampNumber } from '@naturalcycles/js-lib'
4
- import { grey } from '../colors/colors'
5
-
6
- export function getLastGitCommitMsg(): string {
7
- return execSync('git log -1 --pretty=%B')
8
- }
9
-
10
- export function commitMessageToTitleMessage(msg: string): string {
11
- const firstLine = msg.split('\n')[0]!
12
- const [preTitle, title] = firstLine.split(': ')
13
- return title || preTitle!
14
- }
15
-
16
- export function gitHasUncommittedChanges(): boolean {
17
- // git diff-index --quiet HEAD -- || echo "untracked"
18
- try {
19
- cp.execSync('git diff-index --quiet HEAD --', {
20
- encoding: 'utf8',
21
- })
22
- return false
23
- } catch {
24
- return true
25
- }
26
- }
27
-
28
- /**
29
- * @returns true if there were changes
30
- */
31
- export function gitCommitAll(msg: string): boolean {
32
- // git commit -a -m "style(lint-all): $GIT_MSG" || true
33
- const cmd = `git commit -a --no-verify -m "${msg}"`
34
- // const cmd = `git`
35
- // const args = ['commit', '-a', '--no-verify', '-m', msg]
36
-
37
- console.log(grey(cmd))
38
-
39
- try {
40
- cp.execSync(cmd, {
41
- stdio: 'inherit',
42
- })
43
- return true
44
- } catch {
45
- return false
46
- }
47
- }
48
-
49
- /**
50
- * @returns true if there are not pushed commits.
51
- */
52
- export function gitIsAhead(): boolean {
53
- // ahead=`git rev-list HEAD --not --remotes | wc -l | awk '{print $1}'`
54
- const cmd = `git rev-list HEAD --not --remotes | wc -l | awk '{print $1}'`
55
-
56
- const stdout = execSync(cmd)
57
-
58
- // console.log(`gitIsAhead: ${stdout}`)
59
- return Number(stdout) > 0
60
- }
61
-
62
- export function gitPull(): void {
63
- const cmd = 'git pull'
64
- try {
65
- cp.execSync(cmd, {
66
- stdio: 'inherit',
67
- })
68
- } catch {}
69
- }
70
-
71
- export function gitPush(): void {
72
- // git push --set-upstream origin $CIRCLE_BRANCH && echo "pushed, exiting" && exit 0
73
- let cmd = 'git push'
74
-
75
- const branchName = gitCurrentBranchName()
76
-
77
- if (branchName) {
78
- cmd += ` --set-upstream origin ${branchName}`
79
- }
80
-
81
- console.log(grey(cmd))
82
-
83
- cp.execSync(cmd, {
84
- stdio: 'inherit',
85
- })
86
- }
87
-
88
- export function gitCurrentCommitSha(full = false): string {
89
- const sha = execSync('git rev-parse HEAD')
90
- return full ? sha : sha.slice(0, 7)
91
- }
92
-
93
- export function gitCurrentCommitTimestamp(): UnixTimestampNumber {
94
- return Number(execSync('git log -1 --format=%ct'))
95
- }
96
-
97
- export function gitCurrentBranchName(): string {
98
- return execSync('git rev-parse --abbrev-ref HEAD')
99
- }
100
-
101
- export function gitCurrentRepoName(): string {
102
- const originUrl = execSync('git config --get remote.origin.url')
103
- return path.basename(originUrl, '.git')
104
- }
105
-
106
- function execSync(cmd: string): string {
107
- return cp
108
- .execSync(cmd, {
109
- encoding: 'utf8',
110
- // stdio: 'inherit', // no, otherwise we don't get the output returned
111
- })
112
- .trim()
113
- }