@backstage/plugin-scaffolder-backend 1.26.0-next.1 → 1.26.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 (105) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/alpha/package.json +1 -1
  3. package/dist/ScaffolderPlugin.cjs.js +168 -0
  4. package/dist/ScaffolderPlugin.cjs.js.map +1 -0
  5. package/dist/alpha.cjs.js +7 -196
  6. package/dist/alpha.cjs.js.map +1 -1
  7. package/dist/deprecated.cjs.js +15 -0
  8. package/dist/deprecated.cjs.js.map +1 -0
  9. package/dist/index.cjs.js +57 -134
  10. package/dist/index.cjs.js.map +1 -1
  11. package/dist/lib/templating/SecureTemplater.cjs.js +169 -0
  12. package/dist/lib/templating/SecureTemplater.cjs.js.map +1 -0
  13. package/dist/lib/templating/filters.cjs.js +26 -0
  14. package/dist/lib/templating/filters.cjs.js.map +1 -0
  15. package/dist/lib/templating/helpers.cjs.js +13 -0
  16. package/dist/lib/templating/helpers.cjs.js.map +1 -0
  17. package/dist/scaffolder/actions/TemplateActionRegistry.cjs.js +30 -0
  18. package/dist/scaffolder/actions/TemplateActionRegistry.cjs.js.map +1 -0
  19. package/dist/scaffolder/actions/builtin/catalog/fetch.cjs.js +93 -0
  20. package/dist/scaffolder/actions/builtin/catalog/fetch.cjs.js.map +1 -0
  21. package/dist/scaffolder/actions/builtin/catalog/fetch.examples.cjs.js +43 -0
  22. package/dist/scaffolder/actions/builtin/catalog/fetch.examples.cjs.js.map +1 -0
  23. package/dist/scaffolder/actions/builtin/catalog/register.cjs.js +142 -0
  24. package/dist/scaffolder/actions/builtin/catalog/register.cjs.js.map +1 -0
  25. package/dist/scaffolder/actions/builtin/catalog/register.examples.cjs.js +28 -0
  26. package/dist/scaffolder/actions/builtin/catalog/register.examples.cjs.js.map +1 -0
  27. package/dist/scaffolder/actions/builtin/catalog/write.cjs.js +74 -0
  28. package/dist/scaffolder/actions/builtin/catalog/write.cjs.js.map +1 -0
  29. package/dist/scaffolder/actions/builtin/catalog/write.examples.cjs.js +56 -0
  30. package/dist/scaffolder/actions/builtin/catalog/write.examples.cjs.js.map +1 -0
  31. package/dist/scaffolder/actions/builtin/createBuiltinActions.cjs.js +156 -0
  32. package/dist/scaffolder/actions/builtin/createBuiltinActions.cjs.js.map +1 -0
  33. package/dist/scaffolder/actions/builtin/debug/log.cjs.js +66 -0
  34. package/dist/scaffolder/actions/builtin/debug/log.cjs.js.map +1 -0
  35. package/dist/scaffolder/actions/builtin/debug/log.examples.cjs.js +58 -0
  36. package/dist/scaffolder/actions/builtin/debug/log.examples.cjs.js.map +1 -0
  37. package/dist/scaffolder/actions/builtin/debug/wait.cjs.js +66 -0
  38. package/dist/scaffolder/actions/builtin/debug/wait.cjs.js.map +1 -0
  39. package/dist/scaffolder/actions/builtin/debug/wait.examples.cjs.js +58 -0
  40. package/dist/scaffolder/actions/builtin/debug/wait.examples.cjs.js.map +1 -0
  41. package/dist/scaffolder/actions/builtin/fetch/plain.cjs.js +56 -0
  42. package/dist/scaffolder/actions/builtin/fetch/plain.cjs.js.map +1 -0
  43. package/dist/scaffolder/actions/builtin/fetch/plain.examples.cjs.js +44 -0
  44. package/dist/scaffolder/actions/builtin/fetch/plain.examples.cjs.js.map +1 -0
  45. package/dist/scaffolder/actions/builtin/fetch/plainFile.cjs.js +56 -0
  46. package/dist/scaffolder/actions/builtin/fetch/plainFile.cjs.js.map +1 -0
  47. package/dist/scaffolder/actions/builtin/fetch/plainFile.examples.cjs.js +29 -0
  48. package/dist/scaffolder/actions/builtin/fetch/plainFile.examples.cjs.js.map +1 -0
  49. package/dist/scaffolder/actions/builtin/fetch/template.cjs.js +241 -0
  50. package/dist/scaffolder/actions/builtin/fetch/template.cjs.js.map +1 -0
  51. package/dist/scaffolder/actions/builtin/fetch/template.examples.cjs.js +35 -0
  52. package/dist/scaffolder/actions/builtin/fetch/template.examples.cjs.js.map +1 -0
  53. package/dist/scaffolder/actions/builtin/fetch/templateFile.cjs.js +119 -0
  54. package/dist/scaffolder/actions/builtin/fetch/templateFile.cjs.js.map +1 -0
  55. package/dist/scaffolder/actions/builtin/fetch/templateFile.examples.cjs.js +34 -0
  56. package/dist/scaffolder/actions/builtin/fetch/templateFile.examples.cjs.js.map +1 -0
  57. package/dist/scaffolder/actions/builtin/filesystem/delete.cjs.js +54 -0
  58. package/dist/scaffolder/actions/builtin/filesystem/delete.cjs.js.map +1 -0
  59. package/dist/scaffolder/actions/builtin/filesystem/delete.examples.cjs.js +44 -0
  60. package/dist/scaffolder/actions/builtin/filesystem/delete.examples.cjs.js.map +1 -0
  61. package/dist/scaffolder/actions/builtin/filesystem/rename.cjs.js +83 -0
  62. package/dist/scaffolder/actions/builtin/filesystem/rename.cjs.js.map +1 -0
  63. package/dist/scaffolder/actions/builtin/filesystem/rename.examples.cjs.js +48 -0
  64. package/dist/scaffolder/actions/builtin/filesystem/rename.examples.cjs.js.map +1 -0
  65. package/dist/scaffolder/actions/deprecated.cjs.js +74 -0
  66. package/dist/scaffolder/actions/deprecated.cjs.js.map +1 -0
  67. package/dist/scaffolder/dryrun/DecoratedActionsRegistry.cjs.js +57 -0
  68. package/dist/scaffolder/dryrun/DecoratedActionsRegistry.cjs.js.map +1 -0
  69. package/dist/scaffolder/dryrun/createDryRunner.cjs.js +97 -0
  70. package/dist/scaffolder/dryrun/createDryRunner.cjs.js.map +1 -0
  71. package/dist/scaffolder/tasks/DatabaseTaskStore.cjs.js +430 -0
  72. package/dist/scaffolder/tasks/DatabaseTaskStore.cjs.js.map +1 -0
  73. package/dist/scaffolder/tasks/DatabaseWorkspaceProvider.cjs.js +22 -0
  74. package/dist/scaffolder/tasks/DatabaseWorkspaceProvider.cjs.js.map +1 -0
  75. package/dist/scaffolder/tasks/NunjucksWorkflowRunner.cjs.js +545 -0
  76. package/dist/scaffolder/tasks/NunjucksWorkflowRunner.cjs.js.map +1 -0
  77. package/dist/scaffolder/tasks/StorageTaskBroker.cjs.js +318 -0
  78. package/dist/scaffolder/tasks/StorageTaskBroker.cjs.js.map +1 -0
  79. package/dist/scaffolder/tasks/TaskWorker.cjs.js +110 -0
  80. package/dist/scaffolder/tasks/TaskWorker.cjs.js.map +1 -0
  81. package/dist/scaffolder/tasks/WorkspaceService.cjs.js +50 -0
  82. package/dist/scaffolder/tasks/WorkspaceService.cjs.js.map +1 -0
  83. package/dist/scaffolder/tasks/dbUtil.cjs.js +20 -0
  84. package/dist/scaffolder/tasks/dbUtil.cjs.js.map +1 -0
  85. package/dist/scaffolder/tasks/helper.cjs.js +46 -0
  86. package/dist/scaffolder/tasks/helper.cjs.js.map +1 -0
  87. package/dist/scaffolder/tasks/logger.cjs.js +156 -0
  88. package/dist/scaffolder/tasks/logger.cjs.js.map +1 -0
  89. package/dist/scaffolder/tasks/taskRecoveryHelper.cjs.js +18 -0
  90. package/dist/scaffolder/tasks/taskRecoveryHelper.cjs.js.map +1 -0
  91. package/dist/service/conditionExports.cjs.js +26 -0
  92. package/dist/service/conditionExports.cjs.js.map +1 -0
  93. package/dist/service/helpers.cjs.js +92 -0
  94. package/dist/service/helpers.cjs.js.map +1 -0
  95. package/dist/service/router.cjs.js +640 -0
  96. package/dist/service/router.cjs.js.map +1 -0
  97. package/dist/service/rules.cjs.js +97 -0
  98. package/dist/service/rules.cjs.js.map +1 -0
  99. package/dist/util/checkPermissions.cjs.js +25 -0
  100. package/dist/util/checkPermissions.cjs.js.map +1 -0
  101. package/dist/util/metrics.cjs.js +24 -0
  102. package/dist/util/metrics.cjs.js.map +1 -0
  103. package/package.json +24 -24
  104. package/dist/cjs/router-BqZK9yax.cjs.js +0 -4101
  105. package/dist/cjs/router-BqZK9yax.cjs.js.map +0 -1
