@backstage/plugin-scaffolder-backend 2.0.0-next.1 → 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 (48) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/dist/ScaffolderPlugin.cjs.js +7 -16
  3. package/dist/ScaffolderPlugin.cjs.js.map +1 -1
  4. package/dist/index.cjs.js +0 -2
  5. package/dist/index.cjs.js.map +1 -1
  6. package/dist/index.d.ts +81 -95
  7. package/dist/scaffolder/actions/builtin/catalog/fetch.cjs.js +5 -11
  8. package/dist/scaffolder/actions/builtin/catalog/fetch.cjs.js.map +1 -1
  9. package/dist/scaffolder/actions/builtin/catalog/register.cjs.js +26 -62
  10. package/dist/scaffolder/actions/builtin/catalog/register.cjs.js.map +1 -1
  11. package/dist/scaffolder/actions/builtin/catalog/write.cjs.js +4 -5
  12. package/dist/scaffolder/actions/builtin/catalog/write.cjs.js.map +1 -1
  13. package/dist/scaffolder/actions/builtin/debug/log.cjs.js +4 -5
  14. package/dist/scaffolder/actions/builtin/debug/log.cjs.js.map +1 -1
  15. package/dist/scaffolder/actions/builtin/debug/wait.cjs.js +9 -15
  16. package/dist/scaffolder/actions/builtin/debug/wait.cjs.js.map +1 -1
  17. package/dist/scaffolder/actions/builtin/fetch/plain.cjs.js +9 -19
  18. package/dist/scaffolder/actions/builtin/fetch/plain.cjs.js.map +1 -1
  19. package/dist/scaffolder/actions/builtin/fetch/plainFile.cjs.js +9 -19
  20. package/dist/scaffolder/actions/builtin/fetch/plainFile.cjs.js.map +1 -1
  21. package/dist/scaffolder/actions/builtin/fetch/template.cjs.js +33 -55
  22. package/dist/scaffolder/actions/builtin/fetch/template.cjs.js.map +1 -1
  23. package/dist/scaffolder/actions/builtin/fetch/templateFile.cjs.js +24 -34
  24. package/dist/scaffolder/actions/builtin/fetch/templateFile.cjs.js.map +1 -1
  25. package/dist/scaffolder/actions/builtin/filesystem/delete.cjs.js +3 -12
  26. package/dist/scaffolder/actions/builtin/filesystem/delete.cjs.js.map +1 -1
  27. package/dist/scaffolder/actions/builtin/filesystem/read.cjs.js +14 -14
  28. package/dist/scaffolder/actions/builtin/filesystem/read.cjs.js.map +1 -1
  29. package/dist/scaffolder/actions/builtin/filesystem/rename.cjs.js +16 -27
  30. package/dist/scaffolder/actions/builtin/filesystem/rename.cjs.js.map +1 -1
  31. package/dist/scaffolder/dryrun/DecoratedActionsRegistry.cjs.js +2 -11
  32. package/dist/scaffolder/dryrun/DecoratedActionsRegistry.cjs.js.map +1 -1
  33. package/dist/scaffolder/dryrun/createDryRunner.cjs.js.map +1 -1
  34. package/dist/scaffolder/tasks/NunjucksWorkflowRunner.cjs.js +8 -15
  35. package/dist/scaffolder/tasks/NunjucksWorkflowRunner.cjs.js.map +1 -1
  36. package/dist/scaffolder/tasks/StorageTaskBroker.cjs.js.map +1 -1
  37. package/dist/scaffolder/tasks/TaskWorker.cjs.js.map +1 -1
  38. package/dist/service/helpers.cjs.js +4 -2
  39. package/dist/service/helpers.cjs.js.map +1 -1
  40. package/dist/service/router.cjs.js +18 -45
  41. package/dist/service/router.cjs.js.map +1 -1
  42. package/dist/service/rules.cjs.js +11 -11
  43. package/dist/service/rules.cjs.js.map +1 -1
  44. package/dist/util/templating.cjs.js +3 -3
  45. package/dist/util/templating.cjs.js.map +1 -1
  46. package/package.json +16 -17
  47. package/dist/scaffolder/actions/builtin/createBuiltinActions.cjs.js +0 -158
  48. package/dist/scaffolder/actions/builtin/createBuiltinActions.cjs.js.map +0 -1
