@backstage/plugin-scaffolder-node 0.2.6-next.2 → 0.2.7

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 CHANGED
@@ -1,5 +1,27 @@
1
1
  # @backstage/plugin-scaffolder-node
2
2
 
3
+ ## 0.2.7
4
+
5
+ ### Patch Changes
6
+
7
+ - f6c651fe3c6c: Switched to using `"exports"` field for `/alpha` subpath export.
8
+ - Updated dependencies
9
+ - @backstage/backend-common@0.19.9
10
+ - @backstage/backend-plugin-api@0.6.7
11
+
12
+ ## 0.2.6
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies
17
+ - @backstage/backend-common@0.19.8
18
+ - @backstage/integration@1.7.1
19
+ - @backstage/catalog-model@1.4.3
20
+ - @backstage/errors@1.2.3
21
+ - @backstage/backend-plugin-api@0.6.6
22
+ - @backstage/types@1.1.1
23
+ - @backstage/plugin-scaffolder-common@1.4.2
24
+
3
25
  ## 0.2.6-next.2
4
26
 
5
27
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-node",
3
- "version": "0.2.6-next.2",
4
- "main": "../dist/index.cjs.js",
5
- "types": "../dist/index.alpha.d.ts"
3
+ "version": "0.2.7",
4
+ "main": "../dist/alpha.cjs.js",
5
+ "types": "../dist/alpha.d.ts"
6
6
  }
@@ -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;;;;;;"}
@@ -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
@@ -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,C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I,kBAAqB,GAAA,KAAA,CAAA;AACzB,EAAI,IAAA;AAEF,IAAA,IAAI,IAAI,QAAQ,CAAA,CAAA;AAChB,IAAqB,kBAAA,GAAA,IAAA,CAAA;AAAA,GACf,CAAA,MAAA;AAAA,GAER;AACA,EAAO,OAAA,kBAAA,CAAA;AACT,CAAA;AAEA,SAAS,UAAA,CACP,QACA,EAAA,OAAA,EACA,YACA,EAAA;AACA,EAAI,IAAA,kBAAA,CAAmB,QAAQ,CAAG,EAAA;AAChC,IAAO,OAAA,QAAA,CAAA;AAAA,aACE,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,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T,CAAA;AAEA,SAAS,UAAA,CACP,QACA,EAAA,OAAA,EACA,YACA,EAAA;AACA,EAAI,IAAA,kBAAA,CAAmB,QAAQ,CAAG,EAAA;AAChC,IAAO,OAAA,QAAA,CAAA;AAAA,aACE,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;;;;;;;"}
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 { Observable } from '@backstage/types';
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 { ScmIntegrations } from '@backstage/integration';
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 { 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>;
11
+ import { ScmIntegrations } from '@backstage/integration';
85
12
 
86
13
  /**
87
- * Options for {@link executeShellCommand}.
14
+ * TaskSecrets
88
15
  *
89
16
  * @public
90
17
  */
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;
18
+ type TaskSecrets = Record<string, string> & {
19
+ backstageToken?: string;
100
20
  };
101
-
102
21
  /**
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
22
+ * The status of each step of the Task
105
23
  *
106
24
  * @public
107
25
  */
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
-
26
+ type TaskStatus = 'cancelled' | 'completed' | 'failed' | 'open' | 'processing';
116
27
  /**
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`
28
+ * The state of a completed task.
119
29
  *
120
30
  * @public
121
31
  */
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
-
32
+ type TaskCompletionState = 'failed' | 'completed';
142
33
  /**
143
34
  * SerializedTask
144
35
  *
145
36
  * @public
146
37
  */
147
- export declare type SerializedTask = {
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
- export declare type SerializedTaskEvent = {
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
- 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
-
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
- export declare type TaskBrokerDispatchOptions = {
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
- export declare interface TaskContext {
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
- * TaskEventType
101
+ * TaskBroker
243
102
  *
244
103
  * @public
245
104
  */
246
- export declare type TaskEventType = 'completion' | 'log' | 'cancelled';
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
- * TaskSecrets
250
- *
127
+ * ActionContext is passed into scaffolder actions.
251
128
  * @public
252
129
  */
253
- export declare type TaskSecrets = Record<string, string> & {
254
- backstageToken?: string;
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
- export declare type TemplateAction<TActionInput extends JsonObject = JsonObject, TActionOutput extends JsonObject = JsonObject> = {
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
- export declare type TemplateActionOptions<TActionInput extends JsonObject = {}, TActionOutput extends JsonObject = {}, TInputSchema extends Schema | z.ZodType = {}, TOutputSchema extends Schema | z.ZodType = {}> = {
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
- /** @public */
294
- export declare type TemplateExample = {
295
- description: string;
296
- example: string;
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
- /** @public */
300
- export declare type TemplateFilter = (...args: JsonValue[]) => JsonValue | undefined;
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
- export declare type TemplateGlobal = ((...args: JsonValue[]) => JsonValue | undefined) | JsonValue;
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 };