@naturalcycles/nodejs-lib 13.1.0 → 13.1.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/del.js +3 -2
- package/dist/bin/generate-build-info.js +8 -7
- package/dist/bin/json2env.js +3 -2
- package/dist/bin/kpy.js +3 -2
- package/dist/bin/secrets-decrypt.js +3 -2
- package/dist/bin/secrets-encrypt.js +3 -2
- package/dist/bin/secrets-gen-key.js +5 -4
- package/dist/bin/slack-this.js +3 -2
- package/dist/colors/colors.d.ts +1 -1
- package/dist/colors/colors.js +31 -30
- package/dist/fs/del.js +11 -10
- package/dist/fs/fs.util.d.ts +1 -1
- package/dist/fs/fs.util.js +42 -41
- package/dist/fs/json2env.js +6 -5
- package/dist/fs/kpy.js +8 -7
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -5
- package/dist/infra/process.util.js +8 -7
- package/dist/jwt/jwt.service.d.ts +1 -1
- package/dist/jwt/jwt.service.js +6 -5
- package/dist/secret/secrets-decrypt.util.js +9 -8
- package/dist/secret/secrets-encrypt.util.js +8 -7
- package/dist/security/crypto.util.js +9 -8
- package/dist/security/hash.util.js +4 -3
- package/dist/security/id.util.js +4 -3
- package/dist/security/secret.util.js +7 -6
- package/dist/stream/ndjson/ndjsonStreamForEach.js +3 -2
- package/dist/stream/ndjson/pipelineFromNDJsonFile.js +4 -3
- package/dist/stream/ndjson/pipelineToNDJsonFile.js +4 -3
- package/dist/util/env.util.js +3 -2
- package/dist/util/exec.util.js +4 -3
- package/dist/util/git.util.js +9 -8
- package/dist/util/zip.util.js +6 -5
- package/dist/validation/ajv/getAjv.js +2 -1
- package/dist/validation/joi/joi.extensions.d.ts +1 -1
- package/dist/validation/joi/joi.extensions.js +3 -2
- package/dist/validation/joi/number.extensions.d.ts +1 -1
- package/dist/validation/joi/string.extensions.d.ts +1 -1
- package/package.json +1 -1
- package/src/bin/del.ts +1 -1
- package/src/bin/generate-build-info.ts +3 -3
- package/src/bin/json2env.ts +1 -1
- package/src/bin/kpy.ts +1 -1
- package/src/bin/secrets-decrypt.ts +1 -1
- package/src/bin/secrets-encrypt.ts +1 -1
- package/src/bin/secrets-gen-key.ts +2 -2
- package/src/bin/slack-this.ts +1 -1
- package/src/colors/colors.ts +2 -2
- package/src/fs/del.ts +2 -2
- package/src/fs/fs.util.ts +3 -3
- package/src/fs/json2env.ts +1 -1
- package/src/fs/kpy.ts +1 -1
- package/src/index.ts +2 -2
- package/src/infra/process.util.ts +1 -1
- package/src/jwt/jwt.service.ts +1 -1
- package/src/secret/secrets-decrypt.util.ts +2 -2
- package/src/secret/secrets-encrypt.util.ts +2 -2
- package/src/security/crypto.util.ts +1 -1
- package/src/security/hash.util.ts +1 -1
- package/src/security/id.util.ts +1 -1
- package/src/security/secret.util.ts +1 -1
- package/src/stream/ndjson/ndjsonStreamForEach.ts +1 -1
- package/src/stream/ndjson/pipelineFromNDJsonFile.ts +1 -1
- package/src/stream/ndjson/pipelineToNDJsonFile.ts +1 -1
- package/src/util/env.util.ts +1 -1
- package/src/util/exec.util.ts +1 -1
- package/src/util/git.util.ts +2 -2
- package/src/util/zip.util.ts +1 -1
- package/src/validation/joi/joi.extensions.ts +1 -1
- package/src/validation/joi/number.extensions.ts +1 -1
- package/src/validation/joi/string.extensions.ts +1 -1
package/dist/bin/del.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
5
6
|
const del_1 = require("../fs/del");
|
|
6
7
|
const runScript_1 = require("../script/runScript");
|
|
7
8
|
(0, runScript_1.runScript)(async () => {
|
|
8
|
-
const { _: patterns, ...opt } =
|
|
9
|
+
const { _: patterns, ...opt } = yargs_1.default.demandCommand(1).options({
|
|
9
10
|
verbose: {
|
|
10
11
|
type: 'boolean',
|
|
11
12
|
},
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
7
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
7
8
|
const json2env_1 = require("../fs/json2env");
|
|
8
9
|
const runScript_1 = require("../script/runScript");
|
|
9
10
|
const buildInfo_util_1 = require("../util/buildInfo.util");
|
|
10
11
|
(0, runScript_1.runScript)(async () => {
|
|
11
|
-
const { dir, overrideTimestamp } =
|
|
12
|
+
const { dir, overrideTimestamp } = yargs_1.default.options({
|
|
12
13
|
dir: {
|
|
13
14
|
type: 'string',
|
|
14
15
|
desc: 'Output directory',
|
|
@@ -23,9 +24,9 @@ const buildInfo_util_1 = require("../util/buildInfo.util");
|
|
|
23
24
|
});
|
|
24
25
|
console.log(buildInfo);
|
|
25
26
|
if (dir)
|
|
26
|
-
|
|
27
|
-
const buildInfoPath = dir ?
|
|
28
|
-
|
|
27
|
+
node_fs_1.default.mkdirSync(dir, { recursive: true });
|
|
28
|
+
const buildInfoPath = dir ? node_path_1.default.resolve(dir, 'buildInfo.json') : 'buildInfo.json';
|
|
29
|
+
node_fs_1.default.writeFileSync(buildInfoPath, JSON.stringify(buildInfo, null, 2));
|
|
29
30
|
const prefix = 'buildInfo_';
|
|
30
31
|
(0, json2env_1.appendToBashEnv)(buildInfo, prefix);
|
|
31
32
|
(0, json2env_1.appendToGithubEnv)(buildInfo, prefix);
|
package/dist/bin/json2env.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
5
6
|
const json2env_1 = require("../fs/json2env");
|
|
6
7
|
const runScript_1 = require("../script/runScript");
|
|
7
8
|
(0, runScript_1.runScript)(() => {
|
|
8
|
-
const { argv } =
|
|
9
|
+
const { argv } = yargs_1.default.demandCommand(1).options({
|
|
9
10
|
prefix: {
|
|
10
11
|
type: 'string',
|
|
11
12
|
},
|
package/dist/bin/kpy.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
5
6
|
const kpy_1 = require("../fs/kpy");
|
|
6
7
|
const runScript_1 = require("../script/runScript");
|
|
7
8
|
(0, runScript_1.runScript)(() => {
|
|
8
|
-
const { _: [baseDir, ...inputPatterns], ...opt } =
|
|
9
|
+
const { _: [baseDir, ...inputPatterns], ...opt } = yargs_1.default.demandCommand(2).options({
|
|
9
10
|
silent: {
|
|
10
11
|
type: 'boolean',
|
|
11
12
|
descr: 'Suppress all text output', // todo: desc!
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
5
6
|
const colors_1 = require("../colors/colors");
|
|
6
7
|
const runScript_1 = require("../script/runScript");
|
|
7
8
|
const secrets_decrypt_util_1 = require("../secret/secrets-decrypt.util");
|
|
@@ -11,7 +12,7 @@ const secrets_decrypt_util_1 = require("../secret/secrets-decrypt.util");
|
|
|
11
12
|
});
|
|
12
13
|
function getDecryptCLIOptions() {
|
|
13
14
|
require('dotenv').config();
|
|
14
|
-
let { dir, file, encKey, encKeyVar, del, jsonMode } =
|
|
15
|
+
let { dir, file, encKey, encKeyVar, del, jsonMode } = yargs_1.default.options({
|
|
15
16
|
dir: {
|
|
16
17
|
type: 'array',
|
|
17
18
|
desc: 'Directory with secrets. Can be many',
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
5
6
|
const colors_1 = require("../colors/colors");
|
|
6
7
|
const runScript_1 = require("../script/runScript");
|
|
7
8
|
const secrets_encrypt_util_1 = require("../secret/secrets-encrypt.util");
|
|
@@ -11,7 +12,7 @@ const secrets_encrypt_util_1 = require("../secret/secrets-encrypt.util");
|
|
|
11
12
|
});
|
|
12
13
|
function getEncryptCLIOptions() {
|
|
13
14
|
require('dotenv').config();
|
|
14
|
-
let { pattern, file, encKey, encKeyVar, del, jsonMode } =
|
|
15
|
+
let { pattern, file, encKey, encKeyVar, del, jsonMode } = yargs_1.default.options({
|
|
15
16
|
pattern: {
|
|
16
17
|
type: 'string',
|
|
17
18
|
array: true,
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_crypto_1 = tslib_1.__importDefault(require("node:crypto"));
|
|
6
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
6
7
|
const colors_1 = require("../colors/colors");
|
|
7
8
|
const runScript_1 = require("../script/runScript");
|
|
8
9
|
(0, runScript_1.runScript)(() => {
|
|
9
|
-
const { sizeBytes } =
|
|
10
|
+
const { sizeBytes } = yargs_1.default.option('sizeBytes', {
|
|
10
11
|
type: 'number',
|
|
11
12
|
default: 256,
|
|
12
13
|
}).argv;
|
|
13
|
-
const key =
|
|
14
|
+
const key = node_crypto_1.default.randomBytes(sizeBytes).toString('base64');
|
|
14
15
|
console.log((0, colors_1.dimGrey)('\nSECRET_ENCRYPTION_KEY:\n'));
|
|
15
16
|
console.log(key, '\n');
|
|
16
17
|
});
|
package/dist/bin/slack-this.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
5
6
|
const __1 = require("..");
|
|
6
7
|
const runScript_1 = require("../script/runScript");
|
|
7
8
|
(0, runScript_1.runScript)(async () => {
|
|
8
|
-
const { channel, msg, username, emoji, webhook: webhookUrl, } =
|
|
9
|
+
const { channel, msg, username, emoji, webhook: webhookUrl, } = yargs_1.default.options({
|
|
9
10
|
channel: {
|
|
10
11
|
type: 'string',
|
|
11
12
|
demandOption: true,
|
package/dist/colors/colors.d.ts
CHANGED
package/dist/colors/colors.js
CHANGED
|
@@ -1,42 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.boldCyan = exports.dimCyan = exports.cyan = exports.boldMagenta = exports.dimMagenta = exports.magenta = exports.boldBlue = exports.dimBlue = exports.blue = exports.boldRed = exports.dimRed = exports.red = exports.boldGreen = exports.dimGreen = exports.green = exports.inverseYellow = exports.boldYellow = exports.dimYellow = exports.yellow = exports.boldGrey = exports.dimGrey = exports.grey = exports.inverseWhite = exports.boldWhite = exports.dimWhite = exports.white = exports.hasColors = exports.chalk = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_tty_1 = tslib_1.__importDefault(require("node:tty"));
|
|
6
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
7
|
+
exports.chalk = chalk_1.default;
|
|
7
8
|
/**
|
|
8
9
|
* Based on: https://github.com/sindresorhus/yoctocolors/pull/5
|
|
9
10
|
*
|
|
10
11
|
* @experimental
|
|
11
12
|
*/
|
|
12
|
-
exports.hasColors = !process.env['NO_COLOR'] &&
|
|
13
|
+
exports.hasColors = !process.env['NO_COLOR'] && node_tty_1.default.WriteStream.prototype.hasColors();
|
|
13
14
|
// The point of re-exporting is:
|
|
14
15
|
// 1. Fix typings to allow to pass `number` (very common case)
|
|
15
16
|
// 2. Easier/shorter to import, rather than from 'chalk'
|
|
16
17
|
// export type ColorFn = (...args: (string | number)[]) => string
|
|
17
|
-
exports.white =
|
|
18
|
-
exports.dimWhite =
|
|
19
|
-
exports.boldWhite =
|
|
20
|
-
exports.inverseWhite =
|
|
21
|
-
exports.grey =
|
|
22
|
-
exports.dimGrey =
|
|
23
|
-
exports.boldGrey =
|
|
24
|
-
exports.yellow =
|
|
25
|
-
exports.dimYellow =
|
|
26
|
-
exports.boldYellow =
|
|
27
|
-
exports.inverseYellow =
|
|
28
|
-
exports.green =
|
|
29
|
-
exports.dimGreen =
|
|
30
|
-
exports.boldGreen =
|
|
31
|
-
exports.red =
|
|
32
|
-
exports.dimRed =
|
|
33
|
-
exports.boldRed =
|
|
34
|
-
exports.blue =
|
|
35
|
-
exports.dimBlue =
|
|
36
|
-
exports.boldBlue =
|
|
37
|
-
exports.magenta =
|
|
38
|
-
exports.dimMagenta =
|
|
39
|
-
exports.boldMagenta =
|
|
40
|
-
exports.cyan =
|
|
41
|
-
exports.dimCyan =
|
|
42
|
-
exports.boldCyan =
|
|
18
|
+
exports.white = chalk_1.default.white;
|
|
19
|
+
exports.dimWhite = chalk_1.default.dim.white;
|
|
20
|
+
exports.boldWhite = chalk_1.default.bold.white;
|
|
21
|
+
exports.inverseWhite = chalk_1.default.inverse.white;
|
|
22
|
+
exports.grey = chalk_1.default.grey;
|
|
23
|
+
exports.dimGrey = chalk_1.default.dim.grey;
|
|
24
|
+
exports.boldGrey = chalk_1.default.bold.grey;
|
|
25
|
+
exports.yellow = chalk_1.default.yellow;
|
|
26
|
+
exports.dimYellow = chalk_1.default.dim.yellow;
|
|
27
|
+
exports.boldYellow = chalk_1.default.bold.yellow;
|
|
28
|
+
exports.inverseYellow = chalk_1.default.inverse.yellow;
|
|
29
|
+
exports.green = chalk_1.default.green;
|
|
30
|
+
exports.dimGreen = chalk_1.default.dim.green;
|
|
31
|
+
exports.boldGreen = chalk_1.default.bold.green;
|
|
32
|
+
exports.red = chalk_1.default.red;
|
|
33
|
+
exports.dimRed = chalk_1.default.dim.red;
|
|
34
|
+
exports.boldRed = chalk_1.default.bold.red;
|
|
35
|
+
exports.blue = chalk_1.default.blue;
|
|
36
|
+
exports.dimBlue = chalk_1.default.dim.blue;
|
|
37
|
+
exports.boldBlue = chalk_1.default.bold.blue;
|
|
38
|
+
exports.magenta = chalk_1.default.magenta;
|
|
39
|
+
exports.dimMagenta = chalk_1.default.dim.magenta;
|
|
40
|
+
exports.boldMagenta = chalk_1.default.bold.magenta;
|
|
41
|
+
exports.cyan = chalk_1.default.cyan;
|
|
42
|
+
exports.dimCyan = chalk_1.default.dim.cyan;
|
|
43
|
+
exports.boldCyan = chalk_1.default.bold.cyan;
|
package/dist/fs/del.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.delSync = exports.del = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
|
+
const promises_1 = tslib_1.__importDefault(require("node:fs/promises"));
|
|
6
7
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
7
8
|
const colors_1 = require("../colors/colors");
|
|
8
9
|
const index_1 = require("../index");
|
|
@@ -43,7 +44,7 @@ async function del(_opt) {
|
|
|
43
44
|
}
|
|
44
45
|
if (dry)
|
|
45
46
|
return;
|
|
46
|
-
await (0, js_lib_1.pMap)(filenames, filepath =>
|
|
47
|
+
await (0, js_lib_1.pMap)(filenames, filepath => promises_1.default.rm(filepath, {
|
|
47
48
|
force: true,
|
|
48
49
|
}), { concurrency });
|
|
49
50
|
// 2. glob only dirs, expand, delete only empty!
|
|
@@ -54,7 +55,7 @@ async function del(_opt) {
|
|
|
54
55
|
});
|
|
55
56
|
// Add original patterns (if any of them are dirs)
|
|
56
57
|
dirnames = dirnames.concat(await (0, js_lib_1.pFilter)(patterns, async (pattern) => {
|
|
57
|
-
return (await (0, index_1._pathExists)(pattern)) && (await
|
|
58
|
+
return (await (0, index_1._pathExists)(pattern)) && (await promises_1.default.lstat(pattern)).isDirectory();
|
|
58
59
|
}));
|
|
59
60
|
const dirnamesSorted = dirnames.sort().reverse();
|
|
60
61
|
// console.log({ dirnamesSorted })
|
|
@@ -62,7 +63,7 @@ async function del(_opt) {
|
|
|
62
63
|
for await (const dirpath of dirnamesSorted) {
|
|
63
64
|
if (await isEmptyDir(dirpath)) {
|
|
64
65
|
// console.log(`empty dir: ${dirpath}`)
|
|
65
|
-
await
|
|
66
|
+
await promises_1.default.rm(dirpath, { force: true, recursive: true });
|
|
66
67
|
deletedDirs.push(dirpath);
|
|
67
68
|
}
|
|
68
69
|
}
|
|
@@ -100,7 +101,7 @@ function delSync(_opt) {
|
|
|
100
101
|
}
|
|
101
102
|
if (dry)
|
|
102
103
|
return;
|
|
103
|
-
filenames.forEach(filepath =>
|
|
104
|
+
filenames.forEach(filepath => node_fs_1.default.rmSync(filepath, { force: true }));
|
|
104
105
|
// 2. glob only dirs, expand, delete only empty!
|
|
105
106
|
let dirnames = index_1.globby.sync(patterns, {
|
|
106
107
|
dot: true,
|
|
@@ -108,14 +109,14 @@ function delSync(_opt) {
|
|
|
108
109
|
onlyDirectories: true,
|
|
109
110
|
});
|
|
110
111
|
// Add original patterns (if any of them are dirs)
|
|
111
|
-
dirnames = dirnames.concat(patterns.filter(p => (0, index_1._pathExistsSync)(p) &&
|
|
112
|
+
dirnames = dirnames.concat(patterns.filter(p => (0, index_1._pathExistsSync)(p) && node_fs_1.default.lstatSync(p).isDirectory()));
|
|
112
113
|
const dirnamesSorted = dirnames.sort().reverse();
|
|
113
114
|
// console.log({ dirnamesSorted })
|
|
114
115
|
const deletedDirs = [];
|
|
115
116
|
for (const dirpath of dirnamesSorted) {
|
|
116
117
|
if (isEmptyDirSync(dirpath)) {
|
|
117
118
|
// console.log(`empty dir: ${dirpath}`)
|
|
118
|
-
|
|
119
|
+
node_fs_1.default.rmSync(dirpath, { force: true, recursive: true });
|
|
119
120
|
deletedDirs.push(dirpath);
|
|
120
121
|
}
|
|
121
122
|
}
|
|
@@ -131,8 +132,8 @@ exports.delSync = delSync;
|
|
|
131
132
|
// 2. glob only dirs, expand, delete only empty!
|
|
132
133
|
// 3. test each original pattern, if it exists and is directory and is empty - delete
|
|
133
134
|
async function isEmptyDir(dir) {
|
|
134
|
-
return (await
|
|
135
|
+
return (await promises_1.default.readdir(dir)).length === 0;
|
|
135
136
|
}
|
|
136
137
|
function isEmptyDirSync(dir) {
|
|
137
|
-
return
|
|
138
|
+
return node_fs_1.default.readdirSync(dir).length === 0;
|
|
138
139
|
}
|
package/dist/fs/fs.util.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
|
-
import
|
|
4
|
+
import fs from 'node:fs';
|
|
5
5
|
/**
|
|
6
6
|
* fs2 conveniently groups filesystem functions together.
|
|
7
7
|
* Supposed to be almost a drop-in replacement for these things together:
|
package/dist/fs/fs.util.js
CHANGED
|
@@ -16,9 +16,10 @@ Credit to: fs-extra (https://github.com/jprichardson/node-fs-extra)
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports._movePathSync = exports._movePath = exports._copyPathSync = exports._copyPath = exports._emptyDirSync = exports._emptyDir = exports._removePathSync = exports._removePath = exports._ensureFileSync = exports._ensureFile = exports._ensureDirSync = exports._ensureDir = exports._pathExistsSync = exports._pathExists = exports._outputJsonSync = exports._outputJson = exports._writeJsonSync = exports._writeJson = exports._outputFileSync = exports._outputFile = exports._writeFileSync = exports._writeFile = exports._readJsonSync = exports._readJson = exports._readFileAsBufferSync = exports._readFileSync = exports._readFileAsBuffer = exports._readFile = exports.fs2 = void 0;
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
21
|
+
const promises_1 = tslib_1.__importDefault(require("node:fs/promises"));
|
|
22
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
22
23
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
23
24
|
/**
|
|
24
25
|
* fs2 conveniently groups filesystem functions together.
|
|
@@ -31,7 +32,7 @@ const js_lib_1 = require("@naturalcycles/js-lib");
|
|
|
31
32
|
exports.fs2 = {
|
|
32
33
|
// "Omit" is here to workaround this TS error:
|
|
33
34
|
// Exported variable 'fs2' has or is using name 'StreamOptions' from external module "fs" but cannot be named.
|
|
34
|
-
...
|
|
35
|
+
...node_fs_1.default,
|
|
35
36
|
readFile: _readFile,
|
|
36
37
|
readFileSync: _readFileSync,
|
|
37
38
|
readFileAsBuffer: _readFileAsBuffer,
|
|
@@ -65,59 +66,59 @@ exports.fs2 = {
|
|
|
65
66
|
* Convenience wrapper that defaults to utf-8 string output.
|
|
66
67
|
*/
|
|
67
68
|
async function _readFile(filePath) {
|
|
68
|
-
return await
|
|
69
|
+
return await promises_1.default.readFile(filePath, 'utf8');
|
|
69
70
|
}
|
|
70
71
|
exports._readFile = _readFile;
|
|
71
72
|
async function _readFileAsBuffer(filePath) {
|
|
72
|
-
return await
|
|
73
|
+
return await promises_1.default.readFile(filePath);
|
|
73
74
|
}
|
|
74
75
|
exports._readFileAsBuffer = _readFileAsBuffer;
|
|
75
76
|
/**
|
|
76
77
|
* Convenience wrapper that defaults to utf-8 string output.
|
|
77
78
|
*/
|
|
78
79
|
function _readFileSync(filePath) {
|
|
79
|
-
return
|
|
80
|
+
return node_fs_1.default.readFileSync(filePath, 'utf8');
|
|
80
81
|
}
|
|
81
82
|
exports._readFileSync = _readFileSync;
|
|
82
83
|
/**
|
|
83
84
|
* Convenience wrapper that defaults to utf-8 string output.
|
|
84
85
|
*/
|
|
85
86
|
function _readFileAsBufferSync(filePath) {
|
|
86
|
-
return
|
|
87
|
+
return node_fs_1.default.readFileSync(filePath);
|
|
87
88
|
}
|
|
88
89
|
exports._readFileAsBufferSync = _readFileAsBufferSync;
|
|
89
90
|
async function _readJson(filePath) {
|
|
90
|
-
const str = await
|
|
91
|
+
const str = await promises_1.default.readFile(filePath, 'utf8');
|
|
91
92
|
return (0, js_lib_1._jsonParse)(str);
|
|
92
93
|
}
|
|
93
94
|
exports._readJson = _readJson;
|
|
94
95
|
function _readJsonSync(filePath) {
|
|
95
|
-
const str =
|
|
96
|
+
const str = node_fs_1.default.readFileSync(filePath, 'utf8');
|
|
96
97
|
return (0, js_lib_1._jsonParse)(str);
|
|
97
98
|
}
|
|
98
99
|
exports._readJsonSync = _readJsonSync;
|
|
99
100
|
async function _writeFile(filePath, data) {
|
|
100
|
-
await
|
|
101
|
+
await promises_1.default.writeFile(filePath, data);
|
|
101
102
|
}
|
|
102
103
|
exports._writeFile = _writeFile;
|
|
103
104
|
function _writeFileSync(filePath, data) {
|
|
104
|
-
|
|
105
|
+
node_fs_1.default.writeFileSync(filePath, data);
|
|
105
106
|
}
|
|
106
107
|
exports._writeFileSync = _writeFileSync;
|
|
107
108
|
async function _outputFile(filePath, data) {
|
|
108
|
-
const dirPath =
|
|
109
|
+
const dirPath = node_path_1.default.dirname(filePath);
|
|
109
110
|
if (!(await _pathExists(dirPath))) {
|
|
110
111
|
await _ensureDir(dirPath);
|
|
111
112
|
}
|
|
112
|
-
await
|
|
113
|
+
await promises_1.default.writeFile(filePath, data);
|
|
113
114
|
}
|
|
114
115
|
exports._outputFile = _outputFile;
|
|
115
116
|
function _outputFileSync(filePath, data) {
|
|
116
|
-
const dirPath =
|
|
117
|
-
if (!
|
|
117
|
+
const dirPath = node_path_1.default.dirname(filePath);
|
|
118
|
+
if (!node_fs_1.default.existsSync(dirPath)) {
|
|
118
119
|
_ensureDirSync(dirPath);
|
|
119
120
|
}
|
|
120
|
-
|
|
121
|
+
node_fs_1.default.writeFileSync(filePath, data);
|
|
121
122
|
}
|
|
122
123
|
exports._outputFileSync = _outputFileSync;
|
|
123
124
|
function stringify(data, opt) {
|
|
@@ -126,12 +127,12 @@ function stringify(data, opt) {
|
|
|
126
127
|
}
|
|
127
128
|
async function _writeJson(filePath, data, opt) {
|
|
128
129
|
const str = stringify(data, opt);
|
|
129
|
-
await
|
|
130
|
+
await promises_1.default.writeFile(filePath, str);
|
|
130
131
|
}
|
|
131
132
|
exports._writeJson = _writeJson;
|
|
132
133
|
function _writeJsonSync(filePath, data, opt) {
|
|
133
134
|
const str = stringify(data, opt);
|
|
134
|
-
|
|
135
|
+
node_fs_1.default.writeFileSync(filePath, str);
|
|
135
136
|
}
|
|
136
137
|
exports._writeJsonSync = _writeJsonSync;
|
|
137
138
|
async function _outputJson(filePath, data, opt) {
|
|
@@ -146,7 +147,7 @@ function _outputJsonSync(filePath, data, opt) {
|
|
|
146
147
|
exports._outputJsonSync = _outputJsonSync;
|
|
147
148
|
async function _pathExists(filePath) {
|
|
148
149
|
try {
|
|
149
|
-
await
|
|
150
|
+
await promises_1.default.access(filePath);
|
|
150
151
|
return true;
|
|
151
152
|
}
|
|
152
153
|
catch {
|
|
@@ -155,18 +156,18 @@ async function _pathExists(filePath) {
|
|
|
155
156
|
}
|
|
156
157
|
exports._pathExists = _pathExists;
|
|
157
158
|
function _pathExistsSync(filePath) {
|
|
158
|
-
return
|
|
159
|
+
return node_fs_1.default.existsSync(filePath);
|
|
159
160
|
}
|
|
160
161
|
exports._pathExistsSync = _pathExistsSync;
|
|
161
162
|
async function _ensureDir(dirPath) {
|
|
162
|
-
await
|
|
163
|
+
await promises_1.default.mkdir(dirPath, {
|
|
163
164
|
mode: 0o777,
|
|
164
165
|
recursive: true,
|
|
165
166
|
});
|
|
166
167
|
}
|
|
167
168
|
exports._ensureDir = _ensureDir;
|
|
168
169
|
function _ensureDirSync(dirPath) {
|
|
169
|
-
|
|
170
|
+
node_fs_1.default.mkdirSync(dirPath, {
|
|
170
171
|
mode: 0o777,
|
|
171
172
|
recursive: true,
|
|
172
173
|
});
|
|
@@ -175,17 +176,17 @@ exports._ensureDirSync = _ensureDirSync;
|
|
|
175
176
|
async function _ensureFile(filePath) {
|
|
176
177
|
let stats;
|
|
177
178
|
try {
|
|
178
|
-
stats = await
|
|
179
|
+
stats = await promises_1.default.stat(filePath);
|
|
179
180
|
}
|
|
180
181
|
catch { }
|
|
181
182
|
if (stats?.isFile())
|
|
182
183
|
return;
|
|
183
|
-
const dir =
|
|
184
|
+
const dir = node_path_1.default.dirname(filePath);
|
|
184
185
|
try {
|
|
185
|
-
if (!(await
|
|
186
|
+
if (!(await promises_1.default.stat(dir)).isDirectory()) {
|
|
186
187
|
// parent is not a directory
|
|
187
188
|
// This is just to cause an internal ENOTDIR error to be thrown
|
|
188
|
-
await
|
|
189
|
+
await promises_1.default.readdir(dir);
|
|
189
190
|
}
|
|
190
191
|
}
|
|
191
192
|
catch (err) {
|
|
@@ -194,23 +195,23 @@ async function _ensureFile(filePath) {
|
|
|
194
195
|
return await _ensureDir(dir);
|
|
195
196
|
throw err;
|
|
196
197
|
}
|
|
197
|
-
await
|
|
198
|
+
await promises_1.default.writeFile(filePath, '');
|
|
198
199
|
}
|
|
199
200
|
exports._ensureFile = _ensureFile;
|
|
200
201
|
function _ensureFileSync(filePath) {
|
|
201
202
|
let stats;
|
|
202
203
|
try {
|
|
203
|
-
stats =
|
|
204
|
+
stats = node_fs_1.default.statSync(filePath);
|
|
204
205
|
}
|
|
205
206
|
catch { }
|
|
206
207
|
if (stats?.isFile())
|
|
207
208
|
return;
|
|
208
|
-
const dir =
|
|
209
|
+
const dir = node_path_1.default.dirname(filePath);
|
|
209
210
|
try {
|
|
210
|
-
if (!
|
|
211
|
+
if (!node_fs_1.default.statSync(dir).isDirectory()) {
|
|
211
212
|
// parent is not a directory
|
|
212
213
|
// This is just to cause an internal ENOTDIR error to be thrown
|
|
213
|
-
|
|
214
|
+
node_fs_1.default.readdirSync(dir);
|
|
214
215
|
}
|
|
215
216
|
}
|
|
216
217
|
catch (err) {
|
|
@@ -219,44 +220,44 @@ function _ensureFileSync(filePath) {
|
|
|
219
220
|
return _ensureDirSync(dir);
|
|
220
221
|
throw err;
|
|
221
222
|
}
|
|
222
|
-
|
|
223
|
+
node_fs_1.default.writeFileSync(filePath, '');
|
|
223
224
|
}
|
|
224
225
|
exports._ensureFileSync = _ensureFileSync;
|
|
225
226
|
async function _removePath(fileOrDirPath) {
|
|
226
|
-
await
|
|
227
|
+
await promises_1.default.rm(fileOrDirPath, { recursive: true, force: true });
|
|
227
228
|
}
|
|
228
229
|
exports._removePath = _removePath;
|
|
229
230
|
function _removePathSync(fileOrDirPath) {
|
|
230
|
-
|
|
231
|
+
node_fs_1.default.rmSync(fileOrDirPath, { recursive: true, force: true });
|
|
231
232
|
}
|
|
232
233
|
exports._removePathSync = _removePathSync;
|
|
233
234
|
async function _emptyDir(dirPath) {
|
|
234
235
|
let items;
|
|
235
236
|
try {
|
|
236
|
-
items = await
|
|
237
|
+
items = await promises_1.default.readdir(dirPath);
|
|
237
238
|
}
|
|
238
239
|
catch {
|
|
239
240
|
return await _ensureDir(dirPath);
|
|
240
241
|
}
|
|
241
|
-
await Promise.all(items.map(item => _removePath(
|
|
242
|
+
await Promise.all(items.map(item => _removePath(node_path_1.default.join(dirPath, item))));
|
|
242
243
|
}
|
|
243
244
|
exports._emptyDir = _emptyDir;
|
|
244
245
|
function _emptyDirSync(dirPath) {
|
|
245
246
|
let items;
|
|
246
247
|
try {
|
|
247
|
-
items =
|
|
248
|
+
items = node_fs_1.default.readdirSync(dirPath);
|
|
248
249
|
}
|
|
249
250
|
catch {
|
|
250
251
|
return _ensureDirSync(dirPath);
|
|
251
252
|
}
|
|
252
|
-
items.forEach(item => _removePathSync(
|
|
253
|
+
items.forEach(item => _removePathSync(node_path_1.default.join(dirPath, item)));
|
|
253
254
|
}
|
|
254
255
|
exports._emptyDirSync = _emptyDirSync;
|
|
255
256
|
/**
|
|
256
257
|
* Cautious, underlying Node function is currently Experimental.
|
|
257
258
|
*/
|
|
258
259
|
async function _copyPath(src, dest, opt) {
|
|
259
|
-
await
|
|
260
|
+
await promises_1.default.cp(src, dest, {
|
|
260
261
|
recursive: true,
|
|
261
262
|
...opt,
|
|
262
263
|
});
|
|
@@ -266,7 +267,7 @@ exports._copyPath = _copyPath;
|
|
|
266
267
|
* Cautious, underlying Node function is currently Experimental.
|
|
267
268
|
*/
|
|
268
269
|
function _copyPathSync(src, dest, opt) {
|
|
269
|
-
|
|
270
|
+
node_fs_1.default.cpSync(src, dest, {
|
|
270
271
|
recursive: true,
|
|
271
272
|
...opt,
|
|
272
273
|
});
|
package/dist/fs/json2env.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.objectToGithubActionsEnv = exports.objectToShellExport = exports.appendToGithubSummary = exports.appendToGithubOutput = exports.appendToGithubEnv = exports.appendToBashEnv = exports.json2env = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
5
6
|
const colors_1 = require("../colors/colors");
|
|
6
7
|
const fs_util_1 = require("./fs.util");
|
|
7
8
|
const JSON2ENV_OPT_DEF = {
|
|
@@ -54,7 +55,7 @@ function appendToBashEnv(obj, prefix = '') {
|
|
|
54
55
|
const { BASH_ENV } = process.env;
|
|
55
56
|
if (BASH_ENV) {
|
|
56
57
|
const data = objectToShellExport(obj, prefix);
|
|
57
|
-
|
|
58
|
+
node_fs_1.default.appendFileSync(BASH_ENV, data);
|
|
58
59
|
console.log(`BASH_ENV appended:\n${data}`);
|
|
59
60
|
}
|
|
60
61
|
}
|
|
@@ -63,7 +64,7 @@ function appendToGithubEnv(obj, prefix = '') {
|
|
|
63
64
|
const { GITHUB_ENV } = process.env;
|
|
64
65
|
if (GITHUB_ENV) {
|
|
65
66
|
const data = objectToGithubActionsEnv(obj, prefix);
|
|
66
|
-
|
|
67
|
+
node_fs_1.default.appendFileSync(GITHUB_ENV, data);
|
|
67
68
|
console.log(`GITHUB_ENV appended:\n${data}`);
|
|
68
69
|
}
|
|
69
70
|
}
|
|
@@ -72,7 +73,7 @@ function appendToGithubOutput(obj, prefix = '') {
|
|
|
72
73
|
const { GITHUB_OUTPUT } = process.env;
|
|
73
74
|
if (GITHUB_OUTPUT) {
|
|
74
75
|
const data = objectToGithubActionsEnv(obj, prefix);
|
|
75
|
-
|
|
76
|
+
node_fs_1.default.appendFileSync(GITHUB_OUTPUT, data);
|
|
76
77
|
console.log(`GITHUB_OUTPUT appended:\n${data}`);
|
|
77
78
|
}
|
|
78
79
|
}
|
|
@@ -83,7 +84,7 @@ exports.appendToGithubOutput = appendToGithubOutput;
|
|
|
83
84
|
function appendToGithubSummary(str) {
|
|
84
85
|
const { GITHUB_STEP_SUMMARY } = process.env;
|
|
85
86
|
if (GITHUB_STEP_SUMMARY) {
|
|
86
|
-
|
|
87
|
+
node_fs_1.default.appendFileSync(GITHUB_STEP_SUMMARY, str + '\n');
|
|
87
88
|
console.log(`GITHUB_STEP_SUMMARY appended:\n${str}`);
|
|
88
89
|
}
|
|
89
90
|
}
|