@backstage/plugin-scaffolder-node 0.3.1 → 0.3.3-next.0
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 +10 -3
- package/alpha/package.json +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +14 -1
- package/package.json +31 -31
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
# @backstage/plugin-scaffolder-node
|
|
2
2
|
|
|
3
|
-
## 0.3.
|
|
3
|
+
## 0.3.3-next.0
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
+
- 85f4723: Fixed file corruption for non UTF-8 data in fetch contents
|
|
8
|
+
- c6b132e: Introducing checkpoints for scaffolder task action idempotency
|
|
7
9
|
- Updated dependencies
|
|
8
|
-
- @backstage/backend-common@0.21.
|
|
9
|
-
- @backstage/
|
|
10
|
+
- @backstage/backend-common@0.21.3-next.0
|
|
11
|
+
- @backstage/errors@1.2.4-next.0
|
|
12
|
+
- @backstage/backend-plugin-api@0.6.13-next.0
|
|
13
|
+
- @backstage/catalog-model@1.4.5-next.0
|
|
14
|
+
- @backstage/integration@1.9.1-next.0
|
|
15
|
+
- @backstage/types@1.1.1
|
|
16
|
+
- @backstage/plugin-scaffolder-common@1.5.1-next.0
|
|
10
17
|
|
|
11
18
|
## 0.3.0
|
|
12
19
|
|
package/alpha/package.json
CHANGED
package/dist/index.cjs.js
CHANGED
|
@@ -104,7 +104,7 @@ async function fetchFile(options) {
|
|
|
104
104
|
const res = await reader.readUrl(readUrl, { token });
|
|
105
105
|
await fs__default["default"].ensureDir(path__default["default"].dirname(outputPath));
|
|
106
106
|
const buffer = await res.buffer();
|
|
107
|
-
await fs__default["default"].outputFile(outputPath, buffer
|
|
107
|
+
await fs__default["default"].outputFile(outputPath, buffer);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
function isFetchUrlAbsolute(fetchUrl) {
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/actions/createTemplateAction.ts","../src/actions/executeShellCommand.ts","../src/actions/fetch.ts","../src/actions/gitHelpers.ts","../src/actions/util.ts","../src/files/serializeDirectoryContents.ts","../src/files/deserializeDirectoryContents.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 { ActionContext, TemplateAction } from './types';\nimport { z } from 'zod';\nimport { Schema } from 'jsonschema';\nimport zodToJsonSchema from 'zod-to-json-schema';\nimport { JsonObject } from '@backstage/types';\n\n/** @public */\nexport type TemplateExample = {\n description: string;\n example: string;\n};\n\n/** @public */\nexport type TemplateActionOptions<\n TActionInput extends JsonObject = {},\n TActionOutput extends JsonObject = {},\n TInputSchema extends Schema | z.ZodType = {},\n TOutputSchema extends Schema | z.ZodType = {},\n> = {\n id: string;\n description?: string;\n examples?: TemplateExample[];\n supportsDryRun?: boolean;\n schema?: {\n input?: TInputSchema;\n output?: TOutputSchema;\n };\n handler: (ctx: ActionContext<TActionInput, TActionOutput>) => Promise<void>;\n};\n\n/**\n * This function is used to create new template actions to get type safety.\n * Will convert zod schemas to json schemas for use throughout the system.\n * @public\n */\nexport const createTemplateAction = <\n TInputParams extends JsonObject = JsonObject,\n TOutputParams extends JsonObject = JsonObject,\n TInputSchema extends Schema | z.ZodType = {},\n TOutputSchema extends Schema | z.ZodType = {},\n TActionInput extends JsonObject = TInputSchema extends z.ZodType<\n any,\n any,\n infer IReturn\n >\n ? IReturn\n : TInputParams,\n TActionOutput extends JsonObject = TOutputSchema extends z.ZodType<\n any,\n any,\n infer IReturn\n >\n ? IReturn\n : TOutputParams,\n>(\n action: TemplateActionOptions<\n TActionInput,\n TActionOutput,\n TInputSchema,\n TOutputSchema\n >,\n): TemplateAction<TActionInput, TActionOutput> => {\n const inputSchema =\n action.schema?.input && 'safeParseAsync' in action.schema.input\n ? zodToJsonSchema(action.schema.input)\n : action.schema?.input;\n\n const outputSchema =\n action.schema?.output && 'safeParseAsync' in action.schema.output\n ? zodToJsonSchema(action.schema.output)\n : action.schema?.output;\n\n return {\n ...action,\n schema: {\n ...action.schema,\n input: inputSchema as TInputSchema,\n output: outputSchema as TOutputSchema,\n },\n };\n};\n","/*\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 { spawn, SpawnOptionsWithoutStdio } from 'child_process';\nimport { PassThrough, Writable } from 'stream';\n\n/**\n * Options for {@link executeShellCommand}.\n *\n * @public\n */\nexport type ExecuteShellCommandOptions = {\n /** command to run */\n command: string;\n /** arguments to pass the command */\n args: string[];\n /** options to pass to spawn */\n options?: SpawnOptionsWithoutStdio;\n /** stream to capture stdout and stderr output */\n logStream?: Writable;\n};\n\n/**\n * Run a command in a sub-process, normally a shell command.\n *\n * @public\n */\nexport async function executeShellCommand(\n options: ExecuteShellCommandOptions,\n): Promise<void> {\n const {\n command,\n args,\n options: spawnOptions,\n logStream = new PassThrough(),\n } = options;\n\n await new Promise<void>((resolve, reject) => {\n const process = spawn(command, args, spawnOptions);\n\n process.stdout.on('data', stream => {\n logStream.write(stream);\n });\n\n process.stderr.on('data', stream => {\n logStream.write(stream);\n });\n\n process.on('error', error => {\n return reject(error);\n });\n\n process.on('close', code => {\n if (code !== 0) {\n return reject(\n new Error(`Command ${command} failed, exit code: ${code}`),\n );\n }\n return resolve();\n });\n });\n}\n","/*\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, UrlReader } from '@backstage/backend-common';\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrations } from '@backstage/integration';\nimport fs from 'fs-extra';\nimport path from 'path';\n\n/**\n * A helper function that reads the contents of a directory from the given URL.\n * Can be used in your own actions, and also used behind fetch:template and fetch:plain\n *\n * @public\n */\nexport async function fetchContents(options: {\n reader: UrlReader;\n integrations: ScmIntegrations;\n baseUrl?: string;\n fetchUrl?: string;\n outputPath: string;\n token?: string;\n}) {\n const {\n reader,\n integrations,\n baseUrl,\n fetchUrl = '.',\n outputPath,\n token,\n } = options;\n\n const fetchUrlIsAbsolute = isFetchUrlAbsolute(fetchUrl);\n\n // We handle both file locations and url ones\n if (!fetchUrlIsAbsolute && baseUrl?.startsWith('file://')) {\n const basePath = baseUrl.slice('file://'.length);\n const srcDir = resolveSafeChildPath(path.dirname(basePath), fetchUrl);\n await fs.copy(srcDir, outputPath);\n } else {\n const readUrl = getReadUrl(fetchUrl, baseUrl, integrations);\n\n const res = await reader.readTree(readUrl, { token });\n await fs.ensureDir(outputPath);\n await res.dir({ targetDir: outputPath });\n }\n}\n\n/**\n * A helper function that reads the content of a single file from the given URL.\n * Can be used in your own actions, and also used behind `fetch:plain:file`\n *\n * @public\n */\nexport async function fetchFile(options: {\n reader: UrlReader;\n integrations: ScmIntegrations;\n baseUrl?: string;\n fetchUrl?: string;\n outputPath: string;\n token?: string;\n}) {\n const {\n reader,\n integrations,\n baseUrl,\n fetchUrl = '.',\n outputPath,\n token,\n } = options;\n\n const fetchUrlIsAbsolute = isFetchUrlAbsolute(fetchUrl);\n\n // We handle both file locations and url ones\n if (!fetchUrlIsAbsolute && baseUrl?.startsWith('file://')) {\n const basePath = baseUrl.slice('file://'.length);\n const src = resolveSafeChildPath(path.dirname(basePath), fetchUrl);\n await fs.copyFile(src, outputPath);\n } else {\n const readUrl = getReadUrl(fetchUrl, baseUrl, integrations);\n\n const res = await reader.readUrl(readUrl, { token });\n await fs.ensureDir(path.dirname(outputPath));\n const buffer = await res.buffer();\n await fs.outputFile(outputPath, buffer.toString());\n }\n}\n\nfunction isFetchUrlAbsolute(fetchUrl: string) {\n let fetchUrlIsAbsolute = false;\n try {\n // eslint-disable-next-line no-new\n new URL(fetchUrl);\n fetchUrlIsAbsolute = true;\n } catch {\n /* ignored */\n }\n return fetchUrlIsAbsolute;\n}\n\nfunction getReadUrl(\n fetchUrl: string,\n baseUrl: string | undefined,\n integrations: ScmIntegrations,\n) {\n if (isFetchUrlAbsolute(fetchUrl)) {\n return fetchUrl;\n } else if (baseUrl) {\n const integration = integrations.byUrl(baseUrl);\n if (!integration) {\n throw new InputError(`No integration found for location ${baseUrl}`);\n }\n\n return integration.resolveUrl({\n url: fetchUrl,\n base: baseUrl,\n });\n }\n throw new InputError(\n `Failed to fetch, template location could not be determined and the fetch URL is relative, ${fetchUrl}`,\n );\n}\n","/*\n * Copyright 2023 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 { Git } from '@backstage/backend-common';\nimport { Logger } from 'winston';\n\n/**\n * @public\n */\nexport async function initRepoAndPush(input: {\n dir: string;\n remoteUrl: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger: Logger;\n defaultBranch?: string;\n commitMessage?: string;\n gitAuthorInfo?: { name?: string; email?: string };\n}): Promise<{ commitHash: string }> {\n const {\n dir,\n remoteUrl,\n auth,\n logger,\n defaultBranch = 'master',\n commitMessage = 'Initial commit',\n gitAuthorInfo,\n } = input;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.init({\n dir,\n defaultBranch,\n });\n\n await git.add({ dir, filepath: '.' });\n\n // use provided info if possible, otherwise use fallbacks\n const authorInfo = {\n name: gitAuthorInfo?.name ?? 'Scaffolder',\n email: gitAuthorInfo?.email ?? 'scaffolder@backstage.io',\n };\n\n const commitHash = await git.commit({\n dir,\n message: commitMessage,\n author: authorInfo,\n committer: authorInfo,\n });\n await git.addRemote({\n dir,\n url: remoteUrl,\n remote: 'origin',\n });\n\n await git.push({\n dir,\n remote: 'origin',\n });\n\n return { commitHash };\n}\n\n/**\n * @public\n */\nexport async function commitAndPushRepo(input: {\n dir: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger: Logger;\n commitMessage: string;\n gitAuthorInfo?: { name?: string; email?: string };\n branch?: string;\n remoteRef?: string;\n}): Promise<{ commitHash: string }> {\n const {\n dir,\n auth,\n logger,\n commitMessage,\n gitAuthorInfo,\n branch = 'master',\n remoteRef,\n } = input;\n\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.fetch({ dir });\n await git.checkout({ dir, ref: branch });\n await git.add({ dir, filepath: '.' });\n\n // use provided info if possible, otherwise use fallbacks\n const authorInfo = {\n name: gitAuthorInfo?.name ?? 'Scaffolder',\n email: gitAuthorInfo?.email ?? 'scaffolder@backstage.io',\n };\n\n const commitHash = await git.commit({\n dir,\n message: commitMessage,\n author: authorInfo,\n committer: authorInfo,\n });\n\n await git.push({\n dir,\n remote: 'origin',\n remoteRef: remoteRef ?? `refs/heads/${branch}`,\n });\n\n return { commitHash };\n}\n\n/**\n * @public\n */\nexport async function cloneRepo(options: {\n url: string;\n dir: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: Logger | undefined;\n ref?: string | undefined;\n depth?: number | undefined;\n noCheckout?: boolean | undefined;\n}): Promise<void> {\n const { url, dir, auth, logger, ref, depth, noCheckout } = options;\n\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.clone({ url, dir, ref, depth, noCheckout });\n}\n\n/**\n * @public\n */\nexport async function createBranch(options: {\n dir: string;\n ref: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: Logger | undefined;\n}): Promise<void> {\n const { dir, ref, auth, logger } = options;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.checkout({ dir, ref });\n}\n\n/**\n * @public\n */\nexport async function addFiles(options: {\n dir: string;\n filepath: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: Logger | undefined;\n}): Promise<void> {\n const { dir, filepath, auth, logger } = options;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.add({ dir, filepath });\n}\n\n/**\n * @public\n */\nexport async function commitAndPushBranch(options: {\n dir: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: Logger | undefined;\n commitMessage: string;\n gitAuthorInfo?: { name?: string; email?: string };\n branch?: string;\n remoteRef?: string;\n remote?: string;\n}): Promise<{ commitHash: string }> {\n const {\n dir,\n auth,\n logger,\n commitMessage,\n gitAuthorInfo,\n branch = 'master',\n remoteRef,\n remote = 'origin',\n } = options;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n // use provided info if possible, otherwise use fallbacks\n const authorInfo = {\n name: gitAuthorInfo?.name ?? 'Scaffolder',\n email: gitAuthorInfo?.email ?? 'scaffolder@backstage.io',\n };\n\n const commitHash = await git.commit({\n dir,\n message: commitMessage,\n author: authorInfo,\n committer: authorInfo,\n });\n\n await git.push({\n dir,\n remote,\n remoteRef: remoteRef ?? `refs/heads/${branch}`,\n });\n\n return { commitHash };\n}\n","/*\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 { InputError } from '@backstage/errors';\nimport { isChildPath } from '@backstage/backend-common';\nimport { join as joinPath, normalize as normalizePath } from 'path';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\n\n/**\n * @public\n */\nexport const getRepoSourceDirectory = (\n workspacePath: string,\n sourcePath: string | undefined,\n) => {\n if (sourcePath) {\n const safeSuffix = normalizePath(sourcePath).replace(\n /^(\\.\\.(\\/|\\\\|$))+/,\n '',\n );\n const path = joinPath(workspacePath, safeSuffix);\n if (!isChildPath(workspacePath, path)) {\n throw new Error('Invalid source path');\n }\n return path;\n }\n return workspacePath;\n};\n\n/**\n * @public\n */\nexport const parseRepoUrl = (\n repoUrl: string,\n integrations: ScmIntegrationRegistry,\n): {\n repo: string;\n host: string;\n owner?: string;\n organization?: string;\n workspace?: string;\n project?: string;\n} => {\n let parsed;\n try {\n parsed = new URL(`https://${repoUrl}`);\n } catch (error) {\n throw new InputError(\n `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`,\n );\n }\n const host = parsed.host;\n const owner = parsed.searchParams.get('owner') ?? undefined;\n const organization = parsed.searchParams.get('organization') ?? undefined;\n const workspace = parsed.searchParams.get('workspace') ?? undefined;\n const project = parsed.searchParams.get('project') ?? undefined;\n\n const type = integrations.byHost(host)?.type;\n\n if (!type) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n const repo: string = parsed.searchParams.get('repo')!;\n switch (type) {\n case 'bitbucket': {\n if (host === 'www.bitbucket.org') {\n checkRequiredParams(parsed, 'workspace');\n }\n checkRequiredParams(parsed, 'project', 'repo');\n break;\n }\n case 'gitlab': {\n // project is the projectID, and if defined, owner and repo won't be needed.\n if (!project) {\n checkRequiredParams(parsed, 'owner', 'repo');\n }\n break;\n }\n case 'gitea': {\n checkRequiredParams(parsed, 'repo');\n break;\n }\n case 'gerrit': {\n checkRequiredParams(parsed, 'repo');\n break;\n }\n default: {\n checkRequiredParams(parsed, 'repo', 'owner');\n break;\n }\n }\n\n return { host, owner, repo, organization, workspace, project };\n};\n\nfunction checkRequiredParams(repoUrl: URL, ...params: string[]) {\n for (let i = 0; i < params.length; i++) {\n if (!repoUrl.searchParams.get(params[i])) {\n throw new InputError(\n `Invalid repo URL passed to publisher: ${repoUrl.toString()}, missing ${\n params[i]\n }`,\n );\n }\n }\n}\n","/*\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 { promises as fs } from 'fs';\nimport globby from 'globby';\nimport limiterFactory from 'p-limit';\nimport { resolveSafeChildPath } from '@backstage/backend-common';\nimport { SerializedFile } from './types';\nimport { isError } from '@backstage/errors';\n\nconst DEFAULT_GLOB_PATTERNS = ['./**', '!.git'];\n\nexport const isExecutable = (fileMode: number | undefined) => {\n if (!fileMode) {\n return false;\n }\n\n const executeBitMask = 0o000111;\n const res = fileMode & executeBitMask;\n return res > 0;\n};\n\nasync function asyncFilter<T>(\n array: T[],\n callback: (value: T, index: number, array: T[]) => Promise<boolean>,\n): Promise<T[]> {\n const filterMap = await Promise.all(array.map(callback));\n return array.filter((_value, index) => filterMap[index]);\n}\n\n/**\n * @public\n */\nexport async function serializeDirectoryContents(\n sourcePath: string,\n options?: {\n gitignore?: boolean;\n globPatterns?: string[];\n },\n): Promise<SerializedFile[]> {\n const paths = await globby(options?.globPatterns ?? DEFAULT_GLOB_PATTERNS, {\n cwd: sourcePath,\n dot: true,\n gitignore: options?.gitignore,\n followSymbolicLinks: false,\n // In order to pick up 'broken' symlinks, we oxymoronically request files AND folders yet we filter out folders\n // This is because broken symlinks aren't classed as files so we need to glob everything\n onlyFiles: false,\n objectMode: true,\n stats: true,\n });\n\n const limiter = limiterFactory(10);\n\n const valid = await asyncFilter(paths, async ({ dirent, path }) => {\n if (dirent.isDirectory()) return false;\n if (!dirent.isSymbolicLink()) return true;\n\n const safePath = resolveSafeChildPath(sourcePath, path);\n\n // we only want files that don't exist\n try {\n await fs.stat(safePath);\n return false;\n } catch (e) {\n return isError(e) && e.code === 'ENOENT';\n }\n });\n\n return Promise.all(\n valid.map(async ({ dirent, path, stats }) => ({\n path,\n content: await limiter(async () => {\n const absFilePath = resolveSafeChildPath(sourcePath, path);\n if (dirent.isSymbolicLink()) {\n return fs.readlink(absFilePath, 'buffer');\n }\n return fs.readFile(absFilePath);\n }),\n executable: isExecutable(stats?.mode),\n symlink: dirent.isSymbolicLink(),\n })),\n );\n}\n","/*\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 fs from 'fs-extra';\nimport { dirname } from 'path';\nimport { resolveSafeChildPath } from '@backstage/backend-common';\nimport { SerializedFile } from './types';\n\n/**\n * Deserializes a list of serialized files into the target directory.\n *\n * This method uses `resolveSafeChildPath` to make sure that files are\n * not written outside of the target directory.\n *\n * @public\n */\nexport async function deserializeDirectoryContents(\n targetPath: string,\n files: SerializedFile[],\n): Promise<void> {\n for (const file of files) {\n const filePath = resolveSafeChildPath(targetPath, file.path);\n await fs.ensureDir(dirname(filePath));\n await fs.writeFile(filePath, file.content); // Ignore file mode\n }\n}\n"],"names":["zodToJsonSchema","PassThrough","spawn","resolveSafeChildPath","path","fs","InputError","Git","normalizePath","joinPath","isChildPath","globby","limiterFactory","isError","dirname"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmDa,MAAA,oBAAA,GAAuB,CAoBlC,MAMgD,KAAA;AA7ElD,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,CAAA;AA8EE,EAAA,MAAM,gBACJ,EAAO,GAAA,MAAA,CAAA,MAAA,KAAP,IAAe,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,KAAA,KAAS,oBAAoB,MAAO,CAAA,MAAA,CAAO,KACtD,GAAAA,mCAAA,CAAgB,OAAO,MAAO,CAAA,KAAK,CACnC,GAAA,CAAA,EAAA,GAAA,MAAA,CAAO,WAAP,IAAe,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,KAAA,CAAA;AAErB,EAAA,MAAM,iBACJ,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A;AAAA,MACD,UAAA,EAAY,YAAa,CAAA,KAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,KAAA,CAAO,IAAI,CAAA;AAAA,MACpC,OAAA,EAAS,OAAO,cAAe,EAAA;AAAA,KAC/B,CAAA,CAAA;AAAA,GACJ,CAAA;AACF;;ACnEsB,eAAA,4BAAA,CACpB,YACA,KACe,EAAA;AACf,EAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AACxB,IAAA,MAAM,QAAW,GAAAF,kCAAA,CAAqB,UAAY,EAAA,IAAA,CAAK,IAAI,CAAA,CAAA;AAC3D,IAAA,MAAME,sBAAG,CAAA,SAAA,CAAUS,YAAQ,CAAA,QAAQ,CAAC,CAAA,CAAA;AACpC,IAAA,MAAMT,sBAAG,CAAA,SAAA,CAAU,QAAU,EAAA,IAAA,CAAK,OAAO,CAAA,CAAA;AAAA,GAC3C;AACF;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/actions/createTemplateAction.ts","../src/actions/executeShellCommand.ts","../src/actions/fetch.ts","../src/actions/gitHelpers.ts","../src/actions/util.ts","../src/files/serializeDirectoryContents.ts","../src/files/deserializeDirectoryContents.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 { ActionContext, TemplateAction } from './types';\nimport { z } from 'zod';\nimport { Schema } from 'jsonschema';\nimport zodToJsonSchema from 'zod-to-json-schema';\nimport { JsonObject } from '@backstage/types';\n\n/** @public */\nexport type TemplateExample = {\n description: string;\n example: string;\n};\n\n/** @public */\nexport type TemplateActionOptions<\n TActionInput extends JsonObject = {},\n TActionOutput extends JsonObject = {},\n TInputSchema extends Schema | z.ZodType = {},\n TOutputSchema extends Schema | z.ZodType = {},\n> = {\n id: string;\n description?: string;\n examples?: TemplateExample[];\n supportsDryRun?: boolean;\n schema?: {\n input?: TInputSchema;\n output?: TOutputSchema;\n };\n handler: (ctx: ActionContext<TActionInput, TActionOutput>) => Promise<void>;\n};\n\n/**\n * This function is used to create new template actions to get type safety.\n * Will convert zod schemas to json schemas for use throughout the system.\n * @public\n */\nexport const createTemplateAction = <\n TInputParams extends JsonObject = JsonObject,\n TOutputParams extends JsonObject = JsonObject,\n TInputSchema extends Schema | z.ZodType = {},\n TOutputSchema extends Schema | z.ZodType = {},\n TActionInput extends JsonObject = TInputSchema extends z.ZodType<\n any,\n any,\n infer IReturn\n >\n ? IReturn\n : TInputParams,\n TActionOutput extends JsonObject = TOutputSchema extends z.ZodType<\n any,\n any,\n infer IReturn\n >\n ? IReturn\n : TOutputParams,\n>(\n action: TemplateActionOptions<\n TActionInput,\n TActionOutput,\n TInputSchema,\n TOutputSchema\n >,\n): TemplateAction<TActionInput, TActionOutput> => {\n const inputSchema =\n action.schema?.input && 'safeParseAsync' in action.schema.input\n ? zodToJsonSchema(action.schema.input)\n : action.schema?.input;\n\n const outputSchema =\n action.schema?.output && 'safeParseAsync' in action.schema.output\n ? zodToJsonSchema(action.schema.output)\n : action.schema?.output;\n\n return {\n ...action,\n schema: {\n ...action.schema,\n input: inputSchema as TInputSchema,\n output: outputSchema as TOutputSchema,\n },\n };\n};\n","/*\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 { spawn, SpawnOptionsWithoutStdio } from 'child_process';\nimport { PassThrough, Writable } from 'stream';\n\n/**\n * Options for {@link executeShellCommand}.\n *\n * @public\n */\nexport type ExecuteShellCommandOptions = {\n /** command to run */\n command: string;\n /** arguments to pass the command */\n args: string[];\n /** options to pass to spawn */\n options?: SpawnOptionsWithoutStdio;\n /** stream to capture stdout and stderr output */\n logStream?: Writable;\n};\n\n/**\n * Run a command in a sub-process, normally a shell command.\n *\n * @public\n */\nexport async function executeShellCommand(\n options: ExecuteShellCommandOptions,\n): Promise<void> {\n const {\n command,\n args,\n options: spawnOptions,\n logStream = new PassThrough(),\n } = options;\n\n await new Promise<void>((resolve, reject) => {\n const process = spawn(command, args, spawnOptions);\n\n process.stdout.on('data', stream => {\n logStream.write(stream);\n });\n\n process.stderr.on('data', stream => {\n logStream.write(stream);\n });\n\n process.on('error', error => {\n return reject(error);\n });\n\n process.on('close', code => {\n if (code !== 0) {\n return reject(\n new Error(`Command ${command} failed, exit code: ${code}`),\n );\n }\n return resolve();\n });\n });\n}\n","/*\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, UrlReader } from '@backstage/backend-common';\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrations } from '@backstage/integration';\nimport fs from 'fs-extra';\nimport path from 'path';\n\n/**\n * A helper function that reads the contents of a directory from the given URL.\n * Can be used in your own actions, and also used behind fetch:template and fetch:plain\n *\n * @public\n */\nexport async function fetchContents(options: {\n reader: UrlReader;\n integrations: ScmIntegrations;\n baseUrl?: string;\n fetchUrl?: string;\n outputPath: string;\n token?: string;\n}) {\n const {\n reader,\n integrations,\n baseUrl,\n fetchUrl = '.',\n outputPath,\n token,\n } = options;\n\n const fetchUrlIsAbsolute = isFetchUrlAbsolute(fetchUrl);\n\n // We handle both file locations and url ones\n if (!fetchUrlIsAbsolute && baseUrl?.startsWith('file://')) {\n const basePath = baseUrl.slice('file://'.length);\n const srcDir = resolveSafeChildPath(path.dirname(basePath), fetchUrl);\n await fs.copy(srcDir, outputPath);\n } else {\n const readUrl = getReadUrl(fetchUrl, baseUrl, integrations);\n\n const res = await reader.readTree(readUrl, { token });\n await fs.ensureDir(outputPath);\n await res.dir({ targetDir: outputPath });\n }\n}\n\n/**\n * A helper function that reads the content of a single file from the given URL.\n * Can be used in your own actions, and also used behind `fetch:plain:file`\n *\n * @public\n */\nexport async function fetchFile(options: {\n reader: UrlReader;\n integrations: ScmIntegrations;\n baseUrl?: string;\n fetchUrl?: string;\n outputPath: string;\n token?: string;\n}) {\n const {\n reader,\n integrations,\n baseUrl,\n fetchUrl = '.',\n outputPath,\n token,\n } = options;\n\n const fetchUrlIsAbsolute = isFetchUrlAbsolute(fetchUrl);\n\n // We handle both file locations and url ones\n if (!fetchUrlIsAbsolute && baseUrl?.startsWith('file://')) {\n const basePath = baseUrl.slice('file://'.length);\n const src = resolveSafeChildPath(path.dirname(basePath), fetchUrl);\n await fs.copyFile(src, outputPath);\n } else {\n const readUrl = getReadUrl(fetchUrl, baseUrl, integrations);\n\n const res = await reader.readUrl(readUrl, { token });\n await fs.ensureDir(path.dirname(outputPath));\n const buffer = await res.buffer();\n await fs.outputFile(outputPath, buffer);\n }\n}\n\nfunction isFetchUrlAbsolute(fetchUrl: string) {\n let fetchUrlIsAbsolute = false;\n try {\n // eslint-disable-next-line no-new\n new URL(fetchUrl);\n fetchUrlIsAbsolute = true;\n } catch {\n /* ignored */\n }\n return fetchUrlIsAbsolute;\n}\n\nfunction getReadUrl(\n fetchUrl: string,\n baseUrl: string | undefined,\n integrations: ScmIntegrations,\n) {\n if (isFetchUrlAbsolute(fetchUrl)) {\n return fetchUrl;\n } else if (baseUrl) {\n const integration = integrations.byUrl(baseUrl);\n if (!integration) {\n throw new InputError(`No integration found for location ${baseUrl}`);\n }\n\n return integration.resolveUrl({\n url: fetchUrl,\n base: baseUrl,\n });\n }\n throw new InputError(\n `Failed to fetch, template location could not be determined and the fetch URL is relative, ${fetchUrl}`,\n );\n}\n","/*\n * Copyright 2023 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 { Git } from '@backstage/backend-common';\nimport { Logger } from 'winston';\n\n/**\n * @public\n */\nexport async function initRepoAndPush(input: {\n dir: string;\n remoteUrl: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger: Logger;\n defaultBranch?: string;\n commitMessage?: string;\n gitAuthorInfo?: { name?: string; email?: string };\n}): Promise<{ commitHash: string }> {\n const {\n dir,\n remoteUrl,\n auth,\n logger,\n defaultBranch = 'master',\n commitMessage = 'Initial commit',\n gitAuthorInfo,\n } = input;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.init({\n dir,\n defaultBranch,\n });\n\n await git.add({ dir, filepath: '.' });\n\n // use provided info if possible, otherwise use fallbacks\n const authorInfo = {\n name: gitAuthorInfo?.name ?? 'Scaffolder',\n email: gitAuthorInfo?.email ?? 'scaffolder@backstage.io',\n };\n\n const commitHash = await git.commit({\n dir,\n message: commitMessage,\n author: authorInfo,\n committer: authorInfo,\n });\n await git.addRemote({\n dir,\n url: remoteUrl,\n remote: 'origin',\n });\n\n await git.push({\n dir,\n remote: 'origin',\n });\n\n return { commitHash };\n}\n\n/**\n * @public\n */\nexport async function commitAndPushRepo(input: {\n dir: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger: Logger;\n commitMessage: string;\n gitAuthorInfo?: { name?: string; email?: string };\n branch?: string;\n remoteRef?: string;\n}): Promise<{ commitHash: string }> {\n const {\n dir,\n auth,\n logger,\n commitMessage,\n gitAuthorInfo,\n branch = 'master',\n remoteRef,\n } = input;\n\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.fetch({ dir });\n await git.checkout({ dir, ref: branch });\n await git.add({ dir, filepath: '.' });\n\n // use provided info if possible, otherwise use fallbacks\n const authorInfo = {\n name: gitAuthorInfo?.name ?? 'Scaffolder',\n email: gitAuthorInfo?.email ?? 'scaffolder@backstage.io',\n };\n\n const commitHash = await git.commit({\n dir,\n message: commitMessage,\n author: authorInfo,\n committer: authorInfo,\n });\n\n await git.push({\n dir,\n remote: 'origin',\n remoteRef: remoteRef ?? `refs/heads/${branch}`,\n });\n\n return { commitHash };\n}\n\n/**\n * @public\n */\nexport async function cloneRepo(options: {\n url: string;\n dir: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: Logger | undefined;\n ref?: string | undefined;\n depth?: number | undefined;\n noCheckout?: boolean | undefined;\n}): Promise<void> {\n const { url, dir, auth, logger, ref, depth, noCheckout } = options;\n\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.clone({ url, dir, ref, depth, noCheckout });\n}\n\n/**\n * @public\n */\nexport async function createBranch(options: {\n dir: string;\n ref: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: Logger | undefined;\n}): Promise<void> {\n const { dir, ref, auth, logger } = options;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.checkout({ dir, ref });\n}\n\n/**\n * @public\n */\nexport async function addFiles(options: {\n dir: string;\n filepath: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: Logger | undefined;\n}): Promise<void> {\n const { dir, filepath, auth, logger } = options;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.add({ dir, filepath });\n}\n\n/**\n * @public\n */\nexport async function commitAndPushBranch(options: {\n dir: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: Logger | undefined;\n commitMessage: string;\n gitAuthorInfo?: { name?: string; email?: string };\n branch?: string;\n remoteRef?: string;\n remote?: string;\n}): Promise<{ commitHash: string }> {\n const {\n dir,\n auth,\n logger,\n commitMessage,\n gitAuthorInfo,\n branch = 'master',\n remoteRef,\n remote = 'origin',\n } = options;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n // use provided info if possible, otherwise use fallbacks\n const authorInfo = {\n name: gitAuthorInfo?.name ?? 'Scaffolder',\n email: gitAuthorInfo?.email ?? 'scaffolder@backstage.io',\n };\n\n const commitHash = await git.commit({\n dir,\n message: commitMessage,\n author: authorInfo,\n committer: authorInfo,\n });\n\n await git.push({\n dir,\n remote,\n remoteRef: remoteRef ?? `refs/heads/${branch}`,\n });\n\n return { commitHash };\n}\n","/*\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 { InputError } from '@backstage/errors';\nimport { isChildPath } from '@backstage/backend-common';\nimport { join as joinPath, normalize as normalizePath } from 'path';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\n\n/**\n * @public\n */\nexport const getRepoSourceDirectory = (\n workspacePath: string,\n sourcePath: string | undefined,\n) => {\n if (sourcePath) {\n const safeSuffix = normalizePath(sourcePath).replace(\n /^(\\.\\.(\\/|\\\\|$))+/,\n '',\n );\n const path = joinPath(workspacePath, safeSuffix);\n if (!isChildPath(workspacePath, path)) {\n throw new Error('Invalid source path');\n }\n return path;\n }\n return workspacePath;\n};\n\n/**\n * @public\n */\nexport const parseRepoUrl = (\n repoUrl: string,\n integrations: ScmIntegrationRegistry,\n): {\n repo: string;\n host: string;\n owner?: string;\n organization?: string;\n workspace?: string;\n project?: string;\n} => {\n let parsed;\n try {\n parsed = new URL(`https://${repoUrl}`);\n } catch (error) {\n throw new InputError(\n `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`,\n );\n }\n const host = parsed.host;\n const owner = parsed.searchParams.get('owner') ?? undefined;\n const organization = parsed.searchParams.get('organization') ?? undefined;\n const workspace = parsed.searchParams.get('workspace') ?? undefined;\n const project = parsed.searchParams.get('project') ?? undefined;\n\n const type = integrations.byHost(host)?.type;\n\n if (!type) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n const repo: string = parsed.searchParams.get('repo')!;\n switch (type) {\n case 'bitbucket': {\n if (host === 'www.bitbucket.org') {\n checkRequiredParams(parsed, 'workspace');\n }\n checkRequiredParams(parsed, 'project', 'repo');\n break;\n }\n case 'gitlab': {\n // project is the projectID, and if defined, owner and repo won't be needed.\n if (!project) {\n checkRequiredParams(parsed, 'owner', 'repo');\n }\n break;\n }\n case 'gitea': {\n checkRequiredParams(parsed, 'repo');\n break;\n }\n case 'gerrit': {\n checkRequiredParams(parsed, 'repo');\n break;\n }\n default: {\n checkRequiredParams(parsed, 'repo', 'owner');\n break;\n }\n }\n\n return { host, owner, repo, organization, workspace, project };\n};\n\nfunction checkRequiredParams(repoUrl: URL, ...params: string[]) {\n for (let i = 0; i < params.length; i++) {\n if (!repoUrl.searchParams.get(params[i])) {\n throw new InputError(\n `Invalid repo URL passed to publisher: ${repoUrl.toString()}, missing ${\n params[i]\n }`,\n );\n }\n }\n}\n","/*\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 { promises as fs } from 'fs';\nimport globby from 'globby';\nimport limiterFactory from 'p-limit';\nimport { resolveSafeChildPath } from '@backstage/backend-common';\nimport { SerializedFile } from './types';\nimport { isError } from '@backstage/errors';\n\nconst DEFAULT_GLOB_PATTERNS = ['./**', '!.git'];\n\nexport const isExecutable = (fileMode: number | undefined) => {\n if (!fileMode) {\n return false;\n }\n\n const executeBitMask = 0o000111;\n const res = fileMode & executeBitMask;\n return res > 0;\n};\n\nasync function asyncFilter<T>(\n array: T[],\n callback: (value: T, index: number, array: T[]) => Promise<boolean>,\n): Promise<T[]> {\n const filterMap = await Promise.all(array.map(callback));\n return array.filter((_value, index) => filterMap[index]);\n}\n\n/**\n * @public\n */\nexport async function serializeDirectoryContents(\n sourcePath: string,\n options?: {\n gitignore?: boolean;\n globPatterns?: string[];\n },\n): Promise<SerializedFile[]> {\n const paths = await globby(options?.globPatterns ?? DEFAULT_GLOB_PATTERNS, {\n cwd: sourcePath,\n dot: true,\n gitignore: options?.gitignore,\n followSymbolicLinks: false,\n // In order to pick up 'broken' symlinks, we oxymoronically request files AND folders yet we filter out folders\n // This is because broken symlinks aren't classed as files so we need to glob everything\n onlyFiles: false,\n objectMode: true,\n stats: true,\n });\n\n const limiter = limiterFactory(10);\n\n const valid = await asyncFilter(paths, async ({ dirent, path }) => {\n if (dirent.isDirectory()) return false;\n if (!dirent.isSymbolicLink()) return true;\n\n const safePath = resolveSafeChildPath(sourcePath, path);\n\n // we only want files that don't exist\n try {\n await fs.stat(safePath);\n return false;\n } catch (e) {\n return isError(e) && e.code === 'ENOENT';\n }\n });\n\n return Promise.all(\n valid.map(async ({ dirent, path, stats }) => ({\n path,\n content: await limiter(async () => {\n const absFilePath = resolveSafeChildPath(sourcePath, path);\n if (dirent.isSymbolicLink()) {\n return fs.readlink(absFilePath, 'buffer');\n }\n return fs.readFile(absFilePath);\n }),\n executable: isExecutable(stats?.mode),\n symlink: dirent.isSymbolicLink(),\n })),\n );\n}\n","/*\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 fs from 'fs-extra';\nimport { dirname } from 'path';\nimport { resolveSafeChildPath } from '@backstage/backend-common';\nimport { SerializedFile } from './types';\n\n/**\n * Deserializes a list of serialized files into the target directory.\n *\n * This method uses `resolveSafeChildPath` to make sure that files are\n * not written outside of the target directory.\n *\n * @public\n */\nexport async function deserializeDirectoryContents(\n targetPath: string,\n files: SerializedFile[],\n): Promise<void> {\n for (const file of files) {\n const filePath = resolveSafeChildPath(targetPath, file.path);\n await fs.ensureDir(dirname(filePath));\n await fs.writeFile(filePath, file.content); // Ignore file mode\n }\n}\n"],"names":["zodToJsonSchema","PassThrough","spawn","resolveSafeChildPath","path","fs","InputError","Git","normalizePath","joinPath","isChildPath","glob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import { JsonObject, JsonValue, Observable } from '@backstage/types';
|
|
5
5
|
import { TaskSpec, TemplateInfo } from '@backstage/plugin-scaffolder-common';
|
|
6
6
|
import { UserEntity } from '@backstage/catalog-model';
|
|
7
7
|
import { Schema } from 'jsonschema';
|
|
@@ -95,6 +95,18 @@ interface TaskContext {
|
|
|
95
95
|
isDryRun?: boolean;
|
|
96
96
|
complete(result: TaskCompletionState, metadata?: JsonObject): Promise<void>;
|
|
97
97
|
emitLog(message: string, logMetadata?: JsonObject): Promise<void>;
|
|
98
|
+
getTaskState?(): Promise<{
|
|
99
|
+
state?: JsonObject;
|
|
100
|
+
} | undefined>;
|
|
101
|
+
updateCheckpoint?(options: {
|
|
102
|
+
key: string;
|
|
103
|
+
status: 'success';
|
|
104
|
+
value: JsonValue;
|
|
105
|
+
} | {
|
|
106
|
+
key: string;
|
|
107
|
+
status: 'failed';
|
|
108
|
+
reason: string;
|
|
109
|
+
}): Promise<void>;
|
|
98
110
|
getWorkspaceName(): Promise<string>;
|
|
99
111
|
}
|
|
100
112
|
/**
|
|
@@ -134,6 +146,7 @@ type ActionContext<TActionInput extends JsonObject, TActionOutput extends JsonOb
|
|
|
134
146
|
secrets?: TaskSecrets;
|
|
135
147
|
workspacePath: string;
|
|
136
148
|
input: TActionInput;
|
|
149
|
+
checkpoint?<U extends JsonValue>(key: string, fn: () => Promise<U>): Promise<U>;
|
|
137
150
|
output(name: keyof TActionOutput, value: TActionOutput[keyof TActionOutput]): void;
|
|
138
151
|
/**
|
|
139
152
|
* Creates a temporary directory for use by the action, which is then cleaned up automatically.
|
package/package.json
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-scaffolder-node",
|
|
3
|
+
"version": "0.3.3-next.0",
|
|
3
4
|
"description": "The plugin-scaffolder-node module for @backstage/plugin-scaffolder-backend",
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"license": "Apache-2.0",
|
|
5
|
+
"backstage": {
|
|
6
|
+
"role": "node-library"
|
|
7
|
+
},
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
10
10
|
},
|
|
11
|
+
"homepage": "https://backstage.io",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/backstage/backstage",
|
|
15
|
+
"directory": "plugins/scaffolder-node"
|
|
16
|
+
},
|
|
17
|
+
"license": "Apache-2.0",
|
|
11
18
|
"exports": {
|
|
12
19
|
".": {
|
|
13
20
|
"require": "./dist/index.cjs.js",
|
|
@@ -21,31 +28,28 @@
|
|
|
21
28
|
},
|
|
22
29
|
"./package.json": "./package.json"
|
|
23
30
|
},
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"url": "https://github.com/backstage/backstage",
|
|
31
|
-
"directory": "plugins/scaffolder-node"
|
|
32
|
-
},
|
|
31
|
+
"main": "./dist/index.cjs.js",
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"files": [
|
|
34
|
+
"alpha",
|
|
35
|
+
"dist"
|
|
36
|
+
],
|
|
33
37
|
"scripts": {
|
|
34
|
-
"start": "backstage-cli package start",
|
|
35
38
|
"build": "backstage-cli package build",
|
|
36
|
-
"lint": "backstage-cli package lint",
|
|
37
|
-
"test": "backstage-cli package test",
|
|
38
39
|
"clean": "backstage-cli package clean",
|
|
40
|
+
"lint": "backstage-cli package lint",
|
|
39
41
|
"prepack": "backstage-cli package prepack",
|
|
40
|
-
"postpack": "backstage-cli package postpack"
|
|
42
|
+
"postpack": "backstage-cli package postpack",
|
|
43
|
+
"start": "backstage-cli package start",
|
|
44
|
+
"test": "backstage-cli package test"
|
|
41
45
|
},
|
|
42
46
|
"dependencies": {
|
|
43
|
-
"@backstage/backend-common": "^0.21.
|
|
44
|
-
"@backstage/backend-plugin-api": "^0.6.
|
|
45
|
-
"@backstage/catalog-model": "^1.4.
|
|
46
|
-
"@backstage/errors": "^1.2.
|
|
47
|
-
"@backstage/integration": "^1.9.0",
|
|
48
|
-
"@backstage/plugin-scaffolder-common": "^1.5.0",
|
|
47
|
+
"@backstage/backend-common": "^0.21.3-next.0",
|
|
48
|
+
"@backstage/backend-plugin-api": "^0.6.13-next.0",
|
|
49
|
+
"@backstage/catalog-model": "^1.4.5-next.0",
|
|
50
|
+
"@backstage/errors": "^1.2.4-next.0",
|
|
51
|
+
"@backstage/integration": "^1.9.1-next.0",
|
|
52
|
+
"@backstage/plugin-scaffolder-common": "^1.5.1-next.0",
|
|
49
53
|
"@backstage/types": "^1.1.1",
|
|
50
54
|
"fs-extra": "^11.2.0",
|
|
51
55
|
"globby": "^11.0.0",
|
|
@@ -56,12 +60,8 @@
|
|
|
56
60
|
"zod-to-json-schema": "^3.20.4"
|
|
57
61
|
},
|
|
58
62
|
"devDependencies": {
|
|
59
|
-
"@backstage/backend-test-utils": "^0.3.
|
|
60
|
-
"@backstage/cli": "^0.25.
|
|
61
|
-
"@backstage/config": "^1.1.
|
|
62
|
-
}
|
|
63
|
-
"files": [
|
|
64
|
-
"alpha",
|
|
65
|
-
"dist"
|
|
66
|
-
]
|
|
63
|
+
"@backstage/backend-test-utils": "^0.3.3-next.0",
|
|
64
|
+
"@backstage/cli": "^0.25.3-next.0",
|
|
65
|
+
"@backstage/config": "^1.1.2-next.0"
|
|
66
|
+
}
|
|
67
67
|
}
|