@@ -16,40 +16,30 @@ function createFetchTemplateFileAction(options) {
16
16
  examples: templateFile_examples.examples,
17
17
  schema: {
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":";;;;;;;;;;;;;;AA2BO,MAAM,+BAA+B,MAAM;AAChD,EAAA,OAAOA,yCAA0C,CAAA;AAAA,IAC/C,EAAI,EAAA,WAAA;AAAA,IACJ,WAAa,EAAA,kDAAA;AAAA,cACbC,wBAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AA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R;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":";;;;;;;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,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,GAAA,CAAC,CACrB,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,EACP,IAAM,EAAA,CAAA,CAAE,MAAO,EAAA,CAAE,SAAS,+BAA+B,CAAA;AAAA,EACzD,IAAM,EAAA,CAAA,CACH,MAAO,EAAA,CACP,SAAS,yDAAyD,CAAA;AAAA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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,gBACV,IAAM,EAAA;AAAA,kBACJ,IAAM,EAAA,QAAA;AAAA,kBACN,KAAO,EAAA;AAAA,iBACT;AAAA,gBACA,EAAI,EAAA;AAAA,kBACF,IAAM,EAAA,QAAA;AAAA,kBACN,KAAO,EAAA;AAAA,iBACT;AAAA,gBACA,SAAW,EAA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ename.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,CAAC,KAAK,EAAI,EAAA;AAC1B,UAAM,MAAA,IAAIA,kBAAW,4CAA4C,CAAA;AAAA;AAEnE,QAAA,MAAM,cAAiB,GAAAC,qCAAA;AAAA,UACrB,GAAI,CAAA,aAAA;AAAA,UACJ,IAAK,CAAA;AAAA,SACP;AACA,QAAA,MAAM,YAAe,GAAAA,qCAAA,CAAqB,GAAI,CAAA,aAAA,EAAe,KAAK,EAAE,CAAA;AAEpE,QAAI,IAAA;AACF,UAAM,MAAAC,mBAAA,CAAG,IAAK,CAAA,cAAA,EAAgB,YAAc,EAAA;AAAA,YAC1C,SAAA,EAAW,KAAK,SAAa,IAAA;AAAA,WAC9B,CAAA;AACD,UAAA,GAAA,CAAI,MAAO,CAAA,IAAA;AAAA,YACT,CAAA,KAAA,EAAQ,cAAc,CAAA,YAAA,EAAe,YAAY,CAAA,aAAA;AAAA,WACnD;AAAA,iBACO,GAAK,EAAA;AACZ,UAAA,GAAA,CAAI,MAAO,CAAA,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;;;;"}
@@ -7,10 +7,8 @@ require('../actions/builtin/catalog/register.examples.cjs.js');
7
7
  require('fs-extra');
8
8
  require('yaml');
9
9
  require('@backstage/backend-plugin-api');
10
- require('zod');
11
10
  require('../actions/builtin/catalog/write.examples.cjs.js');
12
11
  require('../actions/builtin/catalog/fetch.examples.cjs.js');
13
- require('@backstage/integration');
14
12
  require('path');
15
13
  require('../actions/builtin/debug/log.examples.cjs.js');
16
14
  require('fs');
@@ -24,20 +22,13 @@ require('isbinaryfile');
24
22
  require('@backstage/plugin-scaffolder-node/alpha');
25
23
  require('../../lib/templating/filters/parseEntityRef/filter.cjs.js');
26
24
  require('../../lib/templating/filters/pick/filter.cjs.js');
25
+ require('zod');
27
26
  require('zod-to-json-schema');
28
27
  require('isolated-vm');
29
28
  require('../actions/builtin/fetch/templateFile.examples.cjs.js');
30
29
  require('../actions/builtin/filesystem/delete.examples.cjs.js');
31
30
  require('../actions/builtin/filesystem/rename.examples.cjs.js');
32
- require('../actions/builtin/filesystem/read.cjs.js');
33
- require('@backstage/plugin-scaffolder-backend-module-github');
34
- require('@backstage/plugin-scaffolder-backend-module-azure');
35
- require('@backstage/plugin-scaffolder-backend-module-bitbucket');
36
- require('@backstage/plugin-scaffolder-backend-module-bitbucket-cloud');
37
- require('@backstage/plugin-scaffolder-backend-module-bitbucket-server');
38
- require('@backstage/plugin-scaffolder-backend-module-gerrit');
39
- require('@backstage/plugin-scaffolder-backend-module-gitlab');
40
- require('@backstage/plugin-scaffolder-backend-module-gitea');
31
+ require('fs/promises');
41
32
  var TemplateActionRegistry = require('../actions/TemplateActionRegistry.cjs.js');
42
33
 
43
34
  class DecoratedActionsRegistry extends TemplateActionRegistry.TemplateActionRegistry {
@@ -1 +1 @@
1
- {"version":3,"file":"DecoratedActionsRegistry.cjs.js","sources":["../../../src/scaffolder/dryrun/DecoratedActionsRegistry.ts"],"sourcesContent":["/*\n * Copyright 2022 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 { TemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { TemplateActionRegistry } from '../actions';\n\n/** @internal */\nexport class DecoratedActionsRegistry extends TemplateActionRegistry {\n constructor(\n private readonly innerRegistry: TemplateActionRegistry,\n extraActions: Array<TemplateAction>,\n ) {\n super();\n for (const action of extraActions) {\n this.register(action);\n }\n }\n\n get(actionId: string): TemplateAction {\n try {\n return super.get(actionId);\n } catch {\n return this.innerRegistry.get(actionId);\n }\n }\n}\n"],"names":["TemplateActionRegistry"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBO,MAAM,iCAAiCA,6CAAuB,CAAA;AAAA,EACnE,WAAA,CACmB,eACjB,YACA,EAAA;AACA,IAAM,KAAA,EAAA;AAHW,IAAA,IAAA,CAAA,aAAA,GAAA,aAAA;AAIjB,IAAA,KAAA,MAAW,UAAU,YAAc,EAAA;AACjC,MAAA,IAAA,CAAK,SAAS,MAAM,CAAA;AAAA;AACtB;AACF,EAEA,IAAI,QAAkC,EAAA;AACpC,IAAI,IAAA;AACF,MAAO,OAAA,KAAA,CAAM,IAAI,QAAQ,CAAA;AAAA,KACnB,CAAA,MAAA;AACN,MAAO,OAAA,IAAA,CAAK,aAAc,CAAA,GAAA,CAAI,QAAQ,CAAA;AAAA;AACxC;AAEJ;;;;"}
1
+ {"version":3,"file":"DecoratedActionsRegistry.cjs.js","sources":["../../../src/scaffolder/dryrun/DecoratedActionsRegistry.ts"],"sourcesContent":["/*\n * Copyright 2022 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 { TemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { TemplateActionRegistry } from '../actions';\n\n/** @internal */\nexport class DecoratedActionsRegistry extends TemplateActionRegistry {\n constructor(\n private readonly innerRegistry: TemplateActionRegistry,\n extraActions: Array<TemplateAction>,\n ) {\n super();\n for (const action of extraActions) {\n this.register(action);\n }\n }\n\n get(actionId: string): TemplateAction {\n try {\n return super.get(actionId);\n } catch {\n return this.innerRegistry.get(actionId);\n }\n }\n}\n"],"names":["TemplateActionRegistry"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBO,MAAM,iCAAiCA,6CAAuB,CAAA;AAAA,EACnE,WAAA,CACmB,eACjB,YACA,EAAA;AACA,IAAM,KAAA,EAAA;AAHW,IAAA,IAAA,CAAA,aAAA,GAAA,aAAA;AAIjB,IAAA,KAAA,MAAW,UAAU,YAAc,EAAA;AACjC,MAAA,IAAA,CAAK,SAAS,MAAM,CAAA;AAAA;AACtB;AACF,EAEA,IAAI,QAAkC,EAAA;AACpC,IAAI,IAAA;AACF,MAAO,OAAA,KAAA,CAAM,IAAI,QAAQ,CAAA;AAAA,KACnB,CAAA,MAAA;AACN,MAAO,OAAA,IAAA,CAAK,aAAc,CAAA,GAAA,CAAI,QAAQ,CAAA;AAAA;AACxC;AAEJ;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"createDryRunner.cjs.js","sources":["../../../src/scaffolder/dryrun/createDryRunner.ts"],"sourcesContent":["/*\n * Copyright 2022 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 AuditorService,\n BackstageCredentials,\n} from '@backstage/backend-plugin-api';\nimport type { UserEntity } from '@backstage/catalog-model';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { PermissionEvaluator } from '@backstage/plugin-permission-common';\nimport { TaskSpec, TemplateInfo } from '@backstage/plugin-scaffolder-common';\nimport {\n createTemplateAction,\n deserializeDirectoryContents,\n SerializedFile,\n serializeDirectoryContents,\n TaskSecrets,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport { JsonObject } from '@backstage/types';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { v4 as uuid } from 'uuid';\nimport { Logger } from 'winston';\nimport { TemplateActionRegistry } from '../actions';\nimport { NunjucksWorkflowRunner } from '../tasks/NunjucksWorkflowRunner';\nimport { DecoratedActionsRegistry } from './DecoratedActionsRegistry';\n\ninterface DryRunInput {\n spec: TaskSpec;\n templateInfo: TemplateInfo;\n secrets?: TaskSecrets;\n directoryContents: SerializedFile[];\n credentials: BackstageCredentials;\n user?: {\n entity?: UserEntity;\n ref?: string;\n };\n}\n\ninterface DryRunResult {\n log: Array<{ body: JsonObject }>;\n directoryContents: SerializedFile[];\n output: JsonObject;\n}\n\n/** @internal */\nexport type TemplateTesterCreateOptions = {\n logger: Logger;\n auditor?: AuditorService;\n integrations: ScmIntegrations;\n actionRegistry: TemplateActionRegistry;\n workingDirectory: string;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n permissions?: PermissionEvaluator;\n};\n\n/**\n * Executes a dry-run of the provided template.\n *\n * The provided content will be extracted into a temporary directory\n * which is then use as the base for any relative file fetch paths.\n *\n * @internal\n */\nexport function createDryRunner(options: TemplateTesterCreateOptions) {\n return async function dryRun(input: DryRunInput): Promise<DryRunResult> {\n let contentPromise;\n\n const workflowRunner = new NunjucksWorkflowRunner({\n ...options,\n actionRegistry: new DecoratedActionsRegistry(options.actionRegistry, [\n createTemplateAction({\n id: 'dry-run:extract',\n supportsDryRun: true,\n async handler(ctx) {\n contentPromise = serializeDirectoryContents(ctx.workspacePath);\n await contentPromise.catch(() => {});\n },\n }),\n ]),\n });\n\n // Extracting contentsPath and dryRunId from the baseUrl\n const baseUrl = input.templateInfo.baseUrl;\n if (!baseUrl) {\n throw new Error('baseUrl is required');\n }\n const basePath = fileURLToPath(new URL(baseUrl));\n const contentsPath = path.dirname(basePath);\n const dryRunId = uuid();\n\n const log = new Array<{ body: JsonObject }>();\n\n try {\n await deserializeDirectoryContents(contentsPath, input.directoryContents);\n\n const abortSignal = new AbortController().signal;\n const result = await workflowRunner.execute({\n taskId: dryRunId,\n spec: {\n ...input.spec,\n steps: [\n ...input.spec.steps,\n {\n id: dryRunId,\n name: 'dry-run:extract',\n action: 'dry-run:extract',\n },\n ],\n templateInfo: input.templateInfo,\n },\n secrets: input.secrets,\n getInitiatorCredentials: () => Promise.resolve(input.credentials),\n // No need to update this at the end of the run, so just hard-code it\n done: false,\n isDryRun: true,\n getWorkspaceName: async () => `dry-run-${dryRunId}`,\n cancelSignal: abortSignal,\n async emitLog(message: string, logMetadata?: JsonObject) {\n if (logMetadata?.stepId === dryRunId) {\n return;\n }\n log.push({\n body: {\n ...logMetadata,\n message,\n },\n });\n },\n complete: async () => {\n throw new Error('Not implemented');\n },\n });\n\n if (!contentPromise) {\n throw new Error('Content extraction step was skipped');\n }\n const directoryContents = await contentPromise;\n\n return {\n log,\n directoryContents,\n output: result.output,\n };\n } finally {\n await fs.remove(contentsPath);\n }\n };\n}\n"],"names":["NunjucksWorkflowRunner","DecoratedActionsRegistry","createTemplateAction","serializeDirectoryContents","fileURLToPath","path","uuid","deserializeDirectoryContents","fs"],"mappings":";;;;;;;;;;;;;;;AAiFO,SAAS,gBAAgB,OAAsC,EAAA;AACpE,EAAO,OAAA,eAAe,OAAO,KAA2C,EAAA;AACtE,IAAI,IAAA,cAAA;AAEJ,IAAM,MAAA,cAAA,GAAiB,IAAIA,6CAAuB,CAAA;AAAA,MAChD,GAAG,OAAA;AAAA,MACH,cAAgB,EAAA,IAAIC,iDAAyB,CAAA,OAAA,CAAQ,cAAgB,EAAA;AAAA,QACnEC,yCAAqB,CAAA;AAAA,UACnB,EAAI,EAAA,iBAAA;AAAA,UACJ,cAAgB,EAAA,IAAA;AAAA,UAChB,MAAM,QAAQ,GAAK,EAAA;AACjB,YAAiB,cAAA,GAAAC,+CAAA,CAA2B,IAAI,aAAa,CAAA;AAC7D,YAAM,MAAA,cAAA,CAAe,MAAM,MAAM;AAAA,aAAE,CAAA;AAAA;AACrC,SACD;AAAA,OACF;AAAA,KACF,CAAA;AAGD,IAAM,MAAA,OAAA,GAAU,MAAM,YAAa,CAAA,OAAA;AACnC,IAAA,IAAI,CAAC,O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AA,GAAA,CAAI,IAAK,CAAA;AAAA,YACP,IAAM,EAAA;AAAA,cACJ,GAAG,WAAA;AAAA,cACH;AAAA;AACF,WACD,CAAA;AAAA,SACH;AAAA,QACA,UAAU,YAAY;AACpB,UAAM,MAAA,IAAI,MAAM,iBAAiB,CAAA;AAAA;AACnC,OACD,CAAA;AAED,MAAA,IAAI,CAAC,cAAgB,EAAA;AACnB,QAAM,MAAA,IAAI,MAAM,qCAAqC,CAAA;AAAA;AAEvD,MAAA,MAAM,oBAAoB,MAAM,cAAA;AAEhC,MAAO,OAAA;AAAA,QACL,GAAA;AAAA,QACA,iBAAA;AAAA,QACA,QAAQ,MAAO,CAAA;AAAA,OACjB;AAAA,KACA,SAAA;AACA,MAAM,MAAAC,mBAAA,CAAG,OAAO,YAAY,CAAA;AAAA;AAC9B,GACF;AACF;;;;"}
1
+ {"version":3,"file":"createDryRunner.cjs.js","sources":["../../../src/scaffolder/dryrun/createDryRunner.ts"],"sourcesContent":["/*\n * Copyright 2022 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 AuditorService,\n BackstageCredentials,\n LoggerService,\n} from '@backstage/backend-plugin-api';\nimport type { UserEntity } from '@backstage/catalog-model';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { PermissionEvaluator } from '@backstage/plugin-permission-common';\nimport { TaskSpec, TemplateInfo } from '@backstage/plugin-scaffolder-common';\nimport {\n createTemplateAction,\n deserializeDirectoryContents,\n SerializedFile,\n serializeDirectoryContents,\n TaskSecrets,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport { JsonObject } from '@backstage/types';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { v4 as uuid } from 'uuid';\nimport { TemplateActionRegistry } from '../actions';\nimport { NunjucksWorkflowRunner } from '../tasks/NunjucksWorkflowRunner';\nimport { DecoratedActionsRegistry } from './DecoratedActionsRegistry';\n\ninterface DryRunInput {\n spec: TaskSpec;\n templateInfo: TemplateInfo;\n secrets?: TaskSecrets;\n directoryContents: SerializedFile[];\n credentials: BackstageCredentials;\n user?: {\n entity?: UserEntity;\n ref?: string;\n };\n}\n\ninterface DryRunResult {\n log: Array<{ body: JsonObject }>;\n directoryContents: SerializedFile[];\n output: JsonObject;\n}\n\n/** @internal */\nexport type TemplateTesterCreateOptions = {\n logger: LoggerService;\n auditor?: AuditorService;\n integrations: ScmIntegrations;\n actionRegistry: TemplateActionRegistry;\n workingDirectory: string;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n permissions?: PermissionEvaluator;\n};\n\n/**\n * Executes a dry-run of the provided template.\n *\n * The provided content will be extracted into a temporary directory\n * which is then use as the base for any relative file fetch paths.\n *\n * @internal\n */\nexport function createDryRunner(options: TemplateTesterCreateOptions) {\n return async function dryRun(input: DryRunInput): Promise<DryRunResult> {\n let contentPromise;\n\n const workflowRunner = new NunjucksWorkflowRunner({\n ...options,\n actionRegistry: new DecoratedActionsRegistry(options.actionRegistry, [\n createTemplateAction({\n id: 'dry-run:extract',\n supportsDryRun: true,\n async handler(ctx) {\n contentPromise = serializeDirectoryContents(ctx.workspacePath);\n await contentPromise.catch(() => {});\n },\n }),\n ]),\n });\n\n // Extracting contentsPath and dryRunId from the baseUrl\n const baseUrl = input.templateInfo.baseUrl;\n if (!baseUrl) {\n throw new Error('baseUrl is required');\n }\n const basePath = fileURLToPath(new URL(baseUrl));\n const contentsPath = path.dirname(basePath);\n const dryRunId = uuid();\n\n const log = new Array<{ body: JsonObject }>();\n\n try {\n await deserializeDirectoryContents(contentsPath, input.directoryContents);\n\n const abortSignal = new AbortController().signal;\n const result = await workflowRunner.execute({\n taskId: dryRunId,\n spec: {\n ...input.spec,\n steps: [\n ...input.spec.steps,\n {\n id: dryRunId,\n name: 'dry-run:extract',\n action: 'dry-run:extract',\n },\n ],\n templateInfo: input.templateInfo,\n },\n secrets: input.secrets,\n getInitiatorCredentials: () => Promise.resolve(input.credentials),\n // No need to update this at the end of the run, so just hard-code it\n done: false,\n isDryRun: true,\n getWorkspaceName: async () => `dry-run-${dryRunId}`,\n cancelSignal: abortSignal,\n async emitLog(message: string, logMetadata?: JsonObject) {\n if (logMetadata?.stepId === dryRunId) {\n return;\n }\n log.push({\n body: {\n ...logMetadata,\n message,\n },\n });\n },\n complete: async () => {\n throw new Error('Not implemented');\n },\n });\n\n if (!contentPromise) {\n throw new Error('Content extraction step was skipped');\n }\n const directoryContents = await contentPromise;\n\n return {\n log,\n directoryContents,\n output: result.output,\n };\n } finally {\n await fs.remove(contentsPath);\n }\n };\n}\n"],"names":["NunjucksWorkflowRunner","DecoratedActionsRegistry","createTemplateAction","serializeDirectoryContents","fileURLToPath","path","uuid","deserializeDirectoryContents","fs"],"mappings":";;;;;;;;;;;;;;;AAiFO,SAAS,gBAAgB,OAAsC,EAAA;AACpE,EAAO,OAAA,eAAe,OAAO,KAA2C,EAAA;AACtE,IAAI,IAAA,cAAA;AAEJ,IAAM,MAAA,cAAA,GAAiB,IAAIA,6CAAuB,CAAA;AAAA,MAChD,GAAG,OAAA;AAAA,MACH,cAAgB,EAAA,IAAIC,iDAAyB,CAAA,OAAA,CAAQ,cAAgB,EAAA;AAAA,QACnEC,yCAAqB,CAAA;AAAA,UACnB,EAAI,EAAA,iBAAA;AAAA,UACJ,cAAgB,EAAA,IAAA;AAAA,UAChB,MAAM,QAAQ,GAAK,EAAA;AACjB,YAAiB,cAAA,GAAAC,+CAAA,CAA2B,IAAI,aAAa,CAAA;AAC7D,YAAM,MAAA,cAAA,CAAe,MAAM,M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Ac,EAAA,WAAA;AAAA,QACd,MAAM,OAAQ,CAAA,OAAA,EAAiB,WAA0B,EAAA;AACvD,UAAI,IAAA,WAAA,EAAa,WAAW,QAAU,EAAA;AACpC,YAAA;AAAA;AAEF,UAAA,GAAA,CAAI,IAAK,CAAA;AAAA,YACP,IAAM,EAAA;AAAA,cACJ,GAAG,WAAA;AAAA,cACH;AAAA;AACF,WACD,CAAA;AAAA,SACH;AAAA,QACA,UAAU,YAAY;AACpB,UAAM,MAAA,IAAI,MAAM,iBAAiB,CAAA;AAAA;AACnC,OACD,CAAA;AAED,MAAA,IAAI,CAAC,cAAgB,EAAA;AACnB,QAAM,MAAA,IAAI,MAAM,qCAAqC,CAAA;AAAA;AAEvD,MAAA,MAAM,oBAAoB,MAAM,cAAA;AAEhC,MAAO,OAAA;AAAA,QACL,GAAA;AAAA,QACA,iBAAA;AAAA,QACA,QAAQ,MAAO,CAAA;AAAA,OACjB;AAAA,KACA,SAAA;AACA,MAAM,MAAAC,mBAAA,CAAG,OAAO,YAAY,CAAA;AAAA;AAC9B,GACF;AACF;;;;"}
@@ -6,7 +6,6 @@ var fs = require('fs-extra');
6
6
  var jsonschema = require('jsonschema');
7
7
  var nunjucks = require('nunjucks');
8
8
  var path = require('path');
9
- var stream = require('stream');
10
9
  var winston = require('winston');
11
10
  var SecureTemplater = require('../../lib/templating/SecureTemplater.cjs.js');
12
11
  var helper = require('./helper.cjs.js');
@@ -17,7 +16,6 @@ var createDefaultFilters = require('../../lib/templating/filters/createDefaultFi
17
16
  var rules = require('../../service/rules.cjs.js');
18
17
  var metrics = require('../../util/metrics.cjs.js');
19
18
  var logger = require('./logger.cjs.js');
20
- var loggerToWinstonLogger = require('../../util/loggerToWinstonLogger.cjs.js');
21
19
  var templating = require('../../util/templating.cjs.js');
22
20
 
23
21
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
@@ -62,14 +60,7 @@ const createStepLogger = ({
62
60
  transports: [new logger.BackstageLoggerTransport(rootLogger, task, step.id)]
63
61
  });
64
62
  taskLogger.addRedactions(Object.values(task.secrets ?? {}));
65
- const streamLogger = new stream.PassThrough();
66
- streamLogger.on("data", async (data) => {
67
- const message = data.toString().trim();
68
- if (message?.length > 1) {
69
- taskLogger.info(message);
70
- }
71
- });
72
- return { taskLogger, streamLogger };
63
+ return { taskLogger };
73
64
  };
74
65
  const isActionAuthorized = pluginPermissionNode.createConditionAuthorizer(
75
66
  Object.values(rules.scaffolderActionRules)
@@ -146,7 +137,7 @@ class NunjucksWorkflowRunner {
146
137
  return;
147
138
  }
148
139
  const action = this.options.actionRegistry.get(step.action);
149
- const { taskLogger, streamLogger } = createStepLogger({
140
+ const { taskLogger } = createStepLogger({
150
141
  task,
151
142
  step,
152
143
  rootLogger: this.options.logger
@@ -183,7 +174,11 @@ class NunjucksWorkflowRunner {
183
174
  return;
184
175
  }
185
176
  }
186
- const resolvedEach = step.each && this.render(step.each, context, renderTemplate);
177
+ const resolvedEach = step.each && this.render(
178
+ step.each,
179
+ { ...context, secrets: task.secrets ?? {} },
180
+ renderTemplate
181
+ );
187
182
  if (step.each && !resolvedEach) {
188
183
  throw new errors.InputError(
189
184
  `Invalid value on action ${action.id}.each parameter, "${step.each}" cannot be resolved to a value`
@@ -246,9 +241,7 @@ class NunjucksWorkflowRunner {
246
241
  id: await task.getWorkspaceName()
247
242
  },
248
243
  secrets: task.secrets ?? {},
249
- // TODO(blam): move to LoggerService and away from Winston
250
- logger: loggerToWinstonLogger.loggerToWinstonLogger(taskLogger),
251
- logStream: streamLogger,
244
+ logger: taskLogger,
252
245
  workspacePath,
253
246
  async checkpoint(opts) {
254
247
  const { key: checkpointKey, fn } = opts;