@backstage/repo-tools 0.4.0 → 0.5.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @backstage/repo-tools
2
2
 
3
+ ## 0.5.0-next.0
4
+
5
+ ### Minor Changes
6
+
7
+ - aea8f8d329: **BREAKING**: API Reports generated for sub-path exports now place the name as a suffix rather than prefix, for example `api-report-alpha.md` instead of `alpha-api-report.md`. When upgrading to this version you'll need to re-create any such API reports and delete the old ones.
8
+ - 38340678c3: Adds a new command `schema openapi generate-client` that creates a Typescript client with Backstage flavor, including the discovery API and fetch API. This command doesn't currently generate a complete client and needs to be wrapped or exported manually by a separate Backstage plugin. See `@backstage/catalog-client/src/generated` for example output.
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+ - @backstage/catalog-model@1.4.3
14
+ - @backstage/cli-common@0.1.13
15
+ - @backstage/cli-node@0.2.0
16
+ - @backstage/errors@1.2.3
17
+
3
18
  ## 0.4.0
4
19
 
5
20
  ### Minor Changes
@@ -263,8 +263,8 @@ async function runApiExtraction({
263
263
  "./dist-types",
264
264
  packageDir
265
265
  );
266
- const prefix = name === "index" ? "" : `${name}-`;
267
- const reportFileName = `${prefix}api-report.md`;
266
+ const suffix = name === "index" ? "" : `-${name}`;
267
+ const reportFileName = `api-report${suffix}.md`;
268
268
  const reportPath = path.resolve(projectFolder, reportFileName);
269
269
  const warningCountBefore = await countApiReportWarnings(reportPath);
270
270
  const extractorConfig = apiExtractor.ExtractorConfig.prepare({
@@ -280,7 +280,7 @@ async function runApiExtraction({
280
280
  reportFolder: projectFolder,
281
281
  reportTempFolder: path.resolve(
282
282
  outputDir,
283
- `${prefix}<unscopedPackageName>`
283
+ `<unscopedPackageName>${suffix}`
284
284
  )
285
285
  },
286
286
  docModel: {
@@ -289,7 +289,7 @@ async function runApiExtraction({
289
289
  enabled: name === "index",
290
290
  apiJsonFilePath: path.resolve(
291
291
  outputDir,
292
- `${prefix}<unscopedPackageName>.api.json`
292
+ `<unscopedPackageName>${suffix}.api.json`
293
293
  )
294
294
  },
295
295
  dtsRollup: {
@@ -1150,4 +1150,4 @@ function parseArrayOption(value) {
1150
1150
  }
1151
1151
 
1152
1152
  exports.buildApiReports = buildApiReports;
1153
- //# sourceMappingURL=api-reports-2b0ee2bf.cjs.js.map
1153
+ //# sourceMappingURL=api-reports-0697bd2a.cjs.js.map
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ const YAML_SCHEMA_PATH = "src/schema/openapi.yaml";
4
+ const TS_MODULE = "src/schema/openapi.generated";
5
+ const TS_SCHEMA_PATH = `${TS_MODULE}.ts`;
6
+ const OUTPUT_PATH = "src/generated";
7
+ const OPENAPI_IGNORE_FILES = [
8
+ // Get rid of the default files.
9
+ "*.md",
10
+ // The rest of these have to be explicit, otherwise they get added if this was a *.*
11
+ "apis/baseapi.ts",
12
+ "apis/exception.ts",
13
+ "auth/*",
14
+ "http/*",
15
+ "middleware.ts",
16
+ "servers.ts",
17
+ "util.ts",
18
+ "configuration.ts",
19
+ "rxjsStub.ts",
20
+ ".gitignore",
21
+ // Override the created version.
22
+ "apis/*.ts",
23
+ "!apis/*.client.ts",
24
+ "models/*.ts",
25
+ "!models/*.model.ts",
26
+ // Always include index.ts files.
27
+ "!index.ts",
28
+ "!**/index.ts",
29
+ // Weird API typings.
30
+ "types/ObjectParamAPI.ts",
31
+ "types/ObservableAPI.ts",
32
+ "types/PromiseAPI.ts",
33
+ "git_push.sh",
34
+ "package.json",
35
+ "tsconfig.json"
36
+ ];
37
+
38
+ exports.OPENAPI_IGNORE_FILES = OPENAPI_IGNORE_FILES;
39
+ exports.OUTPUT_PATH = OUTPUT_PATH;
40
+ exports.TS_MODULE = TS_MODULE;
41
+ exports.TS_SCHEMA_PATH = TS_SCHEMA_PATH;
42
+ exports.YAML_SCHEMA_PATH = YAML_SCHEMA_PATH;
43
+ //# sourceMappingURL=constants-866c449d.cjs.js.map
@@ -5,7 +5,8 @@ var YAML = require('js-yaml');
5
5
  var chalk = require('chalk');
6
6
  var path = require('path');
7
7
  var paths = require('./paths-9ab9b8a8.cjs.js');
8
- var constants = require('./constants-f7b16ffc.cjs.js');
8
+ var runner = require('./runner-0e5fc9a8.cjs.js');
9
+ var constants = require('./constants-866c449d.cjs.js');
9
10
  var util = require('util');
10
11
  var child_process = require('child_process');
11
12
  require('@backstage/cli-common');
@@ -52,7 +53,7 @@ export const createOpenApiRouter = async (
52
53
  }
53
54
  }
54
55
  async function bulkCommand(paths = []) {
55
- const resultsList = await constants.runner(
56
+ const resultsList = await runner.runner(
56
57
  paths,
57
58
  (dir) => generate(dir, { skipMissingYamlFile: true })
58
59
  );
@@ -77,4 +78,4 @@ async function bulkCommand(paths = []) {
77
78
  }
78
79
 
79
80
  exports.bulkCommand = bulkCommand;
80
- //# sourceMappingURL=generate-f300e17f.cjs.js.map
81
+ //# sourceMappingURL=generate-4d90ec26.cjs.js.map
@@ -0,0 +1,83 @@
1
+ 'use strict';
2
+
3
+ var chalk = require('chalk');
4
+ var path = require('path');
5
+ var constants = require('./constants-866c449d.cjs.js');
6
+ var paths = require('./paths-9ab9b8a8.cjs.js');
7
+ var fs = require('fs-extra');
8
+ var exec = require('./exec-7bf444eb.cjs.js');
9
+ require('@backstage/cli-common');
10
+ require('@backstage/cli-node');
11
+ require('minimatch');
12
+ require('util');
13
+ require('child_process');
14
+
15
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
+
17
+ var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
18
+ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
19
+
20
+ async function generate(spec, outputDirectory) {
21
+ const resolvedOpenapiPath = path.resolve(spec);
22
+ const resolvedOutputDirectory = path.resolve(outputDirectory, constants.OUTPUT_PATH);
23
+ fs.mkdirpSync(resolvedOutputDirectory);
24
+ await fs__default["default"].mkdirp(resolvedOutputDirectory);
25
+ await fs__default["default"].writeFile(
26
+ path.resolve(resolvedOutputDirectory, ".openapi-generator-ignore"),
27
+ constants.OPENAPI_IGNORE_FILES.join("\n")
28
+ );
29
+ await exec.exec(
30
+ // The actual main.js file for the binary isn't executable but yarn does _something_ to make it executable.
31
+ // TODO (sennyeya@): Make this use the actual binary
32
+ `yarn openapi-generator-cli`,
33
+ [
34
+ "generate",
35
+ "-i",
36
+ resolvedOpenapiPath,
37
+ "-o",
38
+ resolvedOutputDirectory,
39
+ "-g",
40
+ "typescript",
41
+ "-c",
42
+ "templates/typescript-backstage.yaml",
43
+ "--generator-key",
44
+ "v3.0"
45
+ ],
46
+ {
47
+ maxBuffer: Number.MAX_VALUE,
48
+ cwd: paths.paths.ownDir,
49
+ env: {
50
+ ...process.env
51
+ // PWD: outputDirectory,
52
+ }
53
+ }
54
+ );
55
+ await exec.exec(
56
+ `yarn backstage-cli package lint --fix ${resolvedOutputDirectory}`
57
+ );
58
+ if (paths.paths.resolveTargetRoot("node_modules/.bin/prettier")) {
59
+ await exec.exec(`yarn prettier --write ${resolvedOutputDirectory}`);
60
+ }
61
+ fs__default["default"].removeSync(path.resolve(resolvedOutputDirectory, ".openapi-generator-ignore"));
62
+ fs__default["default"].rmSync(path.resolve(resolvedOutputDirectory, ".openapi-generator"), {
63
+ recursive: true,
64
+ force: true
65
+ });
66
+ }
67
+ async function singleCommand({
68
+ inputSpec,
69
+ outputDirectory
70
+ }) {
71
+ try {
72
+ await generate(inputSpec, outputDirectory);
73
+ console.log(chalk__default["default"].green(`Generated client for ${inputSpec}`));
74
+ } catch (err) {
75
+ console.log();
76
+ console.log(chalk__default["default"].red(`Client generation failed in ${outputDirectory}:`));
77
+ console.log(err);
78
+ process.exit(1);
79
+ }
80
+ }
81
+
82
+ exports.singleCommand = singleCommand;
83
+ //# sourceMappingURL=generate-be7745a5.cjs.js.map
@@ -3,7 +3,8 @@
3
3
  var fs = require('fs-extra');
4
4
  var path = require('path');
5
5
  var chalk = require('chalk');
6
- var constants = require('./constants-f7b16ffc.cjs.js');
6
+ var runner = require('./runner-0e5fc9a8.cjs.js');
7
+ var constants = require('./constants-866c449d.cjs.js');
7
8
  var paths = require('./paths-9ab9b8a8.cjs.js');
8
9
  var exec = require('./exec-7bf444eb.cjs.js');
9
10
  require('p-limit');
@@ -63,7 +64,7 @@ async function test(directoryPath, { port }, options) {
63
64
  }
64
65
  }
65
66
  async function bulkCommand(paths = [], options) {
66
- const resultsList = await constants.runner(
67
+ const resultsList = await runner.runner(
67
68
  paths,
68
69
  (dir, runnerOptions) => test(dir, runnerOptions, options),
69
70
  {
@@ -92,4 +93,4 @@ async function bulkCommand(paths = [], options) {
92
93
  }
93
94
 
94
95
  exports.bulkCommand = bulkCommand;
95
- //# sourceMappingURL=index-80206881.cjs.js.map
96
+ //# sourceMappingURL=index-ed4aaab1.cjs.js.map
@@ -2,15 +2,16 @@
2
2
 
3
3
  var fs = require('fs-extra');
4
4
  var path = require('path');
5
- var constants = require('./constants-f7b16ffc.cjs.js');
5
+ var constants = require('./constants-866c449d.cjs.js');
6
6
  var paths = require('./paths-9ab9b8a8.cjs.js');
7
+ var runner = require('./runner-0e5fc9a8.cjs.js');
7
8
  var chalk = require('chalk');
8
9
  var exec = require('./exec-7bf444eb.cjs.js');
9
- require('p-limit');
10
- require('portfinder');
11
10
  require('@backstage/cli-common');
12
11
  require('@backstage/cli-node');
13
12
  require('minimatch');
13
+ require('p-limit');
14
+ require('portfinder');
14
15
  require('util');
15
16
  require('child_process');
16
17
 
@@ -60,7 +61,7 @@ capture:
60
61
  }
61
62
  }
62
63
  async function initCommand(paths = []) {
63
- const resultsList = await constants.runner(paths, (dir) => init(dir), {
64
+ const resultsList = await runner.runner(paths, (dir) => init(dir), {
64
65
  concurrencyLimit: 5
65
66
  });
66
67
  let failed = false;
@@ -82,4 +83,4 @@ async function initCommand(paths = []) {
82
83
  }
83
84
 
84
85
  exports["default"] = initCommand;
85
- //# sourceMappingURL=init-1a47015e.cjs.js.map
86
+ //# sourceMappingURL=init-9d8f5e0f.cjs.js.map
@@ -6,7 +6,8 @@ var ruleset = require('@apisyouwonthate/style-guide');
6
6
  var fs = require('fs-extra');
7
7
  var chalk = require('chalk');
8
8
  var path = require('path');
9
- var constants = require('./constants-f7b16ffc.cjs.js');
9
+ var runner = require('./runner-0e5fc9a8.cjs.js');
10
+ var constants = require('./constants-866c449d.cjs.js');
10
11
  var spectralRulesets = require('@stoplight/spectral-rulesets');
11
12
  var types = require('@stoplight/types');
12
13
  var spectralFormatters = require('@stoplight/spectral-formatters');
@@ -69,7 +70,7 @@ async function lint(directoryPath, config) {
69
70
  }
70
71
  }
71
72
  async function bulkCommand(paths = [], options) {
72
- const resultsList = await constants.runner(
73
+ const resultsList = await runner.runner(
73
74
  paths,
74
75
  (dir) => lint(dir, { skipMissingYamlFile: true, strict: !!options.strict })
75
76
  );
@@ -92,4 +93,4 @@ async function bulkCommand(paths = [], options) {
92
93
  }
93
94
 
94
95
  exports.bulkCommand = bulkCommand;
95
- //# sourceMappingURL=lint-fa452310.cjs.js.map
96
+ //# sourceMappingURL=lint-e06bf899.cjs.js.map
@@ -45,12 +45,5 @@ async function runner(paths$1, command, options) {
45
45
  return resultsList;
46
46
  }
47
47
 
48
- const YAML_SCHEMA_PATH = "src/schema/openapi.yaml";
49
- const TS_MODULE = "src/schema/openapi.generated";
50
- const TS_SCHEMA_PATH = `${TS_MODULE}.ts`;
51
-
52
- exports.TS_MODULE = TS_MODULE;
53
- exports.TS_SCHEMA_PATH = TS_SCHEMA_PATH;
54
- exports.YAML_SCHEMA_PATH = YAML_SCHEMA_PATH;
55
48
  exports.runner = runner;
56
- //# sourceMappingURL=constants-f7b16ffc.cjs.js.map
49
+ //# sourceMappingURL=runner-0e5fc9a8.cjs.js.map
@@ -6,8 +6,9 @@ var lodash = require('lodash');
6
6
  var path = require('path');
7
7
  var chalk = require('chalk');
8
8
  var Parser = require('@apidevtools/swagger-parser');
9
- var constants = require('./constants-f7b16ffc.cjs.js');
9
+ var runner = require('./runner-0e5fc9a8.cjs.js');
10
10
  var paths = require('./paths-9ab9b8a8.cjs.js');
11
+ var constants = require('./constants-866c449d.cjs.js');
11
12
  require('p-limit');
12
13
  require('portfinder');
13
14
  require('@backstage/cli-common');
@@ -62,7 +63,7 @@ async function verify(directoryPath) {
62
63
  }
63
64
  }
64
65
  async function bulkCommand(paths = []) {
65
- const resultsList = await constants.runner(paths, (dir) => verify(dir));
66
+ const resultsList = await runner.runner(paths, (dir) => verify(dir));
66
67
  let failed = false;
67
68
  for (const { relativeDir, resultText } of resultsList) {
68
69
  if (resultText) {
@@ -80,4 +81,4 @@ async function bulkCommand(paths = []) {
80
81
  }
81
82
 
82
83
  exports.bulkCommand = bulkCommand;
83
- //# sourceMappingURL=verify-7bbbd05f.cjs.js.map
84
+ //# sourceMappingURL=verify-fbf86a43.cjs.js.map
package/dist/index.cjs.js CHANGED
@@ -49,16 +49,25 @@ function registerSchemaCommand(program) {
49
49
  const openApiCommand = command.command("openapi [command]").description("Tooling for OpenApi schema");
50
50
  openApiCommand.command("verify [paths...]").description(
51
51
  "Verify that all OpenAPI schemas are valid and have a matching `schemas/openapi.generated.ts` file."
52
- ).action(lazy(() => Promise.resolve().then(function () { return require('./cjs/verify-7bbbd05f.cjs.js'); }).then((m) => m.bulkCommand)));
52
+ ).action(
53
+ lazy(() => Promise.resolve().then(function () { return require('./cjs/verify-fbf86a43.cjs.js'); }).then((m) => m.bulkCommand))
54
+ );
53
55
  openApiCommand.command("generate [paths...]").description(
54
56
  "Generates a Typescript file from an OpenAPI yaml spec. For use with the `@backstage/backend-openapi-utils` ApiRouter type."
55
- ).action(lazy(() => Promise.resolve().then(function () { return require('./cjs/generate-f300e17f.cjs.js'); }).then((m) => m.bulkCommand)));
57
+ ).action(
58
+ lazy(() => Promise.resolve().then(function () { return require('./cjs/generate-4d90ec26.cjs.js'); }).then((m) => m.bulkCommand))
59
+ );
56
60
  openApiCommand.command("lint [paths...]").description("Lint OpenAPI schemas.").option(
57
61
  "--strict",
58
62
  "Fail on any linting severity messages, not just errors."
59
- ).action(lazy(() => Promise.resolve().then(function () { return require('./cjs/lint-fa452310.cjs.js'); }).then((m) => m.bulkCommand)));
60
- openApiCommand.command("test [paths...]").description("Test OpenAPI schemas against written tests").option("--update", "Update the spec on failure.").action(lazy(() => Promise.resolve().then(function () { return require('./cjs/index-80206881.cjs.js'); }).then((m) => m.bulkCommand)));
61
- openApiCommand.command("init <paths...>").description("Creates any config needed for the test command.").action(lazy(() => Promise.resolve().then(function () { return require('./cjs/init-1a47015e.cjs.js'); }).then((m) => m.default)));
63
+ ).action(lazy(() => Promise.resolve().then(function () { return require('./cjs/lint-e06bf899.cjs.js'); }).then((m) => m.bulkCommand)));
64
+ openApiCommand.command("test [paths...]").description("Test OpenAPI schemas against written tests").option("--update", "Update the spec on failure.").action(lazy(() => Promise.resolve().then(function () { return require('./cjs/index-ed4aaab1.cjs.js'); }).then((m) => m.bulkCommand)));
65
+ openApiCommand.command("init <paths...>").description("Creates any config needed for the test command.").action(lazy(() => Promise.resolve().then(function () { return require('./cjs/init-9d8f5e0f.cjs.js'); }).then((m) => m.default)));
66
+ openApiCommand.command("generate-client").requiredOption("--input-spec <file>").requiredOption("--output-directory <directory>").action(
67
+ lazy(
68
+ () => Promise.resolve().then(function () { return require('./cjs/generate-be7745a5.cjs.js'); }).then((m) => m.singleCommand)
69
+ )
70
+ );
62
71
  }
63
72
  function registerCommands(program) {
64
73
  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(
@@ -84,7 +93,7 @@ function registerCommands(program) {
84
93
  "Turn on release tag validation for the public, beta, and alpha APIs"
85
94
  ).description("Generate an API report for selected packages").action(
86
95
  lazy(
87
- () => Promise.resolve().then(function () { return require('./cjs/api-reports-2b0ee2bf.cjs.js'); }).then((m) => m.buildApiReports)
96
+ () => Promise.resolve().then(function () { return require('./cjs/api-reports-0697bd2a.cjs.js'); }).then((m) => m.buildApiReports)
88
97
  )
89
98
  );
90
99
  program.command("type-deps").description("Find inconsistencies in types of all packages and plugins").action(lazy(() => Promise.resolve().then(function () { return require('./cjs/type-deps-5eacd931.cjs.js'); }).then((m) => m.default)));
@@ -116,7 +125,7 @@ function lazy(getActionFunc) {
116
125
  };
117
126
  }
118
127
 
119
- var version = "0.4.0";
128
+ var version = "0.5.0-next.0";
120
129
 
121
130
  const main = (argv) => {
122
131
  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.4.0",
4
+ "version": "0.5.0-next.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -39,6 +39,7 @@
39
39
  "@manypkg/get-packages": "^1.1.3",
40
40
  "@microsoft/api-documenter": "^7.22.33",
41
41
  "@microsoft/api-extractor": "^7.36.4",
42
+ "@openapitools/openapi-generator-cli": "^2.7.0",
42
43
  "@stoplight/spectral-core": "^1.18.0",
43
44
  "@stoplight/spectral-formatters": "^1.1.0",
44
45
  "@stoplight/spectral-functions": "^1.7.2",
@@ -61,7 +62,7 @@
61
62
  "yaml-diff-patch": "^2.0.0"
62
63
  },
63
64
  "devDependencies": {
64
- "@backstage/cli": "^0.24.0",
65
+ "@backstage/cli": "^0.25.0-next.1",
65
66
  "@backstage/types": "^1.1.1",
66
67
  "@types/is-glob": "^4.0.2",
67
68
  "@types/mock-fs": "^4.13.0",