@backstage/cli 0.30.0-next.2 → 0.30.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 (142) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/dist/commands/index.cjs.js +3 -0
  3. package/dist/commands/new/new.cjs.js +39 -80
  4. package/dist/commands/start/command.cjs.js +26 -0
  5. package/dist/lib/bundler/config.cjs.js +1 -1
  6. package/dist/lib/new/createNewPackage.cjs.js +32 -0
  7. package/dist/lib/new/defaultTemplates.cjs.js +16 -0
  8. package/dist/lib/new/execution/PortableTemplater.cjs.js +91 -0
  9. package/dist/lib/new/execution/executePortableTemplate.cjs.js +54 -0
  10. package/dist/lib/new/execution/installNewPackage.cjs.js +127 -0
  11. package/dist/lib/new/execution/writeTemplateContents.cjs.js +111 -0
  12. package/dist/lib/new/preparation/collectPortableTemplateInput.cjs.js +157 -0
  13. package/dist/lib/new/preparation/loadPortableTemplate.cjs.js +82 -0
  14. package/dist/lib/new/preparation/loadPortableTemplateConfig.cjs.js +121 -0
  15. package/dist/lib/new/preparation/resolvePackageParams.cjs.js +40 -0
  16. package/dist/lib/new/preparation/selectTemplateInteractively.cjs.js +38 -0
  17. package/dist/lib/new/types.cjs.js +15 -4
  18. package/dist/lib/tasks.cjs.js +0 -111
  19. package/dist/packages/backend-defaults/package.json.cjs.js +1 -1
  20. package/dist/packages/backend-plugin-api/package.json.cjs.js +1 -1
  21. package/dist/packages/backend-test-utils/package.json.cjs.js +1 -1
  22. package/dist/packages/cli/package.json.cjs.js +4 -3
  23. package/dist/packages/core-app-api/package.json.cjs.js +1 -1
  24. package/dist/packages/core-components/package.json.cjs.js +1 -1
  25. package/dist/packages/core-plugin-api/package.json.cjs.js +1 -1
  26. package/dist/packages/dev-utils/package.json.cjs.js +1 -1
  27. package/dist/packages/test-utils/package.json.cjs.js +1 -1
  28. package/dist/packages/theme/package.json.cjs.js +1 -1
  29. package/dist/plugins/auth-backend/package.json.cjs.js +1 -1
  30. package/dist/plugins/auth-backend-module-guest-provider/package.json.cjs.js +1 -1
  31. package/dist/plugins/catalog-node/package.json.cjs.js +1 -1
  32. package/dist/plugins/scaffolder-node/package.json.cjs.js +1 -1
  33. package/dist/plugins/scaffolder-node-test-utils/package.json.cjs.js +1 -1
  34. package/package.json +30 -29
  35. package/templates/{default-backend-plugin → backend-plugin}/README.md.hbs +4 -4
  36. package/templates/{default-backend-plugin → backend-plugin}/dev/index.ts.hbs +5 -5
  37. package/templates/{default-backend-plugin → backend-plugin}/package.json.hbs +1 -9
  38. package/templates/backend-plugin/portable-template.yaml +5 -0
  39. package/templates/{default-backend-plugin → backend-plugin}/src/plugin.test.ts.hbs +5 -5
  40. package/templates/{default-backend-plugin → backend-plugin}/src/plugin.ts.hbs +1 -1
  41. package/templates/{default-backend-module → backend-plugin-module}/README.md.hbs +1 -1
  42. package/templates/{default-backend-module → backend-plugin-module}/package.json.hbs +1 -9
  43. package/templates/backend-plugin-module/portable-template.yaml +5 -0
  44. package/templates/{default-plugin → frontend-plugin}/README.md.hbs +3 -3
  45. package/templates/{default-plugin → frontend-plugin}/dev/index.tsx.hbs +1 -1
  46. package/templates/{default-plugin → frontend-plugin}/package.json.hbs +1 -9
  47. package/templates/frontend-plugin/portable-template.yaml +6 -0
  48. package/templates/{default-plugin → frontend-plugin}/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs +1 -1
  49. package/templates/{default-plugin → frontend-plugin}/src/components/ExampleComponent/ExampleComponent.tsx.hbs +1 -1
  50. package/templates/{default-plugin → frontend-plugin}/src/plugin.test.ts.hbs +1 -1
  51. package/templates/{default-plugin → frontend-plugin}/src/plugin.ts.hbs +1 -1
  52. package/templates/{default-plugin → frontend-plugin}/src/routes.ts.hbs +1 -1
  53. package/templates/{node-library-package → node-library}/README.md.hbs +2 -2
  54. package/templates/{node-library-package → node-library}/package.json.hbs +1 -9
  55. package/templates/node-library/portable-template.yaml +3 -0
  56. package/templates/plugin-common-library/README.md.hbs +5 -0
  57. package/templates/{default-common-plugin-package → plugin-common-library}/package.json.hbs +2 -10
  58. package/templates/plugin-common-library/portable-template.yaml +3 -0
  59. package/templates/{default-common-plugin-package → plugin-common-library}/src/index.ts.hbs +1 -1
  60. package/templates/plugin-node-library/README.md.hbs +5 -0
  61. package/templates/{default-node-plugin-package → plugin-node-library}/package.json.hbs +2 -10
  62. package/templates/plugin-node-library/portable-template.yaml +3 -0
  63. package/templates/{default-node-plugin-package → plugin-node-library}/src/index.ts.hbs +1 -1
  64. package/templates/plugin-web-library/README.md.hbs +5 -0
  65. package/templates/{default-react-plugin-package → plugin-web-library}/package.json.hbs +2 -10
  66. package/templates/plugin-web-library/portable-template.yaml +3 -0
  67. package/templates/{default-react-plugin-package → plugin-web-library}/src/index.ts.hbs +1 -1
  68. package/templates/scaffolder-backend-module/README.md.hbs +5 -0
  69. package/templates/{scaffolder-module → scaffolder-backend-module}/package.json.hbs +2 -10
  70. package/templates/scaffolder-backend-module/portable-template.yaml +6 -0
  71. package/templates/{scaffolder-module → scaffolder-backend-module}/src/index.ts.hbs +1 -1
  72. package/templates/{web-library-package → web-library}/README.md.hbs +2 -2
  73. package/templates/{web-library-package → web-library}/package.json.hbs +1 -9
  74. package/templates/web-library/portable-template.yaml +3 -0
  75. package/dist/lib/new/FactoryRegistry.cjs.js +0 -96
  76. package/dist/lib/new/factories/backendModule.cjs.js +0 -82
  77. package/dist/lib/new/factories/backendPlugin.cjs.js +0 -78
  78. package/dist/lib/new/factories/common/prompts.cjs.js +0 -57
  79. package/dist/lib/new/factories/common/tasks.cjs.js +0 -66
  80. package/dist/lib/new/factories/common/util.cjs.js +0 -16
  81. package/dist/lib/new/factories/frontendPlugin.cjs.js +0 -107
  82. package/dist/lib/new/factories/index.cjs.js +0 -24
  83. package/dist/lib/new/factories/nodeLibraryPackage.cjs.js +0 -57
  84. package/dist/lib/new/factories/pluginCommon.cjs.js +0 -58
  85. package/dist/lib/new/factories/pluginNode.cjs.js +0 -58
  86. package/dist/lib/new/factories/pluginWeb.cjs.js +0 -58
  87. package/dist/lib/new/factories/scaffolderModule.cjs.js +0 -90
  88. package/dist/lib/new/factories/webLibraryPackage.cjs.js +0 -57
  89. package/templates/default-backend-module/tsconfig.json +0 -9
  90. package/templates/default-backend-plugin/tsconfig.json +0 -13
  91. package/templates/default-common-plugin-package/README.md.hbs +0 -5
  92. package/templates/default-common-plugin-package/tsconfig.json +0 -9
  93. package/templates/default-node-plugin-package/README.md.hbs +0 -5
  94. package/templates/default-node-plugin-package/tsconfig.json +0 -9
  95. package/templates/default-plugin/tsconfig.json +0 -12
  96. package/templates/default-react-plugin-package/README.md.hbs +0 -5
  97. package/templates/default-react-plugin-package/tsconfig.json +0 -11
  98. package/templates/node-library-package/tsconfig.json +0 -11
  99. package/templates/scaffolder-module/README.md.hbs +0 -5
  100. package/templates/scaffolder-module/tsconfig.json +0 -9
  101. package/templates/web-library-package/tsconfig.json +0 -11
  102. /package/templates/{default-backend-plugin → backend-plugin}/.eslintrc.js.hbs +0 -0
  103. /package/templates/{default-backend-plugin → backend-plugin}/src/index.ts.hbs +0 -0
  104. /package/templates/{default-backend-plugin → backend-plugin}/src/router.test.ts +0 -0
  105. /package/templates/{default-backend-plugin → backend-plugin}/src/router.ts +0 -0
  106. /package/templates/{default-backend-plugin → backend-plugin}/src/services/TodoListService/createTodoListService.ts +0 -0
  107. /package/templates/{default-backend-plugin → backend-plugin}/src/services/TodoListService/index.ts +0 -0
  108. /package/templates/{default-backend-plugin → backend-plugin}/src/services/TodoListService/types.ts +0 -0
  109. /package/templates/{default-backend-plugin → backend-plugin}/src/setupTests.ts +0 -0
  110. /package/templates/{default-backend-module → backend-plugin-module}/.eslintrc.js.hbs +0 -0
  111. /package/templates/{default-backend-module → backend-plugin-module}/src/index.ts.hbs +0 -0
  112. /package/templates/{default-backend-module → backend-plugin-module}/src/module.ts.hbs +0 -0
  113. /package/templates/{default-common-plugin-package → frontend-plugin}/.eslintrc.js.hbs +0 -0
  114. /package/templates/{default-plugin → frontend-plugin}/src/components/ExampleComponent/index.ts +0 -0
  115. /package/templates/{default-plugin → frontend-plugin}/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs +0 -0
  116. /package/templates/{default-plugin → frontend-plugin}/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs +0 -0
  117. /package/templates/{default-plugin → frontend-plugin}/src/components/ExampleFetchComponent/index.ts +0 -0
  118. /package/templates/{default-plugin → frontend-plugin}/src/index.ts.hbs +0 -0
  119. /package/templates/{default-plugin → frontend-plugin}/src/setupTests.ts +0 -0
  120. /package/templates/{default-node-plugin-package → node-library}/.eslintrc.js.hbs +0 -0
  121. /package/templates/{node-library-package → node-library}/src/index.ts.hbs +0 -0
  122. /package/templates/{default-common-plugin-package → node-library}/src/setupTests.ts +0 -0
  123. /package/templates/{default-plugin → plugin-common-library}/.eslintrc.js.hbs +0 -0
  124. /package/templates/{default-node-plugin-package → plugin-common-library}/src/setupTests.ts +0 -0
  125. /package/templates/{default-react-plugin-package → plugin-node-library}/.eslintrc.js.hbs +0 -0
  126. /package/templates/{node-library-package → plugin-node-library}/src/setupTests.ts +0 -0
  127. /package/templates/{node-library-package → plugin-web-library}/.eslintrc.js.hbs +0 -0
  128. /package/templates/{default-react-plugin-package → plugin-web-library}/src/components/ExampleComponent/ExampleComponent.test.tsx +0 -0
  129. /package/templates/{default-react-plugin-package → plugin-web-library}/src/components/ExampleComponent/ExampleComponent.tsx +0 -0
  130. /package/templates/{default-react-plugin-package → plugin-web-library}/src/components/ExampleComponent/index.ts +0 -0
  131. /package/templates/{default-react-plugin-package → plugin-web-library}/src/components/index.ts +0 -0
  132. /package/templates/{default-react-plugin-package → plugin-web-library}/src/hooks/index.ts +0 -0
  133. /package/templates/{default-react-plugin-package → plugin-web-library}/src/hooks/useExample/index.ts +0 -0
  134. /package/templates/{default-react-plugin-package → plugin-web-library}/src/hooks/useExample/useExample.ts +0 -0
  135. /package/templates/{default-react-plugin-package → plugin-web-library}/src/setupTests.ts +0 -0
  136. /package/templates/{scaffolder-module → scaffolder-backend-module}/.eslintrc.js.hbs +0 -0
  137. /package/templates/{scaffolder-module → scaffolder-backend-module}/src/actions/example.test.ts +0 -0
  138. /package/templates/{scaffolder-module → scaffolder-backend-module}/src/actions/example.ts +0 -0
  139. /package/templates/{scaffolder-module → scaffolder-backend-module}/src/module.ts +0 -0
  140. /package/templates/{web-library-package → web-library}/.eslintrc.js.hbs +0 -0
  141. /package/templates/{web-library-package → web-library}/src/index.ts.hbs +0 -0
  142. /package/templates/{web-library-package → web-library}/src/setupTests.ts +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,96 @@
