@backstage/repo-tools 0.3.0 → 0.3.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @backstage/repo-tools
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - ee411e7c2623: Adding a new command `schema openapi lint` to lint your OpenAPI specs and ensure consistent style across Backstage plugins.
8
+ - Updated dependencies
9
+ - @backstage/errors@1.2.0
10
+ - @backstage/cli-common@0.1.12
11
+ - @backstage/cli-node@0.1.1
12
+
13
+ ## 0.3.1-next.0
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies
18
+ - @backstage/errors@1.2.0-next.0
19
+ - @backstage/cli-node@0.1.1-next.0
20
+ - @backstage/cli-common@0.1.12
21
+
3
22
  ## 0.3.0
4
23
 
5
24
  ### Minor Changes
@@ -0,0 +1,94 @@
1
+ 'use strict';
2
+
3
+ var spectralCore = require('@stoplight/spectral-core');
4
+ var spectralParsers = require('@stoplight/spectral-parsers');
5
+ var ruleset = require('@apisyouwonthate/style-guide');
6
+ var fs = require('fs-extra');
7
+ var chalk = require('chalk');
8
+ var path = require('path');
9
+ var constants = require('./constants-2eebdd79.cjs.js');
10
+ var spectralRulesets = require('@stoplight/spectral-rulesets');
11
+ var types = require('@stoplight/types');
12
+ var spectralFormatters = require('@stoplight/spectral-formatters');
13
+ require('./paths-9ab9b8a8.cjs.js');
14
+ require('@backstage/cli-common');
15
+ require('@backstage/cli-node');
16
+ require('minimatch');
17
+ require('p-limit');
18
+
19
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
+
21
+ var ruleset__default = /*#__PURE__*/_interopDefaultLegacy(ruleset);
22
+ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
23
+ var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
24
+
25
+ async function lint(directoryPath, config) {
26
+ const { skipMissingYamlFile, strict } = config != null ? config : {};
27
+ const openapiPath = path.resolve(directoryPath, constants.YAML_SCHEMA_PATH);
28
+ if (!await fs__default["default"].pathExists(openapiPath)) {
29
+ if (skipMissingYamlFile) {
30
+ return;
31
+ }
32
+ throw new Error(`Could not find a file at ${openapiPath}.`);
33
+ }
34
+ const openapiFileContent = await fs__default["default"].readFile(openapiPath, "utf8");
35
+ const document = new spectralCore.Document(openapiFileContent, spectralParsers.Yaml, openapiPath);
36
+ const spectral = new spectralCore.Spectral();
37
+ const backstageRuleset = new spectralCore.Ruleset(
38
+ {
39
+ extends: [spectralRulesets.oas, ruleset__default["default"]],
40
+ overrides: [
41
+ {
42
+ files: ["*"],
43
+ rules: {
44
+ "api-health": "off",
45
+ "api-home": "off",
46
+ "api-home-get": "off",
47
+ "operation-tags": "off",
48
+ "hosts-https-only-oas3": "off",
49
+ "no-unknown-error-format": "off"
50
+ }
51
+ }
52
+ ]
53
+ },
54
+ { source: openapiPath }
55
+ );
56
+ spectral.setRuleset(backstageRuleset);
57
+ const result = await spectral.run(document);
58
+ const errors = result.filter((e) => e.severity === types.DiagnosticSeverity.Error);
59
+ const numberOfErrors = strict && result.length || errors.length;
60
+ if (numberOfErrors > 0) {
61
+ console.error(
62
+ spectralFormatters.pretty(result, {
63
+ // Used to fulfill the types, but not used for prettier output.
64
+ failSeverity: types.DiagnosticSeverity.Error
65
+ })
66
+ );
67
+ throw new Error(`${numberOfErrors} error(s) found when linting your spec.`);
68
+ }
69
+ }
70
+ async function bulkCommand(paths = [], options) {
71
+ const resultsList = await constants.runner(
72
+ paths,
73
+ (dir) => lint(dir, { skipMissingYamlFile: true, strict: !!options.strict })
74
+ );
75
+ let failed = false;
76
+ for (const { relativeDir, resultText } of resultsList) {
77
+ if (resultText) {
78
+ console.log();
79
+ console.log(
80
+ chalk__default["default"].red(`OpenAPI yaml file linting failed in ${relativeDir}:`)
81
+ );
82
+ console.log(resultText.trimStart());
83
+ failed = true;
84
+ }
85
+ }
86
+ if (failed) {
87
+ process.exit(1);
88
+ } else {
89
+ console.log(chalk__default["default"].green("Linted all files."));
90
+ }
91
+ }
92
+
93
+ exports.bulkCommand = bulkCommand;
94
+ //# sourceMappingURL=lint-d126add4.cjs.js.map
package/dist/index.cjs.js CHANGED
@@ -46,6 +46,10 @@ function registerSchemaCommand(program) {
46
46
  openApiCommand.command("generate [paths...]").description(
47
47
  "Generates a Typescript file from an OpenAPI yaml spec. For use with the `@backstage/backend-openapi-utils` ApiRouter type."
48
48
  ).action(lazy(() => Promise.resolve().then(function () { return require('./cjs/generate-6f0190dd.cjs.js'); }).then((m) => m.bulkCommand)));
49
+ openApiCommand.command("lint [paths...]").description("Lint OpenAPI schemas.").option(
50
+ "--strict",
51
+ "Fail on any linting severity messages, not just errors."
52
+ ).action(lazy(() => Promise.resolve().then(function () { return require('./cjs/lint-d126add4.cjs.js'); }).then((m) => m.bulkCommand)));
49
53
  }