@@ -0,0 +1,241 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var backendPluginApi = require('@backstage/backend-plugin-api');
5
+ var errors = require('@backstage/errors');
6
+ var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
7
+ var globby = require('globby');
8
+ var fs = require('fs-extra');
9
+ var isbinaryfile = require('isbinaryfile');
10
+ var SecureTemplater = require('../../../../lib/templating/SecureTemplater.cjs.js');
11
+ var filters = require('../../../../lib/templating/filters.cjs.js');
12
+ var template_examples = require('./template.examples.cjs.js');
13
+
14
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
15
+
16
+ var globby__default = /*#__PURE__*/_interopDefaultCompat(globby);
17
+ var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
18
+
19
+ function createFetchTemplateAction(options) {
20
+ const {
21
+ reader,
22
+ integrations,
23
+ additionalTemplateFilters,
24
+ additionalTemplateGlobals
25
+ } = options;
26
+ const defaultTemplateFilters = filters.createDefaultFilters({ integrations });
27
+ return pluginScaffolderNode.createTemplateAction({
28
+ id: "fetch:template",
29
+ description: "Downloads a skeleton, templates variables into file and directory names and content, and places the result in the workspace, or optionally in a subdirectory specified by the `targetPath` input option.",
30
+ examples: template_examples.examples,
31
+ schema: {
32
+ input: {
33
+ type: "object",
34
+ required: ["url"],
35
+ properties: {
36
+ url: {
37
+ title: "Fetch URL",
38
+ description: "Relative path or absolute URL pointing to the directory tree to fetch",
39
+ type: "string"
40
+ },
41
+ targetPath: {
42
+ title: "Target Path",
43
+ description: "Target path within the working directory to download the contents to. Defaults to the working directory root.",
44
+ type: "string"
45
+ },
46
+ values: {
47
+ title: "Template Values",
48
+ description: "Values to pass on to the templating engine",
49
+ type: "object"
50
+ },
51
+ copyWithoutRender: {
52
+ title: "[Deprecated] Copy Without Render",
53
+ description: "An array of glob patterns. Any files or directories which match are copied without being processed as templates.",
54
+ type: "array",
55
+ items: {
56
+ type: "string"
57
+ }
58
+ },
59
+ copyWithoutTemplating: {
60
+ title: "Copy Without Templating",
61
+ description: "An array of glob patterns. Contents of matched files or directories are copied without being processed, but paths are subject to rendering.",
62
+ type: "array",
63
+ items: {
64
+ type: "string"
65
+ }
66
+ },
67
+ cookiecutterCompat: {
68
+ title: "Cookiecutter compatibility mode",
69
+ description: "Enable features to maximise compatibility with templates built for fetch:cookiecutter",
70
+ type: "boolean"
71
+ },
72
+ templateFileExtension: {
73
+ title: "Template File Extension",
74
+ description: "If set, only files with the given extension will be templated. If set to `true`, the default extension `.njk` is used.",
75
+ type: ["string", "boolean"]
76
+ },
77
+ replace: {
78
+ title: "Replace files",
79
+ description: "If set, replace files in targetPath instead of skipping existing ones.",
80
+ type: "boolean"
81
+ },
82
+ token: {
83
+ title: "Token",
84
+ description: "An optional token to use for authentication when reading the resources.",
85
+ type: "string"
86
+ }
87
+ }
88
+ }
89
+ },
90
+ supportsDryRun: true,
91
+ async handler(ctx) {
92
+ ctx.logger.info("Fetching template content from remote URL");
93
+ const workDir = await ctx.createTemporaryDirectory();
94
+ const templateDir = backendPluginApi.resolveSafeChildPath(workDir, "template");
95
+ const targetPath = ctx.input.targetPath ?? "./";
96
+ const outputDir = backendPluginApi.resolveSafeChildPath(ctx.workspacePath, targetPath);
97
+ if (ctx.input.copyWithoutRender && ctx.input.copyWithoutTemplating) {
98
+ throw new errors.InputError(
99
+ "Fetch action input copyWithoutRender and copyWithoutTemplating can not be used at the same time"
100
+ );
101
+ }
102
+ let copyOnlyPatterns;
103
+ let renderFilename;
104
+ if (ctx.input.copyWithoutRender) {
105
+ ctx.logger.warn(
106
+ "[Deprecated] copyWithoutRender is deprecated Please use copyWithoutTemplating instead."
107
+ );
108
+ copyOnlyPatterns = ctx.input.copyWithoutRender;
109
+ renderFilename = false;
110
+ } else {
111
+ copyOnlyPatterns = ctx.input.copyWithoutTemplating;
112
+ renderFilename = true;
113
+ }
114
+ if (copyOnlyPatterns && !Array.isArray(copyOnlyPatterns)) {
115
+ throw new errors.InputError(
116
+ "Fetch action input copyWithoutRender/copyWithoutTemplating must be an Array"
117
+ );
118
+ }
119
+ if (ctx.input.templateFileExtension && (copyOnlyPatterns || ctx.input.cookiecutterCompat)) {
120
+ throw new errors.InputError(
121
+ "Fetch action input extension incompatible with copyWithoutRender/copyWithoutTemplating and cookiecutterCompat"
122
+ );
123
+ }
124
+ let extension = false;
125
+ if (ctx.input.templateFileExtension) {
126
+ extension = ctx.input.templateFileExtension === true ? ".njk" : ctx.input.templateFileExtension;
127
+ if (!extension.startsWith(".")) {
128
+ extension = `.${extension}`;
129
+ }
130
+ }
131
+ await pluginScaffolderNode.fetchContents({
132
+ reader,
133
+ integrations,
134
+ baseUrl: ctx.templateInfo?.baseUrl,
135
+ fetchUrl: ctx.input.url,
136
+ outputPath: templateDir,
137
+ token: ctx.input.token
138
+ });
139
+ ctx.logger.info("Listing files and directories in template");
140
+ const allEntriesInTemplate = await globby__default.default(`**/*`, {
141
+ cwd: templateDir,
142
+ dot: true,
143
+ onlyFiles: false,
144
+ markDirectories: true,
145
+ followSymbolicLinks: false
146
+ });
147
+ const nonTemplatedEntries = new Set(
148
+ await globby__default.default(copyOnlyPatterns || [], {
149
+ cwd: templateDir,
150
+ dot: true,
151
+ onlyFiles: false,
152
+ markDirectories: true,
153
+ followSymbolicLinks: false
154
+ })
155
+ );
156
+ const { cookiecutterCompat, values } = ctx.input;
157
+ const context = {
158
+ [cookiecutterCompat ? "cookiecutter" : "values"]: values
159
+ };
160
+ ctx.logger.info(
161
+ `Processing ${allEntriesInTemplate.length} template files/directories with input values`,
162
+ ctx.input.values
163
+ );
164
+ const renderTemplate = await SecureTemplater.SecureTemplater.loadRenderer({
165
+ cookiecutterCompat: ctx.input.cookiecutterCompat,
166
+ templateFilters: {
167
+ ...defaultTemplateFilters,
168
+ ...additionalTemplateFilters
169
+ },
170
+ templateGlobals: additionalTemplateGlobals,
171
+ nunjucksConfigs: {
172
+ trimBlocks: ctx.input.trimBlocks,
173
+ lstripBlocks: ctx.input.lstripBlocks
174
+ }
175
+ });
176
+ for (const location of allEntriesInTemplate) {
177
+ let renderContents;
178
+ let localOutputPath = location;
179
+ if (extension) {
180
+ renderContents = path.extname(localOutputPath) === extension;
181
+ if (renderContents) {
182
+ localOutputPath = localOutputPath.slice(0, -extension.length);
183
+ }
184
+ localOutputPath = renderTemplate(localOutputPath, context);
185
+ } else {
186
+ renderContents = !nonTemplatedEntries.has(location);
187
+ if (renderFilename) {
188
+ localOutputPath = renderTemplate(localOutputPath, context);
189
+ } else {
190
+ localOutputPath = renderContents ? renderTemplate(localOutputPath, context) : localOutputPath;
191
+ }
192
+ }
193
+ if (containsSkippedContent(localOutputPath)) {
194
+ continue;
195
+ }
196
+ const outputPath = backendPluginApi.resolveSafeChildPath(outputDir, localOutputPath);
197
+ if (fs__default.default.existsSync(outputPath) && !ctx.input.replace) {
198
+ continue;
199
+ }
200
+ if (!renderContents && !extension) {
201
+ ctx.logger.info(
202
+ `Copying file/directory ${location} without processing.`
203
+ );
204
+ }
205
+ if (location.endsWith("/")) {
206
+ ctx.logger.info(
207
+ `Writing directory ${location} to template output path.`
208
+ );
209
+ await fs__default.default.ensureDir(outputPath);
210
+ } else {
211
+ const inputFilePath = backendPluginApi.resolveSafeChildPath(templateDir, location);
212
+ const stats = await fs__default.default.promises.lstat(inputFilePath);
213
+ if (stats.isSymbolicLink() || await isbinaryfile.isBinaryFile(inputFilePath)) {
214
+ ctx.logger.info(
215
+ `Copying file binary or symbolic link at ${location}, to template output path.`
216
+ );
217
+ await fs__default.default.copy(inputFilePath, outputPath);
218
+ } else {
219
+ const statsObj = await fs__default.default.stat(inputFilePath);
220
+ ctx.logger.info(
221
+ `Writing file ${location} to template output path with mode ${statsObj.mode}.`
222
+ );
223
+ const inputFileContents = await fs__default.default.readFile(inputFilePath, "utf-8");
224
+ await fs__default.default.outputFile(
225
+ outputPath,
226
+ renderContents ? renderTemplate(inputFileContents, context) : inputFileContents,
227
+ { mode: statsObj.mode }
228
+ );
229
+ }
230
+ }
231
+ }
232
+ ctx.logger.info(`Template result written to ${outputDir}`);
233
+ }
234
+ });
235
+ }
236
+ function containsSkippedContent(localOutputPath) {
237
+ return localOutputPath === "" || localOutputPath.startsWith("/") || localOutputPath.includes("//");
238
+ }
239
+
240
+ exports.createFetchTemplateAction = createFetchTemplateAction;
241
+ //# sourceMappingURL=template.cjs.js.map
@@ -0,0 +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 { extname } from 'path';\nimport { UrlReaderService } from '@backstage/backend-plugin-api';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n createTemplateAction,\n fetchContents,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport globby from 'globby';\nimport fs from 'fs-extra';\nimport { isBinaryFile } from 'isbinaryfile';\nimport { SecureTemplater } from '../../../../lib/templating/SecureTemplater';\nimport { createDefaultFilters } from '../../../../lib/templating/filters';\nimport { examples } from './template.examples';\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 const {\n reader,\n integrations,\n additionalTemplateFilters,\n additionalTemplateGlobals,\n } = options;\n\n const defaultTemplateFilters = createDefaultFilters({ integrations });\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 async handler(ctx) {\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 const targetPath = ctx.input.targetPath ?? './';\n const outputDir = resolveSafeChildPath(ctx.workspacePath, targetPath);\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\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\n if (copyOnlyPatterns && !Array.isArray(copyOnlyPatterns)) {\n throw new InputError(\n 'Fetch action input copyWithoutRender/copyWithoutTemplating must be an Array',\n );\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\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\n await fetchContents({\n reader,\n integrations,\n baseUrl: ctx.templateInfo?.baseUrl,\n fetchUrl: ctx.input.url,\n outputPath: templateDir,\n token: ctx.input.token,\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 ...defaultTemplateFilters,\n ...additionalTemplateFilters,\n },\n templateGlobals: additionalTemplateGlobals,\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(\n `Copying file/directory ${location} without processing.`,\n );\n }\n\n if (location.endsWith('/')) {\n ctx.logger.info(\n `Writing directory ${location} to template output path.`,\n );\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\n ctx.logger.info(`Template result written to ${outputDir}`);\n },\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":["createDefaultFilters","createTemplateAction","examples","resolveSafeChildPath","InputError","fetchContents","globby","SecureTemplater","extname","fs","isBinaryFile"],"mappings":";;;;;;;;;;;;;;;;;;AAyCO,SAAS,0BAA0B,OAKvC,EAAA;AACD,EAAM,MAAA;AAAA,IACJ,MAAA;AAAA,IACA,YAAA;AAAA,IACA,yBAAA;AAAA,IACA,yBAAA;AAAA,GACE,GAAA,OAAA,CAAA;AAEJ,EAAA,MAAM,sBAAyB,GAAAA,4BAAA,CAAqB,EAAE,YAAA,EAAc,CAAA,CAAA;AAEpE,EAAA,OAAOC,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;AAAA,UACV,GAAK,EAAA;AAAA,YACH,KAAO,EAAA,WAAA;AAAA,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in e ? e : { default: e }; }
6
+
7
+ var yaml__default = /*#__PURE__*/_interopDefaultCompat(yaml);
8
+
9
+ const examples = [
10
+ {
11
+ description: "Downloads a skeleton directory that lives alongside the template file and fill it out with values.",
12
+ example: yaml__default.default.stringify({
13
+ steps: [
14
+ {
15
+ action: "fetch:template",
16
+ id: "fetch-template",
17
+ name: "Fetch template",
18
+ input: {
19
+ url: "./skeleton",
20
+ targetPath: "./target",
21
+ values: {
22
+ name: "test-project",
23
+ count: 1234,
24
+ itemList: ["first", "second", "third"],
25
+ showDummyFile: false
26
+ }
27
+ }
28
+ }
29
+ ]
30
+ })
31
+ }
32
+ ];
33
+
34
+ exports.examples = examples;
35
+ //# sourceMappingURL=template.examples.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template.examples.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/template.examples.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 { TemplateExample } from '@backstage/plugin-scaffolder-node';\nimport yaml from 'yaml';\n\nexport const examples: TemplateExample[] = [\n {\n description:\n 'Downloads a skeleton directory that lives alongside the template file and fill it out with values.',\n example: yaml.stringify({\n steps: [\n {\n action: 'fetch:template',\n id: 'fetch-template',\n name: 'Fetch template',\n input: {\n url: './skeleton',\n targetPath: './target',\n values: {\n name: 'test-project',\n count: 1234,\n itemList: ['first', 'second', 'third'],\n showDummyFile: false,\n },\n },\n },\n ],\n }),\n },\n];\n"],"names":["yaml"],"mappings":";;;;;;;;AAmBO,MAAM,QAA8B,GAAA;AAAA,EACzC;AAAA,IACE,WACE,EAAA,oGAAA;AAAA,IACF,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,MAAQ,EAAA,gBAAA;AAAA,UACR,EAAI,EAAA,gBAAA;AAAA,UACJ,IAAM,EAAA,gBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,GAAK,EAAA,YAAA;AAAA,YACL,UAAY,EAAA,UAAA;AAAA,YACZ,MAAQ,EAAA;AAAA,cACN,IAAM,EAAA,cAAA;AAAA,cACN,KAAO,EAAA,IAAA;AAAA,cACP,QAAU,EAAA,CAAC,OAAS,EAAA,QAAA,EAAU,OAAO,CAAA;AAAA,cACrC,aAAe,EAAA,KAAA;AAAA,aACjB;AAAA,WACF;AAAA,SACF;AAAA,OACF;AAAA,KACD,CAAA;AAAA,GACH;AACF;;;;"}
@@ -0,0 +1,119 @@
1
+ 'use strict';
2
+
3
+ var backendPluginApi = require('@backstage/backend-plugin-api');
4
+ var templateFile_examples = require('./templateFile.examples.cjs.js');
5
+ var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
6
+ var SecureTemplater = require('../../../../lib/templating/SecureTemplater.cjs.js');
7
+ var filters = require('../../../../lib/templating/filters.cjs.js');
8
+ var path = require('path');
9
+ var fs = require('fs-extra');
10
+
11
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
12
+
13
+ var path__default = /*#__PURE__*/_interopDefaultCompat(path);
14
+ var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
15
+
16
+ function createFetchTemplateFileAction(options) {
17
+ const {
18
+ reader,
19
+ integrations,
20
+ additionalTemplateFilters,
21
+ additionalTemplateGlobals
22
+ } = options;
23
+ const defaultTemplateFilters = filters.createDefaultFilters({ integrations });
24
+ return pluginScaffolderNode.createTemplateAction({
25
+ id: "fetch:template:file",
26
+ description: "Downloads single file and places it in the workspace.",
27
+ examples: templateFile_examples.examples,
28
+ schema: {
29
+ input: {
30
+ type: "object",
31
+ required: ["url", "targetPath"],
32
+ properties: {
33
+ url: {
34
+ title: "Fetch URL",
35
+ description: "Relative path or absolute URL pointing to the single file to fetch.",
36
+ type: "string"
37
+ },
38
+ targetPath: {
39
+ title: "Target Path",
40
+ description: "Target path within the working directory to download the file as.",
41
+ type: "string"
42
+ },
43
+ values: {
44
+ title: "Template Values",
45
+ description: "Values to pass on to the templating engine",
46
+ type: "object"
47
+ },
48
+ cookiecutterCompat: {
49
+ title: "Cookiecutter compatibility mode",
50
+ description: "Enable features to maximise compatibility with templates built for fetch:cookiecutter",
51
+ type: "boolean"
52
+ },
53
+ replace: {
54
+ title: "Replace file",
55
+ description: "If set, replace file in targetPath instead of overwriting existing one.",
56
+ type: "boolean"
57
+ },
58
+ token: {
59
+ title: "Token",
60
+ description: "An optional token to use for authentication when reading the resources.",
61
+ type: "string"
62
+ }
63
+ }
64
+ }
65
+ },
66
+ supportsDryRun: true,
67
+ async handler(ctx) {
68
+ ctx.logger.info("Fetching template file content from remote URL");
69
+ const workDir = await ctx.createTemporaryDirectory();
70
+ const tmpFilePath = path__default.default.join(workDir, "tmp");
71
+ const outputPath = backendPluginApi.resolveSafeChildPath(
72
+ ctx.workspacePath,
73
+ ctx.input.targetPath
74
+ );
75
+ if (fs__default.default.existsSync(outputPath) && !ctx.input.replace) {
76
+ ctx.logger.info(
77
+ `File ${ctx.input.targetPath} already exists in workspace, not replacing.`
78
+ );
79
+ return;
80
+ }
81
+ await pluginScaffolderNode.fetchFile({
82
+ reader,
83
+ integrations,
84
+ baseUrl: ctx.templateInfo?.baseUrl,
85
+ fetchUrl: ctx.input.url,
86
+ outputPath: tmpFilePath,
87
+ token: ctx.input.token
88
+ });
89
+ const { cookiecutterCompat, values } = ctx.input;
90
+ const context = {
91
+ [cookiecutterCompat ? "cookiecutter" : "values"]: values
92
+ };
93
+ ctx.logger.info(
94
+ `Processing template file with input values`,
95
+ ctx.input.values
96
+ );
97
+ const renderTemplate = await SecureTemplater.SecureTemplater.loadRenderer({
98
+ cookiecutterCompat,
99
+ templateFilters: {
100
+ ...defaultTemplateFilters,
101
+ ...additionalTemplateFilters
102
+ },
103
+ templateGlobals: additionalTemplateGlobals,
104
+ nunjucksConfigs: {
105
+ trimBlocks: ctx.input.trimBlocks,
106
+ lstripBlocks: ctx.input.lstripBlocks
107
+ }
108
+ });
109
+ const contents = await fs__default.default.readFile(tmpFilePath, "utf-8");
110
+ const result = renderTemplate(contents, context);
111
+ await fs__default.default.ensureDir(path__default.default.dirname(outputPath));
112
+ await fs__default.default.outputFile(outputPath, result);
113
+ ctx.logger.info(`Template file has been written to ${outputPath}`);
114
+ }
115
+ });
116
+ }
117
+
118
+ exports.createFetchTemplateFileAction = createFetchTemplateFileAction;
119
+ //# sourceMappingURL=templateFile.cjs.js.map
@@ -0,0 +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 { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { examples } from './templateFile.examples';\nimport {\n createTemplateAction,\n fetchFile,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport { SecureTemplater } from '../../../../lib/templating/SecureTemplater';\nimport { createDefaultFilters } from '../../../../lib/templating/filters';\nimport path from 'path';\nimport fs from 'fs-extra';\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 const {\n reader,\n integrations,\n additionalTemplateFilters,\n additionalTemplateGlobals,\n } = options;\n\n const defaultTemplateFilters = createDefaultFilters({ integrations });\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 async handler(ctx) {\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 const outputPath = resolveSafeChildPath(\n ctx.workspacePath,\n ctx.input.targetPath,\n );\n\n if (fs.existsSync(outputPath) && !ctx.input.replace) {\n ctx.logger.info(\n `File ${ctx.input.targetPath} already exists in workspace, not replacing.`,\n );\n return;\n }\n\n await fetchFile({\n reader,\n integrations,\n baseUrl: ctx.templateInfo?.baseUrl,\n fetchUrl: ctx.input.url,\n outputPath: tmpFilePath,\n token: ctx.input.token,\n });\n\n const { cookiecutterCompat, values } = ctx.input;\n const context = {\n [cookiecutterCompat ? 'cookiecutter' : 'values']: values,\n };\n\n ctx.logger.info(\n `Processing template file with input values`,\n ctx.input.values,\n );\n\n const renderTemplate = await SecureTemplater.loadRenderer({\n cookiecutterCompat,\n templateFilters: {\n ...defaultTemplateFilters,\n ...additionalTemplateFilters,\n },\n templateGlobals: additionalTemplateGlobals,\n nunjucksConfigs: {\n trimBlocks: ctx.input.trimBlocks,\n lstripBlocks: ctx.input.lstripBlocks,\n },\n });\n\n const contents = await fs.readFile(tmpFilePath, 'utf-8');\n const result = renderTemplate(contents, context);\n await fs.ensureDir(path.dirname(outputPath));\n await fs.outputFile(outputPath, result);\n\n ctx.logger.info(`Template file has been written to ${outputPath}`);\n },\n });\n}\n"],"names":["createDefaultFilters","createTemplateAction","examples","path","resolveSafeChildPath","fs","fetchFile","SecureTemplater"],"mappings":";;;;;;;;;;;;;;;AAqCO,SAAS,8BAA8B,OAK3C,EAAA;AACD,EAAM,MAAA;AAAA,IACJ,MAAA;AAAA,IACA,YAAA;AAAA,IACA,yBAAA;AAAA,IACA,yBAAA;AAAA,GACE,GAAA,OAAA,CAAA;AAEJ,EAAA,MAAM,sBAAyB,GAAAA,4BAAA,CAAqB,EAAE,YAAA,EAAc,CAAA,CAAA;AAEpE,EAAA,OAAOC,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,Y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QAAA,EAAU,OAAO,CAAA,CAAA;AAC/C,MAAA,MAAMA,mBAAG,CAAA,SAAA,CAAUF,qBAAK,CAAA,OAAA,CAAQ,UAAU,CAAC,CAAA,CAAA;AAC3C,MAAM,MAAAE,mBAAA,CAAG,UAAW,CAAA,UAAA,EAAY,MAAM,CAAA,CAAA;AAEtC,MAAA,GAAA,CAAI,MAAO,CAAA,IAAA,CAAK,CAAqC,kCAAA,EAAA,UAAU,CAAE,CAAA,CAAA,CAAA;AAAA,KACnE;AAAA,GACD,CAAA,CAAA;AACH;;;;"}
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ var yaml = require('yaml');
4
+
5
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
6
+
7
+ var yaml__default = /*#__PURE__*/_interopDefaultCompat(yaml);
8
+
9
+ const examples = [
10
+ {
11
+ description: "Downloads a template file and fill it out with values.",
12
+ example: yaml__default.default.stringify({
13
+ steps: [
14
+ {
15
+ action: "fetch:template:file",
16
+ id: "fetch-template-file",
17
+ name: "Fetch template file",
18
+ input: {
19
+ url: "./skeleton.txt",
20
+ targetPath: "./target/skeleton.txt",
21
+ values: {
22
+ name: "test-project",
23
+ count: 1234,
24
+ itemList: ["first", "second", "third"]
25
+ }
26
+ }
27
+ }
28
+ ]
29
+ })
30
+ }
31
+ ];
32
+
33
+ exports.examples = examples;
34
+ //# sourceMappingURL=templateFile.examples.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templateFile.examples.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/templateFile.examples.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 { TemplateExample } from '@backstage/plugin-scaffolder-node';\nimport yaml from 'yaml';\n\nexport const examples: TemplateExample[] = [\n {\n description: 'Downloads a template file and fill it out with values.',\n example: yaml.stringify({\n steps: [\n {\n action: 'fetch:template:file',\n id: 'fetch-template-file',\n name: 'Fetch template file',\n input: {\n url: './skeleton.txt',\n targetPath: './target/skeleton.txt',\n values: {\n name: 'test-project',\n count: 1234,\n itemList: ['first', 'second', 'third'],\n },\n },\n },\n ],\n }),\n },\n];\n"],"names":["yaml"],"mappings":";;;;;;;;AAmBO,MAAM,QAA8B,GAAA;AAAA,EACzC;AAAA,IACE,WAAa,EAAA,wDAAA;AAAA,IACb,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,MAAQ,EAAA,qBAAA;AAAA,UACR,EAAI,EAAA,qBAAA;AAAA,UACJ,IAAM,EAAA,qBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,GAAK,EAAA,gBAAA;AAAA,YACL,UAAY,EAAA,uBAAA;AAAA,YACZ,MAAQ,EAAA;AAAA,cACN,IAAM,EAAA,cAAA;AAAA,cACN,KAAO,EAAA,IAAA;AAAA,cACP,QAAU,EAAA,CAAC,OAAS,EAAA,QAAA,EAAU,OAAO,CAAA;AAAA,aACvC;AAAA,WACF;AAAA,SACF;AAAA,OACF;AAAA,KACD,CAAA;AAAA,GACH;AACF;;;;"}
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
4
+ var errors = require('@backstage/errors');
5
+ var backendPluginApi = require('@backstage/backend-plugin-api');
6
+ var fs = require('fs-extra');
7
+ var delete_examples = require('./delete.examples.cjs.js');
8
+
9
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
10
+
11
+ var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
12
+
13
+ const createFilesystemDeleteAction = () => {
14
+ return pluginScaffolderNode.createTemplateAction({
15
+ id: "fs:delete",
16
+ description: "Deletes files and directories from the workspace",
17
+ examples: delete_examples.examples,
18
+ schema: {
19
+ input: {
20
+ required: ["files"],
21
+ type: "object",
22
+ properties: {
23
+ files: {
24
+ title: "Files",
25
+ description: "A list of files and directories that will be deleted",
26
+ type: "array",
27
+ items: {
28
+ type: "string"
29
+ }
30
+ }
31
+ }
32
+ }
33
+ },
34
+ supportsDryRun: true,
35
+ async handler(ctx) {
36
+ if (!Array.isArray(ctx.input?.files)) {
37
+ throw new errors.InputError("files must be an Array");
38
+ }
39
+ for (const file of ctx.input.files) {
40
+ const filepath = backendPluginApi.resolveSafeChildPath(ctx.workspacePath, file);
41
+ try {
42
+ await fs__default.default.remove(filepath);
43
+ ctx.logger.info(`File ${filepath} deleted successfully`);
44
+ } catch (err) {
45
+ ctx.logger.error(`Failed to delete file ${filepath}:`, err);
46
+ throw err;
47
+ }
48
+ }
49
+ }
50
+ });
51
+ };
52
+
53
+ exports.createFilesystemDeleteAction = createFilesystemDeleteAction;
54
+ //# sourceMappingURL=delete.cjs.js.map
@@ -0,0 +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 { 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 const filepath = resolveSafeChildPath(ctx.workspacePath, file);\n\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"],"names":["createTemplateAction","examples","InputError","resolveSafeChildPath","fs"],"mappings":";;;;;;;;;;;;AA0BO,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;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,WAAa,EAAA,sDAAA;AAAA,YACb,IAAM,EAAA,OAAA;AAAA,YACN,KAAO,EAAA;AAAA,cACL,IAAM,EAAA,QAAA;AAAA,aACR;AAAA,WACF;AAAA,SACF;AAAA,OACF;AAAA,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,CAAA;AAAA,OAC/C;AAEA,MAAW,KAAA,MAAA,IAAA,IAAQ,GAAI,CAAA,KAAA,CAAM,KAAO,EAAA;AAClC,QAAA,MAAM,QAAW,GAAAC,qCAAA,CAAqB,GAAI,CAAA,aAAA,EAAe,IAAI,CAAA,CAAA;AAE7D,QAAI,IAAA;AACF,UAAM,MAAAC,mBAAA,CAAG,OAAO,QAAQ,CAAA,CAAA;AACxB,UAAA,GAAA,CAAI,MAAO,CAAA,IAAA,CAAK,CAAQ,KAAA,EAAA,QAAQ,CAAuB,qBAAA,CAAA,CAAA,CAAA;AAAA,iBAChD,GAAK,EAAA;AACZ,UAAA,GAAA,CAAI,MAAO,CAAA,KAAA,CAAM,CAAyB,sBAAA,EAAA,QAAQ,KAAK,GAAG,CAAA,CAAA;AAC1D,UAAM,MAAA,GAAA,CAAA;AAAA,SACR;AAAA,OACF;AAAA,KACF;AAAA,GACD,CAAA,CAAA;AACH;;;;"}
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ var yaml = require('yaml');
4
+
5
+ function _interopNamespaceCompat(e) {
6
+ if (e && typeof e === 'object' && 'default' in e) return e;
7
+ var n = Object.create(null);
8
+ if (e) {
9
+ Object.keys(e).forEach(function (k) {
10
+ if (k !== 'default') {
11
+ var d = Object.getOwnPropertyDescriptor(e, k);
12
+ Object.defineProperty(n, k, d.get ? d : {
13
+ enumerable: true,
14
+ get: function () { return e[k]; }
15
+ });
16
+ }
17
+ });
18
+ }
19
+ n.default = e;
20
+ return Object.freeze(n);
21
+ }
22
+
23
+ var yaml__namespace = /*#__PURE__*/_interopNamespaceCompat(yaml);
24
+
25
+ const examples = [
26
+ {
27
+ description: "Delete specified files",
28
+ example: yaml__namespace.stringify({
29
+ steps: [
30
+ {
31
+ action: "fs:delete",
32
+ id: "deleteFiles",
33
+ name: "Delete files",
34
+ input: {
35
+ files: ["file1.txt", "file2.txt"]
36
+ }
37
+ }
38
+ ]
39
+ })
40
+ }
41
+ ];
42
+
43
+ exports.examples = examples;
44
+ //# sourceMappingURL=delete.examples.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delete.examples.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/filesystem/delete.examples.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 { TemplateExample } from '@backstage/plugin-scaffolder-node';\nimport * as yaml from 'yaml';\n\nexport const examples: TemplateExample[] = [\n {\n description: 'Delete specified files',\n example: yaml.stringify({\n steps: [\n {\n action: 'fs:delete',\n id: 'deleteFiles',\n name: 'Delete files',\n input: {\n files: ['file1.txt', 'file2.txt'],\n },\n },\n ],\n }),\n },\n];\n"],"names":["yaml"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmBO,MAAM,QAA8B,GAAA;AAAA,EACzC;AAAA,IACE,WAAa,EAAA,wBAAA;AAAA,IACb,OAAA,EAASA,gBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,MAAQ,EAAA,WAAA;AAAA,UACR,EAAI,EAAA,aAAA;AAAA,UACJ,IAAM,EAAA,cAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,KAAA,EAAO,CAAC,WAAA,EAAa,WAAW,CAAA;AAAA,WAClC;AAAA,SACF;AAAA,OACF;AAAA,KACD,CAAA;AAAA,GACH;AACF;;;;"}