@backstage/cli 0.35.4 → 0.36.0-next.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.
Files changed (108) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/config/jest.js +2 -2
  3. package/dist/index.cjs.js +1 -0
  4. package/dist/modules/build/commands/package/build/command.cjs.js +7 -7
  5. package/dist/modules/build/commands/package/clean.cjs.js +21 -0
  6. package/dist/modules/build/commands/package/postpack.cjs.js +15 -0
  7. package/dist/modules/build/commands/package/prepack.cjs.js +29 -0
  8. package/dist/modules/build/commands/package/start/command.cjs.js +3 -3
  9. package/dist/modules/build/commands/package/start/startBackend.cjs.js +2 -2
  10. package/dist/modules/build/commands/package/start/startFrontend.cjs.js +4 -5
  11. package/dist/modules/build/commands/repo/build.cjs.js +7 -8
  12. package/dist/modules/{maintenance → build}/commands/repo/clean.cjs.js +10 -7
  13. package/dist/modules/build/commands/repo/start.cjs.js +3 -3
  14. package/dist/modules/build/index.cjs.js +37 -4
  15. package/dist/modules/build/lib/buildBackend.cjs.js +0 -2
  16. package/dist/modules/build/lib/buildFrontend.cjs.js +3 -6
  17. package/dist/modules/build/lib/builder/config.cjs.js +5 -5
  18. package/dist/modules/build/lib/builder/packager.cjs.js +7 -8
  19. package/dist/modules/build/lib/bundler/config.cjs.js +2 -3
  20. package/dist/modules/build/lib/bundler/hasReactDomClient.cjs.js +2 -2
  21. package/dist/modules/build/lib/bundler/linkWorkspaces.cjs.js +2 -2
  22. package/dist/modules/build/lib/bundler/moduleFederation.cjs.js +3 -3
  23. package/dist/modules/build/lib/bundler/packageDetection.cjs.js +2 -2
  24. package/dist/modules/build/lib/bundler/paths.cjs.js +8 -6
  25. package/dist/modules/build/lib/bundler/server.cjs.js +11 -11
  26. package/dist/modules/build/lib/config.cjs.js +94 -0
  27. package/dist/{lib → modules/build/lib}/optionsParser.cjs.js +2 -2
  28. package/dist/modules/build/lib/packager/createDistWorkspace.cjs.js +10 -10
  29. package/dist/modules/build/lib/packager/productionPack.cjs.js +2 -2
  30. package/dist/{lib → modules/build/lib}/role.cjs.js +2 -2
  31. package/dist/modules/build/lib/runner/runBackend.cjs.js +2 -2
  32. package/dist/{lib → modules/build/lib}/typeDistProject.cjs.js +2 -2
  33. package/dist/modules/config/commands/docs.cjs.js +18 -2
  34. package/dist/modules/config/commands/print.cjs.js +38 -11
  35. package/dist/modules/config/commands/schema.cjs.js +22 -4
  36. package/dist/modules/config/commands/validate.cjs.js +37 -7
  37. package/dist/modules/config/index.cjs.js +6 -65
  38. package/dist/modules/config/lib/config.cjs.js +10 -26
  39. package/dist/modules/create-github-app/commands/create-github-app/index.cjs.js +2 -2
  40. package/dist/modules/create-github-app/index.cjs.js +1 -1
  41. package/dist/modules/info/commands/info.cjs.js +29 -11
  42. package/dist/modules/info/index.cjs.js +1 -23
  43. package/dist/modules/lint/commands/package/lint.cjs.js +4 -4
  44. package/dist/modules/lint/commands/repo/lint.cjs.js +13 -12
  45. package/dist/modules/lint/index.cjs.js +1 -1
  46. package/dist/modules/lint/lib/optionsParser.cjs.js +37 -0
  47. package/dist/modules/maintenance/commands/repo/fix.cjs.js +8 -11
  48. package/dist/modules/maintenance/commands/repo/list-deprecations.cjs.js +4 -4
  49. package/dist/modules/maintenance/index.cjs.js +1 -45
  50. package/dist/modules/migrate/commands/packageExports.cjs.js +9 -11
  51. package/dist/modules/migrate/commands/packageLintConfigs.cjs.js +7 -3
  52. package/dist/modules/migrate/commands/packageRole.cjs.js +5 -3
  53. package/dist/modules/migrate/commands/packageScripts.cjs.js +11 -7
  54. package/dist/modules/migrate/commands/reactRouterDeps.cjs.js +7 -3
  55. package/dist/modules/migrate/commands/versions/bump.cjs.js +15 -18
  56. package/dist/modules/migrate/index.cjs.js +11 -31
  57. package/dist/modules/new/index.cjs.js +1 -1
  58. package/dist/modules/new/lib/codeowners/codeowners.cjs.js +2 -2
  59. package/dist/modules/new/lib/execution/PortableTemplater.cjs.js +6 -11
  60. package/dist/modules/new/lib/execution/installNewPackage.cjs.js +4 -4
  61. package/dist/modules/new/lib/execution/writeTemplateContents.cjs.js +1 -2
  62. package/dist/modules/new/lib/preparation/collectPortableTemplateInput.cjs.js +2 -2
  63. package/dist/modules/new/lib/preparation/loadPortableTemplate.cjs.js +8 -8
  64. package/dist/modules/new/lib/preparation/loadPortableTemplateConfig.cjs.js +18 -18
  65. package/dist/{lib → modules/new/lib}/version.cjs.js +22 -33
  66. package/dist/modules/test/commands/package/test.cjs.js +1 -5
  67. package/dist/modules/test/commands/repo/test.cjs.js +9 -9
  68. package/dist/modules/test/index.cjs.js +4 -2
  69. package/dist/modules/translations/commands/export.cjs.js +127 -0
  70. package/dist/modules/translations/commands/import.cjs.js +164 -0
  71. package/dist/modules/translations/index.cjs.js +24 -0
  72. package/dist/modules/translations/lib/discoverPackages.cjs.js +121 -0
  73. package/dist/modules/translations/lib/extractTranslations.cjs.js +71 -0
  74. package/dist/modules/translations/lib/messageFilePath.cjs.js +43 -0
  75. package/dist/packages/backend-defaults/package.json.cjs.js +1 -1
  76. package/dist/packages/backend-plugin-api/package.json.cjs.js +1 -1
  77. package/dist/packages/backend-test-utils/package.json.cjs.js +1 -1
  78. package/dist/packages/catalog-client/package.json.cjs.js +1 -1
  79. package/dist/packages/cli/package.json.cjs.js +6 -8
  80. package/dist/packages/core-app-api/package.json.cjs.js +1 -1
  81. package/dist/packages/core-components/package.json.cjs.js +1 -1
  82. package/dist/packages/core-plugin-api/package.json.cjs.js +1 -1
  83. package/dist/packages/dev-utils/package.json.cjs.js +1 -1
  84. package/dist/packages/frontend-defaults/package.json.cjs.js +1 -1
  85. package/dist/packages/frontend-plugin-api/package.json.cjs.js +1 -1
  86. package/dist/packages/frontend-test-utils/package.json.cjs.js +1 -1
  87. package/dist/packages/test-utils/package.json.cjs.js +1 -1
  88. package/dist/plugins/auth-backend/package.json.cjs.js +1 -1
  89. package/dist/plugins/auth-backend-module-guest-provider/package.json.cjs.js +1 -1
  90. package/dist/plugins/catalog-node/package.json.cjs.js +1 -1
  91. package/dist/plugins/scaffolder-node/package.json.cjs.js +1 -1
  92. package/dist/plugins/scaffolder-node-test-utils/package.json.cjs.js +1 -1
  93. package/dist/wiring/CliInitializer.cjs.js +12 -5
  94. package/dist/wiring/version.cjs.js +20 -0
  95. package/package.json +34 -36
  96. package/dist/lib/cache/SuccessCache.cjs.js +0 -79
  97. package/dist/lib/parallel.cjs.js +0 -141
  98. package/dist/lib/paths.cjs.js +0 -8
  99. package/dist/lib/versioning/Lockfile.cjs.js +0 -89
  100. package/dist/lib/yarnPlugin.cjs.js +0 -46
  101. package/dist/modules/maintenance/commands/package/clean.cjs.js +0 -19
  102. package/dist/modules/maintenance/commands/package/pack.cjs.js +0 -29
  103. /package/dist/{lib → modules/build/lib}/entryPoints.cjs.js +0 -0
  104. /package/dist/modules/{maintenance → build}/lib/publishing.cjs.js +0 -0
  105. /package/dist/{lib → modules/migrate/lib}/versioning/packages.cjs.js +0 -0
  106. /package/dist/{lib → modules/migrate/lib}/versioning/yarn.cjs.js +0 -0
  107. /package/dist/{lib → wiring}/errors.cjs.js +0 -0
  108. /package/dist/{lib → wiring}/lazy.cjs.js +0 -0
