@backstage/plugin-scaffolder-backend 1.15.2-next.0 → 1.15.2-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.
@@ -20,8 +20,6 @@ var isbinaryfile = require('isbinaryfile');
20
20
  var isolatedVm = require('isolated-vm');
21
21
  var get = require('lodash/get');
22
22
  var octokit = require('octokit');
23
- var child_process = require('child_process');
24
- var stream = require('stream');
25
23
  var Sodium = require('libsodium-wrappers');
26
24
  var webhooks = require('@octokit/webhooks');
27
25
  var azureDevopsNodeApi = require('azure-devops-node-api');
@@ -36,6 +34,7 @@ var ObservableImpl = require('zen-observable');
36
34
  var PQueue = require('p-queue');
37
35
  var winston = require('winston');
38
36
  var nunjucks = require('nunjucks');
37
+ var stream = require('stream');
39
38
  var lodash = require('lodash');
40
39
  var pluginPermissionNode = require('@backstage/plugin-permission-node');
41
40
  var promClient = require('prom-client');
@@ -82,14 +81,13 @@ var winston__namespace = /*#__PURE__*/_interopNamespace(winston);
82
81
  var nunjucks__default = /*#__PURE__*/_interopDefaultLegacy(nunjucks);
83
82
  var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
84
83
 
