@naturalcycles/nodejs-lib 13.39.0 → 13.39.1

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.
package/dist/bin/kpy.js CHANGED
@@ -9,11 +9,11 @@ const runScript_1 = require("../script/runScript");
9
9
  const { _: [baseDir, ...inputPatterns], ...opt } = yargs_1.default.demandCommand(2).options({
10
10
  silent: {
11
11
  type: 'boolean',
12
- descr: 'Suppress all text output', // todo: desc!
12
+ desc: 'Suppress all text output',
13
13
  },
14
14
  verbose: {
15
15
  type: 'boolean',
16
- descr: 'Report progress on every file',
16
+ desc: 'Report progress on every file',
17
17
  },
18
18
  overwrite: {
19
19
  type: 'boolean',
package/dist/fs/fs2.d.ts CHANGED
@@ -61,6 +61,12 @@ declare class FS2 {
61
61
  renamePathAsync(src: string, dest: string): Promise<void>;
62
62
  movePath(src: string, dest: string, opt?: fs.CopySyncOptions): void;
63
63
  movePathAsync(src: string, dest: string, opt?: fs.CopyOptions): Promise<void>;
64
+ /**
65
+ * Returns true if the path is a directory.
66
+ * Otherwise returns false.
67
+ * Doesn't throw, returns false instead.
68
+ */
69
+ isDirectory(filePath: string): boolean;
64
70
  fs: typeof fs;
65
71
  fsp: typeof fs.promises;
66
72
  lstat: fs.StatSyncFn;
package/dist/fs/fs2.js CHANGED
@@ -279,6 +279,18 @@ class FS2 {
279
279
  await this.copyPathAsync(src, dest, opt);
280
280
  await this.removePathAsync(src);
281
281
  }
282
+ /**
283
+ * Returns true if the path is a directory.
284
+ * Otherwise returns false.
285
+ * Doesn't throw, returns false instead.
286
+ */
287
+ isDirectory(filePath) {
288
+ return (exports.fs2
289
+ .stat(filePath, {
290
+ throwIfNoEntry: false,
291
+ })
292
+ ?.isDirectory() || false);
293
+ }
282
294
  /*
283
295
  Returns a Readable of [already parsed] NDJSON objects.
284
296
 
package/dist/fs/kpy.js CHANGED
@@ -8,7 +8,7 @@ const js_lib_1 = require("@naturalcycles/js-lib");
8
8
  const colors_1 = require("../colors/colors");
9
9
  const index_1 = require("../index");
10
10
  async function kpy(opt) {
11
- const started = Date.now();
11
+ const started = js_lib_1.localTime.nowUnixMillis();
12
12
  kpyPrepare(opt);
13
13
  const filenames = await (0, index_1.fastGlob)(opt.inputPatterns, {
14
14
  cwd: opt.baseDir,
@@ -37,7 +37,7 @@ async function kpy(opt) {
37
37
  kpyLogResult(opt, filenames, started);
38
38
  }
39
39
  function kpySync(opt) {
40
- const started = Date.now();
40
+ const started = js_lib_1.localTime.nowUnixMillis();
41
41
  kpyPrepare(opt);
42
42
  const filenames = index_1.fastGlob.sync(opt.inputPatterns, {
43
43
  cwd: opt.baseDir,
@@ -75,6 +75,19 @@ function kpyPrepare(opt) {
75
75
  return;
76
76
  }
77
77
  index_1.fs2.ensureDir(opt.outputDir);
78
+ // Expand directories (ex-globby feature), experimental!
79
+ const extraPatterns = [];
80
+ for (const pattern of opt.inputPatterns) {
81
+ if (pattern.includes('*'))
82
+ continue;
83
+ if (index_1.fs2.isDirectory(node_path_1.default.resolve(opt.baseDir, pattern))) {
84
+ extraPatterns.push(`${pattern}/**`);
85
+ }
86
+ }
87
+ if (opt.verbose) {
88
+ console.log({ extraPatterns });
89
+ }
90
+ opt.inputPatterns.push(...extraPatterns);
78
91
  }
79
92
  function kpyLogFilenames(opt, filenames) {
80
93
  if (opt.silent)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "13.39.0",
3
+ "version": "13.39.1",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build": "dev-lib build",
@@ -14,7 +14,9 @@
14
14
  "secrets-gen-key-debug": "tsn ./src/bin/secrets-gen-key.ts",
15
15
  "secrets-encrypt-debug": "tsn ./src/bin/secrets-encrypt.ts",
16
16
  "secrets-decrypt-debug": "tsn ./src/bin/secrets-decrypt.ts",
17
- "kpy-debug": "tsn ./src/bin/kpy.ts node_modules dist",
17
+ "kpy-debug": "tsn ./src/bin/kpy.ts --verbose scripts tmp/scripts",
18
+ "kpy-debug2": "tsn ./src/bin/kpy.ts --verbose scripts bench non-ex non-ex/** colors* tmp/scripts",
19
+ "kpy-debug3": "tsn ./src/bin/kpy.ts --verbose src colors csv stream non-ex non-ex/** tmp/src",
18
20
  "json2env-debug": "tsn ./src/bin/json2env.ts ./src/test/someFile.json"
19
21
  },
20
22
  "dependencies": {
package/src/bin/kpy.ts CHANGED
@@ -11,11 +11,11 @@ runScript(() => {
11
11
  } = yargs.demandCommand(2).options({
12
12
  silent: {
13
13
  type: 'boolean',
14
- descr: 'Suppress all text output', // todo: desc!
14
+ desc: 'Suppress all text output',
15
15
  },
16
16
  verbose: {
17
17
  type: 'boolean',
18
- descr: 'Report progress on every file',
18
+ desc: 'Report progress on every file',
19
19
  },
20
20
  overwrite: {
21
21
  type: 'boolean',
package/src/fs/fs2.ts CHANGED
@@ -299,6 +299,21 @@ class FS2 {
299
299
  await this.removePathAsync(src)
300
300
  }
301
301
 
302
+ /**
303
+ * Returns true if the path is a directory.
304
+ * Otherwise returns false.
305
+ * Doesn't throw, returns false instead.
306
+ */
307
+ isDirectory(filePath: string): boolean {
308
+ return (
309
+ fs2
310
+ .stat(filePath, {
311
+ throwIfNoEntry: false,
312
+ })
313
+ ?.isDirectory() || false
314
+ )
315
+ }
316
+
302
317
  // Re-export the whole fs/fsp, for the edge cases where they are needed
303
318
  fs = fs
304
319
  fsp = fsp
package/src/fs/kpy.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import path from 'node:path'
2
- import { _since, UnixTimestampMillis } from '@naturalcycles/js-lib'
2
+ import { _since, localTime, UnixTimestampMillis } from '@naturalcycles/js-lib'
3
3
  import { boldWhite, dimGrey, grey, yellow } from '../colors/colors'
4
4
  import { fastGlob, fs2 } from '../index'
5
5
 
@@ -43,7 +43,7 @@ export interface KpyOptions {
43
43
  }
44
44
 
45
45
  export async function kpy(opt: KpyOptions): Promise<void> {
46
- const started = Date.now() as UnixTimestampMillis
46
+ const started = localTime.nowUnixMillis()
47
47
 
48
48
  kpyPrepare(opt)
49
49
 
@@ -82,7 +82,7 @@ export async function kpy(opt: KpyOptions): Promise<void> {
82
82
  }
83
83
 
84
84
  export function kpySync(opt: KpyOptions): void {
85
- const started = Date.now() as UnixTimestampMillis
85
+ const started = localTime.nowUnixMillis()
86
86
 
87
87
  kpyPrepare(opt)
88
88
 
@@ -130,6 +130,21 @@ function kpyPrepare(opt: KpyOptions): void {
130
130
  }
131
131
 
132
132
  fs2.ensureDir(opt.outputDir)
133
+
134
+ // Expand directories (ex-globby feature), experimental!
135
+ const extraPatterns: string[] = []
136
+
137
+ for (const pattern of opt.inputPatterns) {
138
+ if (pattern.includes('*')) continue
139
+ if (fs2.isDirectory(path.resolve(opt.baseDir, pattern))) {
140
+ extraPatterns.push(`${pattern}/**`)
141
+ }
142
+ }
143
+
144
+ if (opt.verbose) {
145
+ console.log({ extraPatterns })
146
+ }
147
+ opt.inputPatterns.push(...extraPatterns)
133
148
  }
134
149
 
135
150
  function kpyLogFilenames(opt: KpyOptions, filenames: string[]): void {