@naturalcycles/nodejs-lib 13.31.1 → 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 (44) 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/transformMap.d.ts +4 -2
  8. package/dist/stream/transform/transformMap.js +2 -2
  9. package/dist/stream/transform/transformSplit.js +2 -2
  10. package/dist/stream/transform/worker/workerClassProxy.js +2 -2
  11. package/dist/stream/writable/writableLimit.js +1 -1
  12. package/dist/stream/writable/writableVoid.js +1 -1
  13. package/dist/util/buildInfo.util.js +5 -5
  14. package/dist/util/exec2.d.ts +167 -0
  15. package/dist/util/exec2.js +204 -0
  16. package/dist/util/git2.d.ts +25 -0
  17. package/dist/util/git2.js +95 -0
  18. package/dist/validation/joi/number.extensions.d.ts +2 -1
  19. package/dist/validation/joi/string.extensions.d.ts +2 -1
  20. package/package.json +3 -2
  21. package/src/csv/csvReader.ts +2 -7
  22. package/src/fs/fs2.ts +11 -7
  23. package/src/index.ts +2 -2
  24. package/src/secret/secrets-decrypt.util.ts +1 -1
  25. package/src/secret/secrets-encrypt.util.ts +1 -1
  26. package/src/slack/slack.service.ts +2 -3
  27. package/src/stream/ndjson/transformJsonParse.ts +1 -1
  28. package/src/stream/stream.model.ts +2 -2
  29. package/src/stream/transform/transformMap.ts +5 -3
  30. package/src/stream/transform/transformSplit.ts +3 -3
  31. package/src/stream/transform/worker/workerClassProxy.js +2 -2
  32. package/src/stream/writable/writableLimit.ts +1 -1
  33. package/src/stream/writable/writableVoid.ts +1 -1
  34. package/src/util/buildInfo.util.ts +5 -10
  35. package/src/util/exec2.ts +326 -0
  36. package/src/util/git2.ts +105 -0
  37. package/src/validation/joi/number.extensions.ts +2 -1
  38. package/src/validation/joi/string.extensions.ts +2 -1
  39. package/dist/util/exec.util.d.ts +0 -10
  40. package/dist/util/exec.util.js +0 -58
  41. package/dist/util/git.util.d.ts +0 -18
  42. package/dist/util/git.util.js +0 -109
  43. package/src/util/exec.util.ts +0 -79
  44. package/src/util/git.util.ts +0 -113
@@ -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
- }