@scalar/cli 0.2.205 → 0.2.206

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/README.md CHANGED
@@ -172,6 +172,20 @@ scalar init
172
172
 
173
173
  This will create a `scalar.config.json` file for you. All commands will use the configured OpenAPI file by default.
174
174
 
175
+ ### check
176
+
177
+ Validate a Scalar Configuration file (`scalar.config.json`), gives helpful hints to fix invalid configurations. To check a `scalar.config.json` in the same folder:
178
+
179
+ ```bash
180
+ scalar check
181
+ ```
182
+
183
+ Or to validate a specific file:
184
+
185
+ ```bash
186
+ scalar check some-custom-folder/scalar.config.json
187
+ ```
188
+
175
189
  ## Options
176
190
 
177
191
  ### --version
@@ -0,0 +1,62 @@
1
+ import { check } from '@scalar/config';
2
+ import { Command } from 'commander';
3
+ import kleur from 'kleur';
4
+ import fs from 'node:fs';
5
+ import path from 'node:path';
6
+ import { ERRORS } from '../../libs/errors.js';
7
+ import { CONFIG_FILE } from '../../utils/useGivenFileOrConfiguration.js';
8
+
9
+ /**
10
+ * Lint users scalar configs (scalar.config.json files)
11
+ */
12
+ function CheckCommand() {
13
+ const cmd = new Command('check');
14
+ cmd.description('Check a Scalar Configuration file');
15
+ cmd.argument('[file]', 'File to check');
16
+ cmd.action(async (inputArgument) => {
17
+ const startTime = performance.now();
18
+ // Read file
19
+ const file = path.resolve(inputArgument ?? CONFIG_FILE);
20
+ // Check if `scalar.config.json` already exists
21
+ if (!fs.existsSync(file)) {
22
+ console.log();
23
+ console.error(kleur.red().bold(`ERROR`));
24
+ console.error(kleur.red(`Couldn’t find the Scalar Configuration file:`));
25
+ console.error(kleur.red(file));
26
+ console.log();
27
+ process.exit(1);
28
+ }
29
+ // Validate
30
+ const result = check(file);
31
+ if (result.valid) {
32
+ console.log();
33
+ console.log(kleur.green().bold('SUCCESS'));
34
+ console.log(kleur.green('The Scalar Configuration is valid:'));
35
+ console.log(kleur.green(file));
36
+ const endTime = performance.now();
37
+ console.log();
38
+ console.log(kleur.green('Scalar Configuration validated'), kleur.grey(`in ${kleur.white(`${kleur.bold(`${Math.round(endTime - startTime)}`)} ms`)}`));
39
+ console.log();
40
+ }
41
+ else {
42
+ console.log();
43
+ console.error(kleur.red().bold('ERROR'));
44
+ console.error(kleur.red(ERRORS.INVALID_SCALAR_CONFIGURATION));
45
+ console.error(kleur.red(file));
46
+ result.errors?.forEach((error) => {
47
+ console.log();
48
+ if (error.path) {
49
+ console.error(kleur.white(`➜ ${error.path}`));
50
+ }
51
+ if (error.message) {
52
+ console.error(kleur.white(` ${error.message}`));
53
+ }
54
+ });
55
+ console.log();
56
+ process.exit(1);
57
+ }
58
+ });
59
+ return cmd;
60
+ }
61
+
62
+ export { CheckCommand };
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ import { ServeCommand } from './commands/serve/ServeCommand.js';
9
9
  import { MockCommand } from './commands/mock/MockCommand.js';
10
10
  import { VoidCommand } from './commands/void/VoidCommand.js';
11
11
  import { ShareCommand } from './commands/share/ShareCommand.js';
12
+ import { CheckCommand } from './commands/check/CheckCommand.js';
12
13
 
13
14
  const program = new Command();
14
15
  program
@@ -25,6 +26,7 @@ program.addCommand(ServeCommand());
25
26
  program.addCommand(MockCommand());
