@backstage/plugin-scaffolder-node 0.2.6 → 0.2.8-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 +14 -0
- package/alpha/package.json +3 -3
- package/dist/alpha.cjs.js +20 -0
- package/dist/alpha.cjs.js.map +1 -0
- package/dist/alpha.d.ts +48 -0
- package/dist/index.cjs.js +0 -14
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +150 -192
- package/package.json +22 -12
- package/dist/index.alpha.d.ts +0 -342
- package/dist/index.beta.d.ts +0 -305
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @backstage/plugin-scaffolder-node
|
|
2
2
|
|
|
3
|
+
## 0.2.8-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8613ba3928: Switched to using `"exports"` field for `/alpha` subpath export.
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/plugin-scaffolder-common@1.4.3-next.0
|
|
10
|
+
- @backstage/backend-common@0.19.9-next.0
|
|
11
|
+
- @backstage/integration@1.7.1
|
|
12
|
+
- @backstage/backend-plugin-api@0.6.7-next.0
|
|
13
|
+
- @backstage/catalog-model@1.4.3
|
|
14
|
+
- @backstage/errors@1.2.3
|
|
15
|
+
- @backstage/types@1.1.1
|
|
16
|
+
|
|
3
17
|
## 0.2.6
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/alpha/package.json
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
6
|
+
|
|
7
|
+
const scaffolderActionsExtensionPoint = backendPluginApi.createExtensionPoint({
|
|
8
|
+
id: "scaffolder.actions"
|
|
9
|
+
});
|
|
10
|
+
const scaffolderTaskBrokerExtensionPoint = backendPluginApi.createExtensionPoint({
|
|
11
|
+
id: "scaffolder.taskBroker"
|
|
12
|
+
});
|
|
13
|
+
const scaffolderTemplatingExtensionPoint = backendPluginApi.createExtensionPoint({
|
|
14
|
+
id: "scaffolder.templating"
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
exports.scaffolderActionsExtensionPoint = scaffolderActionsExtensionPoint;
|
|
18
|
+
exports.scaffolderTaskBrokerExtensionPoint = scaffolderTaskBrokerExtensionPoint;
|
|
19
|
+
exports.scaffolderTemplatingExtensionPoint = scaffolderTemplatingExtensionPoint;
|
|
20
|
+
//# sourceMappingURL=alpha.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alpha.cjs.js","sources":["../src/alpha.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 { createExtensionPoint } from '@backstage/backend-plugin-api';\nimport {\n TemplateAction,\n TemplateFilter,\n TemplateGlobal,\n TaskBroker,\n} from '@backstage/plugin-scaffolder-node';\n\n/**\n * Extension point for managing scaffolder actions.\n *\n * @alpha\n */\nexport interface ScaffolderActionsExtensionPoint {\n addActions(...actions: TemplateAction<any, any>[]): void;\n}\n\n/**\n * Extension point for managing scaffolder actions.\n *\n * @alpha\n */\nexport const scaffolderActionsExtensionPoint =\n createExtensionPoint<ScaffolderActionsExtensionPoint>({\n id: 'scaffolder.actions',\n });\n\n/**\n * Extension point for replacing the scaffolder task broker.\n *\n * @alpha\n */\nexport interface ScaffolderTaskBrokerExtensionPoint {\n setTaskBroker(taskBroker: TaskBroker): void;\n}\n\n/**\n * Extension point for replacing the scaffolder task broker.\n *\n * @alpha\n */\nexport const scaffolderTaskBrokerExtensionPoint =\n createExtensionPoint<ScaffolderTaskBrokerExtensionPoint>({\n id: 'scaffolder.taskBroker',\n });\n\n/**\n * Extension point for adding template filters and globals.\n *\n * @alpha\n */\nexport interface ScaffolderTemplatingExtensionPoint {\n addTemplateFilters(filters: Record<string, TemplateFilter>): void;\n addTemplateGlobals(filters: Record<string, TemplateGlobal>): void;\n}\n\n/**\n * Extension point for adding template filters and globals.\n *\n * @alpha\n */\nexport const scaffolderTemplatingExtensionPoint =\n createExtensionPoint<ScaffolderTemplatingExtensionPoint>({\n id: 'scaffolder.templating',\n });\n"],"names":["createExtensionPoint"],"mappings":";;;;;;AAsCO,MAAM,kCACXA,qCAAsD,CAAA;AAAA,EACpD,EAAI,EAAA,oBAAA;AACN,CAAC,EAAA;AAgBI,MAAM,qCACXA,qCAAyD,CAAA;AAAA,EACvD,EAAI,EAAA,uBAAA;AACN,CAAC,EAAA;AAiBI,MAAM,qCACXA,qCAAyD,CAAA;AAAA,EACvD,EAAI,EAAA,uBAAA;AACN,CAAC;;;;;;"}
|
package/dist/alpha.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
+
import { TemplateAction, TaskBroker, TemplateFilter, TemplateGlobal } from '@backstage/plugin-scaffolder-node';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Extension point for managing scaffolder actions.
|
|
6
|
+
*
|
|
7
|
+
* @alpha
|
|
8
|
+
*/
|
|
9
|
+
interface ScaffolderActionsExtensionPoint {
|
|
10
|
+
addActions(...actions: TemplateAction<any, any>[]): void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Extension point for managing scaffolder actions.
|
|
14
|
+
*
|
|
15
|
+
* @alpha
|
|
16
|
+
*/
|
|
17
|
+
declare const scaffolderActionsExtensionPoint: _backstage_backend_plugin_api.ExtensionPoint<ScaffolderActionsExtensionPoint>;
|
|
18
|
+
/**
|
|
19
|
+
* Extension point for replacing the scaffolder task broker.
|
|
20
|
+
*
|
|
21
|
+
* @alpha
|
|
22
|
+
*/
|
|
23
|
+
interface ScaffolderTaskBrokerExtensionPoint {
|
|
24
|
+
setTaskBroker(taskBroker: TaskBroker): void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Extension point for replacing the scaffolder task broker.
|
|
28
|
+
*
|
|
29
|
+
* @alpha
|
|
30
|
+
*/
|
|
31
|
+
declare const scaffolderTaskBrokerExtensionPoint: _backstage_backend_plugin_api.ExtensionPoint<ScaffolderTaskBrokerExtensionPoint>;
|
|
32
|
+
/**
|
|
33
|
+
* Extension point for adding template filters and globals.
|
|
34
|
+
*
|
|
35
|
+
* @alpha
|
|
36
|
+
*/
|
|
37
|
+
interface ScaffolderTemplatingExtensionPoint {
|
|
38
|
+
addTemplateFilters(filters: Record<string, TemplateFilter>): void;
|
|
39
|
+
addTemplateGlobals(filters: Record<string, TemplateGlobal>): void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Extension point for adding template filters and globals.
|
|
43
|
+
*
|
|
44
|
+
* @alpha
|
|
45
|
+
*/
|
|
46
|
+
declare const scaffolderTemplatingExtensionPoint: _backstage_backend_plugin_api.ExtensionPoint<ScaffolderTemplatingExtensionPoint>;
|
|
47
|
+
|
|
48
|
+
export { ScaffolderActionsExtensionPoint, ScaffolderTaskBrokerExtensionPoint, ScaffolderTemplatingExtensionPoint, scaffolderActionsExtensionPoint, scaffolderTaskBrokerExtensionPoint, scaffolderTemplatingExtensionPoint };
|
package/dist/index.cjs.js
CHANGED
|
@@ -9,7 +9,6 @@ var backendCommon = require('@backstage/backend-common');
|
|
|
9
9
|
var errors = require('@backstage/errors');
|
|
10
10
|
var fs = require('fs-extra');
|
|
11
11
|
var path = require('path');
|
|
12
|
-
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
13
12
|
|
|
14
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
14
|
|
|
@@ -116,21 +115,8 @@ function getReadUrl(fetchUrl, baseUrl, integrations) {
|
|
|
116
115
|
);
|
|
117
116
|
}
|
|
118
117
|
|
|
119
|
-
const scaffolderActionsExtensionPoint = backendPluginApi.createExtensionPoint({
|
|
120
|
-
id: "scaffolder.actions"
|
|
121
|
-
});
|
|
122
|
-
const scaffolderTaskBrokerExtensionPoint = backendPluginApi.createExtensionPoint({
|
|
123
|
-
id: "scaffolder.taskBroker"
|
|
124
|
-
});
|
|
125
|
-
const scaffolderTemplatingExtensionPoint = backendPluginApi.createExtensionPoint({
|
|
126
|
-
id: "scaffolder.templating"
|
|
127
|
-
});
|
|
128
|
-
|
|
129
118
|
exports.createTemplateAction = createTemplateAction;
|
|
130
119
|
exports.executeShellCommand = executeShellCommand;
|
|
131
120
|
exports.fetchContents = fetchContents;
|
|
132
121
|
exports.fetchFile = fetchFile;
|
|
133
|
-
exports.scaffolderActionsExtensionPoint = scaffolderActionsExtensionPoint;
|
|
134
|
-
exports.scaffolderTaskBrokerExtensionPoint = scaffolderTaskBrokerExtensionPoint;
|
|
135
|
-
exports.scaffolderTemplatingExtensionPoint = scaffolderTemplatingExtensionPoint;
|
|
136
122
|
//# sourceMappingURL=index.cjs.js.map
|
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/extensions.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}) {\n const { reader, integrations, baseUrl, fetchUrl = '.', outputPath } = 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);\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}) {\n const { reader, integrations, baseUrl, fetchUrl = '.', outputPath } = 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);\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 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 { createExtensionPoint } from '@backstage/backend-plugin-api';\nimport {\n TemplateAction,\n TemplateFilter,\n TemplateGlobal,\n TaskBroker,\n} from '@backstage/plugin-scaffolder-node';\n\n/**\n * Extension point for managing scaffolder actions.\n *\n * @alpha\n */\nexport interface ScaffolderActionsExtensionPoint {\n addActions(...actions: TemplateAction<any, any>[]): void;\n}\n\n/**\n * Extension point for managing scaffolder actions.\n *\n * @alpha\n */\nexport const scaffolderActionsExtensionPoint =\n createExtensionPoint<ScaffolderActionsExtensionPoint>({\n id: 'scaffolder.actions',\n });\n\n/**\n * Extension point for replacing the scaffolder task broker.\n *\n * @alpha\n */\nexport interface ScaffolderTaskBrokerExtensionPoint {\n setTaskBroker(taskBroker: TaskBroker): void;\n}\n\n/**\n * Extension point for replacing the scaffolder task broker.\n *\n * @alpha\n */\nexport const scaffolderTaskBrokerExtensionPoint =\n createExtensionPoint<ScaffolderTaskBrokerExtensionPoint>({\n id: 'scaffolder.taskBroker',\n });\n\n/**\n * Extension point for adding template filters and globals.\n *\n * @alpha\n */\nexport interface ScaffolderTemplatingExtensionPoint {\n addTemplateFilters(filters: Record<string, TemplateFilter>): void;\n addTemplateGlobals(filters: Record<string, TemplateGlobal>): void;\n}\n\n/**\n * Extension point for adding template filters and globals.\n *\n * @alpha\n */\nexport const scaffolderTemplatingExtensionPoint =\n createExtensionPoint<ScaffolderTemplatingExtensionPoint>({\n id: 'scaffolder.templating',\n });\n"],"names":["zodToJsonSchema","PassThrough","spawn","resolveSafeChildPath","path","fs","InputError","createExtensionPoint"],"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,EAAO,GAAA,MAAA,CAAA,MAAA,KAAP,IAAe,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,MAAA,KAAU,oBAAoB,MAAO,CAAA,MAAA,CAAO,MACvD,GAAAA,mCAAA,CAAgB,OAAO,MAAO,CAAA,MAAM,CACpC,GAAA,CAAA,EAAA,GAAA,MAAA,CAAO,WAAP,IAAe,GAAA,KAAA,CAAA,GAAA,EAA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ACE,OAAS,EAAA;AAClB,IAAM,MAAA,WAAA,GAAc,YAAa,CAAA,KAAA,CAAM,OAAO,CAAA,CAAA;AAC9C,IAAA,IAAI,CAAC,WAAa,EAAA;AAChB,MAAA,MAAM,IAAIC,iBAAA,CAAW,CAAqC,kCAAA,EAAA,OAAO,CAAE,CAAA,CAAA,CAAA;AAAA,KACrE;AAEA,IAAA,OAAO,YAAY,UAAW,CAAA;AAAA,MAC5B,GAAK,EAAA,QAAA;AAAA,MACL,IAAM,EAAA,OAAA;AAAA,KACP,CAAA,CAAA;AAAA,GACH;AACA,EAAA,MAAM,IAAIA,iBAAA;AAAA,IACR,6FAA6F,QAAQ,CAAA,CAAA;AAAA,GACvG,CAAA;AACF;;AChFO,MAAM,kCACXC,qCAAsD,CAAA;AAAA,EACpD,EAAI,EAAA,oBAAA;AACN,CAAC,EAAA;AAgBI,MAAM,qCACXA,qCAAyD,CAAA;AAAA,EACvD,EAAI,EAAA,uBAAA;AACN,CAAC,EAAA;AAiBI,MAAM,qCACXA,qCAAyD,CAAA;AAAA,EACvD,EAAI,EAAA,uBAAA;AACN,CAAC;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/actions/createTemplateAction.ts","../src/actions/executeShellCommand.ts","../src/actions/fetch.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}) {\n const { reader, integrations, baseUrl, fetchUrl = '.', outputPath } = 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);\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}) {\n const { reader, integrations, baseUrl, fetchUrl = '.', outputPath } = 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);\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"],"names":["zodToJsonSchema","PassThrough","spawn","resolveSafeChildPath","path","fs","InputError"],"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,EAAO,GAAA,MAAA,CAAA,MAAA,KAAP,IAAe,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,MAAA,KAAU,oBAAoB,MAAO,CAAA,MAAA,CAAO,MACvD,GAAAA,mCAAA,CAAgB,OAAO,MAAO,CAAA,MAAM,CACpC,GAAA,CAAA,EAAA,GAAA,MAAA,CAAO,WAAP,IAAe,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,MAAA,CAAA;AAErB,EAAO,OAAA;AAAA,IACL,GAAG,MAAA;AAAA,IACH,MAAQ,EAAA;AAAA,MACN,GAAG,MAAO,CAAA,MAAA;AAAA,MACV,KAAO,EAAA,WAAA;AAAA,MACP,MAAQ,EAAA,YAAA;AAAA,KAC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O,CAAE,CAAA,CAAA,CAAA;AAAA,KACrE;AAEA,IAAA,OAAO,YAAY,UAAW,CAAA;AAAA,MAC5B,GAAK,EAAA,QAAA;AAAA,MACL,IAAM,EAAA,OAAA;AAAA,KACP,CAAA,CAAA;AAAA,GACH;AACA,EAAA,MAAM,IAAIA,iBAAA;AAAA,IACR,6FAA6F,QAAQ,CAAA,CAAA;AAAA,GACvG,CAAA;AACF;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,150 +1,41 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The scaffolder-node module for `@backstage/plugin-scaffolder-backend`.
|
|
3
|
-
*
|
|
4
|
-
* @packageDocumentation
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
1
|
/// <reference types="node" />
|
|
8
|
-
|
|
9
|
-
import { ExtensionPoint } from '@backstage/backend-plugin-api';
|
|
10
|
-
import { JsonObject } from '@backstage/types';
|
|
11
|
-
import { JsonValue } from '@backstage/types';
|
|
12
2
|
import { Logger } from 'winston';
|
|
13
|
-
import {
|
|
3
|
+
import { Writable } from 'stream';
|
|
4
|
+
import { JsonObject, Observable, JsonValue } from '@backstage/types';
|
|
5
|
+
import { TaskSpec, TemplateInfo } from '@backstage/plugin-scaffolder-common';
|
|
6
|
+
import { UserEntity } from '@backstage/catalog-model';
|
|
14
7
|
import { Schema } from 'jsonschema';
|
|
15
|
-
import {
|
|
8
|
+
import { z } from 'zod';
|
|
16
9
|
import { SpawnOptionsWithoutStdio } from 'child_process';
|
|
17
|
-
import { TaskBroker as TaskBroker_2 } from '@backstage/plugin-scaffolder-node';
|
|
18
|
-
import { TaskSpec } from '@backstage/plugin-scaffolder-common';
|
|
19
|
-
import { TemplateAction as TemplateAction_2 } from '@backstage/plugin-scaffolder-node';
|
|
20
|
-
import { TemplateFilter as TemplateFilter_2 } from '@backstage/plugin-scaffolder-node';
|
|
21
|
-
import { TemplateGlobal as TemplateGlobal_2 } from '@backstage/plugin-scaffolder-node';
|
|
22
|
-
import { TemplateInfo } from '@backstage/plugin-scaffolder-common';
|
|
23
10
|
import { UrlReader } from '@backstage/backend-common';
|
|
24
|
-
import {
|
|
25
|
-
import { Writable } from 'stream';
|
|
26
|
-
import { z } from 'zod';
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* ActionContext is passed into scaffolder actions.
|
|
30
|
-
* @public
|
|
31
|
-
*/
|
|
32
|
-
export declare type ActionContext<TActionInput extends JsonObject, TActionOutput extends JsonObject = JsonObject> = {
|
|
33
|
-
logger: Logger;
|
|
34
|
-
logStream: Writable;
|
|
35
|
-
secrets?: TaskSecrets;
|
|
36
|
-
workspacePath: string;
|
|
37
|
-
input: TActionInput;
|
|
38
|
-
output(name: keyof TActionOutput, value: TActionOutput[keyof TActionOutput]): void;
|
|
39
|
-
/**
|
|
40
|
-
* Creates a temporary directory for use by the action, which is then cleaned up automatically.
|
|
41
|
-
*/
|
|
42
|
-
createTemporaryDirectory(): Promise<string>;
|
|
43
|
-
templateInfo?: TemplateInfo;
|
|
44
|
-
/**
|
|
45
|
-
* Whether this action invocation is a dry-run or not.
|
|
46
|
-
* This will only ever be true if the actions as marked as supporting dry-runs.
|
|
47
|
-
*/
|
|
48
|
-
isDryRun?: boolean;
|
|
49
|
-
/**
|
|
50
|
-
* The user which triggered the action.
|
|
51
|
-
*/
|
|
52
|
-
user?: {
|
|
53
|
-
/**
|
|
54
|
-
* The decorated entity from the Catalog
|
|
55
|
-
*/
|
|
56
|
-
entity?: UserEntity;
|
|
57
|
-
/**
|
|
58
|
-
* An entity ref for the author of the task
|
|
59
|
-
*/
|
|
60
|
-
ref?: string;
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Implement the signal to make your custom step abortable https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal
|
|
64
|
-
*/
|
|
65
|
-
signal?: AbortSignal;
|
|
66
|
-
/**
|
|
67
|
-
* Optional value of each invocation
|
|
68
|
-
*/
|
|
69
|
-
each?: JsonObject;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* This function is used to create new template actions to get type safety.
|
|
74
|
-
* Will convert zod schemas to json schemas for use throughout the system.
|
|
75
|
-
* @public
|
|
76
|
-
*/
|
|
77
|
-
export declare const createTemplateAction: <TInputParams extends JsonObject = JsonObject, TOutputParams extends JsonObject = JsonObject, TInputSchema extends z.ZodType<any, z.ZodTypeDef, any> | Schema = {}, TOutputSchema extends z.ZodType<any, z.ZodTypeDef, any> | Schema = {}, TActionInput extends JsonObject = TInputSchema extends z.ZodType<any, any, infer IReturn> ? IReturn : TInputParams, TActionOutput extends JsonObject = TOutputSchema extends z.ZodType<any, any, infer IReturn_1> ? IReturn_1 : TOutputParams>(action: TemplateActionOptions<TActionInput, TActionOutput, TInputSchema, TOutputSchema>) => TemplateAction<TActionInput, TActionOutput>;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Run a command in a sub-process, normally a shell command.
|
|
81
|
-
*
|
|
82
|
-
* @public
|
|
83
|
-
*/
|
|
84
|
-
export declare function executeShellCommand(options: ExecuteShellCommandOptions): Promise<void>;
|
|
11
|
+
import { ScmIntegrations } from '@backstage/integration';
|
|
85
12
|
|
|
86
13
|
/**
|
|
87
|
-
*
|
|
14
|
+
* TaskSecrets
|
|
88
15
|
*
|
|
89
16
|
* @public
|
|
90
17
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
command: string;
|
|
94
|
-
/** arguments to pass the command */
|
|
95
|
-
args: string[];
|
|
96
|
-
/** options to pass to spawn */
|
|
97
|
-
options?: SpawnOptionsWithoutStdio;
|
|
98
|
-
/** stream to capture stdout and stderr output */
|
|
99
|
-
logStream?: Writable;
|
|
18
|
+
type TaskSecrets = Record<string, string> & {
|
|
19
|
+
backstageToken?: string;
|
|
100
20
|
};
|
|
101
|
-
|
|
102
21
|
/**
|
|
103
|
-
*
|
|
104
|
-
* Can be used in your own actions, and also used behind fetch:template and fetch:plain
|
|
22
|
+
* The status of each step of the Task
|
|
105
23
|
*
|
|
106
24
|
* @public
|
|
107
25
|
*/
|
|
108
|
-
|
|
109
|
-
reader: UrlReader;
|
|
110
|
-
integrations: ScmIntegrations;
|
|
111
|
-
baseUrl?: string;
|
|
112
|
-
fetchUrl?: string;
|
|
113
|
-
outputPath: string;
|
|
114
|
-
}): Promise<void>;
|
|
115
|
-
|
|
26
|
+
type TaskStatus = 'cancelled' | 'completed' | 'failed' | 'open' | 'processing';
|
|
116
27
|
/**
|
|
117
|
-
*
|
|
118
|
-
* Can be used in your own actions, and also used behind `fetch:plain:file`
|
|
28
|
+
* The state of a completed task.
|
|
119
29
|
*
|
|
120
30
|
* @public
|
|
121
31
|
*/
|
|
122
|
-
|
|
123
|
-
reader: UrlReader;
|
|
124
|
-
integrations: ScmIntegrations;
|
|
125
|
-
baseUrl?: string;
|
|
126
|
-
fetchUrl?: string;
|
|
127
|
-
outputPath: string;
|
|
128
|
-
}): Promise<void>;
|
|
129
|
-
|
|
130
|
-
/* Excluded from this release type: ScaffolderActionsExtensionPoint */
|
|
131
|
-
|
|
132
|
-
/* Excluded from this release type: scaffolderActionsExtensionPoint */
|
|
133
|
-
|
|
134
|
-
/* Excluded from this release type: ScaffolderTaskBrokerExtensionPoint */
|
|
135
|
-
|
|
136
|
-
/* Excluded from this release type: scaffolderTaskBrokerExtensionPoint */
|
|
137
|
-
|
|
138
|
-
/* Excluded from this release type: ScaffolderTemplatingExtensionPoint */
|
|
139
|
-
|
|
140
|
-
/* Excluded from this release type: scaffolderTemplatingExtensionPoint */
|
|
141
|
-
|
|
32
|
+
type TaskCompletionState = 'failed' | 'completed';
|
|
142
33
|
/**
|
|
143
34
|
* SerializedTask
|
|
144
35
|
*
|
|
145
36
|
* @public
|
|
146
37
|
*/
|
|
147
|
-
|
|
38
|
+
type SerializedTask = {
|
|
148
39
|
id: string;
|
|
149
40
|
spec: TaskSpec;
|
|
150
41
|
status: TaskStatus;
|
|
@@ -153,80 +44,49 @@ export declare type SerializedTask = {
|
|
|
153
44
|
createdBy?: string;
|
|
154
45
|
secrets?: TaskSecrets;
|
|
155
46
|
};
|
|
156
|
-
|
|
47
|
+
/**
|
|
48
|
+
* TaskEventType
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
type TaskEventType = 'completion' | 'log' | 'cancelled';
|
|
157
53
|
/**
|
|
158
54
|
* SerializedTaskEvent
|
|
159
55
|
*
|
|
160
56
|
* @public
|
|
161
57
|
*/
|
|
162
|
-
|
|
58
|
+
type SerializedTaskEvent = {
|
|
163
59
|
id: number;
|
|
164
60
|
taskId: string;
|
|
165
61
|
body: JsonObject;
|
|
166
62
|
type: TaskEventType;
|
|
167
63
|
createdAt: string;
|
|
168
64
|
};
|
|
169
|
-
|
|
170
65
|
/**
|
|
171
|
-
* TaskBroker
|
|
66
|
+
* The result of {@link TaskBroker.dispatch}
|
|
172
67
|
*
|
|
173
68
|
* @public
|
|
174
69
|
*/
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
dispatch(options: TaskBrokerDispatchOptions): Promise<TaskBrokerDispatchResult>;
|
|
179
|
-
vacuumTasks(options: {
|
|
180
|
-
timeoutS: number;
|
|
181
|
-
}): Promise<void>;
|
|
182
|
-
event$(options: {
|
|
183
|
-
taskId: string;
|
|
184
|
-
after: number | undefined;
|
|
185
|
-
}): Observable<{
|
|
186
|
-
events: SerializedTaskEvent[];
|
|
187
|
-
}>;
|
|
188
|
-
get(taskId: string): Promise<SerializedTask>;
|
|
189
|
-
list?(options?: {
|
|
190
|
-
createdBy?: string;
|
|
191
|
-
}): Promise<{
|
|
192
|
-
tasks: SerializedTask[];
|
|
193
|
-
}>;
|
|
194
|
-
}
|
|
195
|
-
|
|
70
|
+
type TaskBrokerDispatchResult = {
|
|
71
|
+
taskId: string;
|
|
72
|
+
};
|
|
196
73
|
/**
|
|
197
74
|
* The options passed to {@link TaskBroker.dispatch}
|
|
198
75
|
* Currently a spec and optional secrets
|
|
199
76
|
*
|
|
200
77
|
* @public
|
|
201
78
|
*/
|
|
202
|
-
|
|
79
|
+
type TaskBrokerDispatchOptions = {
|
|
203
80
|
spec: TaskSpec;
|
|
204
81
|
secrets?: TaskSecrets;
|
|
205
82
|
createdBy?: string;
|
|
206
83
|
};
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* The result of {@link TaskBroker.dispatch}
|
|
210
|
-
*
|
|
211
|
-
* @public
|
|
212
|
-
*/
|
|
213
|
-
export declare type TaskBrokerDispatchResult = {
|
|
214
|
-
taskId: string;
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* The state of a completed task.
|
|
219
|
-
*
|
|
220
|
-
* @public
|
|
221
|
-
*/
|
|
222
|
-
export declare type TaskCompletionState = 'failed' | 'completed';
|
|
223
|
-
|
|
224
84
|
/**
|
|
225
85
|
* Task
|
|
226
86
|
*
|
|
227
87
|
* @public
|
|
228
88
|
*/
|
|
229
|
-
|
|
89
|
+
interface TaskContext {
|
|
230
90
|
cancelSignal: AbortSignal;
|
|
231
91
|
spec: TaskSpec;
|
|
232
92
|
secrets?: TaskSecrets;
|
|
@@ -237,32 +97,77 @@ export declare interface TaskContext {
|
|
|
237
97
|
emitLog(message: string, logMetadata?: JsonObject): Promise<void>;
|
|
238
98
|
getWorkspaceName(): Promise<string>;
|
|
239
99
|
}
|
|
240
|
-
|
|
241
100
|
/**
|
|
242
|
-
*
|
|
101
|
+
* TaskBroker
|
|
243
102
|
*
|
|
244
103
|
* @public
|
|
245
104
|
*/
|
|
246
|
-
|
|
105
|
+
interface TaskBroker {
|
|
106
|
+
cancel?(taskId: string): Promise<void>;
|
|
107
|
+
claim(): Promise<TaskContext>;
|
|
108
|
+
dispatch(options: TaskBrokerDispatchOptions): Promise<TaskBrokerDispatchResult>;
|
|
109
|
+
vacuumTasks(options: {
|
|
110
|
+
timeoutS: number;
|
|
111
|
+
}): Promise<void>;
|
|
112
|
+
event$(options: {
|
|
113
|
+
taskId: string;
|
|
114
|
+
after: number | undefined;
|
|
115
|
+
}): Observable<{
|
|
116
|
+
events: SerializedTaskEvent[];
|
|
117
|
+
}>;
|
|
118
|
+
get(taskId: string): Promise<SerializedTask>;
|
|
119
|
+
list?(options?: {
|
|
120
|
+
createdBy?: string;
|
|
121
|
+
}): Promise<{
|
|
122
|
+
tasks: SerializedTask[];
|
|
123
|
+
}>;
|
|
124
|
+
}
|
|
247
125
|
|
|
248
126
|
/**
|
|
249
|
-
*
|
|
250
|
-
*
|
|
127
|
+
* ActionContext is passed into scaffolder actions.
|
|
251
128
|
* @public
|
|
252
129
|
*/
|
|
253
|
-
|
|
254
|
-
|
|
130
|
+
type ActionContext<TActionInput extends JsonObject, TActionOutput extends JsonObject = JsonObject> = {
|
|
131
|
+
logger: Logger;
|
|
132
|
+
logStream: Writable;
|
|
133
|
+
secrets?: TaskSecrets;
|
|
134
|
+
workspacePath: string;
|
|
135
|
+
input: TActionInput;
|
|
136
|
+
output(name: keyof TActionOutput, value: TActionOutput[keyof TActionOutput]): void;
|
|
137
|
+
/**
|
|
138
|
+
* Creates a temporary directory for use by the action, which is then cleaned up automatically.
|
|
139
|
+
*/
|
|
140
|
+
createTemporaryDirectory(): Promise<string>;
|
|
141
|
+
templateInfo?: TemplateInfo;
|
|
142
|
+
/**
|
|
143
|
+
* Whether this action invocation is a dry-run or not.
|
|
144
|
+
* This will only ever be true if the actions as marked as supporting dry-runs.
|
|
145
|
+
*/
|
|
146
|
+
isDryRun?: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* The user which triggered the action.
|
|
149
|
+
*/
|
|
150
|
+
user?: {
|
|
151
|
+
/**
|
|
152
|
+
* The decorated entity from the Catalog
|
|
153
|
+
*/
|
|
154
|
+
entity?: UserEntity;
|
|
155
|
+
/**
|
|
156
|
+
* An entity ref for the author of the task
|
|
157
|
+
*/
|
|
158
|
+
ref?: string;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Implement the signal to make your custom step abortable https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal
|
|
162
|
+
*/
|
|
163
|
+
signal?: AbortSignal;
|
|
164
|
+
/**
|
|
165
|
+
* Optional value of each invocation
|
|
166
|
+
*/
|
|
167
|
+
each?: JsonObject;
|
|
255
168
|
};
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* The status of each step of the Task
|
|
259
|
-
*
|
|
260
|
-
* @public
|
|
261
|
-
*/
|
|
262
|
-
export declare type TaskStatus = 'cancelled' | 'completed' | 'failed' | 'open' | 'processing';
|
|
263
|
-
|
|
264
169
|
/** @public */
|
|
265
|
-
|
|
170
|
+
type TemplateAction<TActionInput extends JsonObject = JsonObject, TActionOutput extends JsonObject = JsonObject> = {
|
|
266
171
|
id: string;
|
|
267
172
|
description?: string;
|
|
268
173
|
examples?: {
|
|
@@ -278,7 +183,12 @@ export declare type TemplateAction<TActionInput extends JsonObject = JsonObject,
|
|
|
278
183
|
};
|
|
279
184
|
|
|
280
185
|
/** @public */
|
|
281
|
-
|
|
186
|
+
type TemplateExample = {
|
|
187
|
+
description: string;
|
|
188
|
+
example: string;
|
|
189
|
+
};
|
|
190
|
+
/** @public */
|
|
191
|
+
type TemplateActionOptions<TActionInput extends JsonObject = {}, TActionOutput extends JsonObject = {}, TInputSchema extends Schema | z.ZodType = {}, TOutputSchema extends Schema | z.ZodType = {}> = {
|
|
282
192
|
id: string;
|
|
283
193
|
description?: string;
|
|
284
194
|
examples?: TemplateExample[];
|
|
@@ -289,17 +199,65 @@ export declare type TemplateActionOptions<TActionInput extends JsonObject = {},
|
|
|
289
199
|
};
|
|
290
200
|
handler: (ctx: ActionContext<TActionInput, TActionOutput>) => Promise<void>;
|
|
291
201
|
};
|
|
202
|
+
/**
|
|
203
|
+
* This function is used to create new template actions to get type safety.
|
|
204
|
+
* Will convert zod schemas to json schemas for use throughout the system.
|
|
205
|
+
* @public
|
|
206
|
+
*/
|
|
207
|
+
declare const createTemplateAction: <TInputParams extends JsonObject = JsonObject, TOutputParams extends JsonObject = JsonObject, TInputSchema extends z.ZodType<any, z.ZodTypeDef, any> | Schema = {}, TOutputSchema extends z.ZodType<any, z.ZodTypeDef, any> | Schema = {}, TActionInput extends JsonObject = TInputSchema extends z.ZodType<any, any, infer IReturn> ? IReturn : TInputParams, TActionOutput extends JsonObject = TOutputSchema extends z.ZodType<any, any, infer IReturn_1> ? IReturn_1 : TOutputParams>(action: TemplateActionOptions<TActionInput, TActionOutput, TInputSchema, TOutputSchema>) => TemplateAction<TActionInput, TActionOutput>;
|
|
292
208
|
|
|
293
|
-
/**
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
209
|
+
/**
|
|
210
|
+
* Options for {@link executeShellCommand}.
|
|
211
|
+
*
|
|
212
|
+
* @public
|
|
213
|
+
*/
|
|
214
|
+
type ExecuteShellCommandOptions = {
|
|
215
|
+
/** command to run */
|
|
216
|
+
command: string;
|
|
217
|
+
/** arguments to pass the command */
|
|
218
|
+
args: string[];
|
|
219
|
+
/** options to pass to spawn */
|
|
220
|
+
options?: SpawnOptionsWithoutStdio;
|
|
221
|
+
/** stream to capture stdout and stderr output */
|
|
222
|
+
logStream?: Writable;
|
|
297
223
|
};
|
|
224
|
+
/**
|
|
225
|
+
* Run a command in a sub-process, normally a shell command.
|
|
226
|
+
*
|
|
227
|
+
* @public
|
|
228
|
+
*/
|
|
229
|
+
declare function executeShellCommand(options: ExecuteShellCommandOptions): Promise<void>;
|
|
298
230
|
|
|
299
|
-
/**
|
|
300
|
-
|
|
231
|
+
/**
|
|
232
|
+
* A helper function that reads the contents of a directory from the given URL.
|
|
233
|
+
* Can be used in your own actions, and also used behind fetch:template and fetch:plain
|
|
234
|
+
*
|
|
235
|
+
* @public
|
|
236
|
+
*/
|
|
237
|
+
declare function fetchContents(options: {
|
|
238
|
+
reader: UrlReader;
|
|
239
|
+
integrations: ScmIntegrations;
|
|
240
|
+
baseUrl?: string;
|
|
241
|
+
fetchUrl?: string;
|
|
242
|
+
outputPath: string;
|
|
243
|
+
}): Promise<void>;
|
|
244
|
+
/**
|
|
245
|
+
* A helper function that reads the content of a single file from the given URL.
|
|
246
|
+
* Can be used in your own actions, and also used behind `fetch:plain:file`
|
|
247
|
+
*
|
|
248
|
+
* @public
|
|
249
|
+
*/
|
|
250
|
+
declare function fetchFile(options: {
|
|
251
|
+
reader: UrlReader;
|
|
252
|
+
integrations: ScmIntegrations;
|
|
253
|
+
baseUrl?: string;
|
|
254
|
+
fetchUrl?: string;
|
|
255
|
+
outputPath: string;
|
|
256
|
+
}): Promise<void>;
|
|
301
257
|
|
|
302
258
|
/** @public */
|
|
303
|
-
|
|
259
|
+
type TemplateFilter = (...args: JsonValue[]) => JsonValue | undefined;
|
|
260
|
+
/** @public */
|
|
261
|
+
type TemplateGlobal = ((...args: JsonValue[]) => JsonValue | undefined) | JsonValue;
|
|
304
262
|
|
|
305
|
-
export { }
|
|
263
|
+
export { ActionContext, ExecuteShellCommandOptions, SerializedTask, SerializedTaskEvent, TaskBroker, TaskBrokerDispatchOptions, TaskBrokerDispatchResult, TaskCompletionState, TaskContext, TaskEventType, TaskSecrets, TaskStatus, TemplateAction, TemplateActionOptions, TemplateExample, TemplateFilter, TemplateGlobal, createTemplateAction, executeShellCommand, fetchContents, fetchFile };
|
package/package.json
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-scaffolder-node",
|
|
3
3
|
"description": "The plugin-scaffolder-node module for @backstage/plugin-scaffolder-backend",
|
|
4
|
-
"version": "0.2.
|
|
5
|
-
"main": "dist/index.cjs.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
4
|
+
"version": "0.2.8-next.0",
|
|
5
|
+
"main": "./dist/index.cjs.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"publishConfig": {
|
|
9
|
-
"access": "public"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"require": "./dist/index.cjs.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.cjs.js"
|
|
16
|
+
},
|
|
17
|
+
"./alpha": {
|
|
18
|
+
"require": "./dist/alpha.cjs.js",
|
|
19
|
+
"types": "./dist/alpha.d.ts",
|
|
20
|
+
"default": "./dist/alpha.cjs.js"
|
|
21
|
+
},
|
|
22
|
+
"./package.json": "./package.json"
|
|
13
23
|
},
|
|
14
24
|
"backstage": {
|
|
15
25
|
"role": "node-library"
|
|
@@ -22,7 +32,7 @@
|
|
|
22
32
|
},
|
|
23
33
|
"scripts": {
|
|
24
34
|
"start": "backstage-cli package start",
|
|
25
|
-
"build": "backstage-cli package build
|
|
35
|
+
"build": "backstage-cli package build",
|
|
26
36
|
"lint": "backstage-cli package lint",
|
|
27
37
|
"test": "backstage-cli package test",
|
|
28
38
|
"clean": "backstage-cli package clean",
|
|
@@ -30,12 +40,12 @@
|
|
|
30
40
|
"postpack": "backstage-cli package postpack"
|
|
31
41
|
},
|
|
32
42
|
"dependencies": {
|
|
33
|
-
"@backstage/backend-common": "^0.19.
|
|
34
|
-
"@backstage/backend-plugin-api": "^0.6.
|
|
43
|
+
"@backstage/backend-common": "^0.19.9-next.0",
|
|
44
|
+
"@backstage/backend-plugin-api": "^0.6.7-next.0",
|
|
35
45
|
"@backstage/catalog-model": "^1.4.3",
|
|
36
46
|
"@backstage/errors": "^1.2.3",
|
|
37
47
|
"@backstage/integration": "^1.7.1",
|
|
38
|
-
"@backstage/plugin-scaffolder-common": "^1.4.
|
|
48
|
+
"@backstage/plugin-scaffolder-common": "^1.4.3-next.0",
|
|
39
49
|
"@backstage/types": "^1.1.1",
|
|
40
50
|
"fs-extra": "10.1.0",
|
|
41
51
|
"jsonschema": "^1.2.6",
|
|
@@ -44,7 +54,7 @@
|
|
|
44
54
|
"zod-to-json-schema": "^3.20.4"
|
|
45
55
|
},
|
|
46
56
|
"devDependencies": {
|
|
47
|
-
"@backstage/cli": "^0.
|
|
57
|
+
"@backstage/cli": "^0.24.0-next.0",
|
|
48
58
|
"@backstage/config": "^1.1.1"
|
|
49
59
|
},
|
|
50
60
|
"files": [
|
package/dist/index.alpha.d.ts
DELETED
|
@@ -1,342 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The scaffolder-node module for `@backstage/plugin-scaffolder-backend`.
|
|
3
|
-
*
|
|
4
|
-
* @packageDocumentation
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/// <reference types="node" />
|
|
8
|
-
|
|
9
|
-
import { ExtensionPoint } from '@backstage/backend-plugin-api';
|
|
10
|
-
import { JsonObject } from '@backstage/types';
|
|
11
|
-
import { JsonValue } from '@backstage/types';
|
|
12
|
-
import { Logger } from 'winston';
|
|
13
|
-
import { Observable } from '@backstage/types';
|
|
14
|
-
import { Schema } from 'jsonschema';
|
|
15
|
-
import { ScmIntegrations } from '@backstage/integration';
|
|
16
|
-
import { SpawnOptionsWithoutStdio } from 'child_process';
|
|
17
|
-
import { TaskBroker as TaskBroker_2 } from '@backstage/plugin-scaffolder-node';
|
|
18
|
-
import { TaskSpec } from '@backstage/plugin-scaffolder-common';
|
|
19
|
-
import { TemplateAction as TemplateAction_2 } from '@backstage/plugin-scaffolder-node';
|
|
20
|
-
import { TemplateFilter as TemplateFilter_2 } from '@backstage/plugin-scaffolder-node';
|
|
21
|
-
import { TemplateGlobal as TemplateGlobal_2 } from '@backstage/plugin-scaffolder-node';
|
|
22
|
-
import { TemplateInfo } from '@backstage/plugin-scaffolder-common';
|
|
23
|
-
import { UrlReader } from '@backstage/backend-common';
|
|
24
|
-
import { UserEntity } from '@backstage/catalog-model';
|
|
25
|
-
import { Writable } from 'stream';
|
|
26
|
-
import { z } from 'zod';
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* ActionContext is passed into scaffolder actions.
|
|
30
|
-
* @public
|
|
31
|
-
*/
|
|
32
|
-
export declare type ActionContext<TActionInput extends JsonObject, TActionOutput extends JsonObject = JsonObject> = {
|
|
33
|
-
logger: Logger;
|
|
34
|
-
logStream: Writable;
|
|
35
|
-
secrets?: TaskSecrets;
|
|
36
|
-
workspacePath: string;
|
|
37
|
-
input: TActionInput;
|
|
38
|
-
output(name: keyof TActionOutput, value: TActionOutput[keyof TActionOutput]): void;
|
|
39
|
-
/**
|
|
40
|
-
* Creates a temporary directory for use by the action, which is then cleaned up automatically.
|
|
41
|
-
*/
|
|
42
|
-
createTemporaryDirectory(): Promise<string>;
|
|
43
|
-
templateInfo?: TemplateInfo;
|
|
44
|
-
/**
|
|
45
|
-
* Whether this action invocation is a dry-run or not.
|
|
46
|
-
* This will only ever be true if the actions as marked as supporting dry-runs.
|
|
47
|
-
*/
|
|
48
|
-
isDryRun?: boolean;
|
|
49
|
-
/**
|
|
50
|
-
* The user which triggered the action.
|
|
51
|
-
*/
|
|
52
|
-
user?: {
|
|
53
|
-
/**
|
|
54
|
-
* The decorated entity from the Catalog
|
|
55
|
-
*/
|
|
56
|
-
entity?: UserEntity;
|
|
57
|
-
/**
|
|
58
|
-
* An entity ref for the author of the task
|
|
59
|
-
*/
|
|
60
|
-
ref?: string;
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Implement the signal to make your custom step abortable https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal
|
|
64
|
-
*/
|
|
65
|
-
signal?: AbortSignal;
|
|
66
|
-
/**
|
|
67
|
-
* Optional value of each invocation
|
|
68
|
-
*/
|
|
69
|
-
each?: JsonObject;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* This function is used to create new template actions to get type safety.
|
|
74
|
-
* Will convert zod schemas to json schemas for use throughout the system.
|
|
75
|
-
* @public
|
|
76
|
-
*/
|
|
77
|
-
export declare const createTemplateAction: <TInputParams extends JsonObject = JsonObject, TOutputParams extends JsonObject = JsonObject, TInputSchema extends z.ZodType<any, z.ZodTypeDef, any> | Schema = {}, TOutputSchema extends z.ZodType<any, z.ZodTypeDef, any> | Schema = {}, TActionInput extends JsonObject = TInputSchema extends z.ZodType<any, any, infer IReturn> ? IReturn : TInputParams, TActionOutput extends JsonObject = TOutputSchema extends z.ZodType<any, any, infer IReturn_1> ? IReturn_1 : TOutputParams>(action: TemplateActionOptions<TActionInput, TActionOutput, TInputSchema, TOutputSchema>) => TemplateAction<TActionInput, TActionOutput>;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Run a command in a sub-process, normally a shell command.
|
|
81
|
-
*
|
|
82
|
-
* @public
|
|
83
|
-
*/
|
|
84
|
-
export declare function executeShellCommand(options: ExecuteShellCommandOptions): Promise<void>;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Options for {@link executeShellCommand}.
|
|
88
|
-
*
|
|
89
|
-
* @public
|
|
90
|
-
*/
|
|
91
|
-
export declare type ExecuteShellCommandOptions = {
|
|
92
|
-
/** command to run */
|
|
93
|
-
command: string;
|
|
94
|
-
/** arguments to pass the command */
|
|
95
|
-
args: string[];
|
|
96
|
-
/** options to pass to spawn */
|
|
97
|
-
options?: SpawnOptionsWithoutStdio;
|
|
98
|
-
/** stream to capture stdout and stderr output */
|
|
99
|
-
logStream?: Writable;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* A helper function that reads the contents of a directory from the given URL.
|
|
104
|
-
* Can be used in your own actions, and also used behind fetch:template and fetch:plain
|
|
105
|
-
*
|
|
106
|
-
* @public
|
|
107
|
-
*/
|
|
108
|
-
export declare function fetchContents(options: {
|
|
109
|
-
reader: UrlReader;
|
|
110
|
-
integrations: ScmIntegrations;
|
|
111
|
-
baseUrl?: string;
|
|
112
|
-
fetchUrl?: string;
|
|
113
|
-
outputPath: string;
|
|
114
|
-
}): Promise<void>;
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* A helper function that reads the content of a single file from the given URL.
|
|
118
|
-
* Can be used in your own actions, and also used behind `fetch:plain:file`
|
|
119
|
-
*
|
|
120
|
-
* @public
|
|
121
|
-
*/
|
|
122
|
-
export declare function fetchFile(options: {
|
|
123
|
-
reader: UrlReader;
|
|
124
|
-
integrations: ScmIntegrations;
|
|
125
|
-
baseUrl?: string;
|
|
126
|
-
fetchUrl?: string;
|
|
127
|
-
outputPath: string;
|
|
128
|
-
}): Promise<void>;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Extension point for managing scaffolder actions.
|
|
132
|
-
*
|
|
133
|
-
* @alpha
|
|
134
|
-
*/
|
|
135
|
-
export declare interface ScaffolderActionsExtensionPoint {
|
|
136
|
-
addActions(...actions: TemplateAction_2<any, any>[]): void;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Extension point for managing scaffolder actions.
|
|
141
|
-
*
|
|
142
|
-
* @alpha
|
|
143
|
-
*/
|
|
144
|
-
export declare const scaffolderActionsExtensionPoint: ExtensionPoint<ScaffolderActionsExtensionPoint>;
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Extension point for replacing the scaffolder task broker.
|
|
148
|
-
*
|
|
149
|
-
* @alpha
|
|
150
|
-
*/
|
|
151
|
-
export declare interface ScaffolderTaskBrokerExtensionPoint {
|
|
152
|
-
setTaskBroker(taskBroker: TaskBroker_2): void;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Extension point for replacing the scaffolder task broker.
|
|
157
|
-
*
|
|
158
|
-
* @alpha
|
|
159
|
-
*/
|
|
160
|
-
export declare const scaffolderTaskBrokerExtensionPoint: ExtensionPoint<ScaffolderTaskBrokerExtensionPoint>;
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Extension point for adding template filters and globals.
|
|
164
|
-
*
|
|
165
|
-
* @alpha
|
|
166
|
-
*/
|
|
167
|
-
export declare interface ScaffolderTemplatingExtensionPoint {
|
|
168
|
-
addTemplateFilters(filters: Record<string, TemplateFilter_2>): void;
|
|
169
|
-
addTemplateGlobals(filters: Record<string, TemplateGlobal_2>): void;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Extension point for adding template filters and globals.
|
|
174
|
-
*
|
|
175
|
-
* @alpha
|
|
176
|
-
*/
|
|
177
|
-
export declare const scaffolderTemplatingExtensionPoint: ExtensionPoint<ScaffolderTemplatingExtensionPoint>;
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* SerializedTask
|
|
181
|
-
*
|
|
182
|
-
* @public
|
|
183
|
-
*/
|
|
184
|
-
export declare type SerializedTask = {
|
|
185
|
-
id: string;
|
|
186
|
-
spec: TaskSpec;
|
|
187
|
-
status: TaskStatus;
|
|
188
|
-
createdAt: string;
|
|
189
|
-
lastHeartbeatAt?: string;
|
|
190
|
-
createdBy?: string;
|
|
191
|
-
secrets?: TaskSecrets;
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* SerializedTaskEvent
|
|
196
|
-
*
|
|
197
|
-
* @public
|
|
198
|
-
*/
|
|
199
|
-
export declare type SerializedTaskEvent = {
|
|
200
|
-
id: number;
|
|
201
|
-
taskId: string;
|
|
202
|
-
body: JsonObject;
|
|
203
|
-
type: TaskEventType;
|
|
204
|
-
createdAt: string;
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* TaskBroker
|
|
209
|
-
*
|
|
210
|
-
* @public
|
|
211
|
-
*/
|
|
212
|
-
export declare interface TaskBroker {
|
|
213
|
-
cancel?(taskId: string): Promise<void>;
|
|
214
|
-
claim(): Promise<TaskContext>;
|
|
215
|
-
dispatch(options: TaskBrokerDispatchOptions): Promise<TaskBrokerDispatchResult>;
|
|
216
|
-
vacuumTasks(options: {
|
|
217
|
-
timeoutS: number;
|
|
218
|
-
}): Promise<void>;
|
|
219
|
-
event$(options: {
|
|
220
|
-
taskId: string;
|
|
221
|
-
after: number | undefined;
|
|
222
|
-
}): Observable<{
|
|
223
|
-
events: SerializedTaskEvent[];
|
|
224
|
-
}>;
|
|
225
|
-
get(taskId: string): Promise<SerializedTask>;
|
|
226
|
-
list?(options?: {
|
|
227
|
-
createdBy?: string;
|
|
228
|
-
}): Promise<{
|
|
229
|
-
tasks: SerializedTask[];
|
|
230
|
-
}>;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* The options passed to {@link TaskBroker.dispatch}
|
|
235
|
-
* Currently a spec and optional secrets
|
|
236
|
-
*
|
|
237
|
-
* @public
|
|
238
|
-
*/
|
|
239
|
-
export declare type TaskBrokerDispatchOptions = {
|
|
240
|
-
spec: TaskSpec;
|
|
241
|
-
secrets?: TaskSecrets;
|
|
242
|
-
createdBy?: string;
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* The result of {@link TaskBroker.dispatch}
|
|
247
|
-
*
|
|
248
|
-
* @public
|
|
249
|
-
*/
|
|
250
|
-
export declare type TaskBrokerDispatchResult = {
|
|
251
|
-
taskId: string;
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* The state of a completed task.
|
|
256
|
-
*
|
|
257
|
-
* @public
|
|
258
|
-
*/
|
|
259
|
-
export declare type TaskCompletionState = 'failed' | 'completed';
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Task
|
|
263
|
-
*
|
|
264
|
-
* @public
|
|
265
|
-
*/
|
|
266
|
-
export declare interface TaskContext {
|
|
267
|
-
cancelSignal: AbortSignal;
|
|
268
|
-
spec: TaskSpec;
|
|
269
|
-
secrets?: TaskSecrets;
|
|
270
|
-
createdBy?: string;
|
|
271
|
-
done: boolean;
|
|
272
|
-
isDryRun?: boolean;
|
|
273
|
-
complete(result: TaskCompletionState, metadata?: JsonObject): Promise<void>;
|
|
274
|
-
emitLog(message: string, logMetadata?: JsonObject): Promise<void>;
|
|
275
|
-
getWorkspaceName(): Promise<string>;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* TaskEventType
|
|
280
|
-
*
|
|
281
|
-
* @public
|
|
282
|
-
*/
|
|
283
|
-
export declare type TaskEventType = 'completion' | 'log' | 'cancelled';
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* TaskSecrets
|
|
287
|
-
*
|
|
288
|
-
* @public
|
|
289
|
-
*/
|
|
290
|
-
export declare type TaskSecrets = Record<string, string> & {
|
|
291
|
-
backstageToken?: string;
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* The status of each step of the Task
|
|
296
|
-
*
|
|
297
|
-
* @public
|
|
298
|
-
*/
|
|
299
|
-
export declare type TaskStatus = 'cancelled' | 'completed' | 'failed' | 'open' | 'processing';
|
|
300
|
-
|
|
301
|
-
/** @public */
|
|
302
|
-
export declare type TemplateAction<TActionInput extends JsonObject = JsonObject, TActionOutput extends JsonObject = JsonObject> = {
|
|
303
|
-
id: string;
|
|
304
|
-
description?: string;
|
|
305
|
-
examples?: {
|
|
306
|
-
description: string;
|
|
307
|
-
example: string;
|
|
308
|
-
}[];
|
|
309
|
-
supportsDryRun?: boolean;
|
|
310
|
-
schema?: {
|
|
311
|
-
input?: Schema;
|
|
312
|
-
output?: Schema;
|
|
313
|
-
};
|
|
314
|
-
handler: (ctx: ActionContext<TActionInput, TActionOutput>) => Promise<void>;
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
/** @public */
|
|
318
|
-
export declare type TemplateActionOptions<TActionInput extends JsonObject = {}, TActionOutput extends JsonObject = {}, TInputSchema extends Schema | z.ZodType = {}, TOutputSchema extends Schema | z.ZodType = {}> = {
|
|
319
|
-
id: string;
|
|
320
|
-
description?: string;
|
|
321
|
-
examples?: TemplateExample[];
|
|
322
|
-
supportsDryRun?: boolean;
|
|
323
|
-
schema?: {
|
|
324
|
-
input?: TInputSchema;
|
|
325
|
-
output?: TOutputSchema;
|
|
326
|
-
};
|
|
327
|
-
handler: (ctx: ActionContext<TActionInput, TActionOutput>) => Promise<void>;
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
/** @public */
|
|
331
|
-
export declare type TemplateExample = {
|
|
332
|
-
description: string;
|
|
333
|
-
example: string;
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
/** @public */
|
|
337
|
-
export declare type TemplateFilter = (...args: JsonValue[]) => JsonValue | undefined;
|
|
338
|
-
|
|
339
|
-
/** @public */
|
|
340
|
-
export declare type TemplateGlobal = ((...args: JsonValue[]) => JsonValue | undefined) | JsonValue;
|
|
341
|
-
|
|
342
|
-
export { }
|
package/dist/index.beta.d.ts
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The scaffolder-node module for `@backstage/plugin-scaffolder-backend`.
|
|
3
|
-
*
|
|
4
|
-
* @packageDocumentation
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/// <reference types="node" />
|
|
8
|
-
|
|
9
|
-
import { ExtensionPoint } from '@backstage/backend-plugin-api';
|
|
10
|
-
import { JsonObject } from '@backstage/types';
|
|
11
|
-
import { JsonValue } from '@backstage/types';
|
|
12
|
-
import { Logger } from 'winston';
|
|
13
|
-
import { Observable } from '@backstage/types';
|
|
14
|
-
import { Schema } from 'jsonschema';
|
|
15
|
-
import { ScmIntegrations } from '@backstage/integration';
|
|
16
|
-
import { SpawnOptionsWithoutStdio } from 'child_process';
|
|
17
|
-
import { TaskBroker as TaskBroker_2 } from '@backstage/plugin-scaffolder-node';
|
|
18
|
-
import { TaskSpec } from '@backstage/plugin-scaffolder-common';
|
|
19
|
-
import { TemplateAction as TemplateAction_2 } from '@backstage/plugin-scaffolder-node';
|
|
20
|
-
import { TemplateFilter as TemplateFilter_2 } from '@backstage/plugin-scaffolder-node';
|
|
21
|
-
import { TemplateGlobal as TemplateGlobal_2 } from '@backstage/plugin-scaffolder-node';
|
|
22
|
-
import { TemplateInfo } from '@backstage/plugin-scaffolder-common';
|
|
23
|
-
import { UrlReader } from '@backstage/backend-common';
|
|
24
|
-
import { UserEntity } from '@backstage/catalog-model';
|
|
25
|
-
import { Writable } from 'stream';
|
|
26
|
-
import { z } from 'zod';
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* ActionContext is passed into scaffolder actions.
|
|
30
|
-
* @public
|
|
31
|
-
*/
|
|
32
|
-
export declare type ActionContext<TActionInput extends JsonObject, TActionOutput extends JsonObject = JsonObject> = {
|
|
33
|
-
logger: Logger;
|
|
34
|
-
logStream: Writable;
|
|
35
|
-
secrets?: TaskSecrets;
|
|
36
|
-
workspacePath: string;
|
|
37
|
-
input: TActionInput;
|
|
38
|
-
output(name: keyof TActionOutput, value: TActionOutput[keyof TActionOutput]): void;
|
|
39
|
-
/**
|
|
40
|
-
* Creates a temporary directory for use by the action, which is then cleaned up automatically.
|
|
41
|
-
*/
|
|
42
|
-
createTemporaryDirectory(): Promise<string>;
|
|
43
|
-
templateInfo?: TemplateInfo;
|
|
44
|
-
/**
|
|
45
|
-
* Whether this action invocation is a dry-run or not.
|
|
46
|
-
* This will only ever be true if the actions as marked as supporting dry-runs.
|
|
47
|
-
*/
|
|
48
|
-
isDryRun?: boolean;
|
|
49
|
-
/**
|
|
50
|
-
* The user which triggered the action.
|
|
51
|
-
*/
|
|
52
|
-
user?: {
|
|
53
|
-
/**
|
|
54
|
-
* The decorated entity from the Catalog
|
|
55
|
-
*/
|
|
56
|
-
entity?: UserEntity;
|
|
57
|
-
/**
|
|
58
|
-
* An entity ref for the author of the task
|
|
59
|
-
*/
|
|
60
|
-
ref?: string;
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Implement the signal to make your custom step abortable https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal
|
|
64
|
-
*/
|
|
65
|
-
signal?: AbortSignal;
|
|
66
|
-
/**
|
|
67
|
-
* Optional value of each invocation
|
|
68
|
-
*/
|
|
69
|
-
each?: JsonObject;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* This function is used to create new template actions to get type safety.
|
|
74
|
-
* Will convert zod schemas to json schemas for use throughout the system.
|
|
75
|
-
* @public
|
|
76
|
-
*/
|
|
77
|
-
export declare const createTemplateAction: <TInputParams extends JsonObject = JsonObject, TOutputParams extends JsonObject = JsonObject, TInputSchema extends z.ZodType<any, z.ZodTypeDef, any> | Schema = {}, TOutputSchema extends z.ZodType<any, z.ZodTypeDef, any> | Schema = {}, TActionInput extends JsonObject = TInputSchema extends z.ZodType<any, any, infer IReturn> ? IReturn : TInputParams, TActionOutput extends JsonObject = TOutputSchema extends z.ZodType<any, any, infer IReturn_1> ? IReturn_1 : TOutputParams>(action: TemplateActionOptions<TActionInput, TActionOutput, TInputSchema, TOutputSchema>) => TemplateAction<TActionInput, TActionOutput>;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Run a command in a sub-process, normally a shell command.
|
|
81
|
-
*
|
|
82
|
-
* @public
|
|
83
|
-
*/
|
|
84
|
-
export declare function executeShellCommand(options: ExecuteShellCommandOptions): Promise<void>;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Options for {@link executeShellCommand}.
|
|
88
|
-
*
|
|
89
|
-
* @public
|
|
90
|
-
*/
|
|
91
|
-
export declare type ExecuteShellCommandOptions = {
|
|
92
|
-
/** command to run */
|
|
93
|
-
command: string;
|
|
94
|
-
/** arguments to pass the command */
|
|
95
|
-
args: string[];
|
|
96
|
-
/** options to pass to spawn */
|
|
97
|
-
options?: SpawnOptionsWithoutStdio;
|
|
98
|
-
/** stream to capture stdout and stderr output */
|
|
99
|
-
logStream?: Writable;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* A helper function that reads the contents of a directory from the given URL.
|
|
104
|
-
* Can be used in your own actions, and also used behind fetch:template and fetch:plain
|
|
105
|
-
*
|
|
106
|
-
* @public
|
|
107
|
-
*/
|
|
108
|
-
export declare function fetchContents(options: {
|
|
109
|
-
reader: UrlReader;
|
|
110
|
-
integrations: ScmIntegrations;
|
|
111
|
-
baseUrl?: string;
|
|
112
|
-
fetchUrl?: string;
|
|
113
|
-
outputPath: string;
|
|
114
|
-
}): Promise<void>;
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* A helper function that reads the content of a single file from the given URL.
|
|
118
|
-
* Can be used in your own actions, and also used behind `fetch:plain:file`
|
|
119
|
-
*
|
|
120
|
-
* @public
|
|
121
|
-
*/
|
|
122
|
-
export declare function fetchFile(options: {
|
|
123
|
-
reader: UrlReader;
|
|
124
|
-
integrations: ScmIntegrations;
|
|
125
|
-
baseUrl?: string;
|
|
126
|
-
fetchUrl?: string;
|
|
127
|
-
outputPath: string;
|
|
128
|
-
}): Promise<void>;
|
|
129
|
-
|
|
130
|
-
/* Excluded from this release type: ScaffolderActionsExtensionPoint */
|
|
131
|
-
|
|
132
|
-
/* Excluded from this release type: scaffolderActionsExtensionPoint */
|
|
133
|
-
|
|
134
|
-
/* Excluded from this release type: ScaffolderTaskBrokerExtensionPoint */
|
|
135
|
-
|
|
136
|
-
/* Excluded from this release type: scaffolderTaskBrokerExtensionPoint */
|
|
137
|
-
|
|
138
|
-
/* Excluded from this release type: ScaffolderTemplatingExtensionPoint */
|
|
139
|
-
|
|
140
|
-
/* Excluded from this release type: scaffolderTemplatingExtensionPoint */
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* SerializedTask
|
|
144
|
-
*
|
|
145
|
-
* @public
|
|
146
|
-
*/
|
|
147
|
-
export declare type SerializedTask = {
|
|
148
|
-
id: string;
|
|
149
|
-
spec: TaskSpec;
|
|
150
|
-
status: TaskStatus;
|
|
151
|
-
createdAt: string;
|
|
152
|
-
lastHeartbeatAt?: string;
|
|
153
|
-
createdBy?: string;
|
|
154
|
-
secrets?: TaskSecrets;
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* SerializedTaskEvent
|
|
159
|
-
*
|
|
160
|
-
* @public
|
|
161
|
-
*/
|
|
162
|
-
export declare type SerializedTaskEvent = {
|
|
163
|
-
id: number;
|
|
164
|
-
taskId: string;
|
|
165
|
-
body: JsonObject;
|
|
166
|
-
type: TaskEventType;
|
|
167
|
-
createdAt: string;
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* TaskBroker
|
|
172
|
-
*
|
|
173
|
-
* @public
|
|
174
|
-
*/
|
|
175
|
-
export declare interface TaskBroker {
|
|
176
|
-
cancel?(taskId: string): Promise<void>;
|
|
177
|
-
claim(): Promise<TaskContext>;
|
|
178
|
-
dispatch(options: TaskBrokerDispatchOptions): Promise<TaskBrokerDispatchResult>;
|
|
179
|
-
vacuumTasks(options: {
|
|
180
|
-
timeoutS: number;
|
|
181
|
-
}): Promise<void>;
|
|
182
|
-
event$(options: {
|
|
183
|
-
taskId: string;
|
|
184
|
-
after: number | undefined;
|
|
185
|
-
}): Observable<{
|
|
186
|
-
events: SerializedTaskEvent[];
|
|
187
|
-
}>;
|
|
188
|
-
get(taskId: string): Promise<SerializedTask>;
|
|
189
|
-
list?(options?: {
|
|
190
|
-
createdBy?: string;
|
|
191
|
-
}): Promise<{
|
|
192
|
-
tasks: SerializedTask[];
|
|
193
|
-
}>;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* The options passed to {@link TaskBroker.dispatch}
|
|
198
|
-
* Currently a spec and optional secrets
|
|
199
|
-
*
|
|
200
|
-
* @public
|
|
201
|
-
*/
|
|
202
|
-
export declare type TaskBrokerDispatchOptions = {
|
|
203
|
-
spec: TaskSpec;
|
|
204
|
-
secrets?: TaskSecrets;
|
|
205
|
-
createdBy?: string;
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* The result of {@link TaskBroker.dispatch}
|
|
210
|
-
*
|
|
211
|
-
* @public
|
|
212
|
-
*/
|
|
213
|
-
export declare type TaskBrokerDispatchResult = {
|
|
214
|
-
taskId: string;
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* The state of a completed task.
|
|
219
|
-
*
|
|
220
|
-
* @public
|
|
221
|
-
*/
|
|
222
|
-
export declare type TaskCompletionState = 'failed' | 'completed';
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Task
|
|
226
|
-
*
|
|
227
|
-
* @public
|
|
228
|
-
*/
|
|
229
|
-
export declare interface TaskContext {
|
|
230
|
-
cancelSignal: AbortSignal;
|
|
231
|
-
spec: TaskSpec;
|
|
232
|
-
secrets?: TaskSecrets;
|
|
233
|
-
createdBy?: string;
|
|
234
|
-
done: boolean;
|
|
235
|
-
isDryRun?: boolean;
|
|
236
|
-
complete(result: TaskCompletionState, metadata?: JsonObject): Promise<void>;
|
|
237
|
-
emitLog(message: string, logMetadata?: JsonObject): Promise<void>;
|
|
238
|
-
getWorkspaceName(): Promise<string>;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* TaskEventType
|
|
243
|
-
*
|
|
244
|
-
* @public
|
|
245
|
-
*/
|
|
246
|
-
export declare type TaskEventType = 'completion' | 'log' | 'cancelled';
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* TaskSecrets
|
|
250
|
-
*
|
|
251
|
-
* @public
|
|
252
|
-
*/
|
|
253
|
-
export declare type TaskSecrets = Record<string, string> & {
|
|
254
|
-
backstageToken?: string;
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* The status of each step of the Task
|
|
259
|
-
*
|
|
260
|
-
* @public
|
|
261
|
-
*/
|
|
262
|
-
export declare type TaskStatus = 'cancelled' | 'completed' | 'failed' | 'open' | 'processing';
|
|
263
|
-
|
|
264
|
-
/** @public */
|
|
265
|
-
export declare type TemplateAction<TActionInput extends JsonObject = JsonObject, TActionOutput extends JsonObject = JsonObject> = {
|
|
266
|
-
id: string;
|
|
267
|
-
description?: string;
|
|
268
|
-
examples?: {
|
|
269
|
-
description: string;
|
|
270
|
-
example: string;
|
|
271
|
-
}[];
|
|
272
|
-
supportsDryRun?: boolean;
|
|
273
|
-
schema?: {
|
|
274
|
-
input?: Schema;
|
|
275
|
-
output?: Schema;
|
|
276
|
-
};
|
|
277
|
-
handler: (ctx: ActionContext<TActionInput, TActionOutput>) => Promise<void>;
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
/** @public */
|
|
281
|
-
export declare type TemplateActionOptions<TActionInput extends JsonObject = {}, TActionOutput extends JsonObject = {}, TInputSchema extends Schema | z.ZodType = {}, TOutputSchema extends Schema | z.ZodType = {}> = {
|
|
282
|
-
id: string;
|
|
283
|
-
description?: string;
|
|
284
|
-
examples?: TemplateExample[];
|
|
285
|
-
supportsDryRun?: boolean;
|
|
286
|
-
schema?: {
|
|
287
|
-
input?: TInputSchema;
|
|
288
|
-
output?: TOutputSchema;
|
|
289
|
-
};
|
|
290
|
-
handler: (ctx: ActionContext<TActionInput, TActionOutput>) => Promise<void>;
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
/** @public */
|
|
294
|
-
export declare type TemplateExample = {
|
|
295
|
-
description: string;
|
|
296
|
-
example: string;
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
/** @public */
|
|
300
|
-
export declare type TemplateFilter = (...args: JsonValue[]) => JsonValue | undefined;
|
|
301
|
-
|
|
302
|
-
/** @public */
|
|
303
|
-
export declare type TemplateGlobal = ((...args: JsonValue[]) => JsonValue | undefined) | JsonValue;
|
|
304
|
-
|
|
305
|
-
export { }
|