yini-cli 1.2.0-beta → 1.2.1-beta
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/commands/validateCommand.js +26 -23
- package/package.json +1 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
2
1
|
import { exit } from 'node:process';
|
|
3
2
|
import YINI from 'yini-parser';
|
|
4
|
-
const IS_DEBUG =
|
|
3
|
+
const IS_DEBUG = false; // For local debugging purposes, etc.
|
|
5
4
|
/*
|
|
6
5
|
TODO / SHOULD-DO:
|
|
7
6
|
|
|
@@ -140,18 +139,8 @@ const IS_DEBUG = true; // For local debugging purposes, etc.
|
|
|
140
139
|
export const validateFile = (file, commandOptions = {}) => {
|
|
141
140
|
let parsedResult = undefined;
|
|
142
141
|
let isCatchedError = true;
|
|
143
|
-
// let failLevel: PreferredFailLevel = 'auto'
|
|
144
|
-
// if (commandOptions.failFast) {
|
|
145
|
-
// failLevel = 'warnings-and-errors'
|
|
146
|
-
// }
|
|
147
|
-
// if (commandOptions.bestEffort) {
|
|
148
|
-
// failLevel = 'ignore-errors'
|
|
149
|
-
// }
|
|
150
142
|
const parseOptions = {
|
|
151
143
|
strictMode: commandOptions.strict ?? false,
|
|
152
|
-
// failLevel: 'errors',
|
|
153
|
-
// failLevel: commandOptions.force ? 'ignore-errors' : 'errors',
|
|
154
|
-
// failLevel: 'ignore-errors',
|
|
155
144
|
failLevel: 'ignore-errors',
|
|
156
145
|
includeMetadata: true,
|
|
157
146
|
includeDiagnostics: true,
|
|
@@ -163,6 +152,10 @@ export const validateFile = (file, commandOptions = {}) => {
|
|
|
163
152
|
}
|
|
164
153
|
catch (err) {
|
|
165
154
|
isCatchedError = true;
|
|
155
|
+
if (!commandOptions.silent) {
|
|
156
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
157
|
+
console.error(`Error: ${message}`);
|
|
158
|
+
}
|
|
166
159
|
}
|
|
167
160
|
let metadata = null;
|
|
168
161
|
let errors = 0;
|
|
@@ -171,9 +164,13 @@ export const validateFile = (file, commandOptions = {}) => {
|
|
|
171
164
|
let infos = 0;
|
|
172
165
|
if (!isCatchedError && parsedResult?.meta) {
|
|
173
166
|
metadata = parsedResult?.meta;
|
|
174
|
-
assert(metadata)
|
|
167
|
+
// assert(metadata) // Make sure there is metadata!
|
|
175
168
|
// printObject(metadata, true)
|
|
176
|
-
assert(metadata.diagnostics)
|
|
169
|
+
// assert(metadata.diagnostics)
|
|
170
|
+
if (!metadata?.diagnostics) {
|
|
171
|
+
console.error('Internal error: Missing diagnostics metadata');
|
|
172
|
+
exit(1);
|
|
173
|
+
}
|
|
177
174
|
const diag = metadata.diagnostics;
|
|
178
175
|
errors = diag.errors.errorCount;
|
|
179
176
|
warnings = diag.warnings.warningCount;
|
|
@@ -183,11 +180,10 @@ export const validateFile = (file, commandOptions = {}) => {
|
|
|
183
180
|
IS_DEBUG && console.log();
|
|
184
181
|
IS_DEBUG && console.log('isCatchedError = ' + isCatchedError);
|
|
185
182
|
IS_DEBUG && console.log('TEMP OUTPUT');
|
|
186
|
-
IS_DEBUG && console.log('isCatchedError = ' + isCatchedError);
|
|
187
183
|
IS_DEBUG && console.log(' errors = ' + errors);
|
|
188
184
|
IS_DEBUG && console.log('warnings = ' + warnings);
|
|
189
185
|
IS_DEBUG && console.log(' notices = ' + notices);
|
|
190
|
-
IS_DEBUG && console.log('
|
|
186
|
+
IS_DEBUG && console.log(' infos = ' + infos);
|
|
191
187
|
IS_DEBUG && console.log('metadata = ' + metadata);
|
|
192
188
|
IS_DEBUG &&
|
|
193
189
|
console.log('includeMetadata = ' +
|
|
@@ -244,17 +240,18 @@ export const validateFile = (file, commandOptions = {}) => {
|
|
|
244
240
|
// if (commandOptions.details) {
|
|
245
241
|
if (errors || warnings) {
|
|
246
242
|
if (!metadata) {
|
|
247
|
-
console.error('Internal
|
|
243
|
+
console.error('Internal error: No metadata available');
|
|
244
|
+
exit(1);
|
|
248
245
|
}
|
|
249
|
-
assert(metadata)
|
|
246
|
+
// assert(metadata) // Make sure there is metadata!
|
|
250
247
|
console.log();
|
|
251
248
|
printIssuesFound(file, metadata);
|
|
252
249
|
}
|
|
253
250
|
if (commandOptions.stats) {
|
|
254
251
|
if (!metadata) {
|
|
255
|
-
console.error('Internal
|
|
252
|
+
console.error('Internal error: No metadata available');
|
|
253
|
+
exit(1);
|
|
256
254
|
}
|
|
257
|
-
assert(metadata); // Make sure there is metadata!
|
|
258
255
|
console.log();
|
|
259
256
|
console.log(formatToStatsReport(file, metadata).trim());
|
|
260
257
|
}
|
|
@@ -278,7 +275,7 @@ mode, errors, warnings, notices, infos) => {
|
|
|
278
275
|
break;
|
|
279
276
|
case 'Passed-with-Warnings':
|
|
280
277
|
// result = '⚠️ Validation finished'
|
|
281
|
-
result = '✔ Validation successful';
|
|
278
|
+
result = '✔ Validation successful (with warnings)';
|
|
282
279
|
break;
|
|
283
280
|
case 'Failed':
|
|
284
281
|
// result = '✖ Validation failed'
|
|
@@ -355,7 +352,10 @@ const formatToStatsReport = (fileWithPath, metadata) => {
|
|
|
355
352
|
// console.log('formatToStatsReport(..)')
|
|
356
353
|
// printObject(metadata)
|
|
357
354
|
// console.log()
|
|
358
|
-
|
|
355
|
+
if (!metadata?.diagnostics) {
|
|
356
|
+
console.error('Internal error: Missing diagnostics');
|
|
357
|
+
exit(1);
|
|
358
|
+
}
|
|
359
359
|
const diag = metadata.diagnostics;
|
|
360
360
|
const issuesCount = diag.errors.errorCount +
|
|
361
361
|
diag.warnings.warningCount +
|
|
@@ -408,7 +408,10 @@ const printIssuesFound = (fileWithPath, metadata) => {
|
|
|
408
408
|
// printObject(metadata)
|
|
409
409
|
// console.log(toPrettyJSON(metadata))
|
|
410
410
|
// console.log()
|
|
411
|
-
|
|
411
|
+
if (!metadata?.diagnostics) {
|
|
412
|
+
console.error('Internal error: Missing diagnostics metadata');
|
|
413
|
+
exit(1);
|
|
414
|
+
}
|
|
412
415
|
const diag = metadata.diagnostics;
|
|
413
416
|
IS_DEBUG && console.log('*** Issues Found');
|
|
414
417
|
IS_DEBUG && console.log('*** ------------');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yini-cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1-beta",
|
|
4
4
|
"description": "CLI tool for YINI text-based format - an INI-like config format with real structure, comments, nested sections, no YAML foot-guns, and less noise than JSON.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yini",
|