@naturalcycles/nodejs-lib 12.93.0 → 12.93.2
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 +1 -1
- package/dist/fs/del.js +6 -4
- package/dist/fs/fs.util.d.ts +30 -6
- package/dist/fs/fs.util.js +37 -13
- package/dist/fs/json2env.js +1 -1
- package/dist/secret/secrets-decrypt.util.js +2 -2
- package/dist/secret/secrets-encrypt.util.js +2 -2
- package/dist/validation/ajv/ajv.util.js +1 -1
- package/dist/validation/ajv/ajvSchema.js +1 -1
- package/package.json +1 -1
- package/src/bin/del.ts +2 -2
- package/src/fs/del.ts +11 -4
- package/src/fs/fs.util.ts +36 -14
- package/src/fs/json2env.ts +2 -2
- package/src/secret/secrets-decrypt.util.ts +3 -3
- package/src/secret/secrets-encrypt.util.ts +3 -3
- package/src/validation/ajv/ajv.util.ts +2 -2
- package/src/validation/ajv/ajvSchema.ts +2 -2
package/dist/bin/del.js
CHANGED
package/dist/fs/del.js
CHANGED
|
@@ -43,7 +43,9 @@ async function del(_opt) {
|
|
|
43
43
|
}
|
|
44
44
|
if (dry)
|
|
45
45
|
return;
|
|
46
|
-
await (0, js_lib_1.pMap)(filenames, filepath => fsp.
|
|
46
|
+
await (0, js_lib_1.pMap)(filenames, filepath => fsp.rm(filepath, {
|
|
47
|
+
force: true,
|
|
48
|
+
}), { concurrency });
|
|
47
49
|
// 2. glob only dirs, expand, delete only empty!
|
|
48
50
|
let dirnames = await (0, index_1.globby)(patterns, {
|
|
49
51
|
dot: true,
|
|
@@ -60,7 +62,7 @@ async function del(_opt) {
|
|
|
60
62
|
for await (const dirpath of dirnamesSorted) {
|
|
61
63
|
if (await isEmptyDir(dirpath)) {
|
|
62
64
|
// console.log(`empty dir: ${dirpath}`)
|
|
63
|
-
await fsp.
|
|
65
|
+
await fsp.rm(dirpath, { force: true, recursive: true });
|
|
64
66
|
deletedDirs.push(dirpath);
|
|
65
67
|
}
|
|
66
68
|
}
|
|
@@ -98,7 +100,7 @@ function delSync(_opt) {
|
|
|
98
100
|
}
|
|
99
101
|
if (dry)
|
|
100
102
|
return;
|
|
101
|
-
filenames.forEach(filepath => fs.
|
|
103
|
+
filenames.forEach(filepath => fs.rmSync(filepath, { force: true }));
|
|
102
104
|
// 2. glob only dirs, expand, delete only empty!
|
|
103
105
|
let dirnames = index_1.globby.sync(patterns, {
|
|
104
106
|
dot: true,
|
|
@@ -113,7 +115,7 @@ function delSync(_opt) {
|
|
|
113
115
|
for (const dirpath of dirnamesSorted) {
|
|
114
116
|
if (isEmptyDirSync(dirpath)) {
|
|
115
117
|
// console.log(`empty dir: ${dirpath}`)
|
|
116
|
-
fs.
|
|
118
|
+
fs.rmSync(dirpath, { force: true, recursive: true });
|
|
117
119
|
deletedDirs.push(dirpath);
|
|
118
120
|
}
|
|
119
121
|
}
|
package/dist/fs/fs.util.d.ts
CHANGED
|
@@ -12,16 +12,40 @@ export declare function _readFile(filePath: string): Promise<string>;
|
|
|
12
12
|
* Convenience wrapper that defaults to utf-8 string output.
|
|
13
13
|
*/
|
|
14
14
|
export declare function _readFileSync(filePath: string): string;
|
|
15
|
-
export declare function
|
|
16
|
-
|
|
15
|
+
export declare function _readJson<T = unknown>(filePath: string): Promise<T>;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated use _readJson
|
|
18
|
+
*/
|
|
19
|
+
export declare const _readJsonFile: typeof _readJson;
|
|
20
|
+
export declare function _readJsonSync<T = unknown>(filePath: string): T;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated use _readJsonSync
|
|
23
|
+
*/
|
|
24
|
+
export declare const _readJsonFileSync: typeof _readJsonSync;
|
|
17
25
|
export declare function _writeFile(filePath: string, data: string | Buffer): Promise<void>;
|
|
18
26
|
export declare function _writeFileSync(filePath: string, data: string | Buffer): void;
|
|
19
27
|
export declare function _outputFile(filePath: string, data: string | Buffer): Promise<void>;
|
|
20
28
|
export declare function _outputFileSync(filePath: string, data: string | Buffer): void;
|
|
21
|
-
export declare function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
export declare function _writeJson(filePath: string, data: any, opt?: JsonOptions): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated use _writeJson
|
|
32
|
+
*/
|
|
33
|
+
export declare const _writeJsonFile: typeof _writeJson;
|
|
34
|
+
export declare function _writeJsonSync(filePath: string, data: any, opt?: JsonOptions): void;
|
|
35
|
+
/**
|
|
36
|
+
* @deprecated use _writeJsonSync
|
|
37
|
+
*/
|
|
38
|
+
export declare const _writeJsonFileSync: typeof _writeJsonSync;
|
|
39
|
+
export declare function _outputJson(filePath: string, data: any, opt?: JsonOptions): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated use _outputJson
|
|
42
|
+
*/
|
|
43
|
+
export declare const _outputJsonFile: typeof _outputJson;
|
|
44
|
+
export declare function _outputJsonSync(filePath: string, data: any, opt?: JsonOptions): void;
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated use _outputJsonSync
|
|
47
|
+
*/
|
|
48
|
+
export declare const _outputJsonFileSync: typeof _outputJsonSync;
|
|
25
49
|
export declare function _pathExists(filePath: string): Promise<boolean>;
|
|
26
50
|
export declare function _pathExistsSync(filePath: string): boolean;
|
|
27
51
|
export declare function _ensureDir(dirPath: string): Promise<void>;
|
package/dist/fs/fs.util.js
CHANGED
|
@@ -15,7 +15,7 @@ Credit to: fs-extra (https://github.com/jprichardson/node-fs-extra)
|
|
|
15
15
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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._outputJsonFileSync = exports._outputJsonFile = exports._writeJsonFileSync = exports._writeJsonFile = exports._outputFileSync = exports._outputFile = exports._writeFileSync = exports._writeFile = exports._readJsonFileSync = exports._readJsonFile = exports._readFileSync = exports._readFile = void 0;
|
|
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._outputJsonFileSync = exports._outputJsonSync = exports._outputJsonFile = exports._outputJson = exports._writeJsonFileSync = exports._writeJsonSync = exports._writeJsonFile = exports._writeJson = exports._outputFileSync = exports._outputFile = exports._writeFileSync = exports._writeFile = exports._readJsonFileSync = exports._readJsonSync = exports._readJsonFile = exports._readJson = exports._readFileSync = exports._readFile = void 0;
|
|
19
19
|
const fs = require("node:fs");
|
|
20
20
|
const fsp = require("node:fs/promises");
|
|
21
21
|
const path = require("node:path");
|
|
@@ -34,16 +34,24 @@ function _readFileSync(filePath) {
|
|
|
34
34
|
return fs.readFileSync(filePath, 'utf8');
|
|
35
35
|
}
|
|
36
36
|
exports._readFileSync = _readFileSync;
|
|
37
|
-
async function
|
|
37
|
+
async function _readJson(filePath) {
|
|
38
38
|
const str = await fsp.readFile(filePath, 'utf8');
|
|
39
39
|
return (0, js_lib_1._jsonParse)(str);
|
|
40
40
|
}
|
|
41
|
-
exports.
|
|
42
|
-
|
|
41
|
+
exports._readJson = _readJson;
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated use _readJson
|
|
44
|
+
*/
|
|
45
|
+
exports._readJsonFile = _readJson;
|
|
46
|
+
function _readJsonSync(filePath) {
|
|
43
47
|
const str = fs.readFileSync(filePath, 'utf8');
|
|
44
48
|
return (0, js_lib_1._jsonParse)(str);
|
|
45
49
|
}
|
|
46
|
-
exports.
|
|
50
|
+
exports._readJsonSync = _readJsonSync;
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated use _readJsonSync
|
|
53
|
+
*/
|
|
54
|
+
exports._readJsonFileSync = _readJsonSync;
|
|
47
55
|
async function _writeFile(filePath, data) {
|
|
48
56
|
await fsp.writeFile(filePath, data);
|
|
49
57
|
}
|
|
@@ -68,26 +76,42 @@ function _outputFileSync(filePath, data) {
|
|
|
68
76
|
fs.writeFileSync(filePath, data);
|
|
69
77
|
}
|
|
70
78
|
exports._outputFileSync = _outputFileSync;
|
|
71
|
-
async function
|
|
79
|
+
async function _writeJson(filePath, data, opt) {
|
|
72
80
|
const str = JSON.stringify(data, null, opt?.spaces);
|
|
73
81
|
await fsp.writeFile(filePath, str);
|
|
74
82
|
}
|
|
75
|
-
exports.
|
|
76
|
-
|
|
83
|
+
exports._writeJson = _writeJson;
|
|
84
|
+
/**
|
|
85
|
+
* @deprecated use _writeJson
|
|
86
|
+
*/
|
|
87
|
+
exports._writeJsonFile = _writeJson;
|
|
88
|
+
function _writeJsonSync(filePath, data, opt) {
|
|
77
89
|
const str = JSON.stringify(data, null, opt?.spaces);
|
|
78
90
|
fs.writeFileSync(filePath, str);
|
|
79
91
|
}
|
|
80
|
-
exports.
|
|
81
|
-
|
|
92
|
+
exports._writeJsonSync = _writeJsonSync;
|
|
93
|
+
/**
|
|
94
|
+
* @deprecated use _writeJsonSync
|
|
95
|
+
*/
|
|
96
|
+
exports._writeJsonFileSync = _writeJsonSync;
|
|
97
|
+
async function _outputJson(filePath, data, opt) {
|
|
82
98
|
const str = JSON.stringify(data, null, opt?.spaces);
|
|
83
99
|
await _outputFile(filePath, str);
|
|
84
100
|
}
|
|
85
|
-
exports.
|
|
86
|
-
|
|
101
|
+
exports._outputJson = _outputJson;
|
|
102
|
+
/**
|
|
103
|
+
* @deprecated use _outputJson
|
|
104
|
+
*/
|
|
105
|
+
exports._outputJsonFile = _outputJson;
|
|
106
|
+
function _outputJsonSync(filePath, data, opt) {
|
|
87
107
|
const str = JSON.stringify(data, null, opt?.spaces);
|
|
88
108
|
_outputFileSync(filePath, str);
|
|
89
109
|
}
|
|
90
|
-
exports.
|
|
110
|
+
exports._outputJsonSync = _outputJsonSync;
|
|
111
|
+
/**
|
|
112
|
+
* @deprecated use _outputJsonSync
|
|
113
|
+
*/
|
|
114
|
+
exports._outputJsonFileSync = _outputJsonSync;
|
|
91
115
|
async function _pathExists(filePath) {
|
|
92
116
|
try {
|
|
93
117
|
await fsp.access(filePath);
|
package/dist/fs/json2env.js
CHANGED
|
@@ -28,7 +28,7 @@ function json2env(opt) {
|
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
30
|
// read file
|
|
31
|
-
const json = (0, fs_util_1.
|
|
31
|
+
const json = (0, fs_util_1._readJsonSync)(jsonPath);
|
|
32
32
|
const exportStr = objectToShellExport(json, prefix);
|
|
33
33
|
const githubStr = objectToGithubActionsEnv(json, prefix);
|
|
34
34
|
if (debug) {
|
|
@@ -24,8 +24,8 @@ function secretsDecrypt(dir, file, encKey, del = false, jsonMode = false) {
|
|
|
24
24
|
(0, js_lib_1._assert)(filename.endsWith('.json'), `${path.basename(filename)} MUST end with '.json'`);
|
|
25
25
|
(0, js_lib_1._assert)(!filename.endsWith('.plain.json'), `${path.basename(filename)} MUST NOT end with '.plain.json'`);
|
|
26
26
|
plainFilename = filename.replace('.json', '.plain.json');
|
|
27
|
-
const json = (0, crypto_util_1.decryptObject)((0, index_1.
|
|
28
|
-
(0, index_1.
|
|
27
|
+
const json = (0, crypto_util_1.decryptObject)((0, index_1._readJsonSync)(filename), encKey);
|
|
28
|
+
(0, index_1._writeJsonSync)(plainFilename, json, { spaces: 2 });
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
31
|
const enc = fs.readFileSync(filename);
|
|
@@ -24,8 +24,8 @@ function secretsEncrypt(pattern, file, encKey, del = false, jsonMode = false) {
|
|
|
24
24
|
if (jsonMode) {
|
|
25
25
|
(0, js_lib_1._assert)(filename.endsWith('.plain.json'), `${path.basename(filename)} MUST end with '.plain.json'`);
|
|
26
26
|
encFilename = filename.replace('.plain', '');
|
|
27
|
-
const json = (0, crypto_util_1.encryptObject)((0, index_1.
|
|
28
|
-
(0, index_1.
|
|
27
|
+
const json = (0, crypto_util_1.encryptObject)((0, index_1._readJsonSync)(filename), encKey);
|
|
28
|
+
(0, index_1._writeJsonSync)(encFilename, json, { spaces: 2 });
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
31
|
const plain = fs.readFileSync(filename);
|
|
@@ -12,7 +12,7 @@ const ajvSchema_1 = require("./ajvSchema");
|
|
|
12
12
|
* @experimental
|
|
13
13
|
*/
|
|
14
14
|
function readJsonSchemas(patterns, opt) {
|
|
15
|
-
return __1.fastGlob.sync(patterns, opt).map(fileName => (0, __1.
|
|
15
|
+
return __1.fastGlob.sync(patterns, opt).map(fileName => (0, __1._readJsonSync)(fileName));
|
|
16
16
|
}
|
|
17
17
|
exports.readJsonSchemas = readJsonSchemas;
|
|
18
18
|
/**
|
|
@@ -59,7 +59,7 @@ class AjvSchema {
|
|
|
59
59
|
*/
|
|
60
60
|
static readJsonSync(filePath, cfg = {}) {
|
|
61
61
|
(0, index_1.requireFileToExist)(filePath);
|
|
62
|
-
const schema = (0, index_1.
|
|
62
|
+
const schema = (0, index_1._readJsonSync)(filePath);
|
|
63
63
|
return new AjvSchema(schema, cfg);
|
|
64
64
|
}
|
|
65
65
|
/**
|
package/package.json
CHANGED
package/src/bin/del.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import * as yargs from 'yargs'
|
|
4
|
-
import {
|
|
4
|
+
import { delSync } from '../fs/del'
|
|
5
5
|
import { runScript } from '../script'
|
|
6
6
|
|
|
7
7
|
runScript(async () => {
|
|
@@ -23,5 +23,5 @@ runScript(async () => {
|
|
|
23
23
|
},
|
|
24
24
|
}).argv
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
delSync({ patterns: patterns as string[], ...opt })
|
|
27
27
|
})
|
package/src/fs/del.ts
CHANGED
|
@@ -71,7 +71,14 @@ export async function del(_opt: DelOptions | DelSingleOption): Promise<void> {
|
|
|
71
71
|
|
|
72
72
|
if (dry) return
|
|
73
73
|
|
|
74
|
-
await pMap(
|
|
74
|
+
await pMap(
|
|
75
|
+
filenames,
|
|
76
|
+
filepath =>
|
|
77
|
+
fsp.rm(filepath, {
|
|
78
|
+
force: true,
|
|
79
|
+
}),
|
|
80
|
+
{ concurrency },
|
|
81
|
+
)
|
|
75
82
|
|
|
76
83
|
// 2. glob only dirs, expand, delete only empty!
|
|
77
84
|
let dirnames = await globby(patterns, {
|
|
@@ -95,7 +102,7 @@ export async function del(_opt: DelOptions | DelSingleOption): Promise<void> {
|
|
|
95
102
|
for await (const dirpath of dirnamesSorted) {
|
|
96
103
|
if (await isEmptyDir(dirpath)) {
|
|
97
104
|
// console.log(`empty dir: ${dirpath}`)
|
|
98
|
-
await fsp.
|
|
105
|
+
await fsp.rm(dirpath, { force: true, recursive: true })
|
|
99
106
|
deletedDirs.push(dirpath)
|
|
100
107
|
}
|
|
101
108
|
}
|
|
@@ -145,7 +152,7 @@ export function delSync(_opt: DelOptions | DelSingleOption): void {
|
|
|
145
152
|
|
|
146
153
|
if (dry) return
|
|
147
154
|
|
|
148
|
-
filenames.forEach(filepath => fs.
|
|
155
|
+
filenames.forEach(filepath => fs.rmSync(filepath, { force: true }))
|
|
149
156
|
|
|
150
157
|
// 2. glob only dirs, expand, delete only empty!
|
|
151
158
|
let dirnames = globby.sync(patterns, {
|
|
@@ -167,7 +174,7 @@ export function delSync(_opt: DelOptions | DelSingleOption): void {
|
|
|
167
174
|
for (const dirpath of dirnamesSorted) {
|
|
168
175
|
if (isEmptyDirSync(dirpath)) {
|
|
169
176
|
// console.log(`empty dir: ${dirpath}`)
|
|
170
|
-
fs.
|
|
177
|
+
fs.rmSync(dirpath, { force: true, recursive: true })
|
|
171
178
|
deletedDirs.push(dirpath)
|
|
172
179
|
}
|
|
173
180
|
}
|
package/src/fs/fs.util.ts
CHANGED
|
@@ -37,16 +37,26 @@ export function _readFileSync(filePath: string): string {
|
|
|
37
37
|
return fs.readFileSync(filePath, 'utf8')
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export async function
|
|
40
|
+
export async function _readJson<T = unknown>(filePath: string): Promise<T> {
|
|
41
41
|
const str = await fsp.readFile(filePath, 'utf8')
|
|
42
42
|
return _jsonParse(str)
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated use _readJson
|
|
47
|
+
*/
|
|
48
|
+
export const _readJsonFile = _readJson
|
|
49
|
+
|
|
50
|
+
export function _readJsonSync<T = unknown>(filePath: string): T {
|
|
46
51
|
const str = fs.readFileSync(filePath, 'utf8')
|
|
47
52
|
return _jsonParse(str)
|
|
48
53
|
}
|
|
49
54
|
|
|
55
|
+
/**
|
|
56
|
+
* @deprecated use _readJsonSync
|
|
57
|
+
*/
|
|
58
|
+
export const _readJsonFileSync = _readJsonSync
|
|
59
|
+
|
|
50
60
|
export async function _writeFile(filePath: string, data: string | Buffer): Promise<void> {
|
|
51
61
|
await fsp.writeFile(filePath, data)
|
|
52
62
|
}
|
|
@@ -73,34 +83,46 @@ export function _outputFileSync(filePath: string, data: string | Buffer): void {
|
|
|
73
83
|
fs.writeFileSync(filePath, data)
|
|
74
84
|
}
|
|
75
85
|
|
|
76
|
-
export async function
|
|
77
|
-
filePath: string,
|
|
78
|
-
data: any,
|
|
79
|
-
opt?: JsonOptions,
|
|
80
|
-
): Promise<void> {
|
|
86
|
+
export async function _writeJson(filePath: string, data: any, opt?: JsonOptions): Promise<void> {
|
|
81
87
|
const str = JSON.stringify(data, null, opt?.spaces)
|
|
82
88
|
await fsp.writeFile(filePath, str)
|
|
83
89
|
}
|
|
84
90
|
|
|
85
|
-
|
|
91
|
+
/**
|
|
92
|
+
* @deprecated use _writeJson
|
|
93
|
+
*/
|
|
94
|
+
export const _writeJsonFile = _writeJson
|
|
95
|
+
|
|
96
|
+
export function _writeJsonSync(filePath: string, data: any, opt?: JsonOptions): void {
|
|
86
97
|
const str = JSON.stringify(data, null, opt?.spaces)
|
|
87
98
|
fs.writeFileSync(filePath, str)
|
|
88
99
|
}
|
|
89
100
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
101
|
+
/**
|
|
102
|
+
* @deprecated use _writeJsonSync
|
|
103
|
+
*/
|
|
104
|
+
export const _writeJsonFileSync = _writeJsonSync
|
|
105
|
+
|
|
106
|
+
export async function _outputJson(filePath: string, data: any, opt?: JsonOptions): Promise<void> {
|
|
95
107
|
const str = JSON.stringify(data, null, opt?.spaces)
|
|
96
108
|
await _outputFile(filePath, str)
|
|
97
109
|
}
|
|
98
110
|
|
|
99
|
-
|
|
111
|
+
/**
|
|
112
|
+
* @deprecated use _outputJson
|
|
113
|
+
*/
|
|
114
|
+
export const _outputJsonFile = _outputJson
|
|
115
|
+
|
|
116
|
+
export function _outputJsonSync(filePath: string, data: any, opt?: JsonOptions): void {
|
|
100
117
|
const str = JSON.stringify(data, null, opt?.spaces)
|
|
101
118
|
_outputFileSync(filePath, str)
|
|
102
119
|
}
|
|
103
120
|
|
|
121
|
+
/**
|
|
122
|
+
* @deprecated use _outputJsonSync
|
|
123
|
+
*/
|
|
124
|
+
export const _outputJsonFileSync = _outputJsonSync
|
|
125
|
+
|
|
104
126
|
export async function _pathExists(filePath: string): Promise<boolean> {
|
|
105
127
|
try {
|
|
106
128
|
await fsp.access(filePath)
|
package/src/fs/json2env.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as fs from 'node:fs'
|
|
2
2
|
import { dimGrey } from '../colors'
|
|
3
|
-
import { _pathExistsSync,
|
|
3
|
+
import { _pathExistsSync, _readJsonSync, _writeFileSync } from './fs.util'
|
|
4
4
|
|
|
5
5
|
export interface Json2EnvOptions {
|
|
6
6
|
jsonPath: string
|
|
@@ -60,7 +60,7 @@ export function json2env(opt: Json2EnvOptions): void {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
// read file
|
|
63
|
-
const json =
|
|
63
|
+
const json = _readJsonSync(jsonPath)
|
|
64
64
|
|
|
65
65
|
const exportStr = objectToShellExport(json, prefix)
|
|
66
66
|
const githubStr = objectToGithubActionsEnv(json, prefix)
|
|
@@ -2,7 +2,7 @@ import * as path from 'node:path'
|
|
|
2
2
|
import * as fs from 'node:fs'
|
|
3
3
|
import { _assert } from '@naturalcycles/js-lib'
|
|
4
4
|
import { dimGrey, yellow } from '../colors'
|
|
5
|
-
import {
|
|
5
|
+
import { _readJsonSync, _writeJsonSync, fastGlob } from '../index'
|
|
6
6
|
import { decryptObject, decryptRandomIVBuffer } from '../security/crypto.util'
|
|
7
7
|
|
|
8
8
|
export interface DecryptCLIOptions {
|
|
@@ -44,9 +44,9 @@ export function secretsDecrypt(
|
|
|
44
44
|
)
|
|
45
45
|
plainFilename = filename.replace('.json', '.plain.json')
|
|
46
46
|
|
|
47
|
-
const json = decryptObject(
|
|
47
|
+
const json = decryptObject(_readJsonSync(filename), encKey)
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
_writeJsonSync(plainFilename, json, { spaces: 2 })
|
|
50
50
|
} else {
|
|
51
51
|
const enc = fs.readFileSync(filename)
|
|
52
52
|
const plain = decryptRandomIVBuffer(enc, encKey)
|
|
@@ -2,7 +2,7 @@ import * as fs from 'node:fs'
|
|
|
2
2
|
import * as path from 'node:path'
|
|
3
3
|
import { _assert } from '@naturalcycles/js-lib'
|
|
4
4
|
import { dimGrey, yellow } from '../colors'
|
|
5
|
-
import {
|
|
5
|
+
import { _readJsonSync, _writeJsonSync, fastGlob } from '../index'
|
|
6
6
|
import { encryptObject, encryptRandomIVBuffer } from '../security/crypto.util'
|
|
7
7
|
|
|
8
8
|
export interface EncryptCLIOptions {
|
|
@@ -41,9 +41,9 @@ export function secretsEncrypt(
|
|
|
41
41
|
)
|
|
42
42
|
encFilename = filename.replace('.plain', '')
|
|
43
43
|
|
|
44
|
-
const json = encryptObject(
|
|
44
|
+
const json = encryptObject(_readJsonSync(filename), encKey)
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
_writeJsonSync(encFilename, json, { spaces: 2 })
|
|
47
47
|
} else {
|
|
48
48
|
const plain = fs.readFileSync(filename)
|
|
49
49
|
const enc = encryptRandomIVBuffer(plain, encKey)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JsonSchema } from '@naturalcycles/js-lib'
|
|
2
|
-
import {
|
|
2
|
+
import { _readJsonSync, fastGlob } from '../..'
|
|
3
3
|
import type { FastGlobOptions } from '../..'
|
|
4
4
|
import { AjvSchema, AjvSchemaCfg } from './ajvSchema'
|
|
5
5
|
|
|
@@ -12,7 +12,7 @@ import { AjvSchema, AjvSchemaCfg } from './ajvSchema'
|
|
|
12
12
|
* @experimental
|
|
13
13
|
*/
|
|
14
14
|
export function readJsonSchemas(patterns: string | string[], opt?: FastGlobOptions): JsonSchema[] {
|
|
15
|
-
return fastGlob.sync(patterns, opt).map(fileName =>
|
|
15
|
+
return fastGlob.sync(patterns, opt).map(fileName => _readJsonSync(fileName))
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
CommonLogger,
|
|
9
9
|
} from '@naturalcycles/js-lib'
|
|
10
10
|
import Ajv, { ValidateFunction } from 'ajv'
|
|
11
|
-
import {
|
|
11
|
+
import { _readJsonSync, inspectAny, requireFileToExist } from '../../index'
|
|
12
12
|
import { AjvValidationError } from './ajvValidationError'
|
|
13
13
|
import { getAjv } from './getAjv'
|
|
14
14
|
|
|
@@ -131,7 +131,7 @@ export class AjvSchema<T = unknown> {
|
|
|
131
131
|
cfg: Partial<AjvSchemaCfg> = {},
|
|
132
132
|
): AjvSchema<T> {
|
|
133
133
|
requireFileToExist(filePath)
|
|
134
|
-
const schema =
|
|
134
|
+
const schema = _readJsonSync<JsonSchema<T>>(filePath)
|
|
135
135
|
return new AjvSchema<T>(schema, cfg)
|
|
136
136
|
}
|
|
137
137
|
|