@@ -1,34 +1,31 @@
1
1
  'use strict';
2
2
 
3
- var fs = require('fs-extra');
4
3
  var semver = require('semver');
5
- var paths = require('./paths.cjs.js');
6
- var _package$k = require('../packages/backend-plugin-api/package.json.cjs.js');
7
- var _package$j = require('../packages/backend-test-utils/package.json.cjs.js');
8
- var _package$i = require('../packages/catalog-client/package.json.cjs.js');
9
- var _package$h = require('../packages/cli/package.json.cjs.js');
10
- var _package$g = require('../packages/config/package.json.cjs.js');
11
- var _package$f = require('../packages/core-app-api/package.json.cjs.js');
12
- var _package$e = require('../packages/core-components/package.json.cjs.js');
13
- var _package$d = require('../packages/core-plugin-api/package.json.cjs.js');
14
- var _package$c = require('../packages/dev-utils/package.json.cjs.js');
15
- var _package$b = require('../packages/errors/package.json.cjs.js');
16
- var _package$a = require('../packages/frontend-defaults/package.json.cjs.js');
17
- var _package$9 = require('../packages/frontend-plugin-api/package.json.cjs.js');
18
- var _package$8 = require('../packages/frontend-test-utils/package.json.cjs.js');
19
- var _package$7 = require('../packages/test-utils/package.json.cjs.js');
20
- var _package$4 = require('../plugins/scaffolder-node/package.json.cjs.js');
21
- var _package$3 = require('../plugins/scaffolder-node-test-utils/package.json.cjs.js');
22
- var _package$2 = require('../plugins/auth-backend/package.json.cjs.js');
23
- var _package$1 = require('../plugins/auth-backend-module-guest-provider/package.json.cjs.js');
24
- var _package = require('../plugins/catalog-node/package.json.cjs.js');
25
- var _package$6 = require('../packages/theme/package.json.cjs.js');
26
- var _package$5 = require('../packages/types/package.json.cjs.js');
27
- var _package$l = require('../packages/backend-defaults/package.json.cjs.js');
4
+ var _package$k = require('../../../packages/backend-plugin-api/package.json.cjs.js');
5
+ var _package$j = require('../../../packages/backend-test-utils/package.json.cjs.js');
6
+ var _package$i = require('../../../packages/catalog-client/package.json.cjs.js');
7
+ var _package$h = require('../../../packages/cli/package.json.cjs.js');
8
+ var _package$g = require('../../../packages/config/package.json.cjs.js');
9
+ var _package$f = require('../../../packages/core-app-api/package.json.cjs.js');
10
+ var _package$e = require('../../../packages/core-components/package.json.cjs.js');
11
+ var _package$d = require('../../../packages/core-plugin-api/package.json.cjs.js');
12
+ var _package$c = require('../../../packages/dev-utils/package.json.cjs.js');
13
+ var _package$b = require('../../../packages/errors/package.json.cjs.js');
14
+ var _package$a = require('../../../packages/frontend-defaults/package.json.cjs.js');
15
+ var _package$9 = require('../../../packages/frontend-plugin-api/package.json.cjs.js');
16
+ var _package$8 = require('../../../packages/frontend-test-utils/package.json.cjs.js');
17
+ var _package$7 = require('../../../packages/test-utils/package.json.cjs.js');
18
+ var _package$4 = require('../../../plugins/scaffolder-node/package.json.cjs.js');
19
+ var _package$3 = require('../../../plugins/scaffolder-node-test-utils/package.json.cjs.js');
20
+ var _package$2 = require('../../../plugins/auth-backend/package.json.cjs.js');
21
+ var _package$1 = require('../../../plugins/auth-backend-module-guest-provider/package.json.cjs.js');
22
+ var _package = require('../../../plugins/catalog-node/package.json.cjs.js');
23
+ var _package$6 = require('../../../packages/theme/package.json.cjs.js');
24
+ var _package$5 = require('../../../packages/types/package.json.cjs.js');
25
+ var _package$l = require('../../../packages/backend-defaults/package.json.cjs.js');
28
26
 
