@backstage/cli 0.36.0-next.1 → 0.36.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.
Files changed (263) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/config/eslint-factory.js +1 -0
  3. package/config/getJestEnvironment.js +7 -29
  4. package/config/jest-environment-jsdom/index.js +9 -43
  5. package/config/jest.js +7 -401
  6. package/config/jestCacheResultProcessor.cjs +10 -6
  7. package/config/jestCachingModuleLoader.js +11 -19
  8. package/config/jestFileTransform.js +11 -28
  9. package/config/jestRejectNetworkRequests.js +10 -53
  10. package/config/jestSucraseTransform.js +10 -70
  11. package/config/jestSwcTransform.js +10 -27
  12. package/config/jestYamlTransform.js +11 -24
  13. package/config/nodeTransform.cjs +10 -70
  14. package/config/nodeTransformHooks.mjs +4 -278
  15. package/config/webpack-public-path.js +10 -14
  16. package/dist/cli-internal/src/InternalCliModule.cjs.js +11 -0
  17. package/dist/cli-internal/src/InternalCommandNode.cjs.js +25 -0
  18. package/dist/cli-internal/src/knownPluginPackages.cjs.js +40 -0
  19. package/dist/index.cjs.js +21 -10
  20. package/dist/wiring/CliInitializer.cjs.js +61 -20
  21. package/dist/wiring/CommandGraph.cjs.js +81 -23
  22. package/dist/wiring/discoverCliModules.cjs.js +44 -0
  23. package/package.json +27 -154
  24. package/dist/modules/build/commands/buildWorkspace.cjs.js +0 -24
  25. package/dist/modules/build/commands/package/build/command.cjs.js +0 -89
  26. package/dist/modules/build/commands/package/build/index.cjs.js +0 -8
  27. package/dist/modules/build/commands/package/clean.cjs.js +0 -21
  28. package/dist/modules/build/commands/package/postpack.cjs.js +0 -15
  29. package/dist/modules/build/commands/package/prepack.cjs.js +0 -29
  30. package/dist/modules/build/commands/package/start/command.cjs.js +0 -23
  31. package/dist/modules/build/commands/package/start/index.cjs.js +0 -8
  32. package/dist/modules/build/commands/package/start/resolveLinkedWorkspace.cjs.js +0 -34
  33. package/dist/modules/build/commands/package/start/startBackend.cjs.js +0 -46
  34. package/dist/modules/build/commands/package/start/startFrontend.cjs.js +0 -50
  35. package/dist/modules/build/commands/package/start/startPackage.cjs.js +0 -53
  36. package/dist/modules/build/commands/repo/build.cjs.js +0 -114
  37. package/dist/modules/build/commands/repo/clean.cjs.js +0 -41
  38. package/dist/modules/build/commands/repo/start.cjs.js +0 -150
  39. package/dist/modules/build/index.cjs.js +0 -192
  40. package/dist/modules/build/lib/buildBackend.cjs.js +0 -81
  41. package/dist/modules/build/lib/buildFrontend.cjs.js +0 -50
  42. package/dist/modules/build/lib/builder/config.cjs.js +0 -257
  43. package/dist/modules/build/lib/builder/packager.cjs.js +0 -131
  44. package/dist/modules/build/lib/builder/plugins.cjs.js +0 -125
  45. package/dist/modules/build/lib/builder/types.cjs.js +0 -10
  46. package/dist/modules/build/lib/bundler/ConfigInjectingHtmlWebpackPlugin.cjs.js +0 -43
  47. package/dist/modules/build/lib/bundler/bundle.cjs.js +0 -189
  48. package/dist/modules/build/lib/bundler/config.cjs.js +0 -308
  49. package/dist/modules/build/lib/bundler/hasReactDomClient.cjs.js +0 -17
  50. package/dist/modules/build/lib/bundler/linkWorkspaces.cjs.js +0 -34
  51. package/dist/modules/build/lib/bundler/moduleFederation.cjs.js +0 -135
  52. package/dist/modules/build/lib/bundler/optimization.cjs.js +0 -68
  53. package/dist/modules/build/lib/bundler/packageDetection.cjs.js +0 -124
  54. package/dist/modules/build/lib/bundler/paths.cjs.js +0 -62
  55. package/dist/modules/build/lib/bundler/server.cjs.js +0 -231
  56. package/dist/modules/build/lib/bundler/transforms.cjs.js +0 -145
  57. package/dist/modules/build/lib/config.cjs.js +0 -94
  58. package/dist/modules/build/lib/entryPoints.cjs.js +0 -49
  59. package/dist/modules/build/lib/ipc/IpcServer.cjs.js +0 -60
  60. package/dist/modules/build/lib/ipc/ServerDataStore.cjs.js +0 -36
  61. package/dist/modules/build/lib/optionsParser.cjs.js +0 -37
  62. package/dist/modules/build/lib/packager/createDistWorkspace.cjs.js +0 -235
  63. package/dist/modules/build/lib/packager/productionPack.cjs.js +0 -160
  64. package/dist/modules/build/lib/publishing.cjs.js +0 -40
  65. package/dist/modules/build/lib/role.cjs.js +0 -24
  66. package/dist/modules/build/lib/runner/runBackend.cjs.js +0 -136
  67. package/dist/modules/build/lib/typeDistProject.cjs.js +0 -89
  68. package/dist/modules/build/lib/urls.cjs.js +0 -13
  69. package/dist/modules/config/commands/docs.cjs.js +0 -62
  70. package/dist/modules/config/commands/print.cjs.js +0 -80
  71. package/dist/modules/config/commands/schema.cjs.js +0 -55
  72. package/dist/modules/config/commands/validate.cjs.js +0 -49
  73. package/dist/modules/config/index.cjs.js +0 -51
  74. package/dist/modules/config/lib/config.cjs.js +0 -94
  75. package/dist/modules/create-github-app/commands/create-github-app/GithubCreateAppServer.cjs.js +0 -127
  76. package/dist/modules/create-github-app/commands/create-github-app/index.cjs.js +0 -115
  77. package/dist/modules/create-github-app/index.cjs.js +0 -27
  78. package/dist/modules/info/commands/info.cjs.js +0 -181
  79. package/dist/modules/info/index.cjs.js +0 -19
  80. package/dist/modules/lint/commands/package/lint.cjs.js +0 -46
  81. package/dist/modules/lint/commands/repo/lint.cjs.js +0 -212
  82. package/dist/modules/lint/index.cjs.js +0 -82
  83. package/dist/modules/lint/lib/optionsParser.cjs.js +0 -37
  84. package/dist/modules/maintenance/commands/repo/fix.cjs.js +0 -400
  85. package/dist/modules/maintenance/commands/repo/list-deprecations.cjs.js +0 -74
  86. package/dist/modules/maintenance/index.cjs.js +0 -42
  87. package/dist/modules/migrate/commands/packageExports.cjs.js +0 -15
  88. package/dist/modules/migrate/commands/packageLintConfigs.cjs.js +0 -77
  89. package/dist/modules/migrate/commands/packageRole.cjs.js +0 -57
  90. package/dist/modules/migrate/commands/packageScripts.cjs.js +0 -87
  91. package/dist/modules/migrate/commands/reactRouterDeps.cjs.js +0 -51
  92. package/dist/modules/migrate/commands/versions/bump.cjs.js +0 -373
  93. package/dist/modules/migrate/commands/versions/migrate.cjs.js +0 -112
  94. package/dist/modules/migrate/index.cjs.js +0 -82
  95. package/dist/modules/migrate/lib/utils.cjs.js +0 -44
  96. package/dist/modules/migrate/lib/versioning/packages.cjs.js +0 -71
  97. package/dist/modules/migrate/lib/versioning/yarn.cjs.js +0 -28
  98. package/dist/modules/new/commands/new.cjs.js +0 -60
  99. package/dist/modules/new/index.cjs.js +0 -68
  100. package/dist/modules/new/lib/codeowners/codeowners.cjs.js +0 -92
  101. package/dist/modules/new/lib/createNewPackage.cjs.js +0 -32
  102. package/dist/modules/new/lib/defaultTemplates.cjs.js +0 -17
  103. package/dist/modules/new/lib/execution/PortableTemplater.cjs.js +0 -89
  104. package/dist/modules/new/lib/execution/executePortableTemplate.cjs.js +0 -66
  105. package/dist/modules/new/lib/execution/installNewPackage.cjs.js +0 -127
  106. package/dist/modules/new/lib/execution/writeTemplateContents.cjs.js +0 -116
  107. package/dist/modules/new/lib/preparation/collectPortableTemplateInput.cjs.js +0 -157
  108. package/dist/modules/new/lib/preparation/loadPortableTemplate.cjs.js +0 -81
  109. package/dist/modules/new/lib/preparation/loadPortableTemplateConfig.cjs.js +0 -132
  110. package/dist/modules/new/lib/preparation/resolvePackageParams.cjs.js +0 -40
  111. package/dist/modules/new/lib/preparation/selectTemplateInteractively.cjs.js +0 -38
  112. package/dist/modules/new/lib/tasks.cjs.js +0 -51
  113. package/dist/modules/new/lib/types.cjs.js +0 -19
  114. package/dist/modules/new/lib/version.cjs.js +0 -91
  115. package/dist/modules/test/commands/package/test.cjs.js +0 -65
  116. package/dist/modules/test/commands/repo/test.cjs.js +0 -288
  117. package/dist/modules/test/index.cjs.js +0 -54
  118. package/dist/modules/translations/commands/export.cjs.js +0 -127
  119. package/dist/modules/translations/commands/import.cjs.js +0 -164
  120. package/dist/modules/translations/index.cjs.js +0 -24
  121. package/dist/modules/translations/lib/discoverPackages.cjs.js +0 -121
  122. package/dist/modules/translations/lib/extractTranslations.cjs.js +0 -71
  123. package/dist/modules/translations/lib/messageFilePath.cjs.js +0 -43
  124. package/dist/packages/backend-defaults/package.json.cjs.js +0 -6
  125. package/dist/packages/backend-plugin-api/package.json.cjs.js +0 -6
  126. package/dist/packages/backend-test-utils/package.json.cjs.js +0 -6
  127. package/dist/packages/catalog-client/package.json.cjs.js +0 -6
  128. package/dist/packages/cli/package.json.cjs.js +0 -156
  129. package/dist/packages/config/package.json.cjs.js +0 -6
  130. package/dist/packages/core-app-api/package.json.cjs.js +0 -6
  131. package/dist/packages/core-components/package.json.cjs.js +0 -6
  132. package/dist/packages/core-plugin-api/package.json.cjs.js +0 -6
  133. package/dist/packages/dev-utils/package.json.cjs.js +0 -6
  134. package/dist/packages/errors/package.json.cjs.js +0 -6
  135. package/dist/packages/frontend-defaults/package.json.cjs.js +0 -6
  136. package/dist/packages/frontend-plugin-api/package.json.cjs.js +0 -6
  137. package/dist/packages/frontend-plugin-api/src/routing/describeParentCallSite.cjs.js +0 -26
  138. package/dist/packages/frontend-test-utils/package.json.cjs.js +0 -6
  139. package/dist/packages/test-utils/package.json.cjs.js +0 -6
  140. package/dist/packages/theme/package.json.cjs.js +0 -6
  141. package/dist/packages/types/package.json.cjs.js +0 -6
  142. package/dist/plugins/auth-backend/package.json.cjs.js +0 -6
  143. package/dist/plugins/auth-backend-module-guest-provider/package.json.cjs.js +0 -6
  144. package/dist/plugins/catalog-node/package.json.cjs.js +0 -6
  145. package/dist/plugins/scaffolder-node/package.json.cjs.js +0 -6
  146. package/dist/plugins/scaffolder-node-test-utils/package.json.cjs.js +0 -6
  147. package/dist/wiring/CommandRegistry.cjs.js +0 -14
  148. package/dist/wiring/factory.cjs.js +0 -15
  149. package/dist/wiring/lazy.cjs.js +0 -22
  150. package/dist/wiring/types.cjs.js +0 -11
  151. package/templates/backend-plugin/.eslintrc.js.hbs +0 -1
  152. package/templates/backend-plugin/README.md.hbs +0 -28
  153. package/templates/backend-plugin/dev/index.ts.hbs +0 -60
  154. package/templates/backend-plugin/package.json.hbs +0 -44
  155. package/templates/backend-plugin/portable-template.yaml +0 -5
  156. package/templates/backend-plugin/src/index.ts.hbs +0 -1
  157. package/templates/backend-plugin/src/plugin.test.ts.hbs +0 -129
  158. package/templates/backend-plugin/src/plugin.ts.hbs +0 -32
  159. package/templates/backend-plugin/src/router.test.ts +0 -67
  160. package/templates/backend-plugin/src/router.ts +0 -51
  161. package/templates/backend-plugin/src/services/TodoListService.ts +0 -155
  162. package/templates/backend-plugin/src/setupTests.ts +0 -1
  163. package/templates/backend-plugin-module/.eslintrc.js.hbs +0 -1
  164. package/templates/backend-plugin-module/README.md.hbs +0 -5
  165. package/templates/backend-plugin-module/package.json.hbs +0 -34
  166. package/templates/backend-plugin-module/portable-template.yaml +0 -5
  167. package/templates/backend-plugin-module/src/index.ts.hbs +0 -8
  168. package/templates/backend-plugin-module/src/module.ts.hbs +0 -17
  169. package/templates/catalog-provider-module/.eslintrc.js.hbs +0 -1
  170. package/templates/catalog-provider-module/README.md.hbs +0 -5
  171. package/templates/catalog-provider-module/config.d.ts.hbs +0 -34
  172. package/templates/catalog-provider-module/package.json.hbs +0 -36
  173. package/templates/catalog-provider-module/portable-template.yaml +0 -9
  174. package/templates/catalog-provider-module/src/index.ts.hbs +0 -8
  175. package/templates/catalog-provider-module/src/module.ts.hbs +0 -29
  176. package/templates/catalog-provider-module/src/provider/readProviderConfigs.ts.hbs +0 -78
  177. package/templates/catalog-provider-module/src/provider/{{providerClass}}.test.ts.hbs +0 -18
  178. package/templates/catalog-provider-module/src/provider/{{providerClass}}.ts.hbs +0 -109
  179. package/templates/frontend-plugin/.eslintrc.js.hbs +0 -1
  180. package/templates/frontend-plugin/README.md.hbs +0 -13
  181. package/templates/frontend-plugin/dev/index.tsx.hbs +0 -11
  182. package/templates/frontend-plugin/package.json.hbs +0 -54
  183. package/templates/frontend-plugin/portable-template.yaml +0 -6
  184. package/templates/frontend-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs +0 -28
  185. package/templates/frontend-plugin/src/components/ExampleComponent/ExampleComponent.tsx.hbs +0 -37
  186. package/templates/frontend-plugin/src/components/ExampleComponent/index.ts +0 -1
  187. package/templates/frontend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs +0 -19
  188. package/templates/frontend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs +0 -308
  189. package/templates/frontend-plugin/src/components/ExampleFetchComponent/index.ts +0 -1
  190. package/templates/frontend-plugin/src/index.ts.hbs +0 -1
  191. package/templates/frontend-plugin/src/plugin.test.ts.hbs +0 -7
  192. package/templates/frontend-plugin/src/plugin.ts.hbs +0 -22
  193. package/templates/frontend-plugin/src/routes.ts.hbs +0 -5
  194. package/templates/frontend-plugin/src/setupTests.ts +0 -1
  195. package/templates/new-frontend-plugin/.eslintrc.js.hbs +0 -1
  196. package/templates/new-frontend-plugin/README.md.hbs +0 -20
  197. package/templates/new-frontend-plugin/dev/index.tsx +0 -10
  198. package/templates/new-frontend-plugin/package.json.hbs +0 -49
  199. package/templates/new-frontend-plugin/portable-template.yaml +0 -5
  200. package/templates/new-frontend-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs +0 -28
  201. package/templates/new-frontend-plugin/src/components/ExampleComponent/ExampleComponent.tsx.hbs +0 -37
  202. package/templates/new-frontend-plugin/src/components/ExampleComponent/index.ts +0 -1
  203. package/templates/new-frontend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs +0 -19
  204. package/templates/new-frontend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs +0 -308
  205. package/templates/new-frontend-plugin/src/components/ExampleFetchComponent/index.ts +0 -1
  206. package/templates/new-frontend-plugin/src/index.ts.hbs +0 -1
  207. package/templates/new-frontend-plugin/src/plugin.test.ts.hbs +0 -7
  208. package/templates/new-frontend-plugin/src/plugin.tsx.hbs +0 -25
  209. package/templates/new-frontend-plugin/src/routes.ts +0 -3
  210. package/templates/new-frontend-plugin/src/setupTests.ts +0 -1
  211. package/templates/new-frontend-plugin-module/.eslintrc.js.hbs +0 -1
  212. package/templates/new-frontend-plugin-module/README.md.hbs +0 -5
  213. package/templates/new-frontend-plugin-module/package.json.hbs +0 -35
  214. package/templates/new-frontend-plugin-module/portable-template.yaml +0 -5
  215. package/templates/new-frontend-plugin-module/src/index.ts.hbs +0 -1
  216. package/templates/new-frontend-plugin-module/src/module.tsx.hbs +0 -8
  217. package/templates/new-frontend-plugin-module/src/setupTests.ts +0 -1
  218. package/templates/node-library/.eslintrc.js.hbs +0 -1
  219. package/templates/node-library/README.md.hbs +0 -12
  220. package/templates/node-library/package.json.hbs +0 -29
  221. package/templates/node-library/portable-template.yaml +0 -3
  222. package/templates/node-library/src/index.ts.hbs +0 -1
  223. package/templates/node-library/src/setupTests.ts +0 -1
  224. package/templates/plugin-common-library/.eslintrc.js.hbs +0 -1
  225. package/templates/plugin-common-library/README.md.hbs +0 -5
  226. package/templates/plugin-common-library/package.json.hbs +0 -31
  227. package/templates/plugin-common-library/portable-template.yaml +0 -3
  228. package/templates/plugin-common-library/src/index.ts.hbs +0 -19
  229. package/templates/plugin-common-library/src/setupTests.ts +0 -1
  230. package/templates/plugin-node-library/.eslintrc.js.hbs +0 -1
  231. package/templates/plugin-node-library/README.md.hbs +0 -5
  232. package/templates/plugin-node-library/package.json.hbs +0 -30
  233. package/templates/plugin-node-library/portable-template.yaml +0 -3
  234. package/templates/plugin-node-library/src/index.ts.hbs +0 -18
  235. package/templates/plugin-node-library/src/setupTests.ts +0 -1
  236. package/templates/plugin-web-library/.eslintrc.js.hbs +0 -1
  237. package/templates/plugin-web-library/README.md.hbs +0 -5
  238. package/templates/plugin-web-library/package.json.hbs +0 -42
  239. package/templates/plugin-web-library/portable-template.yaml +0 -3
  240. package/templates/plugin-web-library/src/components/ExampleComponent/ExampleComponent.test.tsx +0 -17
  241. package/templates/plugin-web-library/src/components/ExampleComponent/ExampleComponent.tsx +0 -28
  242. package/templates/plugin-web-library/src/components/ExampleComponent/index.ts +0 -2
  243. package/templates/plugin-web-library/src/components/index.ts +0 -5
  244. package/templates/plugin-web-library/src/hooks/index.ts +0 -5
  245. package/templates/plugin-web-library/src/hooks/useExample/index.ts +0 -1
  246. package/templates/plugin-web-library/src/hooks/useExample/useExample.ts +0 -15
  247. package/templates/plugin-web-library/src/index.ts.hbs +0 -12
  248. package/templates/plugin-web-library/src/setupTests.ts +0 -1
  249. package/templates/scaffolder-backend-module/.eslintrc.js.hbs +0 -1
  250. package/templates/scaffolder-backend-module/README.md.hbs +0 -5
  251. package/templates/scaffolder-backend-module/package.json.hbs +0 -36
  252. package/templates/scaffolder-backend-module/portable-template.yaml +0 -6
  253. package/templates/scaffolder-backend-module/src/actions/example.test.ts +0 -24
  254. package/templates/scaffolder-backend-module/src/actions/example.ts +0 -39
  255. package/templates/scaffolder-backend-module/src/index.ts.hbs +0 -8
  256. package/templates/scaffolder-backend-module/src/module.ts +0 -21
  257. package/templates/web-library/.eslintrc.js.hbs +0 -1
  258. package/templates/web-library/README.md.hbs +0 -12
  259. package/templates/web-library/package.json.hbs +0 -30
  260. package/templates/web-library/portable-template.yaml +0 -3
  261. package/templates/web-library/src/index.ts.hbs +0 -1
  262. package/templates/web-library/src/setupTests.ts +0 -1
  263. /package/dist/{packages/opaque-internal → opaque-internal}/src/OpaqueType.cjs.js +0 -0
