@backstage/cli 0.22.8-next.0 → 0.22.8-next.2

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 (43) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/cjs/{build-0f8f0f78.cjs.js → build-94b166b9.cjs.js} +7 -7
  3. package/dist/cjs/{buildBackend-b6668077.cjs.js → buildBackend-1610ed47.cjs.js} +6 -6
  4. package/dist/cjs/{buildWorkspace-a1ad431d.cjs.js → buildWorkspace-0729ac23.cjs.js} +4 -4
  5. package/dist/cjs/{bump-d637f839.cjs.js → bump-2e41888b.cjs.js} +5 -5
  6. package/dist/cjs/{clean-03329c21.cjs.js → clean-707fb954.cjs.js} +2 -2
  7. package/dist/cjs/{clean-3ebe5831.cjs.js → clean-fef9647d.cjs.js} +2 -2
  8. package/dist/cjs/{codeowners-a1dfa089.cjs.js → codeowners-5b10b186.cjs.js} +2 -2
  9. package/dist/cjs/{config-5e07cd44.cjs.js → config-1d171d7e.cjs.js} +2 -2
  10. package/dist/cjs/{createDistWorkspace-e9c7663c.cjs.js → createDistWorkspace-6f0f28d5.cjs.js} +3 -3
  11. package/dist/cjs/{createPlugin-7387334c.cjs.js → createPlugin-33d16874.cjs.js} +4 -4
  12. package/dist/cjs/{diff-ca3e092b.cjs.js → diff-c80533a8.cjs.js} +2 -2
  13. package/dist/cjs/{docs-30d19467.cjs.js → docs-c23fb420.cjs.js} +3 -3
  14. package/dist/cjs/{fix-dad6e2d6.cjs.js → fix-7ed7159b.cjs.js} +2 -2
  15. package/dist/cjs/{index-f42dfc80.cjs.js → index-4438059a.cjs.js} +8 -8
  16. package/dist/cjs/index-7b1afb9b.cjs.js +1211 -0
  17. package/dist/cjs/{index-a8c49a1b.cjs.js → index-a83455a6.cjs.js} +7 -7
  18. package/dist/cjs/{index-b5e86b0d.cjs.js → index-ad52f12e.cjs.js} +47 -42
  19. package/dist/cjs/{index-28a697ef.cjs.js → index-dc7cc004.cjs.js} +2 -2
  20. package/dist/cjs/{info-76600f2a.cjs.js → info-5202a3df.cjs.js} +3 -3
  21. package/dist/cjs/{install-b198cdab.cjs.js → install-ad1fcacf.cjs.js} +4 -4
  22. package/dist/cjs/{lint-2ebffd14.cjs.js → lint-0c3133b5.cjs.js} +2 -2
  23. package/dist/cjs/{lint-a2342595.cjs.js → lint-733ca435.cjs.js} +3 -3
  24. package/dist/cjs/{lint-dfb472ac.cjs.js → lint-784a0c3b.cjs.js} +2 -2
  25. package/dist/cjs/{list-deprecations-87e249f0.cjs.js → list-deprecations-9eac9ad6.cjs.js} +2 -2
  26. package/dist/cjs/{new-5f99b9c8.cjs.js → new-dd994b5f.cjs.js} +4 -4
  27. package/dist/cjs/{pack-273421b1.cjs.js → pack-5a0cf2b2.cjs.js} +2 -2
  28. package/dist/cjs/{packageLintConfigs-87149dd5.cjs.js → packageLintConfigs-0041e26e.cjs.js} +3 -3
  29. package/dist/cjs/{packageRole-be3239ca.cjs.js → packageRole-908ff155.cjs.js} +2 -2
  30. package/dist/cjs/{packages-9fc68dee.cjs.js → packages-93128416.cjs.js} +3 -3
  31. package/dist/cjs/{paths-d8c1f54e.cjs.js → paths-82663f40.cjs.js} +3 -3
  32. package/dist/cjs/{print-ed7ecdb5.cjs.js → print-64356633.cjs.js} +3 -3
  33. package/dist/cjs/{role-a7faefb6.cjs.js → role-1007229a.cjs.js} +2 -2
  34. package/dist/cjs/{run-cdf3f08c.cjs.js → run-b5198e24.cjs.js} +2 -2
  35. package/dist/cjs/{schema-010879d0.cjs.js → schema-04967f8e.cjs.js} +3 -3
  36. package/dist/cjs/{test-09399c75.cjs.js → test-dcc99d38.cjs.js} +3 -3
  37. package/dist/cjs/{test-a7b87e2f.cjs.js → test-fc1fa743.cjs.js} +3 -3
  38. package/dist/cjs/{validate-81a7e4c3.cjs.js → validate-e8119f4f.cjs.js} +3 -3
  39. package/dist/index.cjs.js +1 -1
  40. package/package.json +16 -11
  41. package/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs +12 -18
  42. package/templates/default-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs +231 -18
  43. package/dist/cjs/index-9b9f70f2.cjs.js +0 -471
