@player-tools/cli 0.7.1-next.2 → 0.8.0-next.0

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.
@@ -7,6 +7,7 @@ export default class DSLCompile extends BaseCommand {
7
7
  output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
8
8
  "skip-validation": import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
9
9
  exp: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
10
+ severity: import("@oclif/core/lib/interfaces").OptionFlag<string>;
10
11
  config: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
11
12
  };
12
13
  private getOptions;
@@ -35,6 +35,12 @@ class DSLCompile extends base_command_1.BaseCommand {
35
35
  description: "Use experimental language features",
36
36
  default: false,
37
37
  }),
38
+ severity: core_1.Flags.string({
39
+ char: "s",
40
+ description: "The severity of the validation",
41
+ options: ["error", "warn"],
42
+ default: "error",
43
+ }),
38
44
  };
39
45
  async getOptions() {
40
46
  const { flags } = await this.parse(DSLCompile);
@@ -49,10 +55,11 @@ class DSLCompile extends base_command_1.BaseCommand {
49
55
  output: flags.output ?? config.dsl?.outDir ?? "_out",
50
56
  skipValidation: flags["skip-validation"] ?? config.dsl?.skipValidation ?? false,
51
57
  exp,
58
+ severity: flags.severity,
52
59
  };
53
60
  }
54
61
  async run() {
55
- const { input, output, skipValidation, exp } = await this.getOptions();
62
+ const { input, output, skipValidation, exp, severity } = await this.getOptions();
56
63
  const files = await (0, globby_1.default)((0, fs_2.convertToFileGlob)([input], "**/*.(tsx|jsx|js|ts)"), {
57
64
  expandDirectories: true,
58
65
  });
@@ -62,7 +69,7 @@ class DSLCompile extends base_command_1.BaseCommand {
62
69
  (0, babel_register_1.registerForPaths)();
63
70
  this.debug("Found %i files to process", files.length);
64
71
  if (!skipValidation) {
65
- await validate_2.default.run(["-f", input]);
72
+ await validate_2.default.run(["-f", input, "-s", severity]);
66
73
  }
67
74
  const context = await this.createCompilerContext();
68
75
  /** Compile a file from the DSL format into JSON */
@@ -4,6 +4,7 @@ export default class Validate extends BaseCommand {
4
4
  static description: string;
5
5
  static flags: {
6
6
  files: import("@oclif/core/lib/interfaces").OptionFlag<string[]>;
7
+ severity: import("@oclif/core/lib/interfaces").OptionFlag<string>;
7
8
  config: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
8
9
  };
9
10
  private getOptions;
@@ -20,6 +20,12 @@ class Validate extends base_command_1.BaseCommand {
20
20
  description: "A list of files or globs to validate",
21
21
  multiple: true,
22
22
  }),
23
+ severity: core_1.Flags.string({
24
+ char: "s",
25
+ description: "Setting the validation severity to 'warn' will change the validation step into a warning-only, not halting the process with code 1. That exposes an intermediate option between the default behaviour, where it will fail on errors, and skipping validation.",
26
+ options: ["error", "warn"],
27
+ default: "error",
28
+ }),
23
29
  };
24
30
  async getOptions() {
25
31
  const { flags } = await this.parse(Validate);
@@ -30,6 +36,7 @@ class Validate extends base_command_1.BaseCommand {
30
36
  }
31
37
  return {
32
38
  inputFiles: Array.isArray(files) ? files : [files],
39
+ severity: flags.severity,
33
40
  };
34
41
  }
35
42
  getTSConfig(filePath) {
@@ -59,44 +66,72 @@ class Validate extends base_command_1.BaseCommand {
59
66
  return parsedConfigContent.options;
60
67
  }
61
68
  async run() {
62
- const { inputFiles } = await this.getOptions();
69
+ const { inputFiles, severity } = await this.getOptions();
63
70
  const files = await (0, globby_1.default)((0, fs_2.convertToFileGlob)(inputFiles, "**/*.(tsx|jsx|js|ts)"), {
64
71
  expandDirectories: true,
65
72
  });
66
73
  const TSConfig = this.getTSConfig() ?? compiler_options_1.DEFAULT_COMPILER_OPTIONS;
67
74
  const program = ts.createProgram(files, TSConfig);
68
75
  const allDiagnostics = ts.getPreEmitDiagnostics(program);
69
- let diagnosticsCount = 0;
70
76
  const groupedDiagnostics = allDiagnostics.reduce((acc, diagnostic) => {
71
77
  const fileName = diagnostic.file?.fileName;
78
+ const category = diagnostic.category;
72
79
  if (fileName && files.includes(fileName)) {
73
- if (!acc[fileName]) {
74
- acc[fileName] = [];
80
+ if (!acc[category][fileName]) {
81
+ acc[category][fileName] = [];
75
82
  }
76
- acc[fileName].push(diagnostic);
77
- diagnosticsCount += 1;
83
+ acc[category][fileName].push(diagnostic);
78
84
  }
79
85
  return acc;
80
- }, {});
81
- const fileNameList = Object.keys(groupedDiagnostics);
82
- fileNameList.forEach((diagnosticGroup) => {
83
- this.log(`${diagnosticGroup}`);
84
- groupedDiagnostics[diagnosticGroup].forEach((diagnostic) => {
85
- if (diagnostic.file) {
86
- const { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
87
- const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
88
- this.log(` ${log_symbols_1.default.error} (${line + 1},${character + 1}): ${message}`);
89
- }
90
- else {
91
- this.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
92
- }
86
+ }, {
87
+ [ts.DiagnosticCategory.Error]: {},
88
+ [ts.DiagnosticCategory.Warning]: {},
89
+ [ts.DiagnosticCategory.Message]: {},
90
+ [ts.DiagnosticCategory.Suggestion]: {},
91
+ });
92
+ const diagnosticCategories = [
93
+ ts.DiagnosticCategory.Error,
94
+ ts.DiagnosticCategory.Warning,
95
+ ts.DiagnosticCategory.Message,
96
+ ts.DiagnosticCategory.Suggestion,
97
+ ];
98
+ diagnosticCategories.forEach((category) => {
99
+ const diagnosticsList = Object.keys(groupedDiagnostics[category]);
100
+ diagnosticsList.forEach((diagnosticGroup) => {
101
+ this.log(`${diagnosticGroup}`);
102
+ groupedDiagnostics[category][diagnosticGroup].forEach((diagnostic) => {
103
+ if (diagnostic.file) {
104
+ const { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start ?? 0);
105
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
106
+ let logSymbol = log_symbols_1.default.info;
107
+ switch (category) {
108
+ case ts.DiagnosticCategory.Error:
109
+ logSymbol = log_symbols_1.default.error;
110
+ break;
111
+ case ts.DiagnosticCategory.Warning:
112
+ logSymbol = log_symbols_1.default.warning;
113
+ break;
114
+ case ts.DiagnosticCategory.Message:
115
+ logSymbol = log_symbols_1.default.info;
116
+ break;
117
+ case ts.DiagnosticCategory.Suggestion:
118
+ logSymbol = log_symbols_1.default.info;
119
+ break;
120
+ }
121
+ this.log(` ${logSymbol} (${line + 1},${character + 1}): ${message}`);
122
+ }
123
+ else {
124
+ this.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
125
+ }
126
+ });
93
127
  });
94
128
  });
95
- if (fileNameList.length) {
96
- this.log(`${diagnosticsCount} type or syntax errors found in
97
- ${fileNameList.length}
98
- file${fileNameList.length > 1 ? "s" : ""}, exiting program`);
99
- this.exit(1);
129
+ const errorsCount = Object.keys(groupedDiagnostics[ts.DiagnosticCategory.Error]).length;
130
+ if (errorsCount) {
131
+ this.log(`Type or syntax errors found in ${errorsCount} file${errorsCount > 1 ? "s" : ""}, exiting program`);
132
+ if (severity === "error") {
133
+ this.exit(1);
134
+ }
100
135
  }
101
136
  else {
102
137
  this.log(`${log_symbols_1.default.success} No TSX types or errors found.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@player-tools/cli",
3
- "version": "0.7.1-next.2",
3
+ "version": "0.8.0-next.0",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [
@@ -21,12 +21,12 @@
21
21
  "player": "bin/run"
22
22
  },
23
23
  "dependencies": {
24
- "@player-tools/dsl": "0.7.1-next.2",
25
- "@player-tools/json-language-service": "0.7.1-next.2",
26
- "@player-tools/xlr": "0.7.1-next.2",
27
- "@player-tools/xlr-converters": "0.7.1-next.2",
28
- "@player-tools/xlr-sdk": "0.7.1-next.2",
29
- "@player-tools/xlr-utils": "0.7.1-next.2",
24
+ "@player-tools/dsl": "0.8.0-next.0",
25
+ "@player-tools/json-language-service": "0.8.0-next.0",
26
+ "@player-tools/xlr": "0.8.0-next.0",
27
+ "@player-tools/xlr-converters": "0.8.0-next.0",
28
+ "@player-tools/xlr-sdk": "0.8.0-next.0",
29
+ "@player-tools/xlr-utils": "0.8.0-next.0",
30
30
  "@babel/plugin-transform-react-jsx-source": "^7.23.3",
31
31
  "@babel/preset-env": "^7.23.3",
32
32
  "@babel/preset-react": "^7.23.3",