85
- const id$4 = "catalog:register";
86
- const examples$4 = [
84
+ const examples$9 = [
87
85
  {
88
86
  description: "Register with the catalog",
89
87
  example: yaml__default["default"].stringify({
90
88
  steps: [
91
89
  {
92
- action: id$4,
90
+ action: "catalog:register",
93
91
  id: "register-with-catalog",
94
92
  name: "Register with the catalog",
95
93
  input: {
@@ -100,12 +98,14 @@ const examples$4 = [
100
98
  })
101
99
  }
102
100
  ];
101
+
102
+ const id$4 = "catalog:register";
103
103
  function createCatalogRegisterAction(options) {
104
104
  const { catalogClient, integrations } = options;
105
105
  return pluginScaffolderNode.createTemplateAction({
106
106
  id: id$4,
107
107
  description: "Registers entities from a catalog descriptor file in the workspace into the software catalog.",
108
- examples: examples$4,
108
+ examples: examples$9,
109
109
  schema: {
110
110
  input: {
111
111
  oneOf: [
@@ -229,14 +229,13 @@ function createCatalogRegisterAction(options) {
229
229
  });
230
230
  }
231
231
 
232
- const id$3 = "catalog:write";
233
- const examples$3 = [
232
+ const examples$8 = [
234
233
  {
235
234
  description: "Write a catalog yaml file",
236
235
  example: yaml__namespace.stringify({
237
236
  steps: [
238
237
  {
239
- action: id$3,
238
+ action: "catalog:write",
240
239
  id: "create-catalog-info-file",
241
240
  name: "Create catalog file",
242
241
  input: {
@@ -259,6 +258,8 @@ const examples$3 = [
259
258
  })
260
259
  }
261
260
  ];
261
+
262
+ const id$3 = "catalog:write";
262
263
  function createCatalogWriteAction() {
263
264
  return pluginScaffolderNode.createTemplateAction({
264
265
  id: id$3,
@@ -272,7 +273,7 @@ function createCatalogWriteAction() {
272
273
  )
273
274
  })
274
275
  },
275
- examples: examples$3,
276
+ examples: examples$8,
276
277
  supportsDryRun: true,
277
278
  async handler(ctx) {
278
279
  ctx.logStream.write(`Writing catalog-info.yaml`);
@@ -286,14 +287,13 @@ function createCatalogWriteAction() {
286
287
  });
287
288
  }
288
289
 
289
- const id$2 = "catalog:fetch";
290
- const examples$2 = [
290
+ const examples$7 = [
291
291
  {
292
292
  description: "Fetch entity by reference",
293
293
  example: yaml__default["default"].stringify({
294
294
  steps: [
295
295
  {
296
- action: id$2,
296
+ action: "catalog:fetch",
297
297
  id: "fetch",
298
298
  name: "Fetch catalog entity",
299
299
  input: {
@@ -304,11 +304,11 @@ const examples$2 = [
304
304
  })
305
305
  },
306
306
  {
307
- description: "Fetch multiple entities by referencse",
307
+ description: "Fetch multiple entities by reference",
308
308
  example: yaml__default["default"].stringify({
309
309
  steps: [
310
310
  {
311
- action: id$2,
311
+ action: "catalog:fetch",
312
312
  id: "fetchMultiple",
313
313
  name: "Fetch catalog entities",
314
314
  input: {
@@ -319,12 +319,14 @@ const examples$2 = [
319
319
  })
320
320
  }
321
321
  ];
322
+
323
+ const id$2 = "catalog:fetch";
322
324
  function createFetchCatalogEntityAction(options) {
323
325
  const { catalogClient } = options;
324
326
  return pluginScaffolderNode.createTemplateAction({
325
327
  id: id$2,
326
328
  description: "Returns entity or entities from the catalog by entity reference(s)",
327
- examples: examples$2,
329
+ examples: examples$7,
328
330
  supportsDryRun: true,
329
331
  schema: {
330
332
  input: zod.z.object({
@@ -399,14 +401,13 @@ function createFetchCatalogEntityAction(options) {
399
401
  });
400
402
  }
401
403
 
402
- const id$1 = "debug:log";
403
- const examples$1 = [
404
+ const examples$6 = [
404
405
  {
405
406
  description: "Write a debug message",
406
407
  example: yaml__default["default"].stringify({
407
408
  steps: [
408
409
  {
409
- action: id$1,
410
+ action: "debug:log",
410
411
  id: "write-debug-line",
411
412
  name: 'Write "Hello Backstage!" log line',
412
413
  input: {
@@ -421,7 +422,7 @@ const examples$1 = [
421
422
  example: yaml__default["default"].stringify({
422
423
  steps: [
423
424
  {
424
- action: id$1,
425
+ action: "debug:log",
425
426
  id: "write-workspace-directory",
426
427
  name: "List the workspace directory",
427
428
  input: {
@@ -432,11 +433,13 @@ const examples$1 = [
432
433
  })
433
434
  }
434
435
  ];
436
+
437
+ const id$1 = "debug:log";
435
438
  function createDebugLogAction() {
436
439
  return pluginScaffolderNode.createTemplateAction({
437
440
  id: id$1,
438
441
  description: "Writes a message into the log or lists all files in the workspace.",
439
- examples: examples$1,
442
+ examples: examples$6,
440
443
  schema: {
441
444
  input: {
442
445
  type: "object",
@@ -483,15 +486,28 @@ async function recursiveReadDir(dir) {
483
486
  return files.reduce((a, f) => a.concat(f), []);
484
487
  }
485
488
 
486
- const id = "debug:wait";
487
- const MAX_WAIT_TIME_IN_ISO = "T00:00:30";
488
- const examples = [
489
+ const examples$5 = [
490
+ {
491
+ description: "Waiting for 50 milliseconds",
492
+ example: yaml__default["default"].stringify({
493
+ steps: [
494
+ {
495
+ action: "debug:wait",
496
+ id: "wait-milliseconds",
497
+ name: "Waiting for 50 milliseconds",
498
+ input: {
499
+ milliseconds: 50
500
+ }
501
+ }
502
+ ]
503
+ })
504
+ },
489
505
  {
490
506
  description: "Waiting for 5 seconds",
491
507
  example: yaml__default["default"].stringify({
492
508
  steps: [
493
509
  {
494
- action: id,
510
+ action: "debug:wait",
495
511
  id: "wait-5sec",
496
512
  name: "Waiting for 5 seconds",
497
513
  input: {
@@ -502,21 +518,24 @@ const examples = [
502
518
  })
503
519
  },
504
520
  {
505
- description: "Waiting for 5 minutes",
521
+ description: "Waiting for 1 minutes",
506
522
  example: yaml__default["default"].stringify({
507
523
  steps: [
508
524
  {
509
- action: id,
510
- id: "wait-5min",
511
- name: "Waiting for 5 minutes",
525
+ action: "debug:wait",
526
+ id: "wait-1min",
527
+ name: "Waiting for 1 minutes",
512
528
  input: {
513
- minutes: 5
529
+ minutes: 1
514
530
  }
515
531
  }
516
532
  ]
517
533
  })
518
534
  }
519
535
  ];
536
+
537
+ const id = "debug:wait";
538
+ const MAX_WAIT_TIME_IN_ISO = "T00:00:30";
520
539
  function createWaitAction(options) {
521
540
  const toDuration = (maxWaitTime) => {
522
541
  if (maxWaitTime) {
@@ -530,7 +549,7 @@ function createWaitAction(options) {
530
549
  return pluginScaffolderNode.createTemplateAction({
531
550
  id,
532
551
  description: "Waits for a certain period of time.",
533
- examples,
552
+ examples: examples$5,
534
553
  schema: {
535
554
  input: {
536
555
  type: "object",
@@ -575,66 +594,46 @@ function createWaitAction(options) {
575
594
  });
576
595
  }
577
596
 
578
- async function fetchContents(options) {
579
- const { reader, integrations, baseUrl, fetchUrl = ".", outputPath } = options;
580
- const fetchUrlIsAbsolute = isFetchUrlAbsolute(fetchUrl);
581
- if (!fetchUrlIsAbsolute && (baseUrl == null ? void 0 : baseUrl.startsWith("file://"))) {
582
- const basePath = baseUrl.slice("file://".length);
583
- const srcDir = backendCommon.resolveSafeChildPath(path__default["default"].dirname(basePath), fetchUrl);
584
- await fs__default["default"].copy(srcDir, outputPath);
585
- } else {
586
- const readUrl = getReadUrl(fetchUrl, baseUrl, integrations);
587
- const res = await reader.readTree(readUrl);
588
- await fs__default["default"].ensureDir(outputPath);
589
- await res.dir({ targetDir: outputPath });
590
- }
591
- }
592
- async function fetchFile(options) {
593
- const { reader, integrations, baseUrl, fetchUrl = ".", outputPath } = options;
594
- const fetchUrlIsAbsolute = isFetchUrlAbsolute(fetchUrl);
595
- if (!fetchUrlIsAbsolute && (baseUrl == null ? void 0 : baseUrl.startsWith("file://"))) {
596
- const basePath = baseUrl.slice("file://".length);
597
- const src = backendCommon.resolveSafeChildPath(path__default["default"].dirname(basePath), fetchUrl);
598
- await fs__default["default"].copyFile(src, outputPath);
599
- } else {
600
- const readUrl = getReadUrl(fetchUrl, baseUrl, integrations);
601
- const res = await reader.readUrl(readUrl);
602
- await fs__default["default"].ensureDir(path__default["default"].dirname(outputPath));
603
- const buffer = await res.buffer();
604
- await fs__default["default"].outputFile(outputPath, buffer.toString());
605
- }
606
- }
607
- function isFetchUrlAbsolute(fetchUrl) {
608
- let fetchUrlIsAbsolute = false;
609
- try {
610
- new URL(fetchUrl);
611
- fetchUrlIsAbsolute = true;
612
- } catch {
613
- }
614
- return fetchUrlIsAbsolute;
615
- }
616
- function getReadUrl(fetchUrl, baseUrl, integrations) {
617
- if (isFetchUrlAbsolute(fetchUrl)) {
618
- return fetchUrl;
619
- } else if (baseUrl) {
620
- const integration = integrations.byUrl(baseUrl);
621
- if (!integration) {
622
- throw new errors.InputError(`No integration found for location ${baseUrl}`);
623
- }
624
- return integration.resolveUrl({
625
- url: fetchUrl,
626
- base: baseUrl
627
- });
597
+ const examples$4 = [
598
+ {
599
+ description: "Downloads content and places it in the workspace.",
600
+ example: yaml__default["default"].stringify({
601
+ steps: [
602
+ {
603
+ action: "fetch:plain",
604
+ id: "fetch-plain",
605
+ name: "Fetch plain",
606
+ input: {
607
+ url: "https://github.com/backstage/community/tree/main/backstage-community-sessions/assets"
608
+ }
609
+ }
610
+ ]
611
+ })
612
+ },
613
+ {
614
+ description: "Optionally, if you would prefer the data to be downloaded to a subdirectory in the workspace you may specify the \u2018targetPath\u2019 input option.",
615
+ example: yaml__default["default"].stringify({
616
+ steps: [
617
+ {
618
+ action: "fetch:plain",
619
+ id: "fetch-plain",
620
+ name: "Fetch plain",
621
+ input: {
622
+ url: "https://github.com/backstage/community/tree/main/backstage-community-sessions/assets",
623
+ targetPath: "fetched-data"
624
+ }
625
+ }
626
+ ]
627
+ })
628
628
  }
629
- throw new errors.InputError(
630
- `Failed to fetch, template location could not be determined and the fetch URL is relative, ${fetchUrl}`
631
- );
632
- }
629
+ ];
633
630
 
631
+ const ACTION_ID = "fetch:plain";
634
632
  function createFetchPlainAction(options) {
635
633
  const { reader, integrations } = options;
636
634
  return pluginScaffolderNode.createTemplateAction({
637
- id: "fetch:plain",
635
+ id: ACTION_ID,
636
+ examples: examples$4,
638
637
  description: "Downloads content and places it in the workspace, or optionally in a subdirectory specified by the `targetPath` input option.",
639
638
  schema: {
640
639
  input: {
@@ -660,7 +659,7 @@ function createFetchPlainAction(options) {
660
659
  ctx.logger.info("Fetching plain content from remote URL");
661
660
  const targetPath = (_a = ctx.input.targetPath) != null ? _a : "./";
662
661
  const outputPath = backendCommon.resolveSafeChildPath(ctx.workspacePath, targetPath);
663
- await fetchContents({
662
+ await pluginScaffolderNode.fetchContents({
664
663
  reader,
665
664
  integrations,
666
665
  baseUrl: (_b = ctx.templateInfo) == null ? void 0 : _b.baseUrl,
@@ -671,11 +670,31 @@ function createFetchPlainAction(options) {
671
670
  });
672
671
  }
673
672
 
673
+ const examples$3 = [
674
+ {
675
+ description: "Downloads a file and places it in the workspace.",
676
+ example: yaml__default["default"].stringify({
677
+ steps: [
678
+ {
679
+ action: "fetch:plain:file",
680
+ id: "fetch-plain-file",
681
+ name: "Fetch plain file",
682
+ input: {
683
+ url: "https://github.com/backstage/community/tree/main/backstage-community-sessions/assets/Backstage%20Community%20Sessions.png",
684
+ targetPath: "target-path"
685
+ }
686
+ }
687
+ ]
688
+ })
689
+ }
690
+ ];
691
+
674
692
  function createFetchPlainFileAction(options) {
675
693
  const { reader, integrations } = options;
676
694
  return pluginScaffolderNode.createTemplateAction({
677
695
  id: "fetch:plain:file",
678
696
  description: "Downloads single file and places it in the workspace.",
697
+ examples: examples$3,
679
698
  schema: {
680
699
  input: {
681
700
  type: "object",
@@ -702,7 +721,7 @@ function createFetchPlainFileAction(options) {
702
721
  ctx.workspacePath,
703
722
  ctx.input.targetPath
704
723
  );
705
- await fetchFile({
724
+ await pluginScaffolderNode.fetchFile({
706
725
  reader,
707
726
  integrations,
708
727
  baseUrl: (_a = ctx.templateInfo) == null ? void 0 : _a.baseUrl,
@@ -943,6 +962,31 @@ const createDefaultFilters = ({
943
962
  };
944
963
  };
945
964
 
965
+ const examples$2 = [
966
+ {
967
+ description: "Downloads a skelaton directory that lives alongside the template file and fill it out with values.",
968
+ example: yaml__default["default"].stringify({
969
+ steps: [
970
+ {
971
+ action: "fetch:template",
972
+ id: "fetch-template",
973
+ name: "Fetch template",
974
+ input: {
975
+ url: "./skeleton",
976
+ targetPath: "./target",
977
+ values: {
978
+ name: "test-project",
979
+ count: 1234,
980
+ itemList: ["first", "second", "third"],
981
+ showDummyFile: false
982
+ }
983
+ }
984
+ }
985
+ ]
986
+ })
987
+ }
988
+ ];
989
+
946
990
  function createFetchTemplateAction(options) {
947
991
  const {
948
992
  reader,
@@ -954,6 +998,7 @@ function createFetchTemplateAction(options) {
954
998
  return pluginScaffolderNode.createTemplateAction({
955
999
  id: "fetch:template",
956
1000
  description: "Downloads a skeleton, templates variables into file and directory names and content, and places the result in the workspace, or optionally in a subdirectory specified by the `targetPath` input option.",
1001
+ examples: examples$2,
957
1002
  schema: {
958
1003
  input: {
959
1004
  type: "object",
@@ -1050,7 +1095,7 @@ function createFetchTemplateAction(options) {
1050
1095
  extension = `.${extension}`;
1051
1096
  }
1052
1097
  }
1053
- await fetchContents({
1098
+ await pluginScaffolderNode.fetchContents({
1054
1099
  reader,
1055
1100
  integrations,
1056
1101
  baseUrl: (_b = ctx.templateInfo) == null ? void 0 : _b.baseUrl,
@@ -1158,10 +1203,29 @@ function containsSkippedContent(localOutputPath) {
1158
1203
  return localOutputPath === "" || localOutputPath.startsWith("/") || localOutputPath.includes("//");
1159
1204
  }
1160
1205
 
1206
+ const examples$1 = [
1207
+ {
1208
+ description: "Delete specified files",
1209
+ example: yaml__namespace.stringify({
1210
+ steps: [
1211
+ {
1212
+ action: "fs:delete",
1213
+ id: "deleteFiles",
1214
+ name: "Delete files",
1215
+ input: {
1216
+ files: ["file1.txt", "file2.txt"]
1217
+ }
1218
+ }
1219
+ ]
1220
+ })
1221
+ }
1222
+ ];
1223
+
1161
1224
  const createFilesystemDeleteAction = () => {
1162
1225
  return pluginScaffolderNode.createTemplateAction({
1163
1226
  id: "fs:delete",
1164
1227
  description: "Deletes files and directories from the workspace",
1228
+ examples: examples$1,
1165
1229
  schema: {
1166
1230
  input: {
1167
1231
  required: ["files"],
@@ -1198,10 +1262,33 @@ const createFilesystemDeleteAction = () => {
1198
1262
  });
1199
1263
  };
1200
1264
 
1265
+ const examples = [
1266
+ {
1267
+ description: "Rename specified files ",
1268
+ example: yaml__namespace.stringify({
1269
+ steps: [
1270
+ {
1271
+ action: "fs:rename",
1272
+ id: "renameFiles",
1273
+ name: "Rename files",
1274
+ input: {
1275
+ files: [
1276
+ { from: "file1.txt", to: "file1Renamed.txt" },
1277
+ { from: "file2.txt", to: "file2Renamed.txt" },
1278
+ { from: "file3.txt", to: "file3Renamed.txt", overwrite: true }
1279
+ ]
1280
+ }
1281
+ }
1282
+ ]
1283
+ })
1284
+ }
1285
+ ];
1286
+
1201
1287
  const createFilesystemRenameAction = () => {
1202
1288
  return pluginScaffolderNode.createTemplateAction({
1203
1289
  id: "fs:rename",
1204
1290
  description: "Renames files and directories within the workspace",
1291
+ examples,
1205
1292
  schema: {
1206
1293
  input: {
1207
1294
  required: ["files"],
@@ -1267,34 +1354,6 @@ const createFilesystemRenameAction = () => {
1267
1354
  });
1268
1355
  };
1269
1356
 
1270
- const executeShellCommand = async (options) => {
1271
- const {
1272
- command,
1273
- args,
1274
- options: spawnOptions,
1275
- logStream = new stream.PassThrough()
1276
- } = options;
1277
- await new Promise((resolve, reject) => {
1278
- const process = child_process.spawn(command, args, spawnOptions);
1279
- process.stdout.on("data", (stream) => {
1280
- logStream.write(stream);
1281
- });
1282
- process.stderr.on("data", (stream) => {
1283
- logStream.write(stream);
1284
- });
1285
- process.on("error", (error) => {
1286
- return reject(error);
1287
- });
1288
- process.on("close", (code) => {
1289
- if (code !== 0) {
1290
- return reject(
1291
- new Error(`Command ${command} failed, exit code: ${code}`)
1292
- );
1293
- }
1294
- return resolve();
1295
- });
1296
- });
1297
- };
1298
1357
  async function initRepoAndPush({
1299
1358
  dir,
1300
1359
  remoteUrl,
@@ -6801,8 +6860,6 @@ exports.createPublishGitlabAction = createPublishGitlabAction;
6801
6860
  exports.createPublishGitlabMergeRequestAction = createPublishGitlabMergeRequestAction;
6802
6861
  exports.createRouter = createRouter;
6803
6862
  exports.createWaitAction = createWaitAction;
6804
- exports.executeShellCommand = executeShellCommand;
6805
- exports.fetchContents = fetchContents;
6806
6863
  exports.scaffolderActionRules = scaffolderActionRules;
6807
6864
  exports.scaffolderTemplateRules = scaffolderTemplateRules;
6808
- //# sourceMappingURL=ScaffolderEntitiesProcessor-b514f9e5.cjs.js.map
6865
+ //# sourceMappingURL=ScaffolderEntitiesProcessor-82f18a18.cjs.js.map