@@ -1,471 +0,0 @@
1
- 'use strict';
2
-
3
- var chalk = require('chalk');
4
- var inquirer = require('inquirer');
5
- var tasks = require('./tasks-84de240c.cjs.js');
6
- var oauthApp = require('@octokit/oauth-app');
7
- var fs = require('fs-extra');
8
- var yaml = require('yaml');
9
- var cliCommon = require('@backstage/cli-common');
10
- var path = require('path');
11
- var differ = require('diff');
12
- require('handlebars');
13
- require('ora');
14
- require('util');
15
- require('recursive-readdir');
16
- require('child_process');
17
- require('@backstage/errors');
18
-
19
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
-
21
- function _interopNamespace(e) {
22
- if (e && e.__esModule) return e;
23
- var n = Object.create(null);
24
- if (e) {
25
- Object.keys(e).forEach(function (k) {
26
- if (k !== 'default') {
27
- var d = Object.getOwnPropertyDescriptor(e, k);
28
- Object.defineProperty(n, k, d.get ? d : {
29
- enumerable: true,
30
- get: function () { return e[k]; }
31
- });
32
- }
33
- });
34
- }
35
- n["default"] = e;
36
- return Object.freeze(n);
37
- }
38
-
39
- var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
40
- var inquirer__default = /*#__PURE__*/_interopDefaultLegacy(inquirer);
41
- var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
42
- var yaml__default = /*#__PURE__*/_interopDefaultLegacy(yaml);
43
- var path__namespace = /*#__PURE__*/_interopNamespace(path);
44
- var differ__namespace = /*#__PURE__*/_interopNamespace(differ);
45
-
46
- const readYaml = async (file) => {
47
- return yaml__default["default"].parse(await fs__namespace.readFile(file, "utf8"));
48
- };
49
- const updateConfigFile = async (file, config) => {
50
- const staticContent = "# Backstage override configuration for your local development environment \n";
51
- const content = fs__namespace.existsSync(file) ? yaml__default["default"].stringify(
52
- { ...await readYaml(file), ...config },
53
- {
54
- indent: 2
55
- }
56
- ) : staticContent.concat(
57
- yaml__default["default"].stringify(
58
- { ...config },
59
- {
60
- indent: 2
61
- }
62
- )
63
- );
64
- return await fs__namespace.writeFile(file, content, "utf8");
65
- };
66
-
67
- const { targetRoot: targetRoot$1, ownDir } = cliCommon.findPaths(__dirname);
68
- const APP_CONFIG_FILE = path__namespace.join(targetRoot$1, "app-config.local.yaml");
69
- const PATCH_FOLDER = path__namespace.join(
70
- ownDir,
71
- "src",
72
- "commands",
73
- "onboard",
74
- "auth",
75
- "patches"
76
- );
77
-
78
- const { targetRoot } = cliCommon.findPaths(__dirname);
79
- const patch = async (patchFile) => {
80
- const patchContent = await fs__namespace.readFile(
81
- path__namespace.join(PATCH_FOLDER, patchFile),
82
- "utf8"
83
- );
84
- const targetName = patchContent.split("\n")[0].replace("--- a", "");
85
- const targetFile = path__namespace.join(targetRoot, targetName);
86
- const oldContent = await fs__namespace.readFile(targetFile, "utf8");
87
- const newContent = differ__namespace.applyPatch(oldContent, patchContent);
88
- if (!newContent) {
89
- throw new Error(
90
- `Patch ${patchFile} was not applied correctly.
91
- Did you change ${targetName} manually before running this command?`
92
- );
93
- }
94
- return await fs__namespace.writeFile(targetFile, newContent, "utf8");
95
- };
96
-
97
- const validateCredentials = async (clientId, clientSecret) => {
98
- try {
99
- const app = new oauthApp.OAuthApp({
100
- clientId,
101
- clientSecret
102
- });
103
- await app.createToken({
104
- code: "%NOT-VALID-CODE%"
105
- });
106
- } catch (error) {
107
- if (error.response.status !== 200 && error.response.data.error !== "bad_verification_code") {
108
- throw new Error(`Validating GitHub Credentials failed.`);
109
- }
110
- }
111
- };
112
- const getConfig$2 = (answers) => {
113
- const { clientId, clientSecret, hasEnterprise, enterpriseInstanceUrl } = answers;
114
- return {
115
- auth: {
116
- providers: {
117
- github: {
118
- development: {
119
- clientId,
120
- clientSecret,
121
- ...hasEnterprise && {
122
- enterpriseInstanceUrl
123
- }
124
- }
125
- }
126
- }
127
- }
128
- };
129
- };
130
- const github$1 = async () => {
131
- tasks.Task.log(`
132
- To add GitHub authentication, you must create an OAuth App from the GitHub developer settings: ${chalk__default["default"].blue(
133
- "https://github.com/settings/developers"
134
- )}
135
- The Homepage URL should point to Backstage's frontend, while the Authorization callback URL will point to the auth backend.
136
-
137
- Settings for local development:
138
- ${chalk__default["default"].cyan(`
139
- Homepage URL: http://localhost:3000
140
- Authorization callback URL: http://localhost:7007/api/auth/github/handler/frame`)}
141
-
142
- You can find the full documentation page here: ${chalk__default["default"].blue(
143
- "https://backstage.io/docs/auth/github/provider"
144
- )}
145
- `);
146
- const answers = await inquirer__default["default"].prompt([
147
- {
148
- type: "input",
149
- name: "clientId",
150
- message: "What is your Client Id?",
151
- validate: (input) => input.length ? true : false
152
- },
153
- {
154
- type: "input",
155
- name: "clientSecret",
156
- message: "What is your Client Secret?",
157
- validate: (input) => input.length ? true : false
158
- },
159
- {
160
- type: "confirm",
161
- name: "hasEnterprise",
162
- message: "Are you using GitHub Enterprise?"
163
- },
164
- {
165
- type: "input",
166
- name: "enterpriseInstanceUrl",
167
- message: "What is your URL for GitHub Enterprise?",
168
- when: ({ hasEnterprise }) => hasEnterprise,
169
- validate: (input) => Boolean(new URL(input))
170
- }
171
- ]);
172
- const { clientId, clientSecret } = answers;
173
- const config = getConfig$2(answers);
174
- tasks.Task.log("Setting up GitHub Authentication for you...");
175
- await tasks.Task.forItem(
176
- "Validating",
177
- "credentials",
178
- async () => await validateCredentials(clientId, clientSecret)
179
- );
180
- await tasks.Task.forItem(
181
- "Updating",
182
- APP_CONFIG_FILE,
183
- async () => await updateConfigFile(APP_CONFIG_FILE, config)
184
- );
185
- const patches = await fs__namespace.readdir(PATCH_FOLDER);
186
- for (const patchFile of patches.filter((p) => p.includes("github"))) {
187
- await tasks.Task.forItem("Patching", patchFile, async () => {
188
- await patch(patchFile);
189
- });
190
- }
191
- return answers;
192
- };
193
-
194
- const getConfig$1 = (answers) => {
195
- const { clientId, clientSecret, hasAudience, audience } = answers;
196
- return {
197
- auth: {
198
- providers: {
199
- gitlab: {
200
- development: {
201
- clientId,
202
- clientSecret,
203
- ...hasAudience && {
204
- audience
205
- }
206
- }
207
- }
208
- }
209
- }
210
- };
211
- };
212
- const gitlab = async () => {
213
- tasks.Task.log(`
214
- To add GitLab authentication, you must create an Application from the GitLab Settings: ${chalk__default["default"].blue(
215
- "https://gitlab.com/-/profile/applications"
216
- )}
217
- The Redirect URI should point to your Backstage backend auth handler.
218
-
219
- Settings for local development:
220
- ${chalk__default["default"].cyan(`
221
- Name: Backstage (or your custom app name)
222
- Redirect URI: http://localhost:7007/api/auth/gitlab/handler/frame
223
- Scopes: read_api and read_user`)}
224
-
225
- You can find the full documentation page here: ${chalk__default["default"].blue(
226
- "https://backstage.io/docs/auth/gitlab/provider"
227
- )}
228
- `);
229
- const answers = await inquirer__default["default"].prompt([
230
- {
231
- type: "input",
232
- name: "clientId",
233
- message: "What is your Application Id?",
234
- validate: (input) => input.length ? true : false
235
- },
236
- {
237
- type: "input",
238
- name: "clientSecret",
239
- message: "What is your Application Secret?",
240
- validate: (input) => input.length ? true : false
241
- },
242
- {
243
- type: "confirm",
244
- name: "hasAudience",
245
- message: "Do you have a self-hosted instance of GitLab?"
246
- },
247
- {
248
- type: "input",
249
- name: "audience",
250
- message: "What is the URL for your GitLab instance?",
251
- when: ({ hasAudience }) => hasAudience,
252
- validate: (input) => Boolean(new URL(input))
253
- }
254
- ]);
255
- const config = getConfig$1(answers);
256
- tasks.Task.log("Setting up GitLab Authentication for you...");
257
- await tasks.Task.forItem(
258
- "Updating",
259
- APP_CONFIG_FILE,
260
- async () => await updateConfigFile(APP_CONFIG_FILE, config)
261
- );
262
- const patches = await fs__namespace.readdir(PATCH_FOLDER);
263
- for (const patchFile of patches.filter((p) => p.includes("gitlab"))) {
264
- await tasks.Task.forItem("Patching", patchFile, async () => {
265
- await patch(patchFile);
266
- });
267
- }
268
- return answers;
269
- };
270
-
271
- async function auth() {
272
- const answers = await inquirer__default["default"].prompt([
273
- {
274
- type: "list",
275
- name: "provider",
276
- message: "Please select an authentication provider:",
277
- choices: ["GitHub", "GitLab"]
278
- }
279
- ]);
280
- const { provider } = answers;
281
- let providerAnswers;
282
- switch (provider) {
283
- case "GitHub": {
284
- providerAnswers = await github$1();
285
- break;
286
- }
287
- case "GitLab": {
288
- providerAnswers = await gitlab();
289
- break;
290
- }
291
- default:
292
- throw new Error(`Provider ${provider} not implemented yet.`);
293
- }
294
- tasks.Task.log();
295
- tasks.Task.log(`Done setting up ${provider} Authentication!`);
296
- tasks.Task.log();
297
- return {
298
- provider,
299
- answers: providerAnswers
300
- };
301
- }
302
-
303
- const getConfig = ({
304
- hasEnterprise,
305
- apiBaseUrl,
306
- host,
307
- token
308
- }) => ({
309
- integrations: {
310
- github: [
311
- {
312
- host,
313
- token,
314
- ...hasEnterprise && {
315
- apiBaseUrl
316
- }
317
- }
318
- ]
319
- }
320
- });
321
- const github = async (providerAnswers) => {
322
- var _a, _b, _c;
323
- const answers = await inquirer__default["default"].prompt([
324
- {
325
- type: "confirm",
326
- name: "hasEnterprise",
327
- message: "Are you using GitHub Enterprise?",
328
- when: () => typeof providerAnswers === "undefined"
329
- },
330
- {
331
- type: "input",
332
- name: "enterpriseInstanceUrl",
333
- message: "What is your URL for GitHub Enterprise?",
334
- when: ({ hasEnterprise }) => hasEnterprise,
335
- validate: (input) => Boolean(new URL(input))
336
- },
337
- {
338
- type: "input",
339
- name: "apiBaseUrl",
340
- message: "What is your GitHub Enterprise API path?",
341
- default: "/api/v3",
342
- when: ({ hasEnterprise }) => hasEnterprise || (providerAnswers == null ? void 0 : providerAnswers.hasEnterprise)
343
- // TODO(tudi2d): Fetch API using OAuth Token if Auth was set up
344
- }
345
- ]);
346
- const host = new URL(
347
- (_b = (_a = providerAnswers == null ? void 0 : providerAnswers.enterpriseInstanceUrl) != null ? _a : answers == null ? void 0 : answers.enterpriseInstanceUrl) != null ? _b : "http://github.com"
348
- );
349
- tasks.Task.log(`
350
- To create new repositories in GitHub using Software Templates you first need to create a personal access token: ${chalk__default["default"].blue(
351
- `${host.origin}/settings/tokens/new`
352
- )}
353
-
354
- Select the following scopes:
355
-
356
- Reading software components:${chalk__default["default"].cyan(`
357
- - "repo"`)}
358
-
359
- Reading organization data:${chalk__default["default"].cyan(`
360
- - "read:org"
361
- - "read:user"
362
- - "user:email"`)}
363
-
364
- Publishing software templates:${chalk__default["default"].cyan(`
365
- - "repo"
366
- - "workflow" (if templates include GitHub workflows)
367
- `)}
368
-
369
- You can find the full documentation page here: ${chalk__default["default"].blue(
370
- "https://backstage.io/docs/integrations/github/locations"
371
- )}
372
- `);
373
- const { token } = await inquirer__default["default"].prompt([
374
- {
375
- type: "input",
376
- name: "token",
377
- message: "Please insert your personal access token to setup the GitHub Integration"
378
- // TODO(tudi2d): validate
379
- }
380
- ]);
381
- const config = getConfig({
382
- hasEnterprise: (_c = providerAnswers == null ? void 0 : providerAnswers.hasEnterprise) != null ? _c : answers.hasEnterprise,
383
- apiBaseUrl: host.origin + answers.apiBaseUrl,
384
- host: host.hostname,
385
- token
386
- });
387
- tasks.Task.log("Setting up Software Templates using GitHub integration for you...");
388
- await tasks.Task.forItem(
389
- "Updating",
390
- APP_CONFIG_FILE,
391
- async () => await updateConfigFile(APP_CONFIG_FILE, config)
392
- );
393
- };
394
-
395
- const Integrations = ["GitHub" /* GITHUB */];
396
- async function integrations(providerInfo) {
397
- const answers = await inquirer__default["default"].prompt([
398
- {
399
- type: "confirm",
400
- name: "shouldUsePreviousProvider",
401
- message: `Do you want to keep using ${providerInfo == null ? void 0 : providerInfo.provider} as your provider when setting up Software Templates?`,
402
- when: () => (providerInfo == null ? void 0 : providerInfo.provider) && Object.values(Integrations).includes(
403
- providerInfo.provider
404
- )
405
- },
406
- {
407
- // TODO(tudi2d): Let's start with one, but it should be multiple choice in the future
408
- type: "list",
409
- name: "integration",
410
- message: "Please select an integration provider:",
411
- choices: Integrations,
412
- when: ({ shouldUsePreviousProvider }) => !shouldUsePreviousProvider
413
- }
414
- ]);
415
- if (answers.shouldUsePreviousProvider) {
416
- answers.integration = providerInfo.provider;
417
- }
418
- switch (answers.integration) {
419
- case "GitHub" /* GITHUB */: {
420
- const providerAnswers = (providerInfo == null ? void 0 : providerInfo.provider) === "GitHub" ? providerInfo.answers : void 0;
421
- await github(providerAnswers);
422
- break;
423
- }
424
- }
425
- tasks.Task.log();
426
- tasks.Task.log(`Done setting up ${answers.integration} Integration!`);
427
- tasks.Task.log();
428
- }
429
-
430
- async function command() {
431
- const answers = await inquirer__default["default"].prompt([
432
- {
433
- type: "confirm",
434
- name: "shouldSetupAuth",
435
- message: "Do you want to set up Authentication for this project?",
436
- default: true
437
- },
438
- {
439
- type: "confirm",
440
- name: "shouldSetupScaffolder",
441
- message: "Do you want to use Software Templates in this project?",
442
- default: true
443
- }
444
- ]);
445
- const { shouldSetupAuth, shouldSetupScaffolder } = answers;
446
- let providerInfo;
447
- if (shouldSetupAuth) {
448
- providerInfo = await auth();
449
- }
450
- if (shouldSetupScaffolder) {
451
- await integrations(providerInfo);
452
- }
453
- if (!shouldSetupAuth && !shouldSetupScaffolder) {
454
- tasks.Task.log(
455
- chalk__default["default"].yellow(
456
- "If you change your mind, feel free to re-run this command."
457
- )
458
- );
459
- return;
460
- }
461
- tasks.Task.log();
462
- tasks.Task.log(
463
- `You can now start your app with ${chalk__default["default"].inverse(
464
- chalk__default["default"].italic("yarn dev")
465
- )}`
466
- );
467
- tasks.Task.log();
468
- }
469
-
470
- exports.command = command;
471
- //# sourceMappingURL=index-9b9f70f2.cjs.js.map