1
1
  # @backstage/cli
2
2
 
3
+ ## 0.30.0
4
+
5
+ ### Minor Changes
6
+
7
+ - cb76663: **BREAKING**: Add support for native ESM in Node.js code. This changes the behavior of dynamic import expressions in Node.js code. Typically this can be fixed by replacing `import(...)` with `require(...)`, with an `as typeof import(...)` cast if needed for types. This is because dynamic imports will no longer be transformed to `require(...)` calls, but instead be left as-is. This in turn allows you to load ESM modules from CommonJS code using `import(...)`.
8
+
9
+ This change adds support for the following in Node.js packages, across type checking, package builds, runtime transforms and Jest tests:
10
+
11
+ - Dynamic imports that load ESM modules from CommonJS code.
12
+ - Both `.mjs` and `.mts` files as explicit ESM files, as well as `.cjs` and `.cts` as explicit CommonJS files.
13
+ - Support for the `"type": "module"` field in `package.json` to indicate that the package is an ESM package.
14
+
15
+ There are a few caveats to be aware of:
16
+
17
+ - To enable support for native ESM in tests, you need to run the tests with the `--experimental-vm-modules` flag enabled, typically via `NODE_OPTIONS='--experimental-vm-modules'`.
18
+ - Declaring a package as `"type": "module"` in `package.json` is supported, but in tests it will cause all local transitive dependencies to also be treated as ESM, regardless of whether they declare `"type": "module"` or not.
19
+ - Node.js has an [ESM interoperability layer with CommonJS](https://nodejs.org/docs/latest-v22.x/api/esm.html#interoperability-with-commonjs) that allows for imports from ESM to identify named exports in CommonJS packages. This interoperability layer is **only** enabled when importing packages with a `.cts` or `.cjs` extension. This is because the interoperability layer is not fully compatible with the NPM ecosystem, and would break package if it was enabled for `.js` files.
20
+ - Dynamic imports of CommonJS packages will vary in shape depending on the runtime, i.e. test vs local development, etc. It is therefore recommended to avoid dynamic imports of CommonJS packages and instead use `require`, or to use the explicit CommonJS extensions as mentioned above. If you do need to dynamically import CommonJS packages, avoid using `default` exports, as the shape of them vary across different environments and you would otherwise need to manually unwrap the import based on the shape of the module object.
21
+
22
+ - b30e788: The `new` command is now powered by a new template system that allows you to define your own templates in a declarative way, as well as import existing templates from external sources. See the [CLI templates documentation](https://backstage.io/docs/tooling/cli/templates) for more information.
23
+
24
+ The following flags for the `new` command have been deprecated and will be removed in a future release:
25
+
26
+ - `--license=<license>`: Configure the global `license` instead.
27
+ - `--no-private`: Configure the global `private` instead.
28
+ - `--baseVersion=<version>`: Configure the global `version` instead.
29
+ - `--npmRegistry=<url>`: Configure the global `publishRegistry` instead.
30
+ - `--scope=<scope>`: Configure the global `namePrefix` and/or `namePluginInfix` instead.
31
+
32
+ As part of this change the template IDs and their options have changed. The following backwards compatibility mappings for the `--select` and `--option` flags are enabled when using the default set of templates, but they will also be removed in the future:
33
+
34
+ - `--select=plugin` is mapped to `--select=frontend-plugin` instead.
35
+ - `--option=id=<id>` is mapped to `--option=pluginId=<id>` instead.
36
+
37
+ ### Patch Changes
38
+
39
+ - f17ef61: The `versions:bump` command will now reject `*` as a pattern.
40
+ - 86c72c1: The packing process when running `build-workspace` with the `--alwaysYarnPack` flag now respects the `BACKSTAGE_CLI_BUILD_PARALLEL` environment variable, defaulting parallel work limits based on CPU availability.
41
+ - 2167afc: Treat static file assets as always being free from side effects in package builds.
42
+ - f54eed0: Fixed an issue where default feature type information wasn't being added to package.json/exports before publishing if exports didn't exist beforehand
43
+ - 90a1edf: Add check to make sure that the `--link` option for the `start` command is a valid workspace.
44
+ - 207f88f: Fixed the file path pattern of many static assets output as part of the frontend build process, where there was an extra `.` before the extension, leading to names like `image-af7946b..png`.
45
+ - 9638f6d: Only allow pass through of `.mjs` in Jest transform if static ESM is supported.
46
+ - 9d49e04: Replaced dependency `node-libs-browser` with `node-stdlib-browser`
47
+ - 2c14147: Corrected path when trying to add dependency to respective `package.json` when using `yarn new` templates
48
+ - f21b125: Ensure that both global-agent and undici agents are enabled when proxying is enabled.
49
+ - Updated dependencies
50
+ - @backstage/cli-node@0.2.13
51
+ - @backstage/config-loader@1.9.6
52
+ - @backstage/catalog-model@1.7.3
53
+ - @backstage/cli-common@0.1.15
54
+ - @backstage/config@1.3.2
55
+ - @backstage/errors@1.2.7
56
+ - @backstage/eslint-plugin@0.1.10
57
+ - @backstage/integration@1.16.1
58
+ - @backstage/release-manifests@0.0.12
59
+ - @backstage/types@1.2.1
60
+
61
+ ## 0.30.0-next.3
62
+
63
+ ### Minor Changes
64
+
65
+ - b30e788: The `new` command is now powered by a new template system that allows you to define your own templates in a declarative way, as well as import existing templates from external sources. See the [CLI templates documentation](https://backstage.io/docs/tooling/cli/templates) for more information.
66
+
67
+ The following flags for the `new` command have been deprecated and will be removed in a future release:
68
+
69
+ - `--license=<license>`: Configure the global `license` instead.
70
+ - `--no-private`: Configure the global `private` instead.
71
+ - `--baseVersion=<version>`: Configure the global `version` instead.
72
+ - `--npmRegistry=<url>`: Configure the global `publishRegistry` instead.
73
+ - `--scope=<scope>`: Configure the global `namePrefix` and/or `namePluginInfix` instead.
74
+
75
+ As part of this change the template IDs and their options have changed. The following backwards compatibility mappings for the `--select` and `--option` flags are enabled when using the default set of templates, but they will also be removed in the future:
76
+
77
+ - `--select=plugin` is mapped to `--select=frontend-plugin` instead.
78
+ - `--option=id=<id>` is mapped to `--option=pluginId=<id>` instead.
79
+
80
+ ### Patch Changes
81
+
82
+ - Updated dependencies
83
+ - @backstage/cli-node@0.2.13-next.1
84
+ - @backstage/config-loader@1.9.6-next.0
85
+ - @backstage/catalog-model@1.7.3
86
+ - @backstage/cli-common@0.1.15
87
+ - @backstage/config@1.3.2
88
+ - @backstage/errors@1.2.7
89
+ - @backstage/eslint-plugin@0.1.10
90
+ - @backstage/integration@1.16.1
91
+ - @backstage/release-manifests@0.0.12
92
+ - @backstage/types@1.2.1
93
+
3
94
  ## 0.30.0-next.2
4
95
 
5
96
  ### Patch Changes
@@ -118,6 +118,9 @@ function registerCommands(program) {
118
118
  "Pre-fill options for the creation process",
119
119
  (opt, arr) => [...arr, opt],
120
120
  []
121
+ ).option(
122
+ "--skip-install",
123
+ `Skips running 'yarn install' and 'yarn lint --fix'`
121
124
  ).option("--scope <scope>", "The scope to use for new packages").option(
122
125
  "--npm-registry <URL>",
123
126
  "The package registry to use for new packages"
@@ -2,21 +2,46 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var os = require('os');
6
- var fs = require('fs-extra');
7
- var path = require('path');
8
- var FactoryRegistry = require('../../lib/new/FactoryRegistry.cjs.js');
9
- var cliNode = require('@backstage/cli-node');
10
- var paths = require('../../lib/paths.cjs.js');
11
- var errors = require('@backstage/errors');
12
- var tasks = require('../../lib/tasks.cjs.js');
5
+ var createNewPackage = require('../../lib/new/createNewPackage.cjs.js');
13
6
 
14
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
15
-
16
- var os__default = /*#__PURE__*/_interopDefaultCompat(os);
17
- var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
18
-
19
- function parseOptions(optionStrings) {
7
+ var _new = async (opts) => {
8
+ const {
9
+ option: rawArgOptions,
10
+ select: preselectedTemplateId,
11
+ skipInstall,
12
+ scope,
13
+ private: isPrivate,
14
+ ...otherGlobals
15
+ } = opts;
16
+ const prefilledParams = parseParams(rawArgOptions);
17
+ let pluginInfix = void 0;
18
+ let packagePrefix = void 0;
19
+ if (scope) {
20
+ const backstagePrefix = scope.startsWith("backstage") ? "" : "backstage-";
21
+ packagePrefix = scope.includes("/") ? `@${scope}${backstagePrefix}` : `@${scope}/${backstagePrefix}`;
22
+ pluginInfix = scope.includes("backstage") ? "plugin-" : "backstage-plugin-";
23
+ }
24
+ if (isPrivate === false || // set to false with --no-private flag
25
+ Object.values(otherGlobals).filter(Boolean).length !== 0) {
26
+ console.warn(
27
+ `Global template configuration via CLI flags is deprecated, see https://backstage.io/docs/cli/new for information on how to configure package templating`
28
+ );
29
+ }
30
+ await createNewPackage.createNewPackage({
31
+ prefilledParams,
32
+ preselectedTemplateId,
33
+ configOverrides: {
34
+ license: otherGlobals.license,
35
+ version: otherGlobals.baseVersion,
36
+ private: isPrivate,
37
+ publishRegistry: otherGlobals.npmRegistry,
38
+ packageNamePrefix: packagePrefix,
39
+ packageNamePluginInfix: pluginInfix
40
+ },
41
+ skipInstall
42
+ });
43
+ };
44
+ function parseParams(optionStrings) {
20
45
  const options = {};
21
46
  for (const str of optionStrings) {
22
47
  const [key] = str.split("=", 1);
@@ -30,72 +55,6 @@ function parseOptions(optionStrings) {
30
55
  }
31
56
  return options;
32
57
  }
33
- var _new = async (opts) => {
34
- const factory = await FactoryRegistry.FactoryRegistry.interactiveSelect(opts.select);
35
- const providedOptions = parseOptions(opts.option);
36
- const options = await FactoryRegistry.FactoryRegistry.populateOptions(
37
- factory,
38
- providedOptions
39
- );
40
- let defaultVersion = "0.1.0";
41
- if (opts.baseVersion) {
42
- defaultVersion = opts.baseVersion;
43
- } else {
44
- const lernaVersion = await fs__default.default.readJson(paths.paths.resolveTargetRoot("lerna.json")).then((pkg) => pkg.version).catch(() => void 0);
45
- if (lernaVersion) {
46
- defaultVersion = lernaVersion;
47
- }
48
- }
49
- const tempDirs = new Array();
50
- async function createTemporaryDirectory(name) {
51
- const dir = await fs__default.default.mkdtemp(path.join(os__default.default.tmpdir(), name));
52
- tempDirs.push(dir);
53
- return dir;
54
- }
55
- const license = opts.license ?? "Apache-2.0";
56
- let modified = false;
57
- try {
58
- await factory.create(options, {
59
- isMonoRepo: await cliNode.isMonoRepo(),
60
- defaultVersion,
61
- license,
62
- scope: opts.scope?.replace(/^@/, ""),
63
- npmRegistry: opts.npmRegistry,
64
- private: Boolean(opts.private),
65
- createTemporaryDirectory,
66
- markAsModified() {
67
- modified = true;
68
- }
69
- });
70
- tasks.Task.log();
71
- tasks.Task.log(`\u{1F389} Successfully created ${factory.name}`);
72
- tasks.Task.log();
73
- } catch (error) {
74
- errors.assertError(error);
75
- tasks.Task.error(error.message);
76
- if (modified) {
77
- tasks.Task.log("It seems that something went wrong in the creation process \u{1F914}");
78
- tasks.Task.log();
79
- tasks.Task.log(
80
- "We have left the changes that were made intact in case you want to"
81
- );
82
- tasks.Task.log(
83
- "continue manually, but you can also revert the changes and try again."
84
- );
85
- tasks.Task.error(`\u{1F525} Failed to create ${factory.name}!`);
86
- }
87
- } finally {
88
- for (const dir of tempDirs) {
89
- try {
90
- await fs__default.default.remove(dir);
91
- } catch (error) {
92
- console.error(
93
- `Failed to remove temporary directory '${dir}', ${error}`
94
- );
95
- }
96
- }
97
- }
98
- };
99
58
 
100
59
  exports.default = _new;
101
60
  //# sourceMappingURL=new.cjs.js.map
@@ -1,11 +1,37 @@
1
1
  'use strict';
2
2
 
3
+ var fs = require('fs-extra');
4
+ var node_path = require('node:path');
3
5
  var role = require('../../lib/role.cjs.js');
4
6
  var startBackend = require('./startBackend.cjs.js');
5
7
  var startFrontend = require('./startFrontend.cjs.js');
8
+ var errors = require('@backstage/errors');
9
+
10
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
11
+
12
+ var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
6
13
 
7
14
  async function command(opts) {
8
15
  const role$1 = await role.findRoleFromCommand(opts);
16
+ if (opts.link) {
17
+ const dir = node_path.resolve(opts.link);
18
+ if (!fs__default.default.pathExistsSync(dir)) {
19
+ throw new Error(
20
+ `Invalid workspace link, directory does not exist: ${dir}`
21
+ );
22
+ }
23
+ const pkgJson = await fs__default.default.readJson(node_path.resolve(dir, "package.json")).catch((error) => {
24
+ throw new errors.ForwardedError(
25
+ "Failed to read package.json in linked workspace",
26
+ error
27
+ );
28
+ });
29
+ if (!pkgJson.workspaces) {
30
+ throw new Error(
31
+ `Invalid workspace link, directory is not a workspace: ${dir}`
32
+ );
33
+ }
34
+ }
9
35
  const options = {
10
36
  configPaths: opts.config,
11
37
  checksEnabled: Boolean(opts.check),
@@ -318,7 +318,7 @@ async function createConfig(paths, options) {
318
318
  extensions: [".ts", ".tsx", ".mjs", ".js", ".jsx", ".json", ".wasm"],
319
319
  mainFields: ["browser", "module", "main"],
320
320
  fallback: {
321
- ...pickBy__default.default(require("node-libs-browser")),
321
+ ...pickBy__default.default(require("node-stdlib-browser")),
322
322
  module: false,
323
323
  dgram: false,
324
324
  dns: false,
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ var collectPortableTemplateInput = require('./preparation/collectPortableTemplateInput.cjs.js');
4
+ var loadPortableTemplateConfig = require('./preparation/loadPortableTemplateConfig.cjs.js');
5
+ var selectTemplateInteractively = require('./preparation/selectTemplateInteractively.cjs.js');
6
+ var loadPortableTemplate = require('./preparation/loadPortableTemplate.cjs.js');
7
+ var executePortableTemplate = require('./execution/executePortableTemplate.cjs.js');
8
+
9
+ async function createNewPackage(options) {
10
+ const config = await loadPortableTemplateConfig.loadPortableTemplateConfig({
11
+ overrides: options.configOverrides
12
+ });
13
+ const selectedTemplate = await selectTemplateInteractively.selectTemplateInteractively(
14
+ config,
15
+ options.preselectedTemplateId
16
+ );
17
+ const template = await loadPortableTemplate.loadPortableTemplate(selectedTemplate);
18
+ const input = await collectPortableTemplateInput.collectPortableTemplateInput({
19
+ config,
20
+ template,
21
+ prefilledParams: options.prefilledParams
22
+ });
23
+ await executePortableTemplate.executePortableTemplate({
24
+ config,
25
+ template,
26
+ input,
27
+ skipInstall: options.skipInstall
28
+ });
29
+ }
30
+
31
+ exports.createNewPackage = createNewPackage;
32
+ //# sourceMappingURL=createNewPackage.cjs.js.map
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ const defaultTemplates = [
4
+ "@backstage/cli/templates/frontend-plugin",
5
+ "@backstage/cli/templates/backend-plugin",
6
+ "@backstage/cli/templates/backend-plugin-module",
7
+ "@backstage/cli/templates/plugin-web-library",
8
+ "@backstage/cli/templates/plugin-node-library",
9
+ "@backstage/cli/templates/plugin-common-library",
10
+ "@backstage/cli/templates/web-library",
11
+ "@backstage/cli/templates/node-library",
12
+ "@backstage/cli/templates/scaffolder-backend-module"
13
+ ];
14
+
15
+ exports.defaultTemplates = defaultTemplates;
16
+ //# sourceMappingURL=defaultTemplates.cjs.js.map
@@ -0,0 +1,91 @@
1
+ 'use strict';
2
+
3
+ var handlebars = require('handlebars');
4
+ var camelCase = require('lodash/camelCase');
5
+ var kebabCase = require('lodash/kebabCase');
6
+ var lowerCase = require('lodash/lowerCase');
7
+ var snakeCase = require('lodash/snakeCase');
8
+ var startCase = require('lodash/startCase');
9
+ var upperCase = require('lodash/upperCase');
10
+ var upperFirst = require('lodash/upperFirst');
11
+ var lowerFirst = require('lodash/lowerFirst');
12
+ var Lockfile = require('../../versioning/Lockfile.cjs.js');
13
+ require('minimatch');
14
+ require('@manypkg/get-packages');
15
+ require('chalk');
16
+ require('../../yarn.cjs.js');
17
+ require('../../run.cjs.js');
18
+ var paths = require('../../paths.cjs.js');
19
+ var version = require('../../version.cjs.js');
20
+
21
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
22
+
23
+ var handlebars__default = /*#__PURE__*/_interopDefaultCompat(handlebars);
24
+ var camelCase__default = /*#__PURE__*/_interopDefaultCompat(camelCase);
25
+ var kebabCase__default = /*#__PURE__*/_interopDefaultCompat(kebabCase);
26
+ var lowerCase__default = /*#__PURE__*/_interopDefaultCompat(lowerCase);
27
+ var snakeCase__default = /*#__PURE__*/_interopDefaultCompat(snakeCase);
28
+ var startCase__default = /*#__PURE__*/_interopDefaultCompat(startCase);
29
+ var upperCase__default = /*#__PURE__*/_interopDefaultCompat(upperCase);
30
+ var upperFirst__default = /*#__PURE__*/_interopDefaultCompat(upperFirst);
31
+ var lowerFirst__default = /*#__PURE__*/_interopDefaultCompat(lowerFirst);
32
+
33
+ const builtInHelpers = {
34
+ camelCase: camelCase__default.default,
35
+ kebabCase: kebabCase__default.default,
36
+ lowerCase: lowerCase__default.default,
37
+ snakeCase: snakeCase__default.default,
38
+ startCase: startCase__default.default,
39
+ upperCase: upperCase__default.default,
40
+ upperFirst: upperFirst__default.default,
41
+ lowerFirst: lowerFirst__default.default
42
+ };
43
+ class PortableTemplater {
44
+ static async create(options = {}) {
45
+ let lockfile;
46
+ try {
47
+ lockfile = await Lockfile.Lockfile.load(paths.paths.resolveTargetRoot("yarn.lock"));
48
+ } catch {
49
+ }
50
+ const versionProvider = version.createPackageVersionProvider(lockfile);
51
+ const templater = new PortableTemplater(
52
+ {
53
+ versionQuery(name, versionHint) {
54
+ return versionProvider(
55
+ name,
56
+ typeof versionHint === "string" ? versionHint : void 0
57
+ );
58
+ }
59
+ },
60
+ options.values ?? {}
61
+ );
62
+ if (options.templatedValues) {
63
+ templater.appendTemplatedValues(options.templatedValues);
64
+ }
65
+ return templater;
66
+ }
67
+ #templater;
68
+ #values;
69
+ constructor(helpers, values) {
70
+ this.#templater = handlebars__default.default.create();
71
+ this.#templater.registerHelper(builtInHelpers);
72
+ if (helpers) {
73
+ this.#templater.registerHelper(helpers);
74
+ }
75
+ this.#values = values;
76
+ }
77
+ template(content) {
78
+ return this.#templater.compile(content, {
79
+ strict: true
80
+ })(this.#values);
81
+ }
82
+ appendTemplatedValues(record) {
83
+ const newValues = Object.fromEntries(
84
+ Object.entries(record).map(([key, value]) => [key, this.template(value)])
85
+ );
86
+ this.#values = { ...this.#values, ...newValues };
87
+ }
88
+ }
89
+
90
+ exports.PortableTemplater = PortableTemplater;
91
+ //# sourceMappingURL=PortableTemplater.cjs.js.map
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ var errors = require('@backstage/errors');
4
+ var codeowners = require('../../codeowners/codeowners.cjs.js');
5
+ var tasks = require('../../tasks.cjs.js');
6
+ var installNewPackage = require('./installNewPackage.cjs.js');
7
+ var writeTemplateContents = require('./writeTemplateContents.cjs.js');
8
+
9
+ async function executePortableTemplate(options) {
10
+ const { template, input } = options;
11
+ let modified = false;
12
+ try {
13
+ const { targetDir } = await tasks.Task.forItem(
14
+ "templating",
15
+ input.packagePath,
16
+ () => writeTemplateContents.writeTemplateContents(template, input)
17
+ );
18
+ modified = true;
19
+ await installNewPackage.installNewPackage(input);
20
+ if (input.owner) {
21
+ await codeowners.addCodeownersEntry(targetDir, input.owner);
22
+ }
23
+ if (!options.skipInstall) {
24
+ await tasks.Task.forCommand("yarn install", {
25
+ cwd: targetDir,
26
+ optional: true
27
+ });
28
+ await tasks.Task.forCommand("yarn lint --fix", {
29
+ cwd: targetDir,
30
+ optional: true
31
+ });
32
+ }
33
+ tasks.Task.log();
34
+ tasks.Task.log(`\u{1F389} Successfully created ${template.name}`);
35
+ tasks.Task.log();
36
+ } catch (error) {
37
+ errors.assertError(error);
38
+ tasks.Task.error(error.message);
39
+ if (modified) {
40
+ tasks.Task.log("It seems that something went wrong in the creation process \u{1F914}");
41
+ tasks.Task.log();
42
+ tasks.Task.log(
43
+ "We have left the changes that were made intact in case you want to"
44
+ );
45
+ tasks.Task.log(
46
+ "continue manually, but you can also revert the changes and try again."
47
+ );
48
+ tasks.Task.error(`\u{1F525} Failed to create ${template.name}!`);
49
+ }
50
+ }
51
+ }
52
+
53
+ exports.executePortableTemplate = executePortableTemplate;
54
+ //# sourceMappingURL=executePortableTemplate.cjs.js.map
@@ -0,0 +1,127 @@
1
+ 'use strict';
2
+
3
+ var fs = require('fs-extra');
4
+ var upperFirst = require('lodash/upperFirst');
5
+ var camelCase = require('lodash/camelCase');
6
+ var paths = require('../../paths.cjs.js');
7
+ var tasks = require('../../tasks.cjs.js');
8
+
9
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
10
+
11
+ var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
12
+ var upperFirst__default = /*#__PURE__*/_interopDefaultCompat(upperFirst);
13
+ var camelCase__default = /*#__PURE__*/_interopDefaultCompat(camelCase);
14
+
15
+ async function installNewPackage(input) {
16
+ switch (input.roleParams.role) {
17
+ case "web-library":
18
+ case "node-library":
19
+ case "common-library":
20
+ case "plugin-web-library":
21
+ case "plugin-node-library":
22
+ case "plugin-common-library":
23
+ return;
24
+ // No installation action needed for library packages
25
+ case "frontend-plugin":
26
+ await addDependency(input, "packages/app/package.json");
27
+ await tryAddFrontendLegacy(input);
28
+ return;
29
+ case "frontend-plugin-module":
30
+ await addDependency(input, "packages/app/package.json");
31
+ return;
32
+ case "backend-plugin":
33
+ await addDependency(input, "packages/backend/package.json");
34
+ await tryAddBackend(input);
35
+ return;
36
+ case "backend-plugin-module":
37
+ await addDependency(input, "packages/backend/package.json");
38
+ await tryAddBackend(input);
39
+ return;
40
+ default:
41
+ throw new Error(
42
+ `Unsupported role ${input.roleParams.role}`
43
+ );
44
+ }
45
+ }
46
+ async function addDependency(input, path) {
47
+ const pkgJsonPath = paths.paths.resolveTargetRoot(path);
48
+ const pkgJson = await fs__default.default.readJson(pkgJsonPath).catch((error) => {
49
+ if (error.code === "ENOENT") {
50
+ return void 0;
51
+ }
52
+ throw error;
53
+ });
54
+ if (!pkgJson) {
55
+ return;
56
+ }
57
+ try {
58
+ pkgJson.dependencies = {
59
+ ...pkgJson.dependencies,
60
+ [input.packageName]: `workspace:^`
61
+ };
62
+ await fs__default.default.writeJson(path, pkgJson, { spaces: 2 });
63
+ } catch (error) {
64
+ throw new Error(`Failed to add package dependencies, ${error}`);
65
+ }
66
+ }
67
+ async function tryAddFrontendLegacy(input) {
68
+ const { roleParams } = input;
69
+ if (roleParams.role !== "frontend-plugin") {
70
+ throw new Error(
71
+ "add-frontend-legacy can only be used for frontend plugins"
72
+ );
73
+ }
74
+ const appDefinitionPath = paths.paths.resolveTargetRoot("packages/app/src/App.tsx");
75
+ if (!await fs__default.default.pathExists(appDefinitionPath)) {
76
+ return;
77
+ }
78
+ await tasks.Task.forItem("app", "adding import", async () => {
79
+ const content = await fs__default.default.readFile(appDefinitionPath, "utf8");
80
+ const revLines = content.split("\n").reverse();
81
+ const lastImportIndex = revLines.findIndex(
82
+ (line) => line.match(/ from ("|').*("|')/)
83
+ );
84
+ const lastRouteIndex = revLines.findIndex(
85
+ (line) => line.match(/<\/FlatRoutes/)
86
+ );
87
+ if (lastImportIndex !== -1 && lastRouteIndex !== -1) {
88
+ const extensionName = upperFirst__default.default(`${camelCase__default.default(roleParams.pluginId)}Page`);
89
+ const importLine = `import { ${extensionName} } from '${input.packageName}';`;
90
+ if (!content.includes(importLine)) {
91
+ revLines.splice(lastImportIndex, 0, importLine);
92
+ }
93
+ const componentLine = `<Route path="/${roleParams.pluginId}" element={<${extensionName} />} />`;
94
+ if (!content.includes(componentLine)) {
95
+ const [indentation] = revLines[lastRouteIndex + 1].match(/^\s*/) ?? [];
96
+ revLines.splice(lastRouteIndex + 1, 0, indentation + componentLine);
97
+ }
98
+ const newContent = revLines.reverse().join("\n");
99
+ await fs__default.default.writeFile(appDefinitionPath, newContent, "utf8");
100
+ }
101
+ });
102
+ }
103
+ async function tryAddBackend(input) {
104
+ const backendIndexPath = paths.paths.resolveTargetRoot(
105
+ "packages/backend/src/index.ts"
106
+ );
107
+ if (!await fs__default.default.pathExists(backendIndexPath)) {
108
+ return;
109
+ }
110
+ await tasks.Task.forItem("backend", `adding ${input.packageName}`, async () => {
111
+ const content = await fs__default.default.readFile(backendIndexPath, "utf8");
112
+ const lines = content.split("\n");
113
+ const backendAddLine = `backend.add(import('${input.packageName}'));`;
114
+ const backendStartIndex = lines.findIndex(
115
+ (line) => line.match(/backend.start/)
116
+ );
117
+ if (backendStartIndex !== -1) {
118
+ const [indentation] = lines[backendStartIndex].match(/^\s*/);
119
+ lines.splice(backendStartIndex, 0, `${indentation}${backendAddLine}`);
120
+ const newContent = lines.join("\n");
121
+ await fs__default.default.writeFile(backendIndexPath, newContent, "utf8");
122
+ }
123
+ });
124
+ }
125
+
126
+ exports.installNewPackage = installNewPackage;
127
+ //# sourceMappingURL=installNewPackage.cjs.js.map