@naturalcycles/nodejs-lib 12.98.2 → 12.99.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.
@@ -8,13 +8,19 @@ const fs_1 = require("../fs");
8
8
  const script_1 = require("../script");
9
9
  const buildInfo_util_1 = require("../util/buildInfo.util");
10
10
  (0, script_1.runScript)(async () => {
11
- const { dir } = yargs.options({
11
+ const { dir, overrideTimestamp } = yargs.options({
12
12
  dir: {
13
13
  type: 'string',
14
14
  desc: 'Output directory',
15
15
  },
16
+ overrideTimestamp: {
17
+ type: 'number',
18
+ desc: 'This unix timestamp will be used instead of "current time"',
19
+ },
16
20
  }).argv;
17
- const buildInfo = (0, buildInfo_util_1.generateBuildInfo)();
21
+ const buildInfo = (0, buildInfo_util_1.generateBuildInfo)({
22
+ overrideTimestamp,
23
+ });
18
24
  console.log(buildInfo);
19
25
  if (dir)
20
26
  fs.mkdirSync(dir, { recursive: true });
@@ -55,5 +55,7 @@ export declare function objectToShellExport(obj: AnyObject, prefix?: string): st
55
55
  *
56
56
  * Quotes are important, otherwise it'll break on e.g space character in the value.
57
57
  * Includes trailing newline for composability.
58
+ *
59
+ * UPD: Quoted values behave inconsistently, so we're trying to NOT quote now, and-see-what-happens.
58
60
  */
59
61
  export declare function objectToGithubActionsEnv(obj: AnyObject, prefix?: string): string;
@@ -114,6 +114,8 @@ exports.objectToShellExport = objectToShellExport;
114
114
  *
115
115
  * Quotes are important, otherwise it'll break on e.g space character in the value.
116
116
  * Includes trailing newline for composability.
117
+ *
118
+ * UPD: Quoted values behave inconsistently, so we're trying to NOT quote now, and-see-what-happens.
117
119
  */
118
120
  function objectToGithubActionsEnv(obj, prefix = '') {
119
121
  if (!Object.keys(obj).length)
@@ -121,7 +123,7 @@ function objectToGithubActionsEnv(obj, prefix = '') {
121
123
  return (Object.entries(obj)
122
124
  .map(([k, v]) => {
123
125
  if (v) {
124
- return `${prefix}${k}="${v}"`;
126
+ return `${prefix}${k}=${v}`;
125
127
  }
126
128
  })
127
129
  .filter(Boolean)
@@ -1,2 +1,8 @@
1
- import { BuildInfo } from '@naturalcycles/js-lib';
2
- export declare function generateBuildInfo(): BuildInfo;
1
+ import { BuildInfo, UnixTimestampNumber } from '@naturalcycles/js-lib';
2
+ export interface GenerateBuildInfoOptions {
3
+ /**
4
+ * If set - this timestamp will be used, instead of "current time".
5
+ */
6
+ overrideTimestamp?: UnixTimestampNumber;
7
+ }
8
+ export declare function generateBuildInfo(opt?: GenerateBuildInfoOptions): BuildInfo;
@@ -4,10 +4,9 @@ exports.generateBuildInfo = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
5
  const fs_util_1 = require("../fs/fs.util");
6
6
  const git_util_1 = require("./git.util");
7
- function generateBuildInfo() {
8
- const now = (0, js_lib_1.localTime)();
7
+ function generateBuildInfo(opt = {}) {
8
+ const now = (0, js_lib_1.localTime)(opt.overrideTimestamp);
9
9
  const ts = now.unix();
10
- const tsStr = now.toPretty();
11
10
  const rev = (0, git_util_1.gitCurrentCommitSha)();
12
11
  const branchName = (0, git_util_1.gitCurrentBranchName)();
13
12
  const repoName = (0, git_util_1.gitCurrentRepoName)();
@@ -27,7 +26,6 @@ function generateBuildInfo() {
27
26
  return (0, js_lib_1._filterUndefinedValues)({
28
27
  ts,
29
28
  tsCommit,
30
- tsStr,
31
29
  repoName,
32
30
  branchName,
33
31
  rev,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "12.98.2",
3
+ "version": "12.99.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
@@ -8,14 +8,20 @@ import { runScript } from '../script'
8
8
  import { generateBuildInfo } from '../util/buildInfo.util'
9
9
 
10
10
  runScript(async () => {
11
- const { dir } = yargs.options({
11
+ const { dir, overrideTimestamp } = yargs.options({
12
12
  dir: {
13
13
  type: 'string',
14
14
  desc: 'Output directory',
15
15
  },
16
+ overrideTimestamp: {
17
+ type: 'number',
18
+ desc: 'This unix timestamp will be used instead of "current time"',
19
+ },
16
20
  }).argv
17
21
 
18
- const buildInfo = generateBuildInfo()
22
+ const buildInfo = generateBuildInfo({
23
+ overrideTimestamp,
24
+ })
19
25
  console.log(buildInfo)
20
26
 
21
27
  if (dir) fs.mkdirSync(dir, { recursive: true })
@@ -28,7 +28,7 @@ export class CSVWriter {
28
28
  }
29
29
  }
30
30
 
31
- public cfg: CSVWriterConfig & { delimiter: string }
31
+ cfg: CSVWriterConfig & { delimiter: string }
32
32
 
33
33
  writeRows(rows: AnyObject[]): string {
34
34
  let s = ''
@@ -156,6 +156,8 @@ export function objectToShellExport(obj: AnyObject, prefix = ''): string {
156
156
  *
157
157
  * Quotes are important, otherwise it'll break on e.g space character in the value.
158
158
  * Includes trailing newline for composability.
159
+ *
160
+ * UPD: Quoted values behave inconsistently, so we're trying to NOT quote now, and-see-what-happens.
159
161
  */
160
162
  export function objectToGithubActionsEnv(obj: AnyObject, prefix = ''): string {
161
163
  if (!Object.keys(obj).length) return ''
@@ -164,7 +166,7 @@ export function objectToGithubActionsEnv(obj: AnyObject, prefix = ''): string {
164
166
  Object.entries(obj)
165
167
  .map(([k, v]) => {
166
168
  if (v) {
167
- return `${prefix}${k}="${v}"`
169
+ return `${prefix}${k}=${v}`
168
170
  }
169
171
  })
170
172
  .filter(Boolean)
@@ -55,7 +55,7 @@ export class SlackService<CTX = any> {
55
55
  }
56
56
  }
57
57
 
58
- public cfg!: SlackServiceCfg<CTX>
58
+ cfg!: SlackServiceCfg<CTX>
59
59
 
60
60
  /**
61
61
  * Allows to "log" many things at once, similar to `console.log(one, two, three).
@@ -1,4 +1,10 @@
1
- import { _filterUndefinedValues, AnyObject, BuildInfo, localTime } from '@naturalcycles/js-lib'
1
+ import {
2
+ _filterUndefinedValues,
3
+ AnyObject,
4
+ BuildInfo,
5
+ localTime,
6
+ UnixTimestampNumber,
7
+ } from '@naturalcycles/js-lib'
2
8
  import { _pathExistsSync, _readJsonSync } from '../fs/fs.util'
3
9
  import {
4
10
  gitCurrentBranchName,
@@ -7,10 +13,16 @@ import {
7
13
  gitCurrentRepoName,
8
14
  } from './git.util'
9
15
 
10
- export function generateBuildInfo(): BuildInfo {
11
- const now = localTime()
16
+ export interface GenerateBuildInfoOptions {
17
+ /**
18
+ * If set - this timestamp will be used, instead of "current time".
19
+ */
20
+ overrideTimestamp?: UnixTimestampNumber
21
+ }
22
+
23
+ export function generateBuildInfo(opt: GenerateBuildInfoOptions = {}): BuildInfo {
24
+ const now = localTime(opt.overrideTimestamp)
12
25
  const ts = now.unix()
13
- const tsStr = now.toPretty()
14
26
 
15
27
  const rev = gitCurrentCommitSha()
16
28
  const branchName = gitCurrentBranchName()
@@ -34,7 +46,6 @@ export function generateBuildInfo(): BuildInfo {
34
46
  return _filterUndefinedValues({
35
47
  ts,
36
48
  tsCommit,
37
- tsStr,
38
49
  repoName,
39
50
  branchName,
40
51
  rev,