@backstage/plugin-scaffolder-backend 3.1.2-next.0 → 3.1.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.
- package/CHANGELOG.md +15 -34
- package/README.md +29 -0
- package/dist/ScaffolderPlugin.cjs.js +1 -1
- package/dist/scaffolder/actions/builtin/debug/log.cjs.js +2 -2
- package/dist/scaffolder/actions/builtin/debug/log.cjs.js.map +1 -1
- package/dist/scaffolder/actions/builtin/fetch/templateActionHandler.cjs.js +1 -1
- package/dist/scaffolder/actions/builtin/fetch/templateActionHandler.cjs.js.map +1 -1
- package/dist/scaffolder/actions/builtin/fetch/templateFile.cjs.js +1 -1
- package/dist/scaffolder/actions/builtin/fetch/templateFile.cjs.js.map +1 -1
- package/dist/scaffolder/actions/builtin/fetch/templateFileActionHandler.cjs.js +1 -1
- package/dist/scaffolder/actions/builtin/fetch/templateFileActionHandler.cjs.js.map +1 -1
- package/dist/scaffolder/actions/builtin/filesystem/read.cjs.js +2 -2
- package/dist/scaffolder/actions/builtin/filesystem/read.cjs.js.map +1 -1
- package/dist/scaffolder/dryrun/createDryRunner.cjs.js +3 -3
- package/dist/scaffolder/dryrun/createDryRunner.cjs.js.map +1 -1
- package/dist/scaffolder/tasks/NunjucksWorkflowRunner.cjs.js +1 -1
- package/dist/scaffolder/tasks/NunjucksWorkflowRunner.cjs.js.map +1 -1
- package/dist/scaffolder/tasks/TaskWorker.cjs.js +1 -1
- package/dist/scaffolder/tasks/TaskWorker.cjs.js.map +1 -1
- package/dist/service/helpers.cjs.js +1 -1
- package/dist/service/helpers.cjs.js.map +1 -1
- package/dist/service/router.cjs.js +5 -5
- package/dist/service/router.cjs.js.map +1 -1
- package/package.json +33 -32
package/CHANGELOG.md
CHANGED
|
@@ -1,39 +1,20 @@
|
|
|
1
1
|
# @backstage/plugin-scaffolder-backend
|
|
2
2
|
|
|
3
|
-
## 3.1.2
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
- @backstage/
|
|
13
|
-
- @backstage/
|
|
14
|
-
- @backstage/plugin-
|
|
15
|
-
- @backstage/plugin-
|
|
16
|
-
- @backstage/plugin-scaffolder-
|
|
17
|
-
- @backstage/plugin-
|
|
18
|
-
- @backstage/plugin-scaffolder-backend-module-gitlab@0.11.2-next.0
|
|
19
|
-
- @backstage/plugin-scaffolder-backend-module-gitea@0.2.18-next.0
|
|
20
|
-
- @backstage/backend-openapi-utils@0.6.6-next.0
|
|
21
|
-
- @backstage/plugin-bitbucket-cloud-common@0.3.7-next.0
|
|
22
|
-
- @backstage/backend-plugin-api@1.7.0-next.0
|
|
23
|
-
- @backstage/backend-defaults@0.15.1-next.0
|
|
24
|
-
- @backstage/plugin-scaffolder-node@0.12.4-next.0
|
|
25
|
-
- @backstage/integration@1.19.3-next.0
|
|
26
|
-
- @backstage/plugin-auth-node@0.6.12-next.0
|
|
27
|
-
- @backstage/plugin-permission-common@0.9.5-next.0
|
|
28
|
-
- @backstage/plugin-permission-node@0.10.9-next.0
|
|
29
|
-
- @backstage/plugin-events-node@0.4.19-next.0
|
|
30
|
-
- @backstage/plugin-scaffolder-backend-module-bitbucket-server@0.2.18-next.0
|
|
31
|
-
- @backstage/catalog-model@1.7.6
|
|
32
|
-
- @backstage/config@1.3.6
|
|
33
|
-
- @backstage/errors@1.2.7
|
|
34
|
-
- @backstage/types@1.2.2
|
|
35
|
-
- @backstage/plugin-scaffolder-backend-module-azure@0.2.18-next.0
|
|
36
|
-
- @backstage/plugin-scaffolder-common@1.7.6-next.0
|
|
3
|
+
## 3.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5683c85: Bump to latest zod to ensure it has the latest features
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/plugin-scaffolder-backend-module-bitbucket-cloud@0.3.2
|
|
10
|
+
- @backstage/plugin-scaffolder-backend-module-github@0.9.5
|
|
11
|
+
- @backstage/plugin-scaffolder-backend-module-gitlab@0.11.2
|
|
12
|
+
- @backstage/backend-plugin-api@1.6.2
|
|
13
|
+
- @backstage/backend-defaults@0.15.1
|
|
14
|
+
- @backstage/plugin-permission-common@0.9.5
|
|
15
|
+
- @backstage/plugin-permission-node@0.10.9
|
|
16
|
+
- @backstage/plugin-scaffolder-node@0.12.4
|
|
17
|
+
- @backstage/plugin-auth-node@0.6.12
|
|
37
18
|
|
|
38
19
|
## 3.1.1
|
|
39
20
|
|
package/README.md
CHANGED
|
@@ -124,3 +124,32 @@ Default secrets are resolved from environment variables and accessible via `${{
|
|
|
124
124
|
```
|
|
125
125
|
|
|
126
126
|
**Security Note:** Secrets are automatically masked in logs and are only available to backend actions, never exposed to the frontend.
|
|
127
|
+
|
|
128
|
+
## Audit Events
|
|
129
|
+
|
|
130
|
+
The Scaffolder backend emits audit events for various operations. Events are grouped logically by `eventId`, with `subEventId` providing further distinction when needed.
|
|
131
|
+
|
|
132
|
+
**Template Events:**
|
|
133
|
+
|
|
134
|
+
- **`template-parameter-schema`**: Retrieves template parameter schemas. (GET `/v2/templates/:namespace/:kind/:name/parameter-schema`)
|
|
135
|
+
|
|
136
|
+
**Action Events:**
|
|
137
|
+
|
|
138
|
+
- **`action-fetch`**: Retrieves installed actions. (GET `/v2/actions`)
|
|
139
|
+
|
|
140
|
+
**Task Events:**
|
|
141
|
+
|
|
142
|
+
- **`task`**: Operations related to Scaffolder tasks.
|
|
143
|
+
|
|
144
|
+
Filter on `actionType`.
|
|
145
|
+
|
|
146
|
+
- **`create`**: Creates a new task. (POST `/v2/tasks`)
|
|
147
|
+
- **`list`**: Fetches details of all tasks. (GET `/v2/tasks`)
|
|
148
|
+
- **`get`**: Fetches details of a specific task. (GET `/v2/tasks/:taskId`)
|
|
149
|
+
- **`cancel`**: Cancels a running task. (POST `/v2/tasks/:taskId/cancel`)
|
|
150
|
+
- **`retry`**: Retries a failed task. (POST `/v2/tasks/:taskId/retry`)
|
|
151
|
+
- **`stream`**: Retrieves a stream of task logs. (GET `/v2/tasks/:taskId/eventstream`)
|
|
152
|
+
- **`events`**: Retrieves a snapshot of task logs. (GET `/v2/tasks/:taskId/events`)
|
|
153
|
+
- **`dry-run`**: Creates a dry-run task. (POST `/v2/dry-run`) All audit logs for events associated with dry runs have the `meta.isDryLog` flag set to `true`.
|
|
154
|
+
- **`stale-cancel`**: Automated cancellation of stale tasks.
|
|
155
|
+
- **`execute`**: Tracks the initiation and completion of a real scaffolder task execution. This event will not occur during dry runs.
|
|
@@ -27,7 +27,7 @@ require('fs-extra');
|
|
|
27
27
|
require('@backstage/config');
|
|
28
28
|
require('p-queue');
|
|
29
29
|
require('./scaffolder/tasks/NunjucksWorkflowRunner.cjs.js');
|
|
30
|
-
require('
|
|
30
|
+
require('timers/promises');
|
|
31
31
|
var router = require('./service/router.cjs.js');
|
|
32
32
|
var loggerToWinstonLogger = require('./util/loggerToWinstonLogger.cjs.js');
|
|
33
33
|
var templating = require('./util/templating.cjs.js');
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
4
4
|
var fs$1 = require('fs-extra');
|
|
5
|
-
var path = require('
|
|
5
|
+
var path = require('path');
|
|
6
6
|
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
7
7
|
var log_examples = require('./log.examples.cjs.js');
|
|
8
|
-
var fs = require('
|
|
8
|
+
var fs = require('fs');
|
|
9
9
|
|
|
10
10
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
11
11
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/debug/log.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 { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { readdir, stat } from 'fs-extra';\nimport { join, relative } from '
|
|
1
|
+
{"version":3,"file":"log.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/debug/log.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 { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { readdir, stat } from 'fs-extra';\nimport { join, relative } from 'path';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { examples } from './log.examples';\nimport fs from 'fs';\n\nconst id = 'debug:log';\n\n/**\n * Writes a message into the log or lists all files in the workspace\n *\n * @remarks\n *\n * This task is useful for local development and testing of both the scaffolder\n * and scaffolder templates.\n *\n * @public\n */\nexport function createDebugLogAction() {\n return createTemplateAction({\n id,\n description:\n 'Writes a message into the log and/or lists all files in the workspace.',\n examples,\n schema: {\n input: {\n message: z =>\n z.string({ description: 'Message to output.' }).optional(),\n listWorkspace: z =>\n z\n .union([z.boolean(), z.enum(['with-filenames', 'with-contents'])], {\n description:\n 'List all files in the workspace. If used with \"with-contents\", also the file contents are listed.',\n })\n .optional(),\n },\n },\n supportsDryRun: true,\n async handler(ctx) {\n ctx.logger.info(JSON.stringify(ctx.input, null, 2));\n\n if (ctx.input?.message) {\n ctx.logger.info(ctx.input.message);\n }\n\n if (ctx.input?.listWorkspace) {\n const files = await recursiveReadDir(ctx.workspacePath);\n ctx.logger.info(\n `Workspace:\\n${files\n .map(f => {\n const relativePath = relative(ctx.workspacePath, f);\n if (ctx.input?.listWorkspace === 'with-contents') {\n try {\n const safePath = resolveSafeChildPath(\n ctx.workspacePath,\n relativePath,\n );\n const content = fs.readFileSync(safePath, 'utf-8');\n return ` - ${relativePath}:\\n\\n ${content}`;\n } catch {\n return ` - ${relativePath}: [skipped]`;\n }\n }\n return ` - ${relativePath}`;\n })\n .join('\\n')}`,\n );\n }\n },\n });\n}\n\nexport async function recursiveReadDir(dir: string): Promise<string[]> {\n const subdirs = await readdir(dir);\n const files = await Promise.all(\n subdirs.map(async subdir => {\n const res = join(dir, subdir);\n return (await stat(res)).isDirectory() ? recursiveReadDir(res) : [res];\n }),\n );\n return files.reduce((a, f) => a.concat(f), []);\n}\n"],"names":["createTemplateAction","examples","relative","resolveSafeChildPath","fs","readdir","join","stat"],"mappings":";;;;;;;;;;;;;AAuBA,MAAM,EAAA,GAAK,WAAA;AAYJ,SAAS,oBAAA,GAAuB;AACrC,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA;AAAA,IACA,WAAA,EACE,wEAAA;AAAA,cACFC,qBAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,OAAA,EAAS,OACP,CAAA,CAAE,MAAA,CAAO,EAAE,WAAA,EAAa,oBAAA,EAAsB,CAAA,CAAE,QAAA,EAAS;AAAA,QAC3D,aAAA,EAAe,CAAA,CAAA,KACb,CAAA,CACG,KAAA,CAAM,CAAC,CAAA,CAAE,OAAA,EAAQ,EAAG,CAAA,CAAE,KAAK,CAAC,gBAAA,EAAkB,eAAe,CAAC,CAAC,CAAA,EAAG;AAAA,UACjE,WAAA,EACE;AAAA,SACH,EACA,QAAA;AAAS;AAChB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;AACH;AAEA,eAAsB,iBAAiB,GAAA,EAAgC;AACrE,EAAA,MAAM,OAAA,GAAU,MAAMC,YAAA,CAAQ,GAAG,CAAA;AACjC,EAAA,MAAM,KAAA,GAAQ,MAAM,OAAA,CAAQ,GAAA;AAAA,IAC1B,OAAA,CAAQ,GAAA,CAAI,OAAM,MAAA,KAAU;AAC1B,MAAA,MAAM,GAAA,GAAMC,SAAA,CAAK,GAAA,EAAK,MAAM,CAAA;AAC5B,MAAA,OAAA,CAAQ,MAAMC,SAAA,CAAK,GAAG,CAAA,EAAG,WAAA,KAAgB,gBAAA,CAAiB,GAAG,CAAA,GAAI,CAAC,GAAG,CAAA;AAAA,IACvE,CAAC;AAAA,GACH;AACA,EAAA,OAAO,KAAA,CAAM,MAAA,CAAO,CAAC,CAAA,EAAG,CAAA,KAAM,EAAE,MAAA,CAAO,CAAC,CAAA,EAAG,EAAE,CAAA;AAC/C;;;;;"}
|
|
@@ -8,7 +8,7 @@ var isbinaryfile = require('isbinaryfile');
|
|
|
8
8
|
var createDefaultFilters = require('../../../../lib/templating/filters/createDefaultFilters.cjs.js');
|
|
9
9
|
var templating = require('../../../../util/templating.cjs.js');
|
|
10
10
|
var SecureTemplater = require('../../../../lib/templating/SecureTemplater.cjs.js');
|
|
11
|
-
var path = require('
|
|
11
|
+
var path = require('path');
|
|
12
12
|
|
|
13
13
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
14
14
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateActionHandler.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/templateActionHandler.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n isChildPath,\n resolveSafeChildPath,\n} from '@backstage/backend-plugin-api';\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n ActionContext,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport fs from 'fs-extra';\nimport globby from 'globby';\nimport { isBinaryFile } from 'isbinaryfile';\nimport { createDefaultFilters } from '../../../../lib/templating/filters/createDefaultFilters';\nimport { convertFiltersToRecord } from '../../../../util/templating';\nimport { SecureTemplater } from '../../../../lib/templating/SecureTemplater';\nimport { extname } from 'node:path';\n\nexport type TemplateActionInput = {\n targetPath?: string;\n values: any;\n templateFileExtension?: string | boolean;\n copyWithoutTemplating?: string[];\n cookiecutterCompat?: boolean;\n replace?: boolean;\n trimBlocks?: boolean;\n lstripBlocks?: boolean;\n};\n\nexport async function createTemplateActionHandler<\n I extends TemplateActionInput,\n>(options: {\n ctx: ActionContext<I, any, any>;\n resolveTemplate: () => Promise<string>;\n integrations: ScmIntegrations;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n}) {\n const {\n resolveTemplate,\n integrations,\n additionalTemplateFilters,\n additionalTemplateGlobals: templateGlobals,\n ctx,\n } = options;\n\n const templateFilters = {\n ...convertFiltersToRecord(createDefaultFilters({ integrations })),\n ...additionalTemplateFilters,\n };\n\n const { outputDir, copyOnlyPatterns, renderFilename, extension } =\n resolveTemplateActionSettings(ctx);\n\n const templateDir = await resolveTemplate();\n\n if (isChildPath(templateDir, outputDir)) {\n throw new InputError('targetPath must not be within template path');\n }\n\n ctx.logger.info('Listing files and directories in template');\n const allEntriesInTemplate = await globby(`**/*`, {\n cwd: templateDir,\n dot: true,\n onlyFiles: false,\n markDirectories: true,\n followSymbolicLinks: false,\n });\n\n const nonTemplatedEntries = new Set(\n await globby(copyOnlyPatterns || [], {\n cwd: templateDir,\n dot: true,\n onlyFiles: false,\n markDirectories: true,\n followSymbolicLinks: false,\n }),\n );\n\n // Cookiecutter prefixes all parameters in templates with\n // `cookiecutter.`. To replicate this, we wrap our parameters\n // in an object with a `cookiecutter` property when compat\n // mode is enabled.\n const { cookiecutterCompat, values } = ctx.input;\n const context = {\n [cookiecutterCompat ? 'cookiecutter' : 'values']: values,\n };\n\n ctx.logger.info(\n `Processing ${allEntriesInTemplate.length} template files/directories with input values`,\n ctx.input.values,\n );\n\n const renderTemplate = await SecureTemplater.loadRenderer({\n cookiecutterCompat: ctx.input.cookiecutterCompat,\n templateFilters,\n templateGlobals,\n nunjucksConfigs: {\n trimBlocks: ctx.input.trimBlocks,\n lstripBlocks: ctx.input.lstripBlocks,\n },\n });\n\n for (const location of allEntriesInTemplate) {\n let renderContents: boolean;\n\n let localOutputPath = location;\n if (extension) {\n renderContents = extname(localOutputPath) === extension;\n if (renderContents) {\n localOutputPath = localOutputPath.slice(0, -extension.length);\n }\n // extension is mutual exclusive with copyWithoutRender/copyWithoutTemplating,\n // therefore the output path is always rendered.\n localOutputPath = renderTemplate(localOutputPath, context);\n } else {\n renderContents = !nonTemplatedEntries.has(location);\n // The logic here is a bit tangled because it depends on two variables.\n // If renderFilename is true, which means copyWithoutTemplating is used,\n // then the path is always rendered.\n // If renderFilename is false, which means copyWithoutRender is used,\n // then matched file/directory won't be processed, same as before.\n if (renderFilename) {\n localOutputPath = renderTemplate(localOutputPath, context);\n } else {\n localOutputPath = renderContents\n ? renderTemplate(localOutputPath, context)\n : localOutputPath;\n }\n }\n\n if (containsSkippedContent(localOutputPath)) {\n continue;\n }\n\n const outputPath = resolveSafeChildPath(outputDir, localOutputPath);\n if (fs.existsSync(outputPath) && !ctx.input.replace) {\n continue;\n }\n\n if (!renderContents && !extension) {\n ctx.logger.info(`Copying file/directory ${location} without processing.`);\n }\n\n if (location.endsWith('/')) {\n ctx.logger.info(`Writing directory ${location} to template output path.`);\n await fs.ensureDir(outputPath);\n } else {\n const inputFilePath = resolveSafeChildPath(templateDir, location);\n const stats = await fs.promises.lstat(inputFilePath);\n\n if (stats.isSymbolicLink() || (await isBinaryFile(inputFilePath))) {\n ctx.logger.info(\n `Copying file binary or symbolic link at ${location}, to template output path.`,\n );\n await fs.copy(inputFilePath, outputPath);\n } else {\n const statsObj = await fs.stat(inputFilePath);\n ctx.logger.info(\n `Writing file ${location} to template output path with mode ${statsObj.mode}.`,\n );\n const inputFileContents = await fs.readFile(inputFilePath, 'utf-8');\n await fs.outputFile(\n outputPath,\n renderContents\n ? renderTemplate(inputFileContents, context)\n : inputFileContents,\n { mode: statsObj.mode },\n );\n }\n }\n }\n ctx.logger.info(`Template result written to ${outputDir}`);\n}\n\nfunction resolveTemplateActionSettings<I extends TemplateActionInput>(\n ctx: ActionContext<I, any, any>,\n): {\n outputDir: string;\n copyOnlyPatterns?: string[];\n renderFilename: boolean;\n extension: string | false;\n} {\n const targetPath = ctx.input.targetPath ?? './';\n const outputDir = resolveSafeChildPath(ctx.workspacePath, targetPath);\n\n const copyOnlyPatterns = ctx.input.copyWithoutTemplating;\n const renderFilename = true;\n\n if (copyOnlyPatterns && !Array.isArray(copyOnlyPatterns)) {\n throw new InputError(\n 'Fetch action input copyWithoutTemplating must be an Array',\n );\n }\n if (\n ctx.input.templateFileExtension &&\n (copyOnlyPatterns || ctx.input.cookiecutterCompat)\n ) {\n throw new InputError(\n 'Fetch action input extension incompatible with copyWithoutTemplating and cookiecutterCompat',\n );\n }\n let extension: string | false = false;\n if (ctx.input.templateFileExtension) {\n extension =\n ctx.input.templateFileExtension === true\n ? '.njk'\n : ctx.input.templateFileExtension;\n if (!extension.startsWith('.')) {\n extension = `.${extension}`;\n }\n }\n return {\n outputDir,\n copyOnlyPatterns,\n renderFilename,\n extension,\n };\n}\n\nfunction containsSkippedContent(localOutputPath: string): boolean {\n // if the path is empty means that there is a file skipped in the root\n // if the path starts with a separator it means that the root directory has been skipped\n // if the path includes // means that there is a subdirectory skipped\n // All paths returned are considered with / separator because of globby returning the linux separator for all os'.\n return (\n localOutputPath === '' ||\n localOutputPath.startsWith('/') ||\n localOutputPath.includes('//')\n );\n}\n"],"names":["convertFiltersToRecord","createDefaultFilters","isChildPath","InputError","globby","SecureTemplater","extname","resolveSafeChildPath","fs","isBinaryFile"],"mappings":";;;;;;;;;;;;;;;;;AA6CA,eAAsB,4BAEpB,OAAA,EAMC;AACD,EAAA,MAAM;AAAA,IACJ,eAAA;AAAA,IACA,YAAA;AAAA,IACA,yBAAA;AAAA,IACA,yBAAA,EAA2B,eAAA;AAAA,IAC3B;AAAA,GACF,GAAI,OAAA;AAEJ,EAAA,MAAM,eAAA,GAAkB;AAAA,IACtB,GAAGA,iCAAA,CAAuBC,yCAAA,CAAqB,EAAE,YAAA,EAAc,CAAC,CAAA;AAAA,IAChE,GAAG;AAAA,GACL;AAEA,EAAA,MAAM,EAAE,SAAA,EAAW,gBAAA,EAAkB,gBAAgB,SAAA,EAAU,GAC7D,8BAA8B,GAAG,CAAA;AAEnC,EAAA,MAAM,WAAA,GAAc,MAAM,eAAA,EAAgB;AAE1C,EAAA,IAAIC,4BAAA,CAAY,WAAA,EAAa,SAAS,CAAA,EAAG;AACvC,IAAA,MAAM,IAAIC,kBAAW,6CAA6C,CAAA;AAAA,EACpE;AAEA,EAAA,GAAA,CAAI,MAAA,CAAO,KAAK,2CAA2C,CAAA;AAC3D,EAAA,MAAM,oBAAA,GAAuB,MAAMC,uBAAA,CAAO,CAAA,IAAA,CAAA,EAAQ;AAAA,IAChD,GAAA,EAAK,WAAA;AAAA,IACL,GAAA,EAAK,IAAA;AAAA,IACL,SAAA,EAAW,KAAA;AAAA,IACX,eAAA,EAAiB,IAAA;AAAA,IACjB,mBAAA,EAAqB;AAAA,GACtB,CAAA;AAED,EAAA,MAAM,sBAAsB,IAAI,GAAA;AAAA,IAC9B,MAAMA,uBAAA,CAAO,gBAAA,IAAoB,EAAC,EAAG;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AM,kBAAA,CAAA,EAC/B;AACA,IAAA,MAAM,IAAIA,iBAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,IAAI,SAAA,GAA4B,KAAA;AAChC,EAAA,IAAI,GAAA,CAAI,MAAM,qBAAA,EAAuB;AACnC,IAAA,SAAA,GACE,IAAI,KAAA,CAAM,qBAAA,KAA0B,IAAA,GAChC,MAAA,GACA,IAAI,KAAA,CAAM,qBAAA;AAChB,IAAA,IAAI,CAAC,SAAA,CAAU,UAAA,CAAW,GAAG,CAAA,EAAG;AAC9B,MAAA,SAAA,GAAY,IAAI,SAAS,CAAA,CAAA;AAAA,IAC3B;AAAA,EACF;AACA,EAAA,OAAO;AAAA,IACL,SAAA;AAAA,IACA,gBAAA;AAAA,IACA,cAAA;AAAA,IACA;AAAA,GACF;AACF;AAEA,SAAS,uBAAuB,eAAA,EAAkC;AAKhE,EAAA,OACE,eAAA,KAAoB,MACpB,eAAA,CAAgB,UAAA,CAAW,GAAG,CAAA,IAC9B,eAAA,CAAgB,SAAS,IAAI,CAAA;AAEjC;;;;"}
|
|
1
|
+
{"version":3,"file":"templateActionHandler.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/templateActionHandler.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n isChildPath,\n resolveSafeChildPath,\n} from '@backstage/backend-plugin-api';\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n ActionContext,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport fs from 'fs-extra';\nimport globby from 'globby';\nimport { isBinaryFile } from 'isbinaryfile';\nimport { createDefaultFilters } from '../../../../lib/templating/filters/createDefaultFilters';\nimport { convertFiltersToRecord } from '../../../../util/templating';\nimport { SecureTemplater } from '../../../../lib/templating/SecureTemplater';\nimport { extname } from 'path';\n\nexport type TemplateActionInput = {\n targetPath?: string;\n values: any;\n templateFileExtension?: string | boolean;\n copyWithoutTemplating?: string[];\n cookiecutterCompat?: boolean;\n replace?: boolean;\n trimBlocks?: boolean;\n lstripBlocks?: boolean;\n};\n\nexport async function createTemplateActionHandler<\n I extends TemplateActionInput,\n>(options: {\n ctx: ActionContext<I, any, any>;\n resolveTemplate: () => Promise<string>;\n integrations: ScmIntegrations;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n}) {\n const {\n resolveTemplate,\n integrations,\n additionalTemplateFilters,\n additionalTemplateGlobals: templateGlobals,\n ctx,\n } = options;\n\n const templateFilters = {\n ...convertFiltersToRecord(createDefaultFilters({ integrations })),\n ...additionalTemplateFilters,\n };\n\n const { outputDir, copyOnlyPatterns, renderFilename, extension } =\n resolveTemplateActionSettings(ctx);\n\n const templateDir = await resolveTemplate();\n\n if (isChildPath(templateDir, outputDir)) {\n throw new InputError('targetPath must not be within template path');\n }\n\n ctx.logger.info('Listing files and directories in template');\n const allEntriesInTemplate = await globby(`**/*`, {\n cwd: templateDir,\n dot: true,\n onlyFiles: false,\n markDirectories: true,\n followSymbolicLinks: false,\n });\n\n const nonTemplatedEntries = new Set(\n await globby(copyOnlyPatterns || [], {\n cwd: templateDir,\n dot: true,\n onlyFiles: false,\n markDirectories: true,\n followSymbolicLinks: false,\n }),\n );\n\n // Cookiecutter prefixes all parameters in templates with\n // `cookiecutter.`. To replicate this, we wrap our parameters\n // in an object with a `cookiecutter` property when compat\n // mode is enabled.\n const { cookiecutterCompat, values } = ctx.input;\n const context = {\n [cookiecutterCompat ? 'cookiecutter' : 'values']: values,\n };\n\n ctx.logger.info(\n `Processing ${allEntriesInTemplate.length} template files/directories with input values`,\n ctx.input.values,\n );\n\n const renderTemplate = await SecureTemplater.loadRenderer({\n cookiecutterCompat: ctx.input.cookiecutterCompat,\n templateFilters,\n templateGlobals,\n nunjucksConfigs: {\n trimBlocks: ctx.input.trimBlocks,\n lstripBlocks: ctx.input.lstripBlocks,\n },\n });\n\n for (const location of allEntriesInTemplate) {\n let renderContents: boolean;\n\n let localOutputPath = location;\n if (extension) {\n renderContents = extname(localOutputPath) === extension;\n if (renderContents) {\n localOutputPath = localOutputPath.slice(0, -extension.length);\n }\n // extension is mutual exclusive with copyWithoutRender/copyWithoutTemplating,\n // therefore the output path is always rendered.\n localOutputPath = renderTemplate(localOutputPath, context);\n } else {\n renderContents = !nonTemplatedEntries.has(location);\n // The logic here is a bit tangled because it depends on two variables.\n // If renderFilename is true, which means copyWithoutTemplating is used,\n // then the path is always rendered.\n // If renderFilename is false, which means copyWithoutRender is used,\n // then matched file/directory won't be processed, same as before.\n if (renderFilename) {\n localOutputPath = renderTemplate(localOutputPath, context);\n } else {\n localOutputPath = renderContents\n ? renderTemplate(localOutputPath, context)\n : localOutputPath;\n }\n }\n\n if (containsSkippedContent(localOutputPath)) {\n continue;\n }\n\n const outputPath = resolveSafeChildPath(outputDir, localOutputPath);\n if (fs.existsSync(outputPath) && !ctx.input.replace) {\n continue;\n }\n\n if (!renderContents && !extension) {\n ctx.logger.info(`Copying file/directory ${location} without processing.`);\n }\n\n if (location.endsWith('/')) {\n ctx.logger.info(`Writing directory ${location} to template output path.`);\n await fs.ensureDir(outputPath);\n } else {\n const inputFilePath = resolveSafeChildPath(templateDir, location);\n const stats = await fs.promises.lstat(inputFilePath);\n\n if (stats.isSymbolicLink() || (await isBinaryFile(inputFilePath))) {\n ctx.logger.info(\n `Copying file binary or symbolic link at ${location}, to template output path.`,\n );\n await fs.copy(inputFilePath, outputPath);\n } else {\n const statsObj = await fs.stat(inputFilePath);\n ctx.logger.info(\n `Writing file ${location} to template output path with mode ${statsObj.mode}.`,\n );\n const inputFileContents = await fs.readFile(inputFilePath, 'utf-8');\n await fs.outputFile(\n outputPath,\n renderContents\n ? renderTemplate(inputFileContents, context)\n : inputFileContents,\n { mode: statsObj.mode },\n );\n }\n }\n }\n ctx.logger.info(`Template result written to ${outputDir}`);\n}\n\nfunction resolveTemplateActionSettings<I extends TemplateActionInput>(\n ctx: ActionContext<I, any, any>,\n): {\n outputDir: string;\n copyOnlyPatterns?: string[];\n renderFilename: boolean;\n extension: string | false;\n} {\n const targetPath = ctx.input.targetPath ?? './';\n const outputDir = resolveSafeChildPath(ctx.workspacePath, targetPath);\n\n const copyOnlyPatterns = ctx.input.copyWithoutTemplating;\n const renderFilename = true;\n\n if (copyOnlyPatterns && !Array.isArray(copyOnlyPatterns)) {\n throw new InputError(\n 'Fetch action input copyWithoutTemplating must be an Array',\n );\n }\n if (\n ctx.input.templateFileExtension &&\n (copyOnlyPatterns || ctx.input.cookiecutterCompat)\n ) {\n throw new InputError(\n 'Fetch action input extension incompatible with copyWithoutTemplating and cookiecutterCompat',\n );\n }\n let extension: string | false = false;\n if (ctx.input.templateFileExtension) {\n extension =\n ctx.input.templateFileExtension === true\n ? '.njk'\n : ctx.input.templateFileExtension;\n if (!extension.startsWith('.')) {\n extension = `.${extension}`;\n }\n }\n return {\n outputDir,\n copyOnlyPatterns,\n renderFilename,\n extension,\n };\n}\n\nfunction containsSkippedContent(localOutputPath: string): boolean {\n // if the path is empty means that there is a file skipped in the root\n // if the path starts with a separator it means that the root directory has been skipped\n // if the path includes // means that there is a subdirectory skipped\n // All paths returned are considered with / separator because of globby returning the linux separator for all os'.\n return (\n localOutputPath === '' ||\n localOutputPath.startsWith('/') ||\n localOutputPath.includes('//')\n );\n}\n"],"names":["convertFiltersToRecord","createDefaultFilters","isChildPath","InputError","globby","SecureTemplater","extname","resolveSafeChildPath","fs","isBinaryFile"],"mappings":";;;;;;;;;;;;;;;;;AA6CA,eAAsB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CAAM,qBAAA;AAChB,IAAA,IAAI,CAAC,SAAA,CAAU,UAAA,CAAW,GAAG,CAAA,EAAG;AAC9B,MAAA,SAAA,GAAY,IAAI,SAAS,CAAA,CAAA;AAAA,IAC3B;AAAA,EACF;AACA,EAAA,OAAO;AAAA,IACL,SAAA;AAAA,IACA,gBAAA;AAAA,IACA,cAAA;AAAA,IACA;AAAA,GACF;AACF;AAEA,SAAS,uBAAuB,eAAA,EAAkC;AAKhE,EAAA,OACE,eAAA,KAAoB,MACpB,eAAA,CAAgB,UAAA,CAAW,GAAG,CAAA,IAC9B,eAAA,CAAgB,SAAS,IAAI,CAAA;AAEjC;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
4
|
-
var path = require('
|
|
4
|
+
var path = require('path');
|
|
5
5
|
var templateFile_examples = require('./templateFile.examples.cjs.js');
|
|
6
6
|
var templateFileActionHandler = require('./templateFileActionHandler.cjs.js');
|
|
7
7
|
|
|
@@ -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 '
|
|
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,OAAA,EAK3C;AACD,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,qBAAA;AAAA,IACJ,WAAA,EAAa,uDAAA;AAAA,cACbC,8BAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,GAAA,EAAK,CAAA,CAAA,KACH,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EACE;AAAA,SACH,CAAA;AAAA,QACH,UAAA,EAAY,CAAA,CAAA,KACV,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EACE;AAAA,SACH,CAAA;AAAA,QACH,QAAQ,CAAA,CAAA,KACN,CAAA,CACG,MAAA,CAAO,CAAA,CAAE,KAAI,EAAG;AAAA,UACf,WAAA,EAAa;AAAA,SACd,EACA,QAAA,EAAS;AAAA,QACd,kBAAA,EAAoB,CAAA,CAAA,KAClB,CAAA,CACG,OAAA,CAAQ;AAAA,UACP,WAAA,EACE;AAAA,SACH,EACA,QAAA,EAAS;AAAA,QACd,OAAA,EAAS,CAAA,CAAA,KACP,CAAA,CACG,OAAA,CAAQ;AAAA,UACP,WAAA,EACE;AAAA,SACH,EACA,QAAA,EAAS;AAAA,QACd,UAAA,EAAY,CAAA,CAAA,KACV,CAAA,CACG,OAAA,CAAQ;AAAA,UACP,WAAA,EACE;AAAA,SACH,EACA,QAAA,EAAS;AAAA,QACd,YAAA,EAAc,CAAA,CAAA,KACZ,CAAA,CACG,OAAA,CAAQ;AAAA,UACP,WAAA,EACE;AAAA,SACH,EACA,QAAA,EAAS;AAAA,QACd,KAAA,EAAO,CAAA,CAAA,KACL,CAAA,CACG,MAAA,CAAO;AAAA,UACN,WAAA,EACE;AAAA,SACH,EACA,QAAA;AAAS;AAChB,KACF;AAAA,IACA,cAAA,EAAgB,IAAA;AAAA,IAChB,OAAA,EAAS,SACPC,yDAAA,CAAgC;AAAA,MAC9B,GAAA;AAAA,MACA,qBAAqB,YAAY;AAC/B,QAAA,GAAA,CAAI,MAAA,CAAO,KAAK,gDAAgD,CAAA;AAEhE,QAAA,MAAM,OAAA,GAAU,MAAM,GAAA,CAAI,wBAAA,EAAyB;AAEnD,QAAA,MAAM,WAAA,GAAcC,qBAAA,CAAK,IAAA,CAAK,OAAA,EAAS,KAAK,CAAA;AAE5C,QAAA,MAAMC,8BAAA,CAAU;AAAA,UACd,OAAA,EAAS,IAAI,YAAA,EAAc,OAAA;AAAA,UAC3B,QAAA,EAAU,IAAI,KAAA,CAAM,GAAA;AAAA,UACpB,UAAA,EAAY,WAAA;AAAA,UACZ,KAAA,EAAO,IAAI,KAAA,CAAM,KAAA;AAAA,UACjB,GAAG;AAAA,SACJ,CAAA;AACD,QAAA,OAAO,WAAA;AAAA,MACT,CAAA;AAAA,MACA,GAAG;AAAA,KACJ;AAAA,GACJ,CAAA;AACH;;;;"}
|
|
@@ -4,7 +4,7 @@ var fs = require('fs-extra');
|
|
|
4
4
|
var createDefaultFilters = require('../../../../lib/templating/filters/createDefaultFilters.cjs.js');
|
|
5
5
|
var templating = require('../../../../util/templating.cjs.js');
|
|
6
6
|
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
7
|
-
var path = require('
|
|
7
|
+
var path = require('path');
|
|
8
8
|
var SecureTemplater = require('../../../../lib/templating/SecureTemplater.cjs.js');
|
|
9
9
|
|
|
10
10
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateFileActionHandler.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/templateFileActionHandler.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n ActionContext,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport fs from 'fs-extra';\nimport { createDefaultFilters } from '../../../../lib/templating/filters/createDefaultFilters';\nimport { convertFiltersToRecord } from '../../../../util/templating';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport path from '
|
|
1
|
+
{"version":3,"file":"templateFileActionHandler.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/templateFileActionHandler.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { ScmIntegrations } from '@backstage/integration';\nimport {\n ActionContext,\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport fs from 'fs-extra';\nimport { createDefaultFilters } from '../../../../lib/templating/filters/createDefaultFilters';\nimport { convertFiltersToRecord } from '../../../../util/templating';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport path from 'path';\nimport { SecureTemplater } from '../../../../lib/templating/SecureTemplater';\n\nexport type TemplateFileActionInput = {\n targetPath: string;\n values: any;\n cookiecutterCompat?: boolean;\n replace?: boolean;\n trimBlocks?: boolean;\n lstripBlocks?: boolean;\n};\n\nexport async function createTemplateFileActionHandler<\n I extends TemplateFileActionInput = TemplateFileActionInput,\n>(options: {\n ctx: ActionContext<I, any, any>;\n resolveTemplateFile: () => Promise<string>;\n integrations: ScmIntegrations;\n additionalTemplateFilters?: Record<string, TemplateFilter>;\n additionalTemplateGlobals?: Record<string, TemplateGlobal>;\n}) {\n const {\n resolveTemplateFile,\n integrations,\n additionalTemplateFilters,\n additionalTemplateGlobals: templateGlobals,\n ctx,\n } = options;\n\n const templateFilters = {\n ...convertFiltersToRecord(createDefaultFilters({ integrations })),\n ...additionalTemplateFilters,\n };\n\n const 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 const filePath = await resolveTemplateFile();\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 templateGlobals,\n nunjucksConfigs: {\n trimBlocks: ctx.input.trimBlocks,\n lstripBlocks: ctx.input.lstripBlocks,\n },\n });\n\n const contents = await fs.readFile(filePath, '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"],"names":["convertFiltersToRecord","createDefaultFilters","resolveSafeChildPath","fs","SecureTemplater","path"],"mappings":";;;;;;;;;;;;;;AAqCA,eAAsB,gCAEpB,OAAA,EAMC;AACD,EAAA,MAAM;AAAA,IACJ,mBAAA;AAAA,IACA,YAAA;AAAA,IACA,yBAAA;AAAA,IACA,yBAAA,EAA2B,eAAA;AAAA,IAC3B;AAAA,GACF,GAAI,OAAA;AAEJ,EAAA,MAAM,eAAA,GAAkB;AAAA,IACtB,GAAGA,iCAAA,CAAuBC,yCAAA,CAAqB,EAAE,YAAA,EAAc,CAAC,CAAA;AAAA,IAChE,GAAG;AAAA,GACL;AAEA,EAAA,MAAM,UAAA,GAAaC,qCAAA;AAAA,IACjB,GAAA,CAAI,aAAA;AAAA,IACJ,IAAI,KAAA,CAAM;AAAA,GACZ;AAEA,EAAA,IAAIC,oBAAG,UAAA,CAAW,UAAU,KAAK,CAAC,GAAA,CAAI,MAAM,OAAA,EAAS;AACnD,IAAA,GAAA,CAAI,MAAA,CAAO,IAAA;AAAA,MACT,CAAA,KAAA,EAAQ,GAAA,CAAI,KAAA,CAAM,UAAU,CAAA,4CAAA;AAAA,KAC9B;AACA,IAAA;AAAA,EACF;AACA,EAAA,MAAM,QAAA,GAAW,MAAM,mBAAA,EAAoB;AAE3C,EAAA,MAAM,EAAE,kBAAA,EAAoB,MAAA,EAAO,GAAI,GAAA,CAAI,KAAA;AAC3C,EAAA,MAAM,OAAA,GAAU;AAAA,IACd,CAAC,kBAAA,GAAqB,cAAA,GAAiB,QAAQ,GAAG;AAAA,GACpD;AAEA,EAAA,GAAA,CAAI,MAAA,CAAO,IAAA;AAAA,IACT,CAAA,0CAAA,CAAA;AAAA,IACA,IAAI,KAAA,CAAM;AAAA,GACZ;AAEA,EAAA,MAAM,cAAA,GAAiB,MAAMC,+BAAA,CAAgB,YAAA,CAAa;AAAA,IACxD,kBAAA;AAAA,IACA,eAAA;AAAA,IACA,eAAA;AAAA,IACA,eAAA,EAAiB;AAAA,MACf,UAAA,EAAY,IAAI,KAAA,CAAM,UAAA;AAAA,MACtB,YAAA,EAAc,IAAI,KAAA,CAAM;AAAA;AAC1B,GACD,CAAA;AAED,EAAA,MAAM,QAAA,GAAW,MAAMD,mBAAA,CAAG,QAAA,CAAS,UAAU,OAAO,CAAA;AACpD,EAAA,MAAM,MAAA,GAAS,cAAA,CAAe,QAAA,EAAU,OAAO,CAAA;AAC/C,EAAA,MAAMA,mBAAA,CAAG,SAAA,CAAUE,qBAAA,CAAK,OAAA,CAAQ,UAAU,CAAC,CAAA;AAC3C,EAAA,MAAMF,mBAAA,CAAG,UAAA,CAAW,UAAA,EAAY,MAAM,CAAA;AAEtC,EAAA,GAAA,CAAI,MAAA,CAAO,IAAA,CAAK,CAAA,kCAAA,EAAqC,UAAU,CAAA,CAAE,CAAA;AACnE;;;;"}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
4
4
|
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
5
|
-
var fs = require('
|
|
6
|
-
var path = require('
|
|
5
|
+
var fs = require('fs/promises');
|
|
6
|
+
var path = require('path');
|
|
7
7
|
var read_examples = require('./read.examples.cjs.js');
|
|
8
8
|
|
|
9
9
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
@@ -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 { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport fs from '
|
|
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 './read.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,aAAA,GAAgB,CAAC,CAAA,KACrB,CAAA,CAAE,MAAA,CAAO;AAAA,EACP,IAAA,EAAM,CAAA,CAAE,MAAA,EAAO,CAAE,SAAS,+BAA+B,CAAA;AAAA,EACzD,IAAA,EAAM,CAAA,CACH,MAAA,EAAO,CACP,SAAS,yDAAyD,CAAA;AAAA,EACrE,QAAA,EAAU,CAAA,CAAE,MAAA,EAAO,CAAE,SAAS,oCAAoC;AACpE,CAAC,CAAA;AAQI,MAAM,gCAAgC,MAAM;AACjD,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,YAAA;AAAA,IACJ,WAAA,EAAa,gDAAA;AAAA,IACb,cAAA,EAAgB,IAAA;AAAA,cAChBC,sBAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,KAAA,EAAO,OAAK,CAAA,CAAE,KAAA,CAAM,EAAE,MAAA,EAAO,CAAE,GAAA,CAAI,CAAC,CAAC,CAAA;AAAA,QACrC,WAAW,CAAA,CAAA,KAAK,CAAA,CAAE,OAAA,EAAQ,CAAE,QAAQ,KAAK;AAAA,OAC3C;AAAA,MACA,MAAA,EAAQ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/B;AAAA,GACD,CAAA;AACH;;;;"}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
4
4
|
var fs = require('fs-extra');
|
|
5
|
-
var path = require('
|
|
6
|
-
var
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var url = require('url');
|
|
7
7
|
var uuid = require('uuid');
|
|
8
8
|
var NunjucksWorkflowRunner = require('../tasks/NunjucksWorkflowRunner.cjs.js');
|
|
9
9
|
var DecoratedActionsRegistry = require('./DecoratedActionsRegistry.cjs.js');
|
|
@@ -35,7 +35,7 @@ function createDryRunner(options) {
|
|
|
35
35
|
if (!baseUrl) {
|
|
36
36
|
throw new Error("baseUrl is required");
|
|
37
37
|
}
|
|
38
|
-
const basePath =
|
|
38
|
+
const basePath = url.fileURLToPath(new URL(baseUrl));
|
|
39
39
|
const contentsPath = path__default.default.dirname(basePath);
|
|
40
40
|
const dryRunId = uuid.v4();
|
|
41
41
|
const log = new Array();
|
|
@@ -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 LoggerService,\n} from '@backstage/backend-plugin-api';\nimport type { UserEntity } from '@backstage/catalog-model';\nimport { Config } from '@backstage/config';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { PermissionEvaluator } from '@backstage/plugin-permission-common';\nimport {\n ScaffolderTaskStatus,\n TaskSpec,\n TemplateInfo,\n} 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 '
|
|
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 { Config } from '@backstage/config';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { PermissionEvaluator } from '@backstage/plugin-permission-common';\nimport {\n ScaffolderTaskStatus,\n TaskSpec,\n TemplateInfo,\n} 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 { NunjucksWorkflowRunner } from '../tasks/NunjucksWorkflowRunner';\nimport { DecoratedActionsRegistry } from './DecoratedActionsRegistry';\nimport { TemplateActionRegistry } from '../actions';\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<{\n body: {\n message: string;\n stepId?: string;\n status?: ScaffolderTaskStatus;\n };\n }>;\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 config?: Config;\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 config: options.config,\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<{\n body: {\n message: string;\n stepId?: string;\n status?: ScaffolderTaskStatus;\n };\n }>();\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":";;;;;;;;;;;;;;;AA6FO,SAAS,gBAAgB,OAAA,EAAsC;AACpE,EAAA,OAAO,eAAe,OAAO,KAAA,EAA2C;AACtE,IAAA,IAAI,cAAA;AAEJ,IAAA,MAAM,cAAA,GAAiB,IAAIA,6CAAA,CAAuB;AAAA,MAChD,GAAG,OAAA;AAAA,MACH,cAAA,EAAgB,IAAIC,iDAAA,CAAyB,OAAA,CAAQ,cAAA,EAAgB;AAAA,QACnEC,yCAAA,CAAqB;AAAA,UACnB,EAAA,EAAI,iBAAA;AAAA,UACJ,cAAA,EAAgB,IAAA;AAAA,UAChB,MAAM,QAAQ,GAAA,EAAK;AACjB,YAAA,cAAA,GAAiBC,+CAAA,CAA2B,IAAI,aAAa,CAAA;AAC7D,YAAA,MAAM,cAAA,CAAe,MAAM,MAAM;AAAA,YAAC,CAAC,CAAA;AAAA,UACrC;AAAA,SACD;AAAA,OACF,CAAA;AAAA,MACD,QAAQ,OAAA,CAAQ;AAAA,KACjB,CAAA;AAGD,IAAA,MAAM,OAAA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,WAAA,EAAa,WAAW,QAAA,EAAU;AACpC,YAAA;AAAA,UACF;AACA,UAAA,GAAA,CAAI,IAAA,CAAK;AAAA,YACP,IAAA,EAAM;AAAA,cACJ,GAAG,WAAA;AAAA,cACH;AAAA;AACF,WACD,CAAA;AAAA,QACH,CAAA;AAAA,QACA,UAAU,YAAY;AACpB,UAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AAAA,QACnC;AAAA,OACD,CAAA;AAED,MAAA,IAAI,CAAC,cAAA,EAAgB;AACnB,QAAA,MAAM,IAAI,MAAM,qCAAqC,CAAA;AAAA,MACvD;AACA,MAAA,MAAM,oBAAoB,MAAM,cAAA;AAEhC,MAAA,OAAO;AAAA,QACL,GAAA;AAAA,QACA,iBAAA;AAAA,QACA,QAAQ,MAAA,CAAO;AAAA,OACjB;AAAA,IACF,CAAA,SAAE;AACA,MAAA,MAAMC,mBAAA,CAAG,OAAO,YAAY,CAAA;AAAA,IAC9B;AAAA,EACF,CAAA;AACF;;;;"}
|
|
@@ -5,7 +5,7 @@ var api = require('@opentelemetry/api');
|
|
|
5
5
|
var fs = require('fs-extra');
|
|
6
6
|
var jsonschema = require('jsonschema');
|
|
7
7
|
var nunjucks = require('nunjucks');
|
|
8
|
-
var path = require('
|
|
8
|
+
var path = require('path');
|
|
9
9
|
var winston = require('winston');
|
|
10
10
|
var SecureTemplater = require('../../lib/templating/SecureTemplater.cjs.js');
|
|
11
11
|
var helper = require('./helper.cjs.js');
|