@@ -1,127 +0,0 @@
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
@@ -1,164 +0,0 @@
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
@@ -1,24 +0,0 @@
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
@@ -1,121 +0,0 @@
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
@@ -1,71 +0,0 @@
1
- 'use strict';
2
-
3
- var tsMorph = require('ts-morph');
4
-
5
- function extractTranslationRefsFromSourceFile(sourceFile, packageName, exportPath) {
6
- const results = [];
7
- for (const exportSymbol of sourceFile.getExportSymbols()) {
8
- const declarations = exportSymbol.getDeclarations();
9
- if (declarations.length === 0) {
10
- continue;
11
- }
12
- const declaration = declarations[0];
13
- const exportType = declaration.getType();
14
- const refInfo = extractTranslationRefFromType(exportType, declaration);
15
- if (!refInfo) {
16
- continue;
17
- }
18
- results.push({
19
- ...refInfo,
20
- packageName,
21
- exportPath,
22
- exportName: exportSymbol.getName()
23
- });
24
- }
25
- return results;
26
- }
27
- function extractTranslationRefFromType(type, declaration) {
28
- const resolvedType = type.getTargetType() ?? type;
29
- const $$typeProperty = resolvedType.getProperties().find((p) => p.getName() === "$$type");
30
- if (!$$typeProperty) {
31
- return void 0;
32
- }
33
- const $$typeDecl = $$typeProperty.getValueDeclaration();
34
- if (!$$typeDecl) {
35
- return void 0;
36
- }
37
- if (!$$typeDecl.getText().includes("'@backstage/TranslationRef'")) {
38
- return void 0;
39
- }
40
- const typeArgs = type.getTypeArguments();
41
- if (typeArgs.length < 2) {
42
- return void 0;
43
- }
44
- const [idType, messagesType] = typeArgs;
45
- if (!idType.isStringLiteral()) {
46
- return void 0;
47
- }
48
- const id = idType.getLiteralValueOrThrow();
49
- const messages = {};
50
- for (const messageProp of messagesType.getProperties()) {
51
- const key = messageProp.getName();
52
- const propType = messageProp.getTypeAtLocation(declaration);
53
- if (propType.isStringLiteral()) {
54
- messages[key] = propType.getLiteralValueOrThrow();
55
- }
56
- }
57
- if (Object.keys(messages).length === 0) {
58
- return void 0;
59
- }
60
- return { id, messages };
61
- }
62
- function createTranslationProject(tsconfigPath) {
63
- return new tsMorph.Project({
64
- tsConfigFilePath: tsconfigPath,
65
- skipAddingFilesFromTsConfig: true
66
- });
67
- }
68
-
69
- exports.createTranslationProject = createTranslationProject;
70
- exports.extractTranslationRefsFromSourceFile = extractTranslationRefsFromSourceFile;
71
- //# sourceMappingURL=extractTranslations.cjs.js.map
@@ -1,43 +0,0 @@
1
- 'use strict';
2
-
3
- const DEFAULT_LANGUAGE = "en";
4
- const DEFAULT_MESSAGE_PATTERN = "messages/{id}.{lang}.json";
5
- function formatMessagePath(pattern, id, lang) {
6
- return pattern.replace(/\{id\}/g, id).replace(/\{lang\}/g, lang);
7
- }
8
- function createMessagePathParser(pattern) {
9
- validatePattern(pattern);
10
- const escaped = pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\\{id\\}/g, "(?<id>[^/]+)").replace(/\\{lang\\}/g, "(?<lang>[a-z]{2})");
11
- const regex = new RegExp(`^${escaped}$`);
12
- return (relPath) => {
13
- const match = relPath.match(regex);
14
- if (!match?.groups) {
15
- return void 0;
16
- }
17
- return { id: match.groups.id, lang: match.groups.lang };
18
- };
19
- }
20
- function validatePattern(pattern) {
21
- if (!pattern.includes("{id}")) {
22
- throw new Error(
23
- `Invalid message file pattern: must contain {id} placeholder. Got: ${pattern}`
24
- );
25
- }
26
- if (!pattern.includes("{lang}")) {
27
- throw new Error(
28
- `Invalid message file pattern: must contain {lang} placeholder. Got: ${pattern}`
29
- );
30
- }
31
- if (!pattern.endsWith(".json")) {
32
- throw new Error(
33
- `Invalid message file pattern: must end with .json. Got: ${pattern}`
34
- );
35
- }
36
- }
37
-
38
- exports.DEFAULT_LANGUAGE = DEFAULT_LANGUAGE;
39
- exports.DEFAULT_MESSAGE_PATTERN = DEFAULT_MESSAGE_PATTERN;
40
- exports.createMessagePathParser = createMessagePathParser;
41
- exports.formatMessagePath = formatMessagePath;
42
- exports.validatePattern = validatePattern;
43
- //# sourceMappingURL=messageFilePath.cjs.js.map
@@ -1,6 +0,0 @@
1
- 'use strict';
2
-
3
- var version = "0.16.0-next.1";
4
-
5
- exports.version = version;
6
- //# sourceMappingURL=package.json.cjs.js.map
@@ -1,6 +0,0 @@
1
- 'use strict';
2
-
3
- var version = "1.7.1-next.0";
4
-
5
- exports.version = version;
6
- //# sourceMappingURL=package.json.cjs.js.map
@@ -1,6 +0,0 @@
1
- 'use strict';
2
-
3
- var version = "1.11.1-next.1";
4
-
5
- exports.version = version;
6
- //# sourceMappingURL=package.json.cjs.js.map
@@ -1,6 +0,0 @@
1
- 'use strict';
2
-
3
- var version = "1.14.0-next.1";
4
-
5
- exports.version = version;
6
- //# sourceMappingURL=package.json.cjs.js.map