29
27
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
30
28
 
31
- var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
32
29
  var semver__default = /*#__PURE__*/_interopDefaultCompat(semver);
33
30
 
34
31
  const packageVersions = {
@@ -55,12 +52,6 @@ const packageVersions = {
55
52
  "@backstage/plugin-auth-backend-module-guest-provider": _package$1.version,
56
53
  "@backstage/plugin-catalog-node": _package.version
57
54
  };
58
- function findVersion() {
59
- const pkgContent = fs__default.default.readFileSync(paths.paths.resolveOwn("package.json"), "utf8");
60
- return JSON.parse(pkgContent).version;
61
- }
62
- const version = findVersion();
63
- fs__default.default.pathExistsSync(paths.paths.resolveOwn("src"));
64
55
  function createPackageVersionProvider(lockfile, options) {
65
56
  return (name, versionHint) => {
66
57
  const packageVersion = packageVersions[name];
@@ -96,7 +87,5 @@ function createPackageVersionProvider(lockfile, options) {
96
87
  }
97
88
 
98
89
  exports.createPackageVersionProvider = createPackageVersionProvider;
99
- exports.findVersion = findVersion;
100
90
  exports.packageVersions = packageVersions;
101
- exports.version = version;
102
91
  //# sourceMappingURL=version.cjs.js.map
@@ -2,7 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var paths = require('../../../../lib/paths.cjs.js');
6
5
  var cliCommon = require('@backstage/cli-common');
7
6
 
8
7
  function includesAnyOf(hayStack, ...needles) {
@@ -21,7 +20,7 @@ var test = async (_opts, cmd) => {
21
20
  const allArgs = parent.args;
22
21
  const args = allArgs.slice(allArgs.indexOf("test") + 1);
23
22
  if (!includesAnyOf(args, "-c", "--config")) {
24
- args.push("--config", paths.paths.resolveOwn("config/jest.js"));
23
+ args.push("--config", cliCommon.findOwnPaths(__dirname).resolve("config/jest.js"));
25
24
  }
26
25
  if (!includesAnyOf(args, "--no-passWithNoTests", "--passWithNoTests=false")) {
27
26
  args.push("--passWithNoTests");
@@ -46,9 +45,6 @@ var test = async (_opts, cmd) => {
46
45
  if (!process.env.NODE_OPTIONS?.includes("--node-snapshot")) {
47
46
  process.env.NODE_OPTIONS = `${process.env.NODE_OPTIONS ? `${process.env.NODE_OPTIONS} ` : ""}--no-node-snapshot`;
48
47
  }
49
- if (args.includes("--help")) {
50
- process.stdout._handle.setBlocking(true);
51
- }
52
48
  try {
53
49
  require.resolve("jest");
54
50
  } catch {
@@ -6,9 +6,7 @@ var yargs = require('yargs');
6
6
  var jestCli = require('jest-cli');
7
7
  var path = require('node:path');
8
8
  var cliNode = require('@backstage/cli-node');
9
- var paths = require('../../../../lib/paths.cjs.js');
10
9
  var cliCommon = require('@backstage/cli-common');
11
- var SuccessCache = require('../../../../lib/cache/SuccessCache.cjs.js');
12
10
 
13
11
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
14
12
 
@@ -19,7 +17,7 @@ var yargs__default = /*#__PURE__*/_interopDefaultCompat(yargs);
19
17
  async function readPackageTreeHashes(graph) {
20
18
  const pkgs = Array.from(graph.values()).map((pkg) => ({
21
19
  ...pkg,
22
- path: path.relative(paths.paths.targetRoot, pkg.dir)
20
+ path: path.relative(cliCommon.targetPaths.rootDir, pkg.dir)
23
21
  }));
24
22
  const output = await cliCommon.runOutput([
25
23
  "git",
@@ -100,7 +98,7 @@ async function command(opts, cmd) {
100
98
  const hasFlags = createFlagFinder(args);
101
99
  const { _: parsedArgs } = await yargs__default.default(args).options(jestCli.yargsOptions).argv;
102
100
  if (!hasFlags("-c", "--config")) {
103
- args.push("--config", paths.paths.resolveOwn("config/jest.js"));
101
+ args.push("--config", cliCommon.findOwnPaths(__dirname).resolve("config/jest.js"));
104
102
  }
105
103
  if (!hasFlags("--passWithNoTests")) {
106
104
  args.push("--passWithNoTests");
@@ -185,7 +183,6 @@ async function command(opts, cmd) {
185
183
  if (args.includes("--jest-help")) {
186
184
  removeOptionArg(args, "--jest-help");
187
185
  args.push("--help");
188
- process.stdout._handle.setBlocking(true);
189
186
  }
190
187
  if (opts.successCache) {
191
188
  removeOptionArg(args, "--successCache", 1);
@@ -202,7 +199,10 @@ async function command(opts, cmd) {
202
199
  `The --successCache flag can not be combined with the --shard flag`
203
200
  );
204
201
  }
205
- const cache = new SuccessCache.SuccessCache("test", opts.successCacheDir);
202
+ const cache = cliNode.SuccessCache.create({
203
+ name: "test",
204
+ basePath: opts.successCacheDir
205
+ });
206
206
  const graph = await getPackageGraph();
207
207
  const projectHashes = /* @__PURE__ */ new Map();
208
208
  const outputSuccessCache = new Array();
@@ -211,7 +211,7 @@ async function command(opts, cmd) {
211
211
  async filterConfigs(projectConfigs, globalRootConfig) {
212
212
  const cacheEntries = await cache.read();
213
213
  const lockfile = await cliNode.Lockfile.load(
214
- paths.paths.resolveTargetRoot("yarn.lock")
214
+ cliCommon.targetPaths.resolveRoot("yarn.lock")
215
215
  );
216
216
  const getPackageTreeHash = await readPackageTreeHashes(graph);
217
217
  const baseHash = crypto__default.default.createHash("sha1");
@@ -220,7 +220,7 @@ async function command(opts, cmd) {
220
220
  baseHash.update(process.version);
221
221
  baseHash.update("\0");
222
222
  baseHash.update(
223
- SuccessCache.SuccessCache.trimPaths(JSON.stringify(globalRootConfig))
223
+ cliNode.SuccessCache.trimPaths(JSON.stringify(globalRootConfig))
224
224
  );
225
225
  const baseSha = baseHash.digest("hex");
226
226
  return projectConfigs.filter((project) => {
@@ -239,7 +239,7 @@ async function command(opts, cmd) {
239
239
  const depHash = getPackageTreeHash(depPkg.name);
240
240
  hash.update(`${depName}:${depHash}`);
241
241
  }
242
- hash.update(SuccessCache.SuccessCache.trimPaths(JSON.stringify(project)));
242
+ hash.update(cliNode.SuccessCache.trimPaths(JSON.stringify(project)));
243
243
  hash.update(lockfile.getDependencyTreeHash(packageName));
244
244
  const sha = hash.digest("hex");
245
245
  projectHashes.set(packageName, sha);
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var factory = require('../../wiring/factory.cjs.js');
6
6
  var commander = require('commander');
7
- var lazy = require('../../lib/lazy.cjs.js');
7
+ var lazy = require('../../wiring/lazy.cjs.js');
8
8
 
9
9
  var index = factory.createCliPlugin({
10
10
  pluginId: "test",
@@ -15,6 +15,7 @@ var index = factory.createCliPlugin({
15
15
  execute: async ({ args }) => {
16
16
  const command = new commander.Command();
17
17
  command.allowUnknownOption(true);
18
+ command.allowExcessArguments(true);
18
19
  command.option(
19
20
  "--since <ref>",
20
21
  "Only test packages that changed since the specified ref"
@@ -38,7 +39,8 @@ var index = factory.createCliPlugin({
38
39
  execute: async ({ args }) => {
39
40
  const command = new commander.Command();
40
41
  command.allowUnknownOption(true);
41
- command.helpOption(", --backstage-cli-help");
42
+ command.allowExcessArguments(true);
43
+ command.helpOption("--backstage-cli-help");
42
44
  command.action(
43
45
  lazy.lazy(() => import('./commands/package/test.cjs.js'), "default")
44
46
  );
@@ -0,0 +1,127 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var cleye = require('cleye');
6
+ var cliCommon = require('@backstage/cli-common');
7
+ var fs = require('fs-extra');
8
+ var path = require('node:path');
9
+ var discoverPackages = require('../lib/discoverPackages.cjs.js');
10
+ var extractTranslations = require('../lib/extractTranslations.cjs.js');
11
+ var messageFilePath = require('../lib/messageFilePath.cjs.js');
12
+
13
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
14
+
15
+ var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
16
+
17
+ var _export = async ({ args, info }) => {
18
+ const {
19
+ flags: { output, pattern }
20
+ } = cleye.cli(
21
+ {
22
+ help: info,
23
+ flags: {
24
+ output: {
25
+ type: String,
26
+ default: "translations",
27
+ description: "Output directory for exported messages and manifest"
28
+ },
29
+ pattern: {
30
+ type: String,
31
+ default: messageFilePath.DEFAULT_MESSAGE_PATTERN,
32
+ description: "File path pattern for message files, with {id} and {lang} placeholders"
33
+ }
34
+ }
35
+ },
36
+ void 0,
37
+ args
38
+ );
39
+ const options = { output, pattern };
40
+ messageFilePath.validatePattern(options.pattern);
41
+ const targetPackageJson = await discoverPackages.readTargetPackage(
42
+ cliCommon.targetPaths.dir,
43
+ cliCommon.targetPaths.rootDir
44
+ );
45
+ const outputDir = path.resolve(cliCommon.targetPaths.dir, options.output);
46
+ const manifestPath = path.resolve(outputDir, "manifest.json");
47
+ const tsconfigPath = cliCommon.targetPaths.resolveRoot("tsconfig.json");
48
+ if (!await fs__default.default.pathExists(tsconfigPath)) {
49
+ throw new Error(
50
+ `No tsconfig.json found at ${tsconfigPath}. The translations export command requires a tsconfig.json in the repo root.`
51
+ );
52
+ }
53
+ console.log(
54
+ `Discovering frontend dependencies of ${targetPackageJson.name}...`
55
+ );
56
+ const packages = await discoverPackages.discoverFrontendPackages(
57
+ targetPackageJson,
58
+ cliCommon.targetPaths.dir
59
+ );
60
+ console.log(`Found ${packages.length} frontend packages to scan`);
61
+ console.log("Creating TypeScript project...");
62
+ const project = extractTranslations.createTranslationProject(tsconfigPath);
63
+ const allRefs = [];
64
+ for (const pkg of packages) {
65
+ for (const [exportPath, filePath] of pkg.entryPoints) {
66
+ try {
67
+ const sourceFile = project.addSourceFileAtPath(filePath);
68
+ const refs = extractTranslations.extractTranslationRefsFromSourceFile(
69
+ sourceFile,
70
+ pkg.name,
71
+ exportPath
72
+ );
73
+ allRefs.push(...refs);
74
+ } catch (error) {
75
+ console.warn(
76
+ ` Warning: failed to process ${pkg.name} (${exportPath}): ${error}`
77
+ );
78
+ }
79
+ }
80
+ }
81
+ if (allRefs.length === 0) {
82
+ console.log("No translation refs found.");
83
+ return;
84
+ }
85
+ console.log(`Found ${allRefs.length} translation ref(s):`);
86
+ for (const ref of allRefs) {
87
+ const messageCount = Object.keys(ref.messages).length;
88
+ console.log(` ${ref.id} (${ref.packageName}, ${messageCount} messages)`);
89
+ }
90
+ for (const ref of allRefs) {
91
+ const relPath = messageFilePath.formatMessagePath(
92
+ options.pattern,
93
+ ref.id,
94
+ messageFilePath.DEFAULT_LANGUAGE
95
+ );
96
+ const filePath = path.resolve(outputDir, relPath);
97
+ await fs__default.default.ensureDir(path.dirname(filePath));
98
+ await fs__default.default.writeJson(filePath, ref.messages, { spaces: 2 });
99
+ }
100
+ const manifest = {};
101
+ for (const ref of allRefs) {
102
+ manifest[ref.id] = {
103
+ package: ref.packageName,
104
+ exportPath: ref.exportPath,
105
+ exportName: ref.exportName
106
+ };
107
+ }
108
+ await fs__default.default.writeJson(
109
+ manifestPath,
110
+ { pattern: options.pattern, refs: manifest },
111
+ { spaces: 2 }
112
+ );
113
+ const examplePath = messageFilePath.formatMessagePath(
114
+ options.pattern,
115
+ "<ref-id>",
116
+ messageFilePath.DEFAULT_LANGUAGE
117
+ );
118
+ console.log(
119
+ `
120
+ Exported ${allRefs.length} translation ref(s) to ${options.output}/`
121
+ );
122
+ console.log(` Messages: ${options.output}/${examplePath}`);
123
+ console.log(` Manifest: ${options.output}/manifest.json`);
124
+ };
125
+
126
+ exports.default = _export;
127
+ //# sourceMappingURL=export.cjs.js.map
@@ -0,0 +1,164 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var cleye = require('cleye');
6
+ var cliCommon = require('@backstage/cli-common');
7
+ var fs = require('fs-extra');
8
+ var path = require('node:path');
9
+ var discoverPackages = require('../lib/discoverPackages.cjs.js');
10
+ var messageFilePath = require('../lib/messageFilePath.cjs.js');
11
+
12
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
13
+
14
+ var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
15
+
16
+ var _import = async ({ args, info }) => {
17
+ const {
18
+ flags: { input, output }
19
+ } = cleye.cli(
20
+ {
21
+ help: info,
22
+ flags: {
23
+ input: {
24
+ type: String,
25
+ default: "translations",
26
+ description: "Input directory containing the manifest and translated message files"
27
+ },
28
+ output: {
29
+ type: String,
30
+ default: "src/translations/resources.ts",
31
+ description: "Output path for the generated wiring module"
32
+ }
33
+ }
34
+ },
35
+ void 0,
36
+ args
37
+ );
38
+ const options = { input, output };
39
+ await discoverPackages.readTargetPackage(cliCommon.targetPaths.dir, cliCommon.targetPaths.rootDir);
40
+ const inputDir = path.resolve(cliCommon.targetPaths.dir, options.input);
41
+ const manifestPath = path.resolve(inputDir, "manifest.json");
42
+ const outputPath = path.resolve(cliCommon.targetPaths.dir, options.output);
43
+ if (!await fs__default.default.pathExists(manifestPath)) {
44
+ throw new Error(
45
+ `No manifest.json found at ${manifestPath}. Run "backstage-cli translations export" first.`
46
+ );
47
+ }
48
+ const manifest = await fs__default.default.readJson(manifestPath);
49
+ if (!manifest.pattern) {
50
+ throw new Error(
51
+ 'No pattern found in manifest.json. Re-run "backstage-cli translations export" to regenerate it.'
52
+ );
53
+ }
54
+ const pattern = manifest.pattern;
55
+ const parsePath = messageFilePath.createMessagePathParser(pattern);
56
+ const allFiles = (await collectJsonFiles(inputDir)).filter(
57
+ (f) => f !== "manifest.json"
58
+ );
59
+ const translationsByRef = /* @__PURE__ */ new Map();
60
+ let skipped = 0;
61
+ for (const relPath of allFiles) {
62
+ const parsed = parsePath(relPath);
63
+ if (!parsed) {
64
+ skipped++;
65
+ continue;
66
+ }
67
+ if (parsed.lang === messageFilePath.DEFAULT_LANGUAGE) {
68
+ continue;
69
+ }
70
+ if (!manifest.refs[parsed.id]) {
71
+ console.warn(
72
+ ` Warning: skipping ${relPath} - ref '${parsed.id}' not found in manifest`
73
+ );
74
+ continue;
75
+ }
76
+ const existing = translationsByRef.get(parsed.id) ?? [];
77
+ existing.push({ lang: parsed.lang, relPath });
78
+ translationsByRef.set(parsed.id, existing);
79
+ }
80
+ if (skipped > 0) {
81
+ console.warn(
82
+ ` Warning: ${skipped} file(s) did not match the pattern '${pattern}'`
83
+ );
84
+ }
85
+ if (translationsByRef.size === 0) {
86
+ console.log("No translated message files found.");
87
+ const example = messageFilePath.formatMessagePath(pattern, "<ref-id>", "sv");
88
+ console.log(
89
+ `Add translated files as ${example} in the translations directory.`
90
+ );
91
+ return;
92
+ }
93
+ const importLines = [];
94
+ const resourceLines = [];
95
+ importLines.push(
96
+ "import { createTranslationResource } from '@backstage/frontend-plugin-api';"
97
+ );
98
+ for (const [refId, entries] of [...translationsByRef.entries()].sort(
99
+ ([a], [b]) => a.localeCompare(b)
100
+ )) {
101
+ const refEntry = manifest.refs[refId];
102
+ const importPath = refEntry.exportPath === "." ? refEntry.package : `${refEntry.package}/${refEntry.exportPath.replace(/^\.\//, "")}`;
103
+ importLines.push(`import { ${refEntry.exportName} } from '${importPath}';`);
104
+ const translationEntries = entries.sort((a, b) => a.lang.localeCompare(b.lang)).map(({ lang, relPath }) => {
105
+ const jsonRelPath = path.relative(
106
+ path.resolve(outputPath, ".."),
107
+ path.resolve(inputDir, relPath)
108
+ ).split(path.sep).join("/");
109
+ return ` ${JSON.stringify(lang)}: () => import('./${jsonRelPath}'),`;
110
+ }).join("\n");
111
+ resourceLines.push(
112
+ [
113
+ ` createTranslationResource({`,
114
+ ` ref: ${refEntry.exportName},`,
115
+ ` translations: {`,
116
+ translationEntries,
117
+ ` },`,
118
+ ` }),`
119
+ ].join("\n")
120
+ );
121
+ }
122
+ const fileContent = [
123
+ "// This file is auto-generated by backstage-cli translations import",
124
+ "// Do not edit manually.",
125
+ "",
126
+ ...importLines,
127
+ "",
128
+ "export default [",
129
+ ...resourceLines,
130
+ "];",
131
+ ""
132
+ ].join("\n");
133
+ await fs__default.default.ensureDir(path.resolve(outputPath, ".."));
134
+ await fs__default.default.writeFile(outputPath, fileContent, "utf8");
135
+ const totalFiles = [...translationsByRef.values()].reduce(
136
+ (sum, e) => sum + e.length,
137
+ 0
138
+ );
139
+ console.log(`Generated translation resources at ${options.output}`);
140
+ console.log(
141
+ ` ${translationsByRef.size} ref(s), ${totalFiles} translation file(s)`
142
+ );
143
+ console.log(
144
+ "\nImport this file in your app and pass the resources to your translation API setup."
145
+ );
146
+ };
147
+ async function collectJsonFiles(dir, prefix = "") {
148
+ const entries = await fs__default.default.readdir(dir, { withFileTypes: true });
149
+ const results = [];
150
+ for (const entry of entries) {
151
+ const relPath = prefix ? `${prefix}/${entry.name}` : entry.name;
152
+ if (entry.isDirectory()) {
153
+ results.push(
154
+ ...await collectJsonFiles(path.resolve(dir, entry.name), relPath)
155
+ );
156
+ } else if (entry.isFile() && entry.name.endsWith(".json")) {
157
+ results.push(relPath);
158
+ }
159
+ }
160
+ return results;
161
+ }
162
+
163
+ exports.default = _import;
164
+ //# sourceMappingURL=import.cjs.js.map
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var factory = require('../../wiring/factory.cjs.js');
6
+
7
+ var index = factory.createCliPlugin({
8
+ pluginId: "translations",
9
+ init: async (reg) => {
10
+ reg.addCommand({
11
+ path: ["translations", "export"],
12
+ description: "Export translation messages from an app and all of its frontend plugins to JSON files",
13
+ execute: { loader: () => import('./commands/export.cjs.js') }
14
+ });
15
+ reg.addCommand({
16
+ path: ["translations", "import"],
17
+ description: "Generate translation resource wiring from translated JSON files",
18
+ execute: { loader: () => import('./commands/import.cjs.js') }
19
+ });
20
+ }
21
+ });
22
+
23
+ exports.default = index;
24
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1,121 @@
1
+ 'use strict';
2
+
3
+ var cliNode = require('@backstage/cli-node');
4
+ var path = require('node:path');
5
+ var fs = require('fs-extra');
6
+
7
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
8
+
9
+ var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
10
+
11
+ async function readTargetPackage(packageDir, repoRoot) {
12
+ const packageJsonPath = path.resolve(packageDir, "package.json");
13
+ if (!await fs__default.default.pathExists(packageJsonPath)) {
14
+ throw new Error(
15
+ "No package.json found in the current directory. The translations commands must be run from within a package directory."
16
+ );
17
+ }
18
+ if (path.resolve(packageDir) === path.resolve(repoRoot)) {
19
+ throw new Error(
20
+ "The translations commands must be run from within a package directory, not from the repository root. For example: cd packages/app && backstage-cli translations export"
21
+ );
22
+ }
23
+ return fs__default.default.readJson(packageJsonPath);
24
+ }
25
+ async function discoverFrontendPackages(targetPackageJson, targetDir) {
26
+ let workspaceByName;
27
+ try {
28
+ const workspacePackages = await cliNode.PackageGraph.listTargetPackages();
29
+ workspaceByName = new Map(
30
+ workspacePackages.map((p) => [p.packageJson.name, p])
31
+ );
32
+ } catch {
33
+ workspaceByName = /* @__PURE__ */ new Map();
34
+ }
35
+ const visited = /* @__PURE__ */ new Set();
36
+ const result = [];
37
+ async function visit(packageJson, pkgDir, includeDevDeps) {
38
+ const deps = {
39
+ ...packageJson.dependencies,
40
+ ...includeDevDeps ? packageJson.devDependencies ?? {} : {}
41
+ };
42
+ for (const depName of Object.keys(deps)) {
43
+ if (visited.has(depName)) {
44
+ continue;
45
+ }
46
+ visited.add(depName);
47
+ let depPkgJson;
48
+ let depDir;
49
+ let isWorkspace;
50
+ const workspacePkg = workspaceByName.get(depName);
51
+ if (workspacePkg) {
52
+ depPkgJson = workspacePkg.packageJson;
53
+ depDir = workspacePkg.dir;
54
+ isWorkspace = true;
55
+ } else {
56
+ try {
57
+ const pkgJsonPath = require.resolve(`${depName}/package.json`, {
58
+ paths: [pkgDir]
59
+ });
60
+ depPkgJson = await fs__default.default.readJson(pkgJsonPath);
61
+ depDir = path.dirname(pkgJsonPath);
62
+ isWorkspace = false;
63
+ } catch {
64
+ continue;
65
+ }
66
+ }
67
+ if (!depPkgJson.backstage) {
68
+ continue;
69
+ }
70
+ const role = depPkgJson.backstage?.role;
71
+ if (role && isFrontendRole(role)) {
72
+ const entryPoints = resolveEntryPoints(depPkgJson, depDir, isWorkspace);
73
+ if (entryPoints.size > 0) {
74
+ result.push({ name: depName, dir: depDir, entryPoints });
75
+ }
76
+ }
77
+ await visit(depPkgJson, depDir, false);
78
+ }
79
+ }
80
+ await visit(targetPackageJson, targetDir, true);
81
+ return result;
82
+ }
83
+ function resolveEntryPoints(packageJson, packageDir, isWorkspace) {
84
+ const entryPoints = /* @__PURE__ */ new Map();
85
+ const exports$1 = packageJson.exports;
86
+ if (exports$1) {
87
+ for (const [subpath, target] of Object.entries(exports$1)) {
88
+ if (subpath === "./package.json") {
89
+ continue;
90
+ }
91
+ let filePath;
92
+ if (typeof target === "string") {
93
+ filePath = target;
94
+ } else if (isWorkspace) {
95
+ filePath = target?.import ?? target?.types ?? target?.default;
96
+ } else {
97
+ filePath = target?.types ?? target?.import ?? target?.default;
98
+ }
99
+ if (typeof filePath === "string") {
100
+ entryPoints.set(subpath, path.resolve(packageDir, filePath));
101
+ }
102
+ }
103
+ } else {
104
+ const main = isWorkspace ? packageJson.main ?? packageJson.types : packageJson.types ?? packageJson.main;
105
+ if (main) {
106
+ entryPoints.set(".", path.resolve(packageDir, main));
107
+ }
108
+ }
109
+ return entryPoints;
110
+ }
111
+ function isFrontendRole(role) {
112
+ try {
113
+ return cliNode.PackageRoles.getRoleInfo(role).platform === "web";
114
+ } catch {
115
+ return false;
116
+ }
117
+ }
118
+
119
+ exports.discoverFrontendPackages = discoverFrontendPackages;
120
+ exports.readTargetPackage = readTargetPackage;
121
+ //# sourceMappingURL=discoverPackages.cjs.js.map