piral-cli 1.12.3 → 1.12.4-beta.36dc2ff

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-cli",
3
- "version": "1.12.3",
3
+ "version": "1.12.4-beta.36dc2ff",
4
4
  "description": "The standard CLI for creating and building a Piral instance or a Pilet.",
5
5
  "keywords": [
6
6
  "portal",
@@ -14,6 +14,11 @@ export interface ValidatPiletOptions {
14
14
  */
15
15
  logLevel?: LogLevels;
16
16
 
17
+ /**
18
+ * Fails validation if configured validators are missing from the loaded rule set.
19
+ */
20
+ strict?: boolean;
21
+
17
22
  /**
18
23
  * Overrides the Piral instance used as validation blueprint for the pilet.
19
24
  */
@@ -23,6 +28,7 @@ export interface ValidatPiletOptions {
23
28
  export const validatePiletDefaults: ValidatPiletOptions = {
24
29
  entry: './src/index',
25
30
  logLevel: LogLevels.info,
31
+ strict: false,
26
32
  app: undefined,
27
33
  };
28
34
 
@@ -30,6 +36,7 @@ export async function validatePilet(baseDir = process.cwd(), options: ValidatPil
30
36
  const {
31
37
  entry = validatePiletDefaults.entry,
32
38
  logLevel = validatePiletDefaults.logLevel,
39
+ strict = validatePiletDefaults.strict,
33
40
  app = validatePiletDefaults.app,
34
41
  } = options;
35
42
 
@@ -79,7 +86,7 @@ export async function validatePilet(baseDir = process.cwd(), options: ValidatPil
79
86
  piletPackage,
80
87
  };
81
88
 
82
- await runRules(rules, context, validators);
89
+ await runRules(rules, context, validators, strict);
83
90
  }
84
91
 
85
92
  ruleSummary(errors, warnings);
package/src/commands.ts CHANGED
@@ -900,6 +900,9 @@ const allCommands: Array<ToolCommand<any>> = [
900
900
  .number('log-level')
901
901
  .describe('log-level', 'Sets the log level to use (1-5).')
902
902
  .default('log-level', apps.validatePiletDefaults.logLevel)
903
+ .boolean('strict')
904
+ .describe('strict', 'Fails validation if configured validators are missing from the loaded rule set.')
905
+ .default('strict', apps.validatePiletDefaults.strict)
903
906
  .string('app')
904
907
  .describe('app', 'Sets the name of the Piral instance.')
905
908
  .string('base')
@@ -910,6 +913,7 @@ const allCommands: Array<ToolCommand<any>> = [
910
913
  return apps.validatePilet(args.base as string, {
911
914
  entry: args.entry as string,
912
915
  logLevel: args['log-level'] as LogLevels,
916
+ strict: args.strict as boolean,
913
917
  app: args.app as string,
914
918
  });
915
919
  },
@@ -27,4 +27,24 @@ describe('Rules Module', () => {
27
27
  await runRules([], {} as any, {}).then((result) => expect(result).toBeUndefined());
28
28
  await runRules([rule], {} as any, { test: {} }).then((result) => expect(result).toBeUndefined());
29
29
  });
30
+
31
+ it('warns about missing configured rules by default', async () => {
32
+ const warning = vitest.fn();
33
+ const error = vitest.fn();
34
+
35
+ await runRules([], { warning, error } as any, { missing: {} });
36
+
37
+ expect(warning).toHaveBeenCalledWith('Configured validator(s) could not be loaded: missing');
38
+ expect(error).not.toHaveBeenCalled();
39
+ });
40
+
41
+ it('errors about missing configured rules in strict mode', async () => {
42
+ const warning = vitest.fn();
43
+ const error = vitest.fn();
44
+
45
+ await runRules([], { warning, error } as any, { missing: {} }, true);
46
+
47
+ expect(error).toHaveBeenCalledWith('Configured validator(s) could not be loaded: missing');
48
+ expect(warning).not.toHaveBeenCalled();
49
+ });
30
50
  });
@@ -15,7 +15,21 @@ export async function runRules<T extends RuleContext>(
15
15
  rules: Array<Rule<T>>,
16
16
  context: T,
17
17
  configurations: Record<string, any> = {},
18
+ strict = false,
18
19
  ) {
20
+ const loadedRules = new Set(rules.map(rule => rule.name));
21
+ const missingRules = Object.keys(configurations).filter(name => !loadedRules.has(name));
22
+
23
+ if (missingRules.length > 0) {
24
+ const message = `Configured validator(s) could not be loaded: ${missingRules.join(', ')}`;
25
+
26
+ if (strict) {
27
+ context.error(message);
28
+ } else {
29
+ context.warning(message);
30
+ }
31
+ }
32
+
19
33
  for (const rule of rules) {
20
34
  log('generalDebug_0003', `Running rule "${rule?.name}" ...`);
21
35
  const options = configurations[rule.name];