50
54
  function registerCommands(program) {
51
55
  program.command("api-reports [paths...]").option("--ci", "CI run checks that there is no changes on API reports").option("--tsc", "executes the tsc compilation before extracting the APIs").option("--docs", "generates the api documentation").option(
@@ -90,7 +94,7 @@ function lazy(getActionFunc) {
90
94
  };
91
95
  }
92
96
 
93
- var version = "0.3.0";
97
+ var version = "0.3.1";
94
98
 
95
99
  const main = (argv) => {
96
100
  commander.program.name("backstage-repo-tools").version(version);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@backstage/repo-tools",
3
3
  "description": "CLI for Backstage repo tooling ",
4
- "version": "0.3.0",
4
+ "version": "0.3.1",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -31,12 +31,20 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@apidevtools/swagger-parser": "^10.1.0",
34
+ "@apisyouwonthate/style-guide": "^1.4.0",
34
35
  "@backstage/cli-common": "^0.1.12",
35
- "@backstage/cli-node": "^0.1.0",
36
- "@backstage/errors": "^1.1.5",
36
+ "@backstage/cli-node": "^0.1.1",
37
+ "@backstage/errors": "^1.2.0",
37
38
  "@manypkg/get-packages": "^1.1.3",
38
39
  "@microsoft/api-documenter": "^7.19.27",
39
40
  "@microsoft/api-extractor": "^7.33.7",
41
+ "@stoplight/spectral-core": "^1.18.0",
42
+ "@stoplight/spectral-formatters": "^1.1.0",
43
+ "@stoplight/spectral-functions": "^1.7.2",
44
+ "@stoplight/spectral-parsers": "^1.0.2",
45
+ "@stoplight/spectral-rulesets": "^1.16.0",
46
+ "@stoplight/spectral-runtime": "^1.1.2",
47
+ "@stoplight/types": "^13.14.0",
40
48
  "chalk": "^4.0.0",
41
49
  "commander": "^9.1.0",
42
50
  "fs-extra": "10.1.0",
@@ -49,8 +57,8 @@
49
57
  "ts-node": "^10.0.0"
50
58
  },
51
59
  "devDependencies": {
52
- "@backstage/cli": "^0.22.7",
53
- "@backstage/types": "^1.0.2",
60
+ "@backstage/cli": "^0.22.8",
61
+ "@backstage/types": "^1.1.0",
54
62
  "@types/is-glob": "^4.0.2",
55
63
  "@types/mock-fs": "^4.13.0",
56
64
  "@types/node": "^16.11.26",