@backstage/plugin-scaffolder-backend 1.33.1-next.0 → 2.0.0-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 (65) hide show
  1. package/CHANGELOG.md +171 -0
  2. package/dist/ScaffolderPlugin.cjs.js +7 -19
  3. package/dist/ScaffolderPlugin.cjs.js.map +1 -1
  4. package/dist/alpha.cjs.js +5 -9
  5. package/dist/alpha.cjs.js.map +1 -1
  6. package/dist/alpha.d.ts +1 -5
  7. package/dist/index.cjs.js +0 -28
  8. package/dist/index.cjs.js.map +1 -1
  9. package/dist/index.d.ts +120 -450
  10. package/dist/lib/templating/SecureTemplater.cjs.js.map +1 -1
  11. package/dist/scaffolder/actions/TemplateActionRegistry.cjs.js.map +1 -1
  12. package/dist/scaffolder/actions/builtin/catalog/fetch.cjs.js +5 -11
  13. package/dist/scaffolder/actions/builtin/catalog/fetch.cjs.js.map +1 -1
  14. package/dist/scaffolder/actions/builtin/catalog/register.cjs.js +26 -62
  15. package/dist/scaffolder/actions/builtin/catalog/register.cjs.js.map +1 -1
  16. package/dist/scaffolder/actions/builtin/catalog/write.cjs.js +4 -5
  17. package/dist/scaffolder/actions/builtin/catalog/write.cjs.js.map +1 -1
  18. package/dist/scaffolder/actions/builtin/debug/log.cjs.js +4 -5
  19. package/dist/scaffolder/actions/builtin/debug/log.cjs.js.map +1 -1
  20. package/dist/scaffolder/actions/builtin/debug/wait.cjs.js +9 -15
  21. package/dist/scaffolder/actions/builtin/debug/wait.cjs.js.map +1 -1
  22. package/dist/scaffolder/actions/builtin/fetch/plain.cjs.js +9 -19
  23. package/dist/scaffolder/actions/builtin/fetch/plain.cjs.js.map +1 -1
  24. package/dist/scaffolder/actions/builtin/fetch/plainFile.cjs.js +9 -19
  25. package/dist/scaffolder/actions/builtin/fetch/plainFile.cjs.js.map +1 -1
  26. package/dist/scaffolder/actions/builtin/fetch/template.cjs.js +33 -55
  27. package/dist/scaffolder/actions/builtin/fetch/template.cjs.js.map +1 -1
  28. package/dist/scaffolder/actions/builtin/fetch/templateActionHandler.cjs.js +4 -19
  29. package/dist/scaffolder/actions/builtin/fetch/templateActionHandler.cjs.js.map +1 -1
  30. package/dist/scaffolder/actions/builtin/fetch/templateFile.cjs.js +24 -34
  31. package/dist/scaffolder/actions/builtin/fetch/templateFile.cjs.js.map +1 -1
  32. package/dist/scaffolder/actions/builtin/filesystem/delete.cjs.js +3 -12
  33. package/dist/scaffolder/actions/builtin/filesystem/delete.cjs.js.map +1 -1
  34. package/dist/scaffolder/actions/builtin/filesystem/read.cjs.js +14 -14
  35. package/dist/scaffolder/actions/builtin/filesystem/read.cjs.js.map +1 -1
  36. package/dist/scaffolder/actions/builtin/filesystem/rename.cjs.js +16 -27
  37. package/dist/scaffolder/actions/builtin/filesystem/rename.cjs.js.map +1 -1
  38. package/dist/scaffolder/dryrun/DecoratedActionsRegistry.cjs.js +2 -11
  39. package/dist/scaffolder/dryrun/DecoratedActionsRegistry.cjs.js.map +1 -1
  40. package/dist/scaffolder/dryrun/createDryRunner.cjs.js.map +1 -1
  41. package/dist/scaffolder/tasks/DatabaseTaskStore.cjs.js.map +1 -1
  42. package/dist/scaffolder/tasks/NunjucksWorkflowRunner.cjs.js +8 -15
  43. package/dist/scaffolder/tasks/NunjucksWorkflowRunner.cjs.js.map +1 -1
  44. package/dist/scaffolder/tasks/StorageTaskBroker.cjs.js.map +1 -1
  45. package/dist/scaffolder/tasks/TaskWorker.cjs.js.map +1 -1
  46. package/dist/service/{conditionExports.cjs.js → alpha.cjs.js} +1 -1
  47. package/dist/service/alpha.cjs.js.map +1 -0
  48. package/dist/service/helpers.cjs.js +4 -2
  49. package/dist/service/helpers.cjs.js.map +1 -1
  50. package/dist/service/permissions.cjs.js +14 -0
  51. package/dist/service/permissions.cjs.js.map +1 -0
  52. package/dist/service/router.cjs.js +48 -140
  53. package/dist/service/router.cjs.js.map +1 -1
  54. package/dist/service/rules.cjs.js +11 -11
  55. package/dist/service/rules.cjs.js.map +1 -1
  56. package/dist/util/templating.cjs.js +3 -3
  57. package/dist/util/templating.cjs.js.map +1 -1
  58. package/package.json +24 -27
  59. package/dist/deprecated.cjs.js +0 -15
  60. package/dist/deprecated.cjs.js.map +0 -1
  61. package/dist/scaffolder/actions/builtin/createBuiltinActions.cjs.js +0 -158
  62. package/dist/scaffolder/actions/builtin/createBuiltinActions.cjs.js.map +0 -1
  63. package/dist/scaffolder/actions/deprecated.cjs.js +0 -48
  64. package/dist/scaffolder/actions/deprecated.cjs.js.map +0 -1
  65. package/dist/service/conditionExports.cjs.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"plainFile.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/plainFile.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { UrlReaderService } from '@backstage/backend-plugin-api';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { examples } from './plainFile.examples';\nimport {\n createTemplateAction,\n fetchFile,\n} from '@backstage/plugin-scaffolder-node';\n\n/**\n * Downloads content and places it in the workspace, or optionally\n * in a subdirectory specified by the 'targetPath' input option.\n * @public\n */\nexport function createFetchPlainFileAction(options: {\n reader: UrlReaderService;\n integrations: ScmIntegrations;\n}) {\n const { reader, integrations } = options;\n\n return createTemplateAction<{\n url: string;\n targetPath: string;\n token?: string;\n }>({\n id: 'fetch:plain:file',\n description: 'Downloads single file and places it in the workspace.',\n examples,\n schema: {\n input: {\n type: 'object',\n required: ['url', 'targetPath'],\n properties: {\n url: {\n title: 'Fetch URL',\n description:\n 'Relative path or absolute URL pointing to the single file to fetch.',\n type: 'string',\n },\n targetPath: {\n title: 'Target Path',\n description:\n 'Target path within the working directory to download the file as.',\n type: 'string',\n },\n token: {\n title: 'Token',\n description:\n 'An optional token to use for authentication when reading the resources.',\n type: 'string',\n },\n },\n },\n },\n supportsDryRun: true,\n async handler(ctx) {\n ctx.logger.info('Fetching plain content from remote URL');\n\n // Finally move the template result into the task workspace\n const outputPath = resolveSafeChildPath(\n ctx.workspacePath,\n ctx.input.targetPath,\n );\n\n await fetchFile({\n reader,\n integrations,\n baseUrl: ctx.templateInfo?.baseUrl,\n fetchUrl: ctx.input.url,\n outputPath,\n token: ctx.input.token,\n });\n },\n });\n}\n"],"names":["createTemplateAction","examples","resolveSafeChildPath","fetchFile"],"mappings":";;;;;;AA8BO,SAAS,2BAA2B,OAGxC,EAAA;AACD,EAAM,MAAA,EAAE,MAAQ,EAAA,YAAA,EAAiB,GAAA,OAAA;AAEjC,EAAA,OAAOA,yCAIJ,CAAA;AAAA,IACD,EAAI,EAAA,kBAAA;AAAA,IACJ,WAAa,EAAA,uDAAA;AAAA,cACbC,2BAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,IAAM,EAAA,QAAA;AAAA,QACN,QAAA,EAAU,CAAC,KAAA,EAAO,YAAY,CAAA;AAAA,QAC9B,UAAY,EAAA;AAAA,UACV,GAAK,EAAA;AAAA,YACH,KAAO,EAAA,WAAA;AAAA,YACP,WACE,EAAA,qEAAA;AAAA,YACF,IAAM,EAAA;AAAA,WACR;AAAA,UACA,UAAY,EAAA;AAAA,YACV,KAAO,EAAA,aAAA;AAAA,YACP,WACE,EAAA,mEAAA;AAAA,YACF,IAAM,EAAA;AAAA,WACR;AAAA,UACA,KAAO,EAAA;AAAA,YACL,KAAO,EAAA,OAAA;AAAA,YACP,WACE,EAAA,yEAAA;AAAA,YACF,IAAM,EAAA;AAAA;AACR;AACF;AACF,KACF;AAAA,IACA,cAAgB,EAAA,IAAA;AAAA,IAChB,MAAM,QAAQ,GAAK,EAAA;AACjB,MAAI,GAAA,CAAA,MAAA,CAAO,KAAK,wCAAwC,CAAA;AAGxD,MAAA,MAAM,UAAa,GAAAC,qCAAA;AAAA,QACjB,GAAI,CAAA,aAAA;AAAA,QACJ,IAAI,KAAM,CAAA;AAAA,OACZ;AAEA,MAAA,MAAMC,8BAAU,CAAA;AAAA,QACd,MAAA;AAAA,QACA,YAAA;AAAA,QACA,OAAA,EAAS,IAAI,YAAc,EAAA,OAAA;AAAA,QAC3B,QAAA,EAAU,IAAI,KAAM,CAAA,GAAA;AAAA,QACpB,UAAA;AAAA,QACA,KAAA,EAAO,IAAI,KAAM,CAAA;AAAA,OAClB,CAAA;AAAA;AACH,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"plainFile.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/plainFile.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n resolveSafeChildPath,\n UrlReaderService,\n} from '@backstage/backend-plugin-api';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { examples } from './plainFile.examples';\n\nimport {\n createTemplateAction,\n fetchFile,\n} from '@backstage/plugin-scaffolder-node';\n\n/**\n * Downloads a single file and places it in the workspace.\n * @public\n */\nexport function createFetchPlainFileAction(options: {\n reader: UrlReaderService;\n integrations: ScmIntegrations;\n}) {\n const { reader, integrations } = options;\n\n return createTemplateAction({\n id: 'fetch:plain:file',\n description: 'Downloads single file and places it in the workspace.',\n examples,\n schema: {\n input: {\n url: z =>\n z.string({\n description:\n 'Relative path or absolute URL pointing to the single file to fetch.',\n }),\n targetPath: z =>\n z.string({\n description:\n 'Target path within the working directory to download the file as.',\n }),\n token: z =>\n z\n .string({\n description:\n 'An optional token to use for authentication when reading the resources.',\n })\n .optional(),\n },\n },\n supportsDryRun: true,\n async handler(ctx) {\n ctx.logger.info('Fetching plain content from remote URL');\n\n // Finally move the template result into the task workspace\n const outputPath = resolveSafeChildPath(\n ctx.workspacePath,\n ctx.input.targetPath,\n );\n\n await fetchFile({\n reader,\n integrations,\n baseUrl: ctx.templateInfo?.baseUrl,\n fetchUrl: ctx.input.url,\n outputPath,\n token: ctx.input.token,\n });\n },\n });\n}\n"],"names":["createTemplateAction","examples","resolveSafeChildPath","fetchFile"],"mappings":";;;;;;AAgCO,SAAS,2BAA2B,OAGxC,EAAA;AACD,EAAM,MAAA,EAAE,MAAQ,EAAA,YAAA,EAAiB,GAAA,OAAA;AAEjC,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,kBAAA;AAAA,IACJ,WAAa,EAAA,uDAAA;AAAA,cACbC,2BAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,GAAA,EAAK,CACH,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WACE,EAAA;AAAA,SACH,CAAA;AAAA,QACH,UAAA,EAAY,CACV,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WACE,EAAA;AAAA,SACH,CAAA;AAAA,QACH,KAAA,EAAO,CACL,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WACE,EAAA;AAAA,SACH,EACA,QAAS;AAAA;AAChB,KACF;AAAA,IACA,cAAgB,EAAA,IAAA;AAAA,IAChB,MAAM,QAAQ,GAAK,EAAA;AACjB,MAAI,GAAA,CAAA,MAAA,CAAO,KAAK,wCAAwC,CAAA;AAGxD,MAAA,MAAM,UAAa,GAAAC,qCAAA;AAAA,QACjB,GAAI,CAAA,aAAA;AAAA,QACJ,IAAI,KAAM,CAAA;AAAA,OACZ;AAEA,MAAA,MAAMC,8BAAU,CAAA;AAAA,QACd,MAAA;AAAA,QACA,YAAA;AAAA,QACA,OAAA,EAAS,IAAI,YAAc,EAAA,OAAA;AAAA,QAC3B,QAAA,EAAU,IAAI,KAAM,CAAA,GAAA;AAAA,QACpB,UAAA;AAAA,QACA,KAAA,EAAO,IAAI,KAAM,CAAA;AAAA,OAClB,CAAA;AAAA;AACH,GACD,CAAA;AACH;;;;"}
@@ -12,61 +12,39 @@ function createFetchTemplateAction(options) {
12
12
  examples: template_examples.examples,
13
13
  schema: {
14
14
  input: {
15
- type: "object",
16
- required: ["url"],
17
- properties: {
18
- url: {
19
- title: "Fetch URL",
20
- description: "Relative path or absolute URL pointing to the directory tree to fetch",
21
- type: "string"
22
- },
23
- targetPath: {
24
- title: "Target Path",
25
- description: "Target path within the working directory to download the contents to. Defaults to the working directory root.",
26
- type: "string"
27
- },
28
- values: {
29
- title: "Template Values",
30
- description: "Values to pass on to the templating engine",
31
- type: "object"
32
- },
33
- copyWithoutRender: {
34
- title: "[Deprecated] Copy Without Render",
35
- description: "An array of glob patterns. Any files or directories which match are copied without being processed as templates.",
36
- type: "array",
37
- items: {
38
- type: "string"
39
- }
40
- },
41
- copyWithoutTemplating: {
42
- title: "Copy Without Templating",
43
- description: "An array of glob patterns. Contents of matched files or directories are copied without being processed, but paths are subject to rendering.",
44
- type: "array",
45
- items: {
46
- type: "string"
47
- }
48
- },
49
- cookiecutterCompat: {
50
- title: "Cookiecutter compatibility mode",
51
- description: "Enable features to maximise compatibility with templates built for fetch:cookiecutter",
52
- type: "boolean"
53
- },
54
- templateFileExtension: {
55
- title: "Template File Extension",
56
- description: "If set, only files with the given extension will be templated. If set to `true`, the default extension `.njk` is used.",
57
- type: ["string", "boolean"]
58
- },
59
- replace: {
60
- title: "Replace files",
61
- description: "If set, replace files in targetPath instead of skipping existing ones.",
62
- type: "boolean"
63
- },
64
- token: {
65
- title: "Token",
66
- description: "An optional token to use for authentication when reading the resources.",
67
- type: "string"
68
- }
69
- }
15
+ url: (z) => z.string({
16
+ description: "Relative path or absolute URL pointing to the directory tree to fetch"
17
+ }),
18
+ targetPath: (z) => z.string({
19
+ description: "Target path within the working directory to download the contents to. Defaults to the working directory root."
20
+ }).optional(),
21
+ values: (z) => z.record(z.any(), {
22
+ description: "Values to pass on to the templating engine"
23
+ }).optional(),
24
+ copyWithoutRender: (z) => z.array(z.string(), {
25
+ description: "An array of glob patterns. Any files or directories which match are copied without being processed as templates."
26
+ }).optional(),
27
+ copyWithoutTemplating: (z) => z.array(z.string(), {
28
+ description: "An array of glob patterns. Contents of matched files or directories are copied without being processed, but paths are subject to rendering."
29
+ }).optional(),
30
+ cookiecutterCompat: (z) => z.boolean({
31
+ description: "Enable features to maximise compatibility with templates built for fetch:cookiecutter"
32
+ }).optional(),
33
+ templateFileExtension: (z) => z.union([z.string(), z.boolean()], {
34
+ description: "If set, only files with the given extension will be templated. If set to `true`, the default extension `.njk` is used."
35
+ }).optional(),
36
+ replace: (z) => z.boolean({
37
+ description: "If set, replace files in targetPath instead of skipping existing ones."
38
+ }).optional(),
39
+ trimBlocks: (z) => z.boolean({
40
+ description: "If set, the first newline after a block is removed (block, not variable tag)."
41
+ }).optional(),
42
+ lstripBlocks: (z) => z.boolean({
43
+ description: "If set, leading spaces and tabs are stripped from the start of a line to a block."
44
+ }).optional(),
45
+ token: (z) => z.string({
46
+ description: "An optional token to use for authentication when reading the resources."
47
+ }).optional()
70
48
  }
71
49
  },
72
50
  supportsDryRun: true,
@@ -1 +1 @@
1
- {"version":3,"file":"template.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/template.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n resolveSafeChildPath,\n UrlReaderService,\n} from '@backstage/backend-plugin-api';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n createTemplateAction,\n fetchContents,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport { examples } from './template.examples';\nimport { createTemplateActionHandler } from './templateActionHandler';\n\n/**\n * Downloads a skeleton, templates variables into file and directory names and content.\n * Then places the result in the workspace, or optionally in a subdirectory\n * specified by the 'targetPath' input option.\n *\n * @public\n */\nexport function createFetchTemplateAction(options: {\n reader: UrlReaderService;\n integrations: ScmIntegrations;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n}) {\n return createTemplateAction<{\n url: string;\n targetPath?: string;\n values: any;\n templateFileExtension?: string | boolean;\n\n // Cookiecutter compat options\n /**\n * @deprecated This field is deprecated in favor of copyWithoutTemplating.\n */\n copyWithoutRender?: string[];\n copyWithoutTemplating?: string[];\n cookiecutterCompat?: boolean;\n replace?: boolean;\n trimBlocks?: boolean;\n lstripBlocks?: boolean;\n token?: string;\n }>({\n id: 'fetch:template',\n description:\n '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.',\n examples,\n schema: {\n input: {\n type: 'object',\n required: ['url'],\n properties: {\n url: {\n title: 'Fetch URL',\n description:\n 'Relative path or absolute URL pointing to the directory tree to fetch',\n type: 'string',\n },\n targetPath: {\n title: 'Target Path',\n description:\n 'Target path within the working directory to download the contents to. Defaults to the working directory root.',\n type: 'string',\n },\n values: {\n title: 'Template Values',\n description: 'Values to pass on to the templating engine',\n type: 'object',\n },\n copyWithoutRender: {\n title: '[Deprecated] Copy Without Render',\n description:\n 'An array of glob patterns. Any files or directories which match are copied without being processed as templates.',\n type: 'array',\n items: {\n type: 'string',\n },\n },\n copyWithoutTemplating: {\n title: 'Copy Without Templating',\n description:\n 'An array of glob patterns. Contents of matched files or directories are copied without being processed, but paths are subject to rendering.',\n type: 'array',\n items: {\n type: 'string',\n },\n },\n cookiecutterCompat: {\n title: 'Cookiecutter compatibility mode',\n description:\n 'Enable features to maximise compatibility with templates built for fetch:cookiecutter',\n type: 'boolean',\n },\n templateFileExtension: {\n title: 'Template File Extension',\n description:\n 'If set, only files with the given extension will be templated. If set to `true`, the default extension `.njk` is used.',\n type: ['string', 'boolean'],\n },\n replace: {\n title: 'Replace files',\n description:\n 'If set, replace files in targetPath instead of skipping existing ones.',\n type: 'boolean',\n },\n token: {\n title: 'Token',\n description:\n 'An optional token to use for authentication when reading the resources.',\n type: 'string',\n },\n },\n },\n },\n supportsDryRun: true,\n handler: ctx =>\n createTemplateActionHandler({\n ctx,\n resolveTemplate: async () => {\n ctx.logger.info('Fetching template content from remote URL');\n\n const workDir = await ctx.createTemporaryDirectory();\n const templateDir = resolveSafeChildPath(workDir, 'template');\n\n await fetchContents({\n baseUrl: ctx.templateInfo?.baseUrl,\n fetchUrl: ctx.input.url,\n outputPath: templateDir,\n token: ctx.input.token,\n ...options,\n });\n\n return templateDir;\n },\n ...options,\n }),\n });\n}\n"],"names":["createTemplateAction","examples","createTemplateActionHandler","resolveSafeChildPath","fetchContents"],"mappings":";;;;;;;AAqCO,SAAS,0BAA0B,OAKvC,EAAA;AACD,EAAA,OAAOA,yCAiBJ,CAAA;AAAA,IACD,EAAI,EAAA,gBAAA;AAAA,IACJ,WACE,EAAA,0MAAA;AAAA,cACFC,0BAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,IAAM,EAAA,QAAA;AAAA,QACN,QAAA,EAAU,CAAC,KAAK,CAAA;AAAA,QAChB,UAAY,EAAA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AAA;AAAA,IAChB,OAAA,EAAS,SACPC,iDAA4B,CAAA;AAAA,MAC1B,GAAA;AAAA,MACA,iBAAiB,YAAY;AAC3B,QAAI,GAAA,CAAA,MAAA,CAAO,KAAK,2CAA2C,CAAA;AAE3D,QAAM,MAAA,OAAA,GAAU,MAAM,GAAA,CAAI,wBAAyB,EAAA;AACnD,QAAM,MAAA,WAAA,GAAcC,qCAAqB,CAAA,OAAA,EAAS,UAAU,CAAA;AAE5D,QAAA,MAAMC,kCAAc,CAAA;AAAA,UAClB,OAAA,EAAS,IAAI,YAAc,EAAA,OAAA;AAAA,UAC3B,QAAA,EAAU,IAAI,KAAM,CAAA,GAAA;AAAA,UACpB,UAAY,EAAA,WAAA;AAAA,UACZ,KAAA,EAAO,IAAI,KAAM,CAAA,KAAA;AAAA,UACjB,GAAG;AAAA,SACJ,CAAA;AAED,QAAO,OAAA,WAAA;AAAA,OACT;AAAA,MACA,GAAG;AAAA,KACJ;AAAA,GACJ,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"template.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/template.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n resolveSafeChildPath,\n UrlReaderService,\n} from '@backstage/backend-plugin-api';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n createTemplateAction,\n fetchContents,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport { examples } from './template.examples';\nimport { createTemplateActionHandler } from './templateActionHandler';\n\n/**\n * Downloads a skeleton, templates variables into file and directory names and content.\n * Then places the result in the workspace, or optionally in a subdirectory\n * specified by the 'targetPath' input option.\n *\n * @public\n */\nexport function createFetchTemplateAction(options: {\n reader: UrlReaderService;\n integrations: ScmIntegrations;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n}) {\n return createTemplateAction({\n id: 'fetch:template',\n description:\n '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.',\n examples,\n schema: {\n input: {\n url: z =>\n z.string({\n description:\n 'Relative path or absolute URL pointing to the directory tree to fetch',\n }),\n targetPath: z =>\n z\n .string({\n description:\n 'Target path within the working directory to download the contents to. Defaults to the working directory root.',\n })\n .optional(),\n values: z =>\n z\n .record(z.any(), {\n description: 'Values to pass on to the templating engine',\n })\n .optional(),\n copyWithoutRender: z =>\n z\n .array(z.string(), {\n description:\n 'An array of glob patterns. Any files or directories which match are copied without being processed as templates.',\n })\n .optional(),\n copyWithoutTemplating: z =>\n z\n .array(z.string(), {\n description:\n 'An array of glob patterns. Contents of matched files or directories are copied without being processed, but paths are subject to rendering.',\n })\n .optional(),\n cookiecutterCompat: z =>\n z\n .boolean({\n description:\n 'Enable features to maximise compatibility with templates built for fetch:cookiecutter',\n })\n .optional(),\n templateFileExtension: z =>\n z\n .union([z.string(), z.boolean()], {\n description:\n 'If set, only files with the given extension will be templated. If set to `true`, the default extension `.njk` is used.',\n })\n .optional(),\n replace: z =>\n z\n .boolean({\n description:\n 'If set, replace files in targetPath instead of skipping existing ones.',\n })\n .optional(),\n trimBlocks: z =>\n z\n .boolean({\n description:\n 'If set, the first newline after a block is removed (block, not variable tag).',\n })\n .optional(),\n lstripBlocks: z =>\n z\n .boolean({\n description:\n 'If set, leading spaces and tabs are stripped from the start of a line to a block.',\n })\n .optional(),\n token: z =>\n z\n .string({\n description:\n 'An optional token to use for authentication when reading the resources.',\n })\n .optional(),\n },\n },\n supportsDryRun: true,\n handler: ctx =>\n createTemplateActionHandler({\n ctx,\n resolveTemplate: async () => {\n ctx.logger.info('Fetching template content from remote URL');\n\n const workDir = await ctx.createTemporaryDirectory();\n const templateDir = resolveSafeChildPath(workDir, 'template');\n\n await fetchContents({\n baseUrl: ctx.templateInfo?.baseUrl,\n fetchUrl: ctx.input.url,\n outputPath: templateDir,\n token: ctx.input.token,\n ...options,\n });\n\n return templateDir;\n },\n ...options,\n }),\n });\n}\n"],"names":["createTemplateAction","examples","createTemplateActionHandler","resolveSafeChildPath","fetchContents"],"mappings":";;;;;;;AAqCO,SAAS,0BAA0B,OAKvC,EAAA;AACD,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,gBAAA;AAAA,IACJ,WACE,EAAA,0MAAA;AAAA,cACFC,0BAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,GAAA,EAAK,CACH,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WACE,EAAA;AAAA,SACH,CAAA;AAAA,QACH,UAAA,EAAY,CACV,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WACE,EAAA;AAAA,SACH,EACA,QAAS,EAAA;AAAA,QACd,QAAQ,CACN,CAAA,KAAA,CAAA,CACG,MAAO,CAAA,CAAA,CAAE,KAAO,EAAA;AAAA,UACf,WAAa,EAAA;AAAA,SACd,EACA,QAAS,EAAA;AAAA,QACd,mBAAmB,CACjB,CAAA,KAAA,CAAA,CACG,KAAM,CAAA,CAAA,CAAE,QAAU,EAAA;AAAA,UACjB,WACE,EAAA;AAAA,SACH,EACA,QAAS,EAAA;AAAA,QACd,uBAAuB,CACrB,CAAA,KAAA,CAAA,CACG,KAAM,CAAA,CAAA,CAAE,QAAU,EAAA;AAAA,UACjB,WACE,EAAA;AAAA,SACH,EACA,QAAS,EAAA;AAAA,QACd,kBAAA,EAAoB,CAClB,CAAA,KAAA,CAAA,CACG,OAAQ,CAAA;AAAA,UACP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AAA,SACJ,CAAA;AAED,QAAO,OAAA,WAAA;AAAA,OACT;AAAA,MACA,GAAG;AAAA,KACJ;AAAA,GACJ,CAAA;AACH;;;;"}
@@ -123,31 +123,16 @@ async function createTemplateActionHandler(options) {
123
123
  function resolveTemplateActionSettings(ctx) {
124
124
  const targetPath = ctx.input.targetPath ?? "./";
125
125
  const outputDir = backendPluginApi.resolveSafeChildPath(ctx.workspacePath, targetPath);
126
- if (ctx.input.copyWithoutRender && ctx.input.copyWithoutTemplating) {
127
- throw new errors.InputError(
128
- "Fetch action input copyWithoutRender and copyWithoutTemplating can not be used at the same time"
129
- );
130
- }
131
- let copyOnlyPatterns;
132
- let renderFilename;
133
- if (ctx.input.copyWithoutRender) {
134
- ctx.logger.warn(
135
- "[Deprecated] copyWithoutRender is deprecated Please use copyWithoutTemplating instead."
136
- );
137
- copyOnlyPatterns = ctx.input.copyWithoutRender;
138
- renderFilename = false;
139
- } else {
140
- copyOnlyPatterns = ctx.input.copyWithoutTemplating;
141
- renderFilename = true;
142
- }
126
+ const copyOnlyPatterns = ctx.input.copyWithoutTemplating;
127
+ const renderFilename = true;
143
128
  if (copyOnlyPatterns && !Array.isArray(copyOnlyPatterns)) {
144
129
  throw new errors.InputError(
145
- "Fetch action input copyWithoutRender/copyWithoutTemplating must be an Array"
130
+ "Fetch action input copyWithoutTemplating must be an Array"
146
131
  );
147
132
  }
148
133
  if (ctx.input.templateFileExtension && (copyOnlyPatterns || ctx.input.cookiecutterCompat)) {
149
134
  throw new errors.InputError(
150
- "Fetch action input extension incompatible with copyWithoutRender/copyWithoutTemplating and cookiecutterCompat"
135
+ "Fetch action input extension incompatible with copyWithoutTemplating and cookiecutterCompat"
151
136
  );
152
137
  }
153
138
  let extension = false;
@@ -1 +1 @@
1
- {"version":3,"file":"templateActionHandler.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/templateActionHandler.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n isChildPath,\n resolveSafeChildPath,\n} from '@backstage/backend-plugin-api';\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n ActionContext,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport fs from 'fs-extra';\nimport globby from 'globby';\nimport { isBinaryFile } from 'isbinaryfile';\nimport { createDefaultFilters } from '../../../../lib/templating/filters/createDefaultFilters';\nimport { convertFiltersToRecord } from '../../../../util/templating';\nimport { SecureTemplater } from '../../../../lib/templating/SecureTemplater';\nimport { extname } from 'path';\n\nexport type TemplateActionInput = {\n targetPath?: string;\n values: any;\n templateFileExtension?: string | boolean;\n\n // Cookiecutter compat options\n /**\n * @deprecated This field is deprecated in favor of copyWithoutTemplating.\n */\n copyWithoutRender?: string[];\n copyWithoutTemplating?: string[];\n cookiecutterCompat?: boolean;\n replace?: boolean;\n trimBlocks?: boolean;\n lstripBlocks?: boolean;\n};\n\nexport async function createTemplateActionHandler<\n I extends TemplateActionInput,\n>(options: {\n ctx: ActionContext<I, any, any>;\n resolveTemplate: () => Promise<string>;\n integrations: ScmIntegrations;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n}) {\n const {\n resolveTemplate,\n integrations,\n additionalTemplateFilters,\n additionalTemplateGlobals: templateGlobals,\n ctx,\n } = options;\n\n const templateFilters = {\n ...convertFiltersToRecord(createDefaultFilters({ integrations })),\n ...additionalTemplateFilters,\n };\n\n const { outputDir, copyOnlyPatterns, renderFilename, extension } =\n resolveTemplateActionSettings(ctx);\n\n const templateDir = await resolveTemplate();\n\n if (isChildPath(templateDir, outputDir)) {\n throw new InputError('targetPath must not be within template path');\n }\n\n ctx.logger.info('Listing files and directories in template');\n const allEntriesInTemplate = await globby(`**/*`, {\n cwd: templateDir,\n dot: true,\n onlyFiles: false,\n markDirectories: true,\n followSymbolicLinks: false,\n });\n\n const nonTemplatedEntries = new Set(\n await globby(copyOnlyPatterns || [], {\n cwd: templateDir,\n dot: true,\n onlyFiles: false,\n markDirectories: true,\n followSymbolicLinks: false,\n }),\n );\n\n // Cookiecutter prefixes all parameters in templates with\n // `cookiecutter.`. To replicate this, we wrap our parameters\n // in an object with a `cookiecutter` property when compat\n // mode is enabled.\n const { cookiecutterCompat, values } = ctx.input;\n const context = {\n [cookiecutterCompat ? 'cookiecutter' : 'values']: values,\n };\n\n ctx.logger.info(\n `Processing ${allEntriesInTemplate.length} template files/directories with input values`,\n ctx.input.values,\n );\n\n const renderTemplate = await SecureTemplater.loadRenderer({\n cookiecutterCompat: ctx.input.cookiecutterCompat,\n templateFilters,\n templateGlobals,\n nunjucksConfigs: {\n trimBlocks: ctx.input.trimBlocks,\n lstripBlocks: ctx.input.lstripBlocks,\n },\n });\n\n for (const location of allEntriesInTemplate) {\n let renderContents: boolean;\n\n let localOutputPath = location;\n if (extension) {\n renderContents = extname(localOutputPath) === extension;\n if (renderContents) {\n localOutputPath = localOutputPath.slice(0, -extension.length);\n }\n // extension is mutual exclusive with copyWithoutRender/copyWithoutTemplating,\n // therefore the output path is always rendered.\n localOutputPath = renderTemplate(localOutputPath, context);\n } else {\n renderContents = !nonTemplatedEntries.has(location);\n // The logic here is a bit tangled because it depends on two variables.\n // If renderFilename is true, which means copyWithoutTemplating is used,\n // then the path is always rendered.\n // If renderFilename is false, which means copyWithoutRender is used,\n // then matched file/directory won't be processed, same as before.\n if (renderFilename) {\n localOutputPath = renderTemplate(localOutputPath, context);\n } else {\n localOutputPath = renderContents\n ? renderTemplate(localOutputPath, context)\n : localOutputPath;\n }\n }\n\n if (containsSkippedContent(localOutputPath)) {\n continue;\n }\n\n const outputPath = resolveSafeChildPath(outputDir, localOutputPath);\n if (fs.existsSync(outputPath) && !ctx.input.replace) {\n continue;\n }\n\n if (!renderContents && !extension) {\n ctx.logger.info(`Copying file/directory ${location} without processing.`);\n }\n\n if (location.endsWith('/')) {\n ctx.logger.info(`Writing directory ${location} to template output path.`);\n await fs.ensureDir(outputPath);\n } else {\n const inputFilePath = resolveSafeChildPath(templateDir, location);\n const stats = await fs.promises.lstat(inputFilePath);\n\n if (stats.isSymbolicLink() || (await isBinaryFile(inputFilePath))) {\n ctx.logger.info(\n `Copying file binary or symbolic link at ${location}, to template output path.`,\n );\n await fs.copy(inputFilePath, outputPath);\n } else {\n const statsObj = await fs.stat(inputFilePath);\n ctx.logger.info(\n `Writing file ${location} to template output path with mode ${statsObj.mode}.`,\n );\n const inputFileContents = await fs.readFile(inputFilePath, 'utf-8');\n await fs.outputFile(\n outputPath,\n renderContents\n ? renderTemplate(inputFileContents, context)\n : inputFileContents,\n { mode: statsObj.mode },\n );\n }\n }\n }\n ctx.logger.info(`Template result written to ${outputDir}`);\n}\n\nfunction resolveTemplateActionSettings<I extends TemplateActionInput>(\n ctx: ActionContext<I, any, any>,\n): {\n outputDir: string;\n copyOnlyPatterns?: string[];\n renderFilename: boolean;\n extension: string | false;\n} {\n const targetPath = ctx.input.targetPath ?? './';\n const outputDir = resolveSafeChildPath(ctx.workspacePath, targetPath);\n\n if (ctx.input.copyWithoutRender && ctx.input.copyWithoutTemplating) {\n throw new InputError(\n 'Fetch action input copyWithoutRender and copyWithoutTemplating can not be used at the same time',\n );\n }\n let copyOnlyPatterns: string[] | undefined;\n let renderFilename: boolean;\n if (ctx.input.copyWithoutRender) {\n ctx.logger.warn(\n '[Deprecated] copyWithoutRender is deprecated Please use copyWithoutTemplating instead.',\n );\n copyOnlyPatterns = ctx.input.copyWithoutRender;\n renderFilename = false;\n } else {\n copyOnlyPatterns = ctx.input.copyWithoutTemplating;\n renderFilename = true;\n }\n if (copyOnlyPatterns && !Array.isArray(copyOnlyPatterns)) {\n throw new InputError(\n 'Fetch action input copyWithoutRender/copyWithoutTemplating must be an Array',\n );\n }\n if (\n ctx.input.templateFileExtension &&\n (copyOnlyPatterns || ctx.input.cookiecutterCompat)\n ) {\n throw new InputError(\n 'Fetch action input extension incompatible with copyWithoutRender/copyWithoutTemplating and cookiecutterCompat',\n );\n }\n let extension: string | false = false;\n if (ctx.input.templateFileExtension) {\n extension =\n ctx.input.templateFileExtension === true\n ? '.njk'\n : ctx.input.templateFileExtension;\n if (!extension.startsWith('.')) {\n extension = `.${extension}`;\n }\n }\n return {\n outputDir,\n copyOnlyPatterns,\n renderFilename,\n extension,\n };\n}\n\nfunction containsSkippedContent(localOutputPath: string): boolean {\n // if the path is empty means that there is a file skipped in the root\n // if the path starts with a separator it means that the root directory has been skipped\n // if the path includes // means that there is a subdirectory skipped\n // All paths returned are considered with / separator because of globby returning the linux separator for all os'.\n return (\n localOutputPath === '' ||\n localOutputPath.startsWith('/') ||\n localOutputPath.includes('//')\n );\n}\n"],"names":["convertFiltersToRecord","createDefaultFilters","isChildPath","InputError","globby","SecureTemplater","extname","resolveSafeChildPath","fs","isBinaryFile"],"mappings":";;;;;;;;;;;;;;;;;AAmDA,eAAsB,4BAEpB,OAMC,EAAA;AACD,EAAM,MAAA;AAAA,IACJ,eAAA;AAAA,IACA,YAAA;AAAA,IACA,yBAAA;AAAA,IACA,yBAA2B,EAAA,eAAA;AAAA,IAC3B;AAAA,GACE,GAAA,OAAA;AAEJ,EAAA,MAAM,eAAkB,GAAA;AAAA,IACtB,GAAGA,iCAAuB,CAAAC,yCAAA,CAAqB,EAAE,YAAA,EAAc,CAAC,CAAA;AAAA,IAChE,GAAG;AAAA,GACL;AAEA,EAAA,MAAM,EAAE,SAAW,EAAA,gBAAA,EAAkB,gBAAgB,SAAU,EAAA,GAC7D,8BAA8B,GAAG,CAAA;AAEnC,EAAM,MAAA,WAAA,GAAc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AI,SAAS,CAAA,CAAA;AAAA;AAC3B;AAEF,EAAO,OAAA;AAAA,IACL,SAAA;AAAA,IACA,gBAAA;AAAA,IACA,cAAA;AAAA,IACA;AAAA,GACF;AACF;AAEA,SAAS,uBAAuB,eAAkC,EAAA;AAKhE,EACE,OAAA,eAAA,KAAoB,MACpB,eAAgB,CAAA,UAAA,CAAW,GAAG,CAC9B,IAAA,eAAA,CAAgB,SAAS,IAAI,CAAA;AAEjC;;;;"}
1
+ {"version":3,"file":"templateActionHandler.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/templateActionHandler.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n isChildPath,\n resolveSafeChildPath,\n} from '@backstage/backend-plugin-api';\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n ActionContext,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport fs from 'fs-extra';\nimport globby from 'globby';\nimport { isBinaryFile } from 'isbinaryfile';\nimport { createDefaultFilters } from '../../../../lib/templating/filters/createDefaultFilters';\nimport { convertFiltersToRecord } from '../../../../util/templating';\nimport { SecureTemplater } from '../../../../lib/templating/SecureTemplater';\nimport { extname } from 'path';\n\nexport type TemplateActionInput = {\n targetPath?: string;\n values: any;\n templateFileExtension?: string | boolean;\n copyWithoutTemplating?: string[];\n cookiecutterCompat?: boolean;\n replace?: boolean;\n trimBlocks?: boolean;\n lstripBlocks?: boolean;\n};\n\nexport async function createTemplateActionHandler<\n I extends TemplateActionInput,\n>(options: {\n ctx: ActionContext<I, any, any>;\n resolveTemplate: () => Promise<string>;\n integrations: ScmIntegrations;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n}) {\n const {\n resolveTemplate,\n integrations,\n additionalTemplateFilters,\n additionalTemplateGlobals: templateGlobals,\n ctx,\n } = options;\n\n const templateFilters = {\n ...convertFiltersToRecord(createDefaultFilters({ integrations })),\n ...additionalTemplateFilters,\n };\n\n const { outputDir, copyOnlyPatterns, renderFilename, extension } =\n resolveTemplateActionSettings(ctx);\n\n const templateDir = await resolveTemplate();\n\n if (isChildPath(templateDir, outputDir)) {\n throw new InputError('targetPath must not be within template path');\n }\n\n ctx.logger.info('Listing files and directories in template');\n const allEntriesInTemplate = await globby(`**/*`, {\n cwd: templateDir,\n dot: true,\n onlyFiles: false,\n markDirectories: true,\n followSymbolicLinks: false,\n });\n\n const nonTemplatedEntries = new Set(\n await globby(copyOnlyPatterns || [], {\n cwd: templateDir,\n dot: true,\n onlyFiles: false,\n markDirectories: true,\n followSymbolicLinks: false,\n }),\n );\n\n // Cookiecutter prefixes all parameters in templates with\n // `cookiecutter.`. To replicate this, we wrap our parameters\n // in an object with a `cookiecutter` property when compat\n // mode is enabled.\n const { cookiecutterCompat, values } = ctx.input;\n const context = {\n [cookiecutterCompat ? 'cookiecutter' : 'values']: values,\n };\n\n ctx.logger.info(\n `Processing ${allEntriesInTemplate.length} template files/directories with input values`,\n ctx.input.values,\n );\n\n const renderTemplate = await SecureTemplater.loadRenderer({\n cookiecutterCompat: ctx.input.cookiecutterCompat,\n templateFilters,\n templateGlobals,\n nunjucksConfigs: {\n trimBlocks: ctx.input.trimBlocks,\n lstripBlocks: ctx.input.lstripBlocks,\n },\n });\n\n for (const location of allEntriesInTemplate) {\n let renderContents: boolean;\n\n let localOutputPath = location;\n if (extension) {\n renderContents = extname(localOutputPath) === extension;\n if (renderContents) {\n localOutputPath = localOutputPath.slice(0, -extension.length);\n }\n // extension is mutual exclusive with copyWithoutRender/copyWithoutTemplating,\n // therefore the output path is always rendered.\n localOutputPath = renderTemplate(localOutputPath, context);\n } else {\n renderContents = !nonTemplatedEntries.has(location);\n // The logic here is a bit tangled because it depends on two variables.\n // If renderFilename is true, which means copyWithoutTemplating is used,\n // then the path is always rendered.\n // If renderFilename is false, which means copyWithoutRender is used,\n // then matched file/directory won't be processed, same as before.\n if (renderFilename) {\n localOutputPath = renderTemplate(localOutputPath, context);\n } else {\n localOutputPath = renderContents\n ? renderTemplate(localOutputPath, context)\n : localOutputPath;\n }\n }\n\n if (containsSkippedContent(localOutputPath)) {\n continue;\n }\n\n const outputPath = resolveSafeChildPath(outputDir, localOutputPath);\n if (fs.existsSync(outputPath) && !ctx.input.replace) {\n continue;\n }\n\n if (!renderContents && !extension) {\n ctx.logger.info(`Copying file/directory ${location} without processing.`);\n }\n\n if (location.endsWith('/')) {\n ctx.logger.info(`Writing directory ${location} to template output path.`);\n await fs.ensureDir(outputPath);\n } else {\n const inputFilePath = resolveSafeChildPath(templateDir, location);\n const stats = await fs.promises.lstat(inputFilePath);\n\n if (stats.isSymbolicLink() || (await isBinaryFile(inputFilePath))) {\n ctx.logger.info(\n `Copying file binary or symbolic link at ${location}, to template output path.`,\n );\n await fs.copy(inputFilePath, outputPath);\n } else {\n const statsObj = await fs.stat(inputFilePath);\n ctx.logger.info(\n `Writing file ${location} to template output path with mode ${statsObj.mode}.`,\n );\n const inputFileContents = await fs.readFile(inputFilePath, 'utf-8');\n await fs.outputFile(\n outputPath,\n renderContents\n ? renderTemplate(inputFileContents, context)\n : inputFileContents,\n { mode: statsObj.mode },\n );\n }\n }\n }\n ctx.logger.info(`Template result written to ${outputDir}`);\n}\n\nfunction resolveTemplateActionSettings<I extends TemplateActionInput>(\n ctx: ActionContext<I, any, any>,\n): {\n outputDir: string;\n copyOnlyPatterns?: string[];\n renderFilename: boolean;\n extension: string | false;\n} {\n const targetPath = ctx.input.targetPath ?? './';\n const outputDir = resolveSafeChildPath(ctx.workspacePath, targetPath);\n\n const copyOnlyPatterns = ctx.input.copyWithoutTemplating;\n const renderFilename = true;\n\n if (copyOnlyPatterns && !Array.isArray(copyOnlyPatterns)) {\n throw new InputError(\n 'Fetch action input copyWithoutTemplating must be an Array',\n );\n }\n if (\n ctx.input.templateFileExtension &&\n (copyOnlyPatterns || ctx.input.cookiecutterCompat)\n ) {\n throw new InputError(\n 'Fetch action input extension incompatible with copyWithoutTemplating and cookiecutterCompat',\n );\n }\n let extension: string | false = false;\n if (ctx.input.templateFileExtension) {\n extension =\n ctx.input.templateFileExtension === true\n ? '.njk'\n : ctx.input.templateFileExtension;\n if (!extension.startsWith('.')) {\n extension = `.${extension}`;\n }\n }\n return {\n outputDir,\n copyOnlyPatterns,\n renderFilename,\n extension,\n };\n}\n\nfunction containsSkippedContent(localOutputPath: string): boolean {\n // if the path is empty means that there is a file skipped in the root\n // if the path starts with a separator it means that the root directory has been skipped\n // if the path includes // means that there is a subdirectory skipped\n // All paths returned are considered with / separator because of globby returning the linux separator for all os'.\n return (\n localOutputPath === '' ||\n localOutputPath.startsWith('/') ||\n localOutputPath.includes('//')\n );\n}\n"],"names":["convertFiltersToRecord","createDefaultFilters","isChildPath","InputError","globby","SecureTemplater","extname","resolveSafeChildPath","fs","isBinaryFile"],"mappings":";;;;;;;;;;;;;;;;;AA6CA,eAAsB,4BAEpB,OAMC,EAAA;AACD,EAAM,MAAA;AAAA,IACJ,eAAA;AAAA,IACA,YAAA;AAAA,IACA,yBAAA;AAAA,IACA,yBAA2B,EAAA,eAAA;AAAA,IAC3B;AAAA,GACE,GAAA,OAAA;AAEJ,EAAA,MAAM,eAAkB,GAAA;AAAA,IACtB,GAAGA,iCAAuB,CAAAC,yCAAA,CAAqB,EAAE,YAAA,EAAc,CAAC,CAAA;AAAA,IAChE,GAAG;AAAA,GACL;AAEA,EAAA,MAAM,EAAE,SAAW,EAAA,gBAAA,EAAkB,gBAAgB,SAAU,EAAA,GAC7D,8BAA8B,GA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18
18
  input: {
19
- type: "object",
20
- required: ["url", "targetPath"],
21
- properties: {
22
- url: {
23
- title: "Fetch URL",
24
- description: "Relative path or absolute URL pointing to the single file to fetch.",
25
- type: "string"
26
- },
27
- targetPath: {
28
- title: "Target Path",
29
- description: "Target path within the working directory to download the file as.",
30
- type: "string"
31
- },
32
- values: {
33
- title: "Template Values",
34
- description: "Values to pass on to the templating engine",
35
- type: "object"
36
- },
37
- cookiecutterCompat: {
38
- title: "Cookiecutter compatibility mode",
39
- description: "Enable features to maximise compatibility with templates built for fetch:cookiecutter",
40
- type: "boolean"
41
- },
42
- replace: {
43
- title: "Replace file",
44
- description: "If set, replace file in targetPath instead of overwriting existing one.",
45
- type: "boolean"
46
- },
47
- token: {
48
- title: "Token",
49
- description: "An optional token to use for authentication when reading the resources.",
50
- type: "string"
51
- }
52
- }
19
+ url: (z) => z.string({
20
+ description: "Relative path or absolute URL pointing to the single file to fetch."
21
+ }),
22
+ targetPath: (z) => z.string({
23
+ description: "Target path within the working directory to download the file as."
24
+ }),
25
+ values: (z) => z.record(z.any(), {
26
+ description: "Values to pass on to the templating engine"
27
+ }).optional(),
28
+ cookiecutterCompat: (z) => z.boolean({
29
+ description: "Enable features to maximise compatibility with templates built for fetch:cookiecutter"
30
+ }).optional(),
31
+ replace: (z) => z.boolean({
32
+ description: "If set, replace file in targetPath instead of overwriting existing one."
33
+ }).optional(),
34
+ trimBlocks: (z) => z.boolean({
35
+ description: "If set, the first newline after a block is removed (block, not variable tag)."
36
+ }).optional(),
37
+ lstripBlocks: (z) => z.boolean({
38
+ description: "If set, leading spaces and tabs are stripped from the start of a line to a block."
39
+ }).optional(),
40
+ token: (z) => z.string({
41
+ description: "An optional token to use for authentication when reading the resources."
42
+ }).optional()
53
43
  }
54
44
  },
55
45
  supportsDryRun: true,
@@ -1 +1 @@
1
- {"version":3,"file":"templateFile.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/templateFile.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { UrlReaderService } from '@backstage/backend-plugin-api';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n createTemplateAction,\n fetchFile,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport path from 'path';\nimport { examples } from './templateFile.examples';\nimport { createTemplateFileActionHandler } from './templateFileActionHandler';\n\n/**\n * Downloads a single file and templates variables into file.\n * Then places the result in the workspace, or optionally in a subdirectory\n * specified by the 'targetPath' input option.\n * @public\n */\nexport function createFetchTemplateFileAction(options: {\n reader: UrlReaderService;\n integrations: ScmIntegrations;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n}) {\n return createTemplateAction<{\n url: string;\n targetPath: string;\n values: any;\n cookiecutterCompat?: boolean;\n replace?: boolean;\n trimBlocks?: boolean;\n lstripBlocks?: boolean;\n token?: string;\n }>({\n id: 'fetch:template:file',\n description: 'Downloads single file and places it in the workspace.',\n examples,\n schema: {\n input: {\n type: 'object',\n required: ['url', 'targetPath'],\n properties: {\n url: {\n title: 'Fetch URL',\n description:\n 'Relative path or absolute URL pointing to the single file to fetch.',\n type: 'string',\n },\n targetPath: {\n title: 'Target Path',\n description:\n 'Target path within the working directory to download the file as.',\n type: 'string',\n },\n values: {\n title: 'Template Values',\n description: 'Values to pass on to the templating engine',\n type: 'object',\n },\n cookiecutterCompat: {\n title: 'Cookiecutter compatibility mode',\n description:\n 'Enable features to maximise compatibility with templates built for fetch:cookiecutter',\n type: 'boolean',\n },\n replace: {\n title: 'Replace file',\n description:\n 'If set, replace file in targetPath instead of overwriting existing one.',\n type: 'boolean',\n },\n token: {\n title: 'Token',\n description:\n 'An optional token to use for authentication when reading the resources.',\n type: 'string',\n },\n },\n },\n },\n supportsDryRun: true,\n handler: ctx =>\n createTemplateFileActionHandler({\n ctx,\n resolveTemplateFile: async () => {\n ctx.logger.info('Fetching template file content from remote URL');\n\n const workDir = await ctx.createTemporaryDirectory();\n // Write to a tmp file, render the template, then copy to workspace.\n const tmpFilePath = path.join(workDir, 'tmp');\n\n await fetchFile({\n baseUrl: ctx.templateInfo?.baseUrl,\n fetchUrl: ctx.input.url,\n outputPath: tmpFilePath,\n token: ctx.input.token,\n ...options,\n });\n return tmpFilePath;\n },\n ...options,\n }),\n });\n}\n"],"names":["createTemplateAction","examples","createTemplateFileActionHandler","path","fetchFile"],"mappings":";;;;;;;;;;;AAkCO,SAAS,8BAA8B,OAK3C,EAAA;AACD,EAAA,OAAOA,yCASJ,CAAA;AAAA,IACD,EAAI,EAAA,qBAAA;AAAA,IACJ,WAAa,EAAA,uDAAA;AAAA,cACbC,8BAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,IAAM,EAAA,QAAA;AAAA,QACN,QAAA,EAAU,CAAC,KAAA,EAAO,YAAY,CAAA;AAAA,QAC9B,UAAY,EAAA;AAAA,UACV,GAAK,EAAA;AAAA,YACH,KAAO,EAAA,WAAA;AAAA,YACP,WACE,EAAA,qEAAA;AAAA,YACF,IAAM,EAAA;AAAA,WACR;AAAA,UACA,UAAY,EAAA;AAAA,YACV,KAAO,EAAA,aAAA;AAAA,YACP,WACE,EAAA,mEAAA;AAAA,YACF,IAAM,EAAA;AAAA,WACR;AAAA,UACA,MAAQ,EAAA;AAAA,YACN,KAAO,EAAA,iBAAA;AAAA,YACP,WAAa,EAAA,4CAAA;AAAA,YACb,IAAM,EAAA;AAAA,WACR;AAAA,UACA,kBAAoB,EAAA;AAAA,YAClB,KAAO,EAAA,iCAAA;AAAA,YACP,WACE,EAAA,uFAAA;AAAA,YACF,IAAM,EAAA;AAAA,WACR;AAAA,UACA,OAAS,EAAA;AAAA,YACP,KAAO,EAAA,cAAA;AAAA,YACP,WACE,EAAA,yEAAA;AAAA,YACF,IAAM,EAAA;AAAA,WACR;AAAA,UACA,KAAO,EAAA;AAAA,YACL,KAAO,EAAA,OAAA;AAAA,YACP,WACE,EAAA,yEAAA;AAAA,YACF,IAAM,EAAA;AAAA;AACR;AACF;AACF,KACF;AAAA,IACA,cAAgB,EAAA,IAAA;AAAA,IAChB,OAAA,EAAS,SACPC,yDAAgC,CAAA;AAAA,MAC9B,GAAA;AAAA,MACA,qBAAqB,YAAY;AAC/B,QAAI,GAAA,CAAA,MAAA,CAAO,KAAK,gDAAgD,CAAA;AAEhE,QAAM,MAAA,OAAA,GAAU,MAAM,GAAA,CAAI,wBAAyB,EAAA;AAEnD,QAAA,MAAM,WAAc,GAAAC,qBAAA,CAAK,IAAK,CAAA,OAAA,EAAS,KAAK,CAAA;AAE5C,QAAA,MAAMC,8BAAU,CAAA;AAAA,UACd,OAAA,EAAS,IAAI,YAAc,EAAA,OAAA;AAAA,UAC3B,QAAA,EAAU,IAAI,KAAM,CAAA,GAAA;AAAA,UACpB,UAAY,EAAA,WAAA;AAAA,UACZ,KAAA,EAAO,IAAI,KAAM,CAAA,KAAA;AAAA,UACjB,GAAG;AAAA,SACJ,CAAA;AACD,QAAO,OAAA,WAAA;AAAA,OACT;AAAA,MACA,GAAG;AAAA,KACJ;AAAA,GACJ,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"templateFile.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/templateFile.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { UrlReaderService } from '@backstage/backend-plugin-api';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n createTemplateAction,\n fetchFile,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport path from 'path';\nimport { examples } from './templateFile.examples';\nimport { createTemplateFileActionHandler } from './templateFileActionHandler';\n\n/**\n * Downloads a single file and templates variables into file.\n * Then places the result in the workspace, or optionally in a subdirectory\n * specified by the 'targetPath' input option.\n * @public\n */\nexport function createFetchTemplateFileAction(options: {\n reader: UrlReaderService;\n integrations: ScmIntegrations;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n}) {\n return createTemplateAction({\n id: 'fetch:template:file',\n description: 'Downloads single file and places it in the workspace.',\n examples,\n schema: {\n input: {\n url: z =>\n z.string({\n description:\n 'Relative path or absolute URL pointing to the single file to fetch.',\n }),\n targetPath: z =>\n z.string({\n description:\n 'Target path within the working directory to download the file as.',\n }),\n values: z =>\n z\n .record(z.any(), {\n description: 'Values to pass on to the templating engine',\n })\n .optional(),\n cookiecutterCompat: z =>\n z\n .boolean({\n description:\n 'Enable features to maximise compatibility with templates built for fetch:cookiecutter',\n })\n .optional(),\n replace: z =>\n z\n .boolean({\n description:\n 'If set, replace file in targetPath instead of overwriting existing one.',\n })\n .optional(),\n trimBlocks: z =>\n z\n .boolean({\n description:\n 'If set, the first newline after a block is removed (block, not variable tag).',\n })\n .optional(),\n lstripBlocks: z =>\n z\n .boolean({\n description:\n 'If set, leading spaces and tabs are stripped from the start of a line to a block.',\n })\n .optional(),\n token: z =>\n z\n .string({\n description:\n 'An optional token to use for authentication when reading the resources.',\n })\n .optional(),\n },\n },\n supportsDryRun: true,\n handler: ctx =>\n createTemplateFileActionHandler({\n ctx,\n resolveTemplateFile: async () => {\n ctx.logger.info('Fetching template file content from remote URL');\n\n const workDir = await ctx.createTemporaryDirectory();\n // Write to a tmp file, render the template, then copy to workspace.\n const tmpFilePath = path.join(workDir, 'tmp');\n\n await fetchFile({\n baseUrl: ctx.templateInfo?.baseUrl,\n fetchUrl: ctx.input.url,\n outputPath: tmpFilePath,\n token: ctx.input.token,\n ...options,\n });\n return tmpFilePath;\n },\n ...options,\n }),\n });\n}\n"],"names":["createTemplateAction","examples","createTemplateFileActionHandler","path","fetchFile"],"mappings":";;;;;;;;;;;AAkCO,SAAS,8BAA8B,OAK3C,EAAA;AACD,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,qBAAA;AAAA,IACJ,WAAa,EAAA,uDAAA;AAAA,cACbC,8BAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,GAAA,EAAK,CACH,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WACE,EAAA;AAAA,SACH,CAAA;AAAA,QACH,UAAA,EAAY,CACV,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WACE,EAAA;AAAA,SACH,CAAA;AAAA,QACH,QAAQ,CACN,CAAA,KAAA,CAAA,CACG,MAAO,CAAA,CAAA,CAAE,KAAO,EAAA;AAAA,UACf,WAAa,EAAA;AAAA,SACd,EACA,QAAS,EAAA;AAAA,QACd,kBAAA,EAAoB,CAClB,CAAA,KAAA,CAAA,CACG,OAAQ,CAAA;AAAA,UACP,WACE,EAAA;AAAA,SACH,EACA,QAAS,EAAA;AAAA,QACd,OAAA,EAAS,CACP,CAAA,KAAA,CAAA,CACG,OAAQ,CAAA;AAAA,UACP,WACE,EAAA;AAAA,SACH,EACA,QAAS,EAAA;AAAA,QACd,UAAA,EAAY,CACV,CAAA,KAAA,CAAA,CACG,OAAQ,CAAA;AAAA,UACP,WACE,EAAA;AAAA,SACH,EACA,QAAS,EAAA;AAAA,QACd,YAAA,EAAc,CACZ,CAAA,KAAA,CAAA,CACG,OAAQ,CAAA;AAAA,UACP,WACE,EAAA;AAAA,SACH,EACA,QAAS,EAAA;AAAA,QACd,KAAA,EAAO,CACL,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WACE,EAAA;AAAA,SACH,EACA,QAAS;AAAA;AAChB,KACF;AAAA,IACA,cAAgB,EAAA,IAAA;AAAA,IAChB,OAAA,EAAS,SACPC,yDAAgC,CAAA;AAAA,MAC9B,GAAA;AAAA,MACA,qBAAqB,YAAY;AAC/B,QAAI,GAAA,CAAA,MAAA,CAAO,KAAK,gDAAgD,CAAA;AAEhE,QAAM,MAAA,OAAA,GAAU,MAAM,GAAA,CAAI,wBAAyB,EAAA;AAEnD,QAAA,MAAM,WAAc,GAAAC,qBAAA,CAAK,IAAK,CAAA,OAAA,EAAS,KAAK,CAAA;AAE5C,QAAA,MAAMC,8BAAU,CAAA;AAAA,UACd,OAAA,EAAS,IAAI,YAAc,EAAA,OAAA;AAAA,UAC3B,QAAA,EAAU,IAAI,KAAM,CAAA,GAAA;AAAA,UACpB,UAAY,EAAA,WAAA;AAAA,UACZ,KAAA,EAAO,IAAI,KAAM,CAAA,KAAA;AAAA,UACjB,GAAG;AAAA,SACJ,CAAA;AACD,QAAO,OAAA,WAAA;AAAA,OACT;AAAA,MACA,GAAG;AAAA,KACJ;AAAA,GACJ,CAAA;AACH;;;;"}
@@ -19,18 +19,9 @@ const createFilesystemDeleteAction = () => {
19
19
  examples: delete_examples.examples,
20
20
  schema: {
21
21
  input: {
22
- required: ["files"],
23
- type: "object",
24
- properties: {
25
- files: {
26
- title: "Files",
27
- description: "A list of files and directories that will be deleted",
28
- type: "array",
29
- items: {
30
- type: "string"
31
- }
32
- }
33
- }
22
+ files: (z) => z.array(z.string(), {
23
+ description: "A list of files and directories that will be deleted"
24
+ })
34
25
  }
35
26
  },
36
27
  supportsDryRun: true,
@@ -1 +1 @@
1
- {"version":3,"file":"delete.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/filesystem/delete.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { InputError } from '@backstage/errors';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport fs from 'fs-extra';\nimport globby from 'globby';\nimport { examples } from './delete.examples';\n\n/**\n * Creates new action that enables deletion of files and directories in the workspace.\n * @public\n */\nexport const createFilesystemDeleteAction = () => {\n return createTemplateAction<{ files: string[] }>({\n id: 'fs:delete',\n description: 'Deletes files and directories from the workspace',\n examples,\n schema: {\n input: {\n required: ['files'],\n type: 'object',\n properties: {\n files: {\n title: 'Files',\n description: 'A list of files and directories that will be deleted',\n type: 'array',\n items: {\n type: 'string',\n },\n },\n },\n },\n },\n supportsDryRun: true,\n async handler(ctx) {\n if (!Array.isArray(ctx.input?.files)) {\n throw new InputError('files must be an Array');\n }\n\n for (const file of ctx.input.files) {\n // globby cannot handle backslash file separators\n const safeFilepath = resolveSafeChildPath(\n ctx.workspacePath,\n file,\n ).replace(/\\\\/g, '/');\n const resolvedPaths = await globby(safeFilepath, {\n cwd: ctx.workspacePath,\n absolute: true,\n dot: true,\n });\n\n for (const filepath of resolvedPaths) {\n try {\n await fs.remove(filepath);\n ctx.logger.info(`File ${filepath} deleted successfully`);\n } catch (err) {\n ctx.logger.error(`Failed to delete file ${filepath}:`, err);\n throw err;\n }\n }\n }\n },\n });\n};\n"],"names":["createTemplateAction","examples","InputError","resolveSafeChildPath","globby","fs"],"mappings":";;;;;;;;;;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AAA,EAAA,QAAQ,CAAuB,qBAAA,CAAA,CAAA;AAAA,mBAChD,GAAK,EAAA;AACZ,YAAA,GAAA,CAAI,MAAO,CAAA,KAAA,CAAM,CAAyB,sBAAA,EAAA,QAAQ,KAAK,GAAG,CAAA;AAC1D,YAAM,MAAA,GAAA;AAAA;AACR;AACF;AACF;AACF,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"delete.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/filesystem/delete.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { InputError } from '@backstage/errors';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport fs from 'fs-extra';\nimport globby from 'globby';\nimport { examples } from './delete.examples';\n\n/**\n * Creates new action that enables deletion of files and directories in the workspace.\n * @public\n */\nexport const createFilesystemDeleteAction = () => {\n return createTemplateAction({\n id: 'fs:delete',\n description: 'Deletes files and directories from the workspace',\n examples,\n schema: {\n input: {\n files: z =>\n z.array(z.string(), {\n description: 'A list of files and directories that will be deleted',\n }),\n },\n },\n supportsDryRun: true,\n async handler(ctx) {\n if (!Array.isArray(ctx.input?.files)) {\n throw new InputError('files must be an Array');\n }\n\n for (const file of ctx.input.files) {\n // globby cannot handle backslash file separators\n const safeFilepath = resolveSafeChildPath(\n ctx.workspacePath,\n file,\n ).replace(/\\\\/g, '/');\n const resolvedPaths = await globby(safeFilepath, {\n cwd: ctx.workspacePath,\n absolute: true,\n dot: true,\n });\n\n for (const filepath of resolvedPaths) {\n try {\n await fs.remove(filepath);\n ctx.logger.info(`File ${filepath} deleted successfully`);\n } catch (err) {\n ctx.logger.error(`Failed to delete file ${filepath}:`, err);\n throw err;\n }\n }\n }\n },\n });\n};\n"],"names":["createTemplateAction","examples","InputError","resolveSafeChildPath","globby","fs"],"mappings":";;;;;;;;;;;;;;AA2BO,MAAM,+BAA+B,MAAM;AAChD,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,WAAA;AAAA,IACJ,WAAa,EAAA,kDAAA;AAAA,cACbC,wBAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,OAAO,CACL,CAAA,KAAA,CAAA,CAAE,KAAM,CAAA,CAAA,CAAE,QAAU,EAAA;AAAA,UAClB,WAAa,EAAA;AAAA,SACd;AAAA;AACL,KACF;AAAA,IACA,cAAgB,EAAA,IAAA;AAAA,IAChB,MAAM,QAAQ,GAAK,EAAA;AACjB,MAAA,IAAI,CAAC,KAAM,CAAA,OAAA,CAAQ,GAAI,CAAA,KAAA,EAAO,KAAK,CAAG,EAAA;AACpC,QAAM,MAAA,IAAIC,kBAAW,wBAAwB,CAAA;AAAA;AAG/C,MAAW,KAAA,MAAA,IAAA,IAAQ,GAAI,CAAA,KAAA,CAAM,KAAO,EAAA;AAElC,QAAA,MAAM,YAAe,GAAAC,qCAAA;AAAA,UACnB,GAAI,CAAA,aAAA;AAAA,UACJ;AAAA,SACF,CAAE,OAAQ,CAAA,KAAA,EAAO,GAAG,CAAA;AACpB,QAAM,MAAA,aAAA,GAAgB,MAAMC,uBAAA,CAAO,YAAc,EAAA;AAAA,UAC/C,KAAK,GAAI,CAAA,aAAA;AAAA,UACT,QAAU,EAAA,IAAA;AAAA,UACV,GAAK,EAAA;AAAA,SACN,CAAA;AAED,QAAA,KAAA,MAAW,YAAY,aAAe,EAAA;AACpC,UAAI,IAAA;AACF,YAAM,MAAAC,mBAAA,CAAG,OAAO,QAAQ,CAAA;AACxB,YAAA,GAAA,CAAI,MAAO,CAAA,IAAA,CAAK,CAAQ,KAAA,EAAA,QAAQ,CAAuB,qBAAA,CAAA,CAAA;AAAA,mBAChD,GAAK,EAAA;AACZ,YAAA,GAAA,CAAI,MAAO,CAAA,KAAA,CAAM,CAAyB,sBAAA,EAAA,QAAQ,KAAK,GAAG,CAAA;AAC1D,YAAM,MAAA,GAAA;AAAA;AACR;AACF;AACF;AACF,GACD,CAAA;AACH;;;;"}
@@ -1,36 +1,36 @@
1
1
  'use strict';
2
2
 
3
3
  var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
4
- var z = require('zod');
5
4
  var backendPluginApi = require('@backstage/backend-plugin-api');
6
5
  var fs = require('fs/promises');
7
6
  var path = require('path');
7
+ var rename_examples = require('./rename.examples.cjs.js');
8
8
 
9
9
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
10
10
 
11
- var z__default = /*#__PURE__*/_interopDefaultCompat(z);
12
11
  var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
13
12
  var path__default = /*#__PURE__*/_interopDefaultCompat(path);
14
13
 
15
- const contentSchema = z__default.default.object({
16
- name: z__default.default.string().describe("Name of the file or directory"),
17
- path: z__default.default.string().describe("path to the file or directory relative to the workspace"),
18
- fullPath: z__default.default.string().describe("full path to the file or directory")
14
+ const contentSchema = (z) => z.object({
15
+ name: z.string().describe("Name of the file or directory"),
16
+ path: z.string().describe("path to the file or directory relative to the workspace"),
17
+ fullPath: z.string().describe("full path to the file or directory")
19
18
  });
20
19
  const createFilesystemReadDirAction = () => {
21
20
  return pluginScaffolderNode.createTemplateAction({
22
21
  id: "fs:readdir",
23
22
  description: "Reads files and directories from the workspace",
24
23
  supportsDryRun: true,
24
+ examples: rename_examples.examples,
25
25
  schema: {
26
- input: z__default.default.object({
27
- paths: z__default.default.array(z__default.default.string().min(1)),
28
- recursive: z__default.default.boolean().default(false)
29
- }),
30
- output: z__default.default.object({
31
- files: z__default.default.array(contentSchema),
32
- folders: z__default.default.array(contentSchema)
33
- })
26
+ input: {
27
+ paths: (z) => z.array(z.string().min(1)),
28
+ recursive: (z) => z.boolean().default(false)
29
+ },
30
+ output: {
31
+ files: (z) => z.array(contentSchema(z)),
32
+ folders: (z) => z.array(contentSchema(z))
33
+ }
34
34
  },
35
35
  async handler(ctx) {
36
36
  const files = [];
@@ -1 +1 @@
1
- {"version":3,"file":"read.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/filesystem/read.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport z from 'zod';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport fs from 'fs/promises';\nimport path from 'path';\n\nconst contentSchema = z.object({\n name: z.string().describe('Name of the file or directory'),\n path: z\n .string()\n .describe('path to the file or directory relative to the workspace'),\n fullPath: z.string().describe('full path to the file or directory'),\n});\ntype Content = z.infer<typeof contentSchema>;\n\n/**\n * Creates new action that enables reading directories in the workspace.\n * @public\n */\nexport const createFilesystemReadDirAction = () => {\n return createTemplateAction({\n id: 'fs:readdir',\n description: 'Reads files and directories from the workspace',\n supportsDryRun: true,\n schema: {\n input: z.object({\n paths: z.array(z.string().min(1)),\n recursive: z.boolean().default(false),\n }),\n output: z.object({\n files: z.array(contentSchema),\n folders: z.array(contentSchema),\n }),\n },\n async handler(ctx) {\n const files: Content[] = [];\n const folders: Content[] = [];\n\n for (const localPath of ctx.input.paths) {\n const fullWorkspacePath = resolveSafeChildPath(\n ctx.workspacePath,\n localPath,\n );\n const content = await fs.readdir(fullWorkspacePath, {\n recursive: ctx.input.recursive,\n withFileTypes: true,\n });\n for (const dirent of content) {\n const fullPath = path.join(dirent.parentPath, dirent.name);\n const element = {\n name: dirent.name,\n path: path.relative(ctx.workspacePath, fullPath),\n fullPath,\n };\n if (dirent.isDirectory()) {\n folders.push(element);\n } else {\n files.push(element);\n }\n }\n }\n\n ctx.output('files', files);\n ctx.output('folders', folders);\n },\n });\n};\n"],"names":["z","createTemplateAction","resolveSafeChildPath","fs","path"],"mappings":";;;;;;;;;;;;;;AAqBA,MAAM,aAAA,GAAgBA,mBAAE,MAAO,CAAA;AAAA,EAC7B,IAAM,EAAAA,kBAAA,CAAE,MAAO,EAAA,CAAE,SAAS,+BAA+B,CAAA;AAAA,EACzD,IAAM,EAAAA,kBAAA,CACH,MAAO,EAAA,CACP,SAAS,yDAAyD,CAAA;AAAA,EACrE,QAAU,EAAAA,kBAAA,CAAE,MAAO,EAAA,CAAE,SAAS,oCAAoC;AACpE,CAAC,CAAA;AAOM,MAAM,gCAAgC,MAAM;AACjD,EAAA,OAAOC,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,YAAA;AAAA,IACJ,WAAa,EAAA,gDAAA;AAAA,IACb,cAAgB,EAAA,IAAA;AAAA,IAChB,MAAQ,EAAA;AAAA,MACN,KAAA,EAAOD,mBAAE,MAAO,CAAA;AAAA,QACd,KAAA,EAAOA,mBAAE,KAAM,CAAAA,kBAAA,CAAE,QAAS,CAAA,GAAA,CAAI,CAAC,CAAC,CAAA;AAAA,QAChC,SAAW,EAAAA,kBAAA,CAAE,OAAQ,EAAA,CAAE,QAAQ,KAAK;AAAA,OACrC,CAAA;AAAA,MACD,MAAA,EAAQA,mBAAE,MAAO,CAAA;AAAA,QACf,KAAA,EAAOA,kBAAE,CAAA,KAAA,CAAM,aAAa,CAAA;AAAA,QAC5B,OAAA,EAASA,kBAAE,CAAA,KAAA,CAAM,aAAa;AAAA,OAC/B;AAAA,KACH;AAAA,IACA,MAAM,QAAQ,GAAK,EAAA;AACjB,MAAA,MAAM,QAAmB,EAAC;AAC1B,MAAA,MAAM,UAAqB,EAAC;AAE5B,MAAW,KAAA,MAAA,SAAA,IAAa,GAAI,CAAA,KAAA,CAAM,KAAO,EAAA;AACvC,QAAA,MAAM,iBAAoB,GAAAE,qCAAA;AAAA,UACxB,GAAI,CAAA,aAAA;AAAA,UACJ;AAAA,SACF;AACA,QAAA,MAAM,OAAU,GAAA,MAAMC,mBAAG,CAAA,OAAA,CAAQ,iBAAmB,EAAA;AAAA,UAClD,SAAA,EAAW,IAAI,KAAM,CAAA,SAAA;AAAA,UACrB,aAAe,EAAA;AAAA,SAChB,CAAA;AACD,QAAA,KAAA,MAAW,UAAU,OAAS,EAAA;AAC5B,UAAA,MAAM,WAAWC,qBAAK,CAAA,IAAA,CAAK,MAAO,CAAA,UAAA,EAAY,OAAO,IAAI,CAAA;AACzD,UAAA,MAAM,OAAU,GAAA;AAAA,YACd,MAAM,MAAO,CAAA,IAAA;AAAA,YACb,IAAM,EAAAA,qBAAA,CAAK,QAAS,CAAA,GAAA,CAAI,eAAe,QAAQ,CAAA;AAAA,YAC/C;AAAA,WACF;AACA,UAAI,IAAA,MAAA,CAAO,aAAe,EAAA;AACxB,YAAA,OAAA,CAAQ,KAAK,OAAO,CAAA;AAAA,WACf,MAAA;AACL,YAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAAA;AACpB;AACF;AAGF,MAAI,GAAA,CAAA,MAAA,CAAO,SAAS,KAAK,CAAA;AACzB,MAAI,GAAA,CAAA,MAAA,CAAO,WAAW,OAAO,CAAA;AAAA;AAC/B,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"read.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/filesystem/read.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport fs from 'fs/promises';\nimport path from 'path';\nimport { z as zod } from 'zod';\nimport { examples } from './rename.examples';\n\nconst contentSchema = (z: typeof zod) =>\n z.object({\n name: z.string().describe('Name of the file or directory'),\n path: z\n .string()\n .describe('path to the file or directory relative to the workspace'),\n fullPath: z.string().describe('full path to the file or directory'),\n });\n\ntype Content = zod.infer<ReturnType<typeof contentSchema>>;\n\n/**\n * Creates new action that enables reading directories in the workspace.\n * @public\n */\nexport const createFilesystemReadDirAction = () => {\n return createTemplateAction({\n id: 'fs:readdir',\n description: 'Reads files and directories from the workspace',\n supportsDryRun: true,\n examples,\n schema: {\n input: {\n paths: z => z.array(z.string().min(1)),\n recursive: z => z.boolean().default(false),\n },\n output: {\n files: z => z.array(contentSchema(z)),\n folders: z => z.array(contentSchema(z)),\n },\n },\n async handler(ctx) {\n const files: Content[] = [];\n const folders: Content[] = [];\n\n for (const localPath of ctx.input.paths) {\n const fullWorkspacePath = resolveSafeChildPath(\n ctx.workspacePath,\n localPath,\n );\n const content = await fs.readdir(fullWorkspacePath, {\n recursive: ctx.input.recursive,\n withFileTypes: true,\n });\n for (const dirent of content) {\n const fullPath = path.join(dirent.parentPath, dirent.name);\n const element = {\n name: dirent.name,\n path: path.relative(ctx.workspacePath, fullPath),\n fullPath,\n };\n if (dirent.isDirectory()) {\n folders.push(element);\n } else {\n files.push(element);\n }\n }\n }\n\n ctx.output('files', files);\n ctx.output('folders', folders);\n },\n });\n};\n"],"names":["createTemplateAction","examples","resolveSafeChildPath","fs","path"],"mappings":";;;;;;;;;;;;;AAsBA,MAAM,aAAgB,G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AAA,CAAQ,iBAAmB,EAAA;AAAA,UAClD,SAAA,EAAW,IAAI,KAAM,CAAA,SAAA;AAAA,UACrB,aAAe,EAAA;AAAA,SAChB,CAAA;AACD,QAAA,KAAA,MAAW,UAAU,OAAS,EAAA;AAC5B,UAAA,MAAM,WAAWC,qBAAK,CAAA,IAAA,CAAK,MAAO,CAAA,UAAA,EAAY,OAAO,IAAI,CAAA;AACzD,UAAA,MAAM,OAAU,GAAA;AAAA,YACd,MAAM,MAAO,CAAA,IAAA;AAAA,YACb,IAAM,EAAAA,qBAAA,CAAK,QAAS,CAAA,GAAA,CAAI,eAAe,QAAQ,CAAA;AAAA,YAC/C;AAAA,WACF;AACA,UAAI,IAAA,MAAA,CAAO,aAAe,EAAA;AACxB,YAAA,OAAA,CAAQ,KAAK,OAAO,CAAA;AAAA,WACf,MAAA;AACL,YAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAAA;AACpB;AACF;AAGF,MAAI,GAAA,CAAA,MAAA,CAAO,SAAS,KAAK,CAAA;AACzB,MAAI,GAAA,CAAA,MAAA,CAAO,WAAW,OAAO,CAAA;AAAA;AAC/B,GACD,CAAA;AACH;;;;"}
@@ -2,9 +2,9 @@
2
2
 
3
3
  var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
4
4
  var backendPluginApi = require('@backstage/backend-plugin-api');
5
- var errors = require('@backstage/errors');
6
5
  var fs = require('fs-extra');
7
6
  var rename_examples = require('./rename.examples.cjs.js');
7
+ var errors = require('@backstage/errors');
8
8
 
9
9
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
10
10
 
@@ -17,33 +17,22 @@ const createFilesystemRenameAction = () => {
17
17
  examples: rename_examples.examples,
18
18
  schema: {
19
19
  input: {
20
- required: ["files"],
21
- type: "object",
22
- properties: {
23
- files: {
24
- title: "Files",
25
- description: "A list of file and directory names that will be renamed",
26
- type: "array",
27
- items: {
28
- type: "object",
29
- required: ["from", "to"],
30
- properties: {
31
- from: {
32
- type: "string",
33
- title: "The source location of the file to be renamed"
34
- },
35
- to: {
36
- type: "string",
37
- title: "The destination of the new file"
38
- },
39
- overwrite: {
40
- type: "boolean",
41
- title: "Overwrite existing file or directory, default is false"
42
- }
43
- }
44
- }
20
+ files: (z) => z.array(
21
+ z.object({
22
+ from: z.string({
23
+ description: "The source location of the file to be renamed"
24
+ }),
25
+ to: z.string({
26
+ description: "The destination of the new file"
27
+ }),
28
+ overwrite: z.boolean({
29
+ description: "Overwrite existing file or directory, default is false"
30
+ }).optional()
31
+ }),
32
+ {
33
+ description: "A list of file and directory names that will be renamed"
45
34
  }
46
- }
35
+ )
47
36
  }
48
37
  },
49
38
  supportsDryRun: true,
@@ -1 +1 @@
1
- {"version":3,"file":"rename.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/filesystem/rename.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { InputError } from '@backstage/errors';\nimport fs from 'fs-extra';\nimport { examples } from './rename.examples';\n\n/**\n * Creates a new action that allows renames of files and directories in the workspace.\n * @public\n */\nexport const createFilesystemRenameAction = () => {\n return createTemplateAction<{\n files: Array<{\n from: string;\n to: string;\n overwrite?: boolean;\n }>;\n }>({\n id: 'fs:rename',\n description: 'Renames files and directories within the workspace',\n examples,\n schema: {\n input: {\n required: ['files'],\n type: 'object',\n properties: {\n files: {\n title: 'Files',\n description:\n 'A list of file and directory names that will be renamed',\n type: 'array',\n items: {\n type: 'object',\n required: ['from', 'to'],\n properties: {\n from: {\n type: 'string',\n title: 'The source location of the file to be renamed',\n },\n to: {\n type: 'string',\n title: 'The destination of the new file',\n },\n overwrite: {\n type: 'boolean',\n title:\n 'Overwrite existing file or directory, default is false',\n },\n },\n },\n },\n },\n },\n },\n supportsDryRun: true,\n async handler(ctx) {\n if (!Array.isArray(ctx.input?.files)) {\n throw new InputError('files must be an Array');\n }\n\n for (const file of ctx.input.files) {\n if (!file.from || !file.to) {\n throw new InputError('each file must have a from and to property');\n }\n\n const sourceFilepath = resolveSafeChildPath(\n ctx.workspacePath,\n file.from,\n );\n const destFilepath = resolveSafeChildPath(ctx.workspacePath, file.to);\n\n try {\n await fs.move(sourceFilepath, destFilepath, {\n overwrite: file.overwrite ?? false,\n });\n ctx.logger.info(\n `File ${sourceFilepath} renamed to ${destFilepath} successfully`,\n );\n } catch (err) {\n ctx.logger.error(\n `Failed to rename file ${sourceFilepath} to ${destFilepath}:`,\n err,\n );\n throw err;\n }\n }\n },\n });\n};\n"],"names":["createTemplateAction","examples","InputError","resolveSafeChildPath","fs"],"mappings":";;;;;;;;;;;;AA0BO,MAAM,+BAA+B,MAAM;AAChD,EAAA,OAAOA,yCAMJ,CAAA;AAAA,IACD,EAAI,EAAA,WAAA;AAAA,IACJ,WAAa,EAAA,oDAAA;AAAA,cACbC,wBAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,QAAA,EAAU,CAAC,OAAO,CAAA;AAAA,QAClB,IAAM,EAAA,QAAA;AAAA,QACN,UAAY,EAAA;AAAA,UACV,KAAO,EAAA;AAAA,YACL,KAAO,EAAA,OAAA;AAAA,YACP,WACE,EAAA,yDAAA;AAAA,YACF,IAAM,EAAA,OAAA;AAAA,YACN,KAAO,EAAA;AAAA,cACL,IAAM,EAAA,QAAA;AAAA,cACN,QAAA,EAAU,CAAC,MAAA,EAAQ,IAAI,CAAA;AAAA,cACvB,UAAY,EAAA;AAAA,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AA,KAAA;AAAA,YACT,CAAA,sBAAA,EAAyB,cAAc,CAAA,IAAA,EAAO,YAAY,CAAA,CAAA,CAAA;AAAA,YAC1D;AAAA,WACF;AACA,UAAM,MAAA,GAAA;AAAA;AACR;AACF;AACF,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"rename.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/filesystem/rename.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport fs from 'fs-extra';\nimport { examples } from './rename.examples';\nimport { InputError } from '@backstage/errors';\n\n/**\n * Creates a new action that allows renames of files and directories in the workspace.\n * @public\n */\nexport const createFilesystemRenameAction = () => {\n return createTemplateAction({\n id: 'fs:rename',\n description: 'Renames files and directories within the workspace',\n examples,\n schema: {\n input: {\n files: z =>\n z.array(\n z.object({\n from: z.string({\n description: 'The source location of the file to be renamed',\n }),\n to: z.string({\n description: 'The destination of the new file',\n }),\n overwrite: z\n .boolean({\n description:\n 'Overwrite existing file or directory, default is false',\n })\n .optional(),\n }),\n {\n description:\n 'A list of file and directory names that will be renamed',\n },\n ),\n },\n },\n supportsDryRun: true,\n async handler(ctx) {\n if (!Array.isArray(ctx.input?.files)) {\n throw new InputError('files must be an Array');\n }\n\n for (const file of ctx.input.files) {\n if (!file.from || !file.to) {\n throw new InputError('each file must have a from and to property');\n }\n const sourceFilepath = resolveSafeChildPath(\n ctx.workspacePath,\n file.from,\n );\n const destFilepath = resolveSafeChildPath(ctx.workspacePath, file.to);\n\n try {\n await fs.move(sourceFilepath, destFilepath, {\n overwrite: file.overwrite ?? false,\n });\n ctx.logger.info(\n `File ${sourceFilepath} renamed to ${destFilepath} successfully`,\n );\n } catch (err) {\n ctx.logger.error(\n `Failed to rename file ${sourceFilepath} to ${destFilepath}:`,\n err,\n );\n throw err;\n }\n }\n },\n });\n};\n"],"names":["createTemplateAction","examples","InputError","resolveSafeChildPath","fs"],"mappings":";;;;;;;;;;;;AA0BO,MAAM,+BAA+B,MAAM;AAChD,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,WAAA;AAAA,IACJ,WAAa,EAAA,oDAAA;AAAA,cACbC,wBAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,KAAA,EAAO,OACL,CAAE,CAAA,KAAA;AAAA,UACA,EAAE,MAAO,CAAA;AAAA,YACP,IAAA,EAAM,EAAE,MAAO,CAAA;AAAA,cACb,WAAa,EAAA;AAAA,aACd,CAAA;AAAA,YACD,EAAA,EAAI,EAAE,MAAO,CAAA;AAAA,cACX,WAAa,EAAA;AAAA,aACd,CAAA;AAAA,YACD,SAAA,EAAW,EACR,OAAQ,CAAA;AAAA,cACP,WACE,EAAA;AAAA,aACH,EACA,QAAS;AAAA,WACb,CAAA;AAAA,UACD;AAAA,YACE,WACE,EAAA;AAAA;AACJ;AACF;AACJ,KACF;AAAA,IACA,cAAgB,EAAA,IAAA;AAAA,IAChB,MAAM,QAAQ,GAAK,EAAA;AACjB,MAAA,IAAI,CAAC,KAAM,CAAA,OAAA,CAAQ,GAAI,CAAA,KAAA,EAAO,KAAK,CAAG,EAAA;AACpC,QAAM,MAAA,IAAIC,kBAAW,wBAAwB,CAAA;AAAA;AAG/C,MAAW,KAAA,MAAA,IAAA,IAAQ,GAAI,CAAA,KAAA,CAAM,KAAO,EAAA;AAClC,QAAA,IAAI,CAAC,IAAA,CAAK,IAAQ,IAAA,C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