26
27
  program.addCommand(VoidCommand());
27
28
  program.addCommand(ShareCommand());
29
+ program.addCommand(CheckCommand());
28
30
  /** display help if no argument has been provided */
29
31
  if (process.argv.length === 2) {
30
32
  program.help();
@@ -0,0 +1,6 @@
1
+ /** Centralized list of all error messages */
2
+ const ERRORS = {
3
+ INVALID_SCALAR_CONFIGURATION: 'The given Scalar Configuration is invalid.',
4
+ };
5
+
6
+ export { ERRORS };
@@ -1,3 +1,3 @@
1
- var version = "0.2.205";
1
+ var version = "0.2.206";
2
2
 
3
3
  export { version };
@@ -0,0 +1,6 @@
1
+ import { Command } from 'commander';
2
+ /**
3
+ * Lint users scalar configs (scalar.config.json files)
4
+ */
5
+ export declare function CheckCommand(): Command;
6
+ //# sourceMappingURL=CheckCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CheckCommand.d.ts","sourceRoot":"","sources":["../../../../src/commands/check/CheckCommand.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAQnC;;GAEG;AACH,wBAAgB,YAAY,YAiE3B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=check.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check.test.d.ts","sourceRoot":"","sources":["../../../../src/commands/check/check.test.ts"],"names":[],"mappings":""}
@@ -1,6 +1,7 @@
1
1
  export * from './bundle/BundleCommand';
2
2
  export * from './format/FormatCommand';
3
3
  export * from './init/InitCommand';
4
+ export * from './check/CheckCommand';
4
5
  export * from './mock/MockCommand';
5
6
  export * from './serve/ServeCommand';
6
7
  export * from './share/ShareCommand';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,oBAAoB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,oBAAoB,CAAA"}
@@ -0,0 +1,5 @@
1
+ /** Centralized list of all error messages */
2
+ export declare const ERRORS: {
3
+ readonly INVALID_SCALAR_CONFIGURATION: "The given Scalar Configuration is invalid.";
4
+ };
5
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/libs/errors.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,eAAO,MAAM,MAAM;;CAET,CAAA"}
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "swagger",
17
17
  "cli"
18
18
  ],
19
- "version": "0.2.205",
19
+ "version": "0.2.206",
20
20
  "engines": {
21
21
  "node": ">=18"
22
22
  },
@@ -43,12 +43,13 @@
43
43
  "hono": "^4.2.7",
44
44
  "kleur": "^4.1.5",
45
45
  "prettyjson": "^1.2.5",
46
- "@scalar/oas-utils": "0.2.48",
47
- "@scalar/mock-server": "0.2.52",
46
+ "@scalar/api-reference": "1.25.23",
47
+ "@scalar/config": "0.1.0",
48
+ "@scalar/mock-server": "0.2.53",
49
+ "@scalar/oas-utils": "0.2.49",
50
+ "@scalar/void-server": "2.0.11",
48
51
  "@scalar/openapi-parser": "0.8.4",
49
- "@scalar/api-reference": "1.25.22",
50
- "@scalar/openapi-types": "0.1.1",
51
- "@scalar/void-server": "2.0.11"
52
+ "@scalar/openapi-types": "0.1.1"
52
53
  },
53
54
  "devDependencies": {
54
55
  "@rollup/plugin-json": "^6.1.0",
@@ -65,7 +66,7 @@
65
66
  "scripts": {
66
67
  "@scalar/cli": "pnpm vite-node src/index.ts",
67
68
  "build": "scalar-build-rollup",
68
- "link:cli": "pnpm run build && npm unlink -g @scalar/cli && npm link",
69
+ "cli:link": "pnpm run build && npm unlink -g @scalar/cli && npm link",
69
70
  "lint:check": "eslint .",
70
71
  "lint:fix": "eslint . --fix",
71
72
  "screenshot": "./scripts/take-screenshots.sh",