@backstage/plugin-scaffolder-node 0.5.0-next.1 → 0.5.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 CHANGED
@@ -1,5 +1,37 @@
1
1
  # @backstage/plugin-scaffolder-node
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 3ec4e6d: Added pagination support for listing of tasks and the ability to filter on several users and task statuses.
8
+
9
+ ### Patch Changes
10
+
11
+ - 094eaa3: Remove references to in-repo backend-common
12
+ - 11e0752: Make it possible to manually retry the scaffolder template from the step it failed
13
+ - d7a736c: Use `branch` function instead of `checkout` function when creating branch
14
+ - Updated dependencies
15
+ - @backstage/integration@1.15.1
16
+ - @backstage/backend-plugin-api@1.0.1
17
+ - @backstage/catalog-model@1.7.0
18
+ - @backstage/errors@1.2.4
19
+ - @backstage/types@1.1.1
20
+ - @backstage/plugin-scaffolder-common@1.5.6
21
+
22
+ ## 0.5.0-next.2
23
+
24
+ ### Patch Changes
25
+
26
+ - d7a736c: Use `branch` function instead of `checkout` function when creating branch
27
+ - Updated dependencies
28
+ - @backstage/integration@1.15.1-next.1
29
+ - @backstage/backend-plugin-api@1.0.1-next.1
30
+ - @backstage/catalog-model@1.7.0
31
+ - @backstage/errors@1.2.4
32
+ - @backstage/types@1.1.1
33
+ - @backstage/plugin-scaffolder-common@1.5.6
34
+
3
35
  ## 0.5.0-next.1
4
36
 
5
37
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-node__alpha",
3
- "version": "0.5.0-next.1",
3
+ "version": "0.5.0",
4
4
  "main": "../dist/alpha.cjs.js",
5
5
  "types": "../dist/alpha.d.ts"
6
6
  }
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ var zodToJsonSchema = require('zod-to-json-schema');
4
+
5
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
6
+
7
+ var zodToJsonSchema__default = /*#__PURE__*/_interopDefaultCompat(zodToJsonSchema);
8
+
9
+ const createTemplateAction = (action) => {
10
+ const inputSchema = action.schema?.input && "safeParseAsync" in action.schema.input ? zodToJsonSchema__default.default(action.schema.input) : action.schema?.input;
11
+ const outputSchema = action.schema?.output && "safeParseAsync" in action.schema.output ? zodToJsonSchema__default.default(action.schema.output) : action.schema?.output;
12
+ return {
13
+ ...action,
14
+ schema: {
15
+ ...action.schema,
16
+ input: inputSchema,
17
+ output: outputSchema
18
+ }
19
+ };
20
+ };
21
+
22
+ exports.createTemplateAction = createTemplateAction;
23
+ //# sourceMappingURL=createTemplateAction.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTemplateAction.cjs.js","sources":["../../src/actions/createTemplateAction.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"],"names":["zodToJsonSchema"],"mappings":";;;;;;;;AAmDa,MAAA,oBAAA,GAAuB,CAoBlC,MAMgD,KAAA;AAChD,EAAA,MAAM,WACJ,GAAA,MAAA,CAAO,MAAQ,EAAA,KAAA,IAAS,oBAAoB,MAAO,CAAA,MAAA,CAAO,KACtD,GAAAA,gCAAA,CAAgB,MAAO,CAAA,MAAA,CAAO,KAAK,CAAA,GACnC,OAAO,MAAQ,EAAA,KAAA,CAAA;AAErB,EAAA,MAAM,YACJ,GAAA,MAAA,CAAO,MAAQ,EAAA,MAAA,IAAU,oBAAoB,MAAO,CAAA,MAAA,CAAO,MACvD,GAAAA,gCAAA,CAAgB,MAAO,CAAA,MAAA,CAAO,MAAM,CAAA,GACpC,OAAO,MAAQ,EAAA,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,KACV;AAAA,GACF,CAAA;AACF;;;;"}
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ var child_process = require('child_process');
4
+ var stream = require('stream');
5
+
6
+ async function executeShellCommand(options) {
7
+ const {
8
+ command,
9
+ args,
10
+ options: spawnOptions,
11
+ logStream = new stream.PassThrough()
12
+ } = options;
13
+ await new Promise((resolve, reject) => {
14
+ const process = child_process.spawn(command, args, spawnOptions);
15
+ process.stdout.on("data", (stream) => {
16
+ logStream.write(stream);
17
+ });
18
+ process.stderr.on("data", (stream) => {
19
+ logStream.write(stream);
20
+ });
21
+ process.on("error", (error) => {
22
+ return reject(error);
23
+ });
24
+ process.on("close", (code) => {
25
+ if (code !== 0) {
26
+ return reject(
27
+ new Error(`Command ${command} failed, exit code: ${code}`)
28
+ );
29
+ }
30
+ return resolve();
31
+ });
32
+ });
33
+ }
34
+
35
+ exports.executeShellCommand = executeShellCommand;
36
+ //# sourceMappingURL=executeShellCommand.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executeShellCommand.cjs.js","sources":["../../src/actions/executeShellCommand.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 { 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"],"names":["PassThrough","spawn"],"mappings":";;;;;AAwCA,eAAsB,oBACpB,OACe,EAAA;AACf,EAAM,MAAA;AAAA,IACJ,OAAA;AAAA,IACA,IAAA;AAAA,IACA,OAAS,EAAA,YAAA;AAAA,IACT,SAAA,GAAY,IAAIA,kBAAY,EAAA;AAAA,GAC1B,GAAA,OAAA,CAAA;AAEJ,EAAA,MAAM,IAAI,OAAA,CAAc,CAAC,OAAA,EAAS,MAAW,KAAA;AAC3C,IAAA,MAAM,OAAU,GAAAC,mBAAA,CAAM,OAAS,EAAA,IAAA,EAAM,YAAY,CAAA,CAAA;AAEjD,IAAQ,OAAA,CAAA,MAAA,CAAO,EAAG,CAAA,MAAA,EAAQ,CAAU,MAAA,KAAA;AAClC,MAAA,SAAA,CAAU,MAAM,MAAM,CAAA,CAAA;AAAA,KACvB,CAAA,CAAA;AAED,IAAQ,OAAA,CAAA,MAAA,CAAO,EAAG,CAAA,MAAA,EAAQ,CAAU,MAAA,KAAA;AAClC,MAAA,SAAA,CAAU,MAAM,MAAM,CAAA,CAAA;AAAA,KACvB,CAAA,CAAA;AAED,IAAQ,OAAA,CAAA,EAAA,CAAG,SAAS,CAAS,KAAA,KAAA;AAC3B,MAAA,OAAO,OAAO,KAAK,CAAA,CAAA;AAAA,KACpB,CAAA,CAAA;AAED,IAAQ,OAAA,CAAA,EAAA,CAAG,SAAS,CAAQ,IAAA,KAAA;AAC1B,MAAA,IAAI,SAAS,CAAG,EAAA;AACd,QAAO,OAAA,MAAA;AAAA,UACL,IAAI,KAAM,CAAA,CAAA,QAAA,EAAW,OAAO,CAAA,oBAAA,EAAuB,IAAI,CAAE,CAAA,CAAA;AAAA,SAC3D,CAAA;AAAA,OACF;AACA,MAAA,OAAO,OAAQ,EAAA,CAAA;AAAA,KAChB,CAAA,CAAA;AAAA,GACF,CAAA,CAAA;AACH;;;;"}
@@ -0,0 +1,85 @@
1
+ 'use strict';
2
+
3
+ var backendPluginApi = require('@backstage/backend-plugin-api');
4
+ var errors = require('@backstage/errors');
5
+ var fs = require('fs-extra');
6
+ var path = require('path');
7
+
8
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
9
+
10
+ var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
11
+ var path__default = /*#__PURE__*/_interopDefaultCompat(path);
12
+
13
+ async function fetchContents(options) {
14
+ const {
15
+ reader,
16
+ integrations,
17
+ baseUrl,
18
+ fetchUrl = ".",
19
+ outputPath,
20
+ token
21
+ } = options;
22
+ const fetchUrlIsAbsolute = isFetchUrlAbsolute(fetchUrl);
23
+ if (!fetchUrlIsAbsolute && baseUrl?.startsWith("file://")) {
24
+ const basePath = baseUrl.slice("file://".length);
25
+ const srcDir = backendPluginApi.resolveSafeChildPath(path__default.default.dirname(basePath), fetchUrl);
26
+ await fs__default.default.copy(srcDir, outputPath);
27
+ } else {
28
+ const readUrl = getReadUrl(fetchUrl, baseUrl, integrations);
29
+ const res = await reader.readTree(readUrl, { token });
30
+ await fs__default.default.ensureDir(outputPath);
31
+ await res.dir({ targetDir: outputPath });
32
+ }
33
+ }
34
+ async function fetchFile(options) {
35
+ const {
36
+ reader,
37
+ integrations,
38
+ baseUrl,
39
+ fetchUrl = ".",
40
+ outputPath,
41
+ token
42
+ } = options;
43
+ const fetchUrlIsAbsolute = isFetchUrlAbsolute(fetchUrl);
44
+ if (!fetchUrlIsAbsolute && baseUrl?.startsWith("file://")) {
45
+ const basePath = baseUrl.slice("file://".length);
46
+ const src = backendPluginApi.resolveSafeChildPath(path__default.default.dirname(basePath), fetchUrl);
47
+ await fs__default.default.copyFile(src, outputPath);
48
+ } else {
49
+ const readUrl = getReadUrl(fetchUrl, baseUrl, integrations);
50
+ const res = await reader.readUrl(readUrl, { token });
51
+ await fs__default.default.ensureDir(path__default.default.dirname(outputPath));
52
+ const buffer = await res.buffer();
53
+ await fs__default.default.outputFile(outputPath, buffer);
54
+ }
55
+ }
56
+ function isFetchUrlAbsolute(fetchUrl) {
57
+ let fetchUrlIsAbsolute = false;
58
+ try {
59
+ new URL(fetchUrl);
60
+ fetchUrlIsAbsolute = true;
61
+ } catch {
62
+ }
63
+ return fetchUrlIsAbsolute;
64
+ }
65
+ function getReadUrl(fetchUrl, baseUrl, integrations) {
66
+ if (isFetchUrlAbsolute(fetchUrl)) {
67
+ return fetchUrl;
68
+ } else if (baseUrl) {
69
+ const integration = integrations.byUrl(baseUrl);
70
+ if (!integration) {
71
+ throw new errors.InputError(`No integration found for location ${baseUrl}`);
72
+ }
73
+ return integration.resolveUrl({
74
+ url: fetchUrl,
75
+ base: baseUrl
76
+ });
77
+ }
78
+ throw new errors.InputError(
79
+ `Failed to fetch, template location could not be determined and the fetch URL is relative, ${fetchUrl}`
80
+ );
81
+ }
82
+
83
+ exports.fetchContents = fetchContents;
84
+ exports.fetchFile = fetchFile;
85
+ //# sourceMappingURL=fetch.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.cjs.js","sources":["../../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 { UrlReaderService } from '@backstage/backend-plugin-api';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\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: UrlReaderService;\n integrations: ScmIntegrations;\n baseUrl?: string;\n fetchUrl?: string;\n outputPath: string;\n token?: string;\n}) {\n const {\n reader,\n integrations,\n baseUrl,\n fetchUrl = '.',\n outputPath,\n token,\n } = options;\n\n const fetchUrlIsAbsolute = isFetchUrlAbsolute(fetchUrl);\n\n // We handle both file locations and url ones\n if (!fetchUrlIsAbsolute && baseUrl?.startsWith('file://')) {\n const basePath = baseUrl.slice('file://'.length);\n const srcDir = resolveSafeChildPath(path.dirname(basePath), fetchUrl);\n await fs.copy(srcDir, outputPath);\n } else {\n const readUrl = getReadUrl(fetchUrl, baseUrl, integrations);\n\n const res = await reader.readTree(readUrl, { token });\n await fs.ensureDir(outputPath);\n await res.dir({ targetDir: outputPath });\n }\n}\n\n/**\n * A helper function that reads the content of a single file from the given URL.\n * Can be used in your own actions, and also used behind `fetch:plain:file`\n *\n * @public\n */\nexport async function fetchFile(options: {\n reader: UrlReaderService;\n integrations: ScmIntegrations;\n baseUrl?: string;\n fetchUrl?: string;\n outputPath: string;\n token?: string;\n}) {\n const {\n reader,\n integrations,\n baseUrl,\n fetchUrl = '.',\n outputPath,\n token,\n } = options;\n\n const fetchUrlIsAbsolute = isFetchUrlAbsolute(fetchUrl);\n\n // We handle both file locations and url ones\n if (!fetchUrlIsAbsolute && baseUrl?.startsWith('file://')) {\n const basePath = baseUrl.slice('file://'.length);\n const src = resolveSafeChildPath(path.dirname(basePath), fetchUrl);\n await fs.copyFile(src, outputPath);\n } else {\n const readUrl = getReadUrl(fetchUrl, baseUrl, integrations);\n\n const res = await reader.readUrl(readUrl, { token });\n await fs.ensureDir(path.dirname(outputPath));\n const buffer = await res.buffer();\n await fs.outputFile(outputPath, buffer);\n }\n}\n\nfunction isFetchUrlAbsolute(fetchUrl: string) {\n let fetchUrlIsAbsolute = false;\n try {\n // eslint-disable-next-line no-new\n new URL(fetchUrl);\n fetchUrlIsAbsolute = true;\n } catch {\n /* ignored */\n }\n return fetchUrlIsAbsolute;\n}\n\nfunction getReadUrl(\n fetchUrl: string,\n baseUrl: string | undefined,\n integrations: ScmIntegrations,\n) {\n if (isFetchUrlAbsolute(fetchUrl)) {\n return fetchUrl;\n } else if (baseUrl) {\n const integration = integrations.byUrl(baseUrl);\n if (!integration) {\n throw new InputError(`No integration found for location ${baseUrl}`);\n }\n\n return integration.resolveUrl({\n url: fetchUrl,\n base: baseUrl,\n });\n }\n throw new InputError(\n `Failed to fetch, template location could not be determined and the fetch URL is relative, ${fetchUrl}`,\n );\n}\n"],"names":["resolveSafeChildPath","path","fs","InputError"],"mappings":";;;;;;;;;;;;AA6BA,eAAsB,cAAc,OAOjC,EAAA;AACD,EAAM,MAAA;AAAA,IACJ,MAAA;AAAA,IACA,YAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAW,GAAA,GAAA;AAAA,IACX,UAAA;AAAA,IACA,KAAA;AAAA,GACE,GAAA,OAAA,CAAA;AAEJ,EAAM,MAAA,kBAAA,GAAqB,mBAAmB,QAAQ,CAAA,CAAA;AAGtD,EAAA,IAAI,CAAC,kBAAA,IAAsB,OAAS,EAAA,UAAA,CAAW,SAAS,CAAG,EAAA;AACzD,IAAA,MAAM,QAAW,GAAA,OAAA,CAA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;"}
@@ -0,0 +1,142 @@
1
+ 'use strict';
2
+
3
+ var git = require('../scm/git.cjs.js');
4
+
5
+ async function initRepoAndPush(input) {
6
+ const {
7
+ dir,
8
+ remoteUrl,
9
+ auth,
10
+ logger,
11
+ defaultBranch = "master",
12
+ commitMessage = "Initial commit",
13
+ gitAuthorInfo
14
+ } = input;
15
+ const git$1 = git.Git.fromAuth({
16
+ ...auth,
17
+ logger
18
+ });
19
+ await git$1.init({
20
+ dir,
21
+ defaultBranch
22
+ });
23
+ await git$1.add({ dir, filepath: "." });
24
+ const authorInfo = {
25
+ name: gitAuthorInfo?.name ?? "Scaffolder",
26
+ email: gitAuthorInfo?.email ?? "scaffolder@backstage.io"
27
+ };
28
+ const commitHash = await git$1.commit({
29
+ dir,
30
+ message: commitMessage,
31
+ author: authorInfo,
32
+ committer: authorInfo
33
+ });
34
+ await git$1.addRemote({
35
+ dir,
36
+ url: remoteUrl,
37
+ remote: "origin"
38
+ });
39
+ await git$1.push({
40
+ dir,
41
+ remote: "origin"
42
+ });
43
+ return { commitHash };
44
+ }
45
+ async function commitAndPushRepo(input) {
46
+ const {
47
+ dir,
48
+ auth,
49
+ logger,
50
+ commitMessage,
51
+ gitAuthorInfo,
52
+ branch = "master",
53
+ remoteRef
54
+ } = input;
55
+ const git$1 = git.Git.fromAuth({
56
+ ...auth,
57
+ logger
58
+ });
59
+ await git$1.fetch({ dir });
60
+ await git$1.checkout({ dir, ref: branch });
61
+ await git$1.add({ dir, filepath: "." });
62
+ const authorInfo = {
63
+ name: gitAuthorInfo?.name ?? "Scaffolder",
64
+ email: gitAuthorInfo?.email ?? "scaffolder@backstage.io"
65
+ };
66
+ const commitHash = await git$1.commit({
67
+ dir,
68
+ message: commitMessage,
69
+ author: authorInfo,
70
+ committer: authorInfo
71
+ });
72
+ await git$1.push({
73
+ dir,
74
+ remote: "origin",
75
+ remoteRef: remoteRef ?? `refs/heads/${branch}`
76
+ });
77
+ return { commitHash };
78
+ }
79
+ async function cloneRepo(options) {
80
+ const { url, dir, auth, logger, ref, depth, noCheckout } = options;
81
+ const git$1 = git.Git.fromAuth({
82
+ ...auth,
83
+ logger
84
+ });
85
+ await git$1.clone({ url, dir, ref, depth, noCheckout });
86
+ }
87
+ async function createBranch(options) {
88
+ const { dir, ref, auth, logger } = options;
89
+ const git$1 = git.Git.fromAuth({
90
+ ...auth,
91
+ logger
92
+ });
93
+ await git$1.branch({ dir, ref });
94
+ }
95
+ async function addFiles(options) {
96
+ const { dir, filepath, auth, logger } = options;
97
+ const git$1 = git.Git.fromAuth({
98
+ ...auth,
99
+ logger
100
+ });
101
+ await git$1.add({ dir, filepath });
102
+ }
103
+ async function commitAndPushBranch(options) {
104
+ const {
105
+ dir,
106
+ auth,
107
+ logger,
108
+ commitMessage,
109
+ gitAuthorInfo,
110
+ branch = "master",
111
+ remoteRef,
112
+ remote = "origin"
113
+ } = options;
114
+ const git$1 = git.Git.fromAuth({
115
+ ...auth,
116
+ logger
117
+ });
118
+ const authorInfo = {
119
+ name: gitAuthorInfo?.name ?? "Scaffolder",
120
+ email: gitAuthorInfo?.email ?? "scaffolder@backstage.io"
121
+ };
122
+ const commitHash = await git$1.commit({
123
+ dir,
124
+ message: commitMessage,
125
+ author: authorInfo,
126
+ committer: authorInfo
127
+ });
128
+ await git$1.push({
129
+ dir,
130
+ remote,
131
+ remoteRef: remoteRef ?? `refs/heads/${branch}`
132
+ });
133
+ return { commitHash };
134
+ }
135
+
136
+ exports.addFiles = addFiles;
137
+ exports.cloneRepo = cloneRepo;
138
+ exports.commitAndPushBranch = commitAndPushBranch;
139
+ exports.commitAndPushRepo = commitAndPushRepo;
140
+ exports.createBranch = createBranch;
141
+ exports.initRepoAndPush = initRepoAndPush;
142
+ //# sourceMappingURL=gitHelpers.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gitHelpers.cjs.js","sources":["../../src/actions/gitHelpers.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Logger } from 'winston';\nimport { Git } from '../scm';\n\n/**\n * @public\n */\nexport async function initRepoAndPush(input: {\n dir: string;\n remoteUrl: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger: Logger;\n defaultBranch?: string;\n commitMessage?: string;\n gitAuthorInfo?: { name?: string; email?: string };\n}): Promise<{ commitHash: string }> {\n const {\n dir,\n remoteUrl,\n auth,\n logger,\n defaultBranch = 'master',\n commitMessage = 'Initial commit',\n gitAuthorInfo,\n } = input;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.init({\n dir,\n defaultBranch,\n });\n\n await git.add({ dir, filepath: '.' });\n\n // use provided info if possible, otherwise use fallbacks\n const authorInfo = {\n name: gitAuthorInfo?.name ?? 'Scaffolder',\n email: gitAuthorInfo?.email ?? 'scaffolder@backstage.io',\n };\n\n const commitHash = await git.commit({\n dir,\n message: commitMessage,\n author: authorInfo,\n committer: authorInfo,\n });\n await git.addRemote({\n dir,\n url: remoteUrl,\n remote: 'origin',\n });\n\n await git.push({\n dir,\n remote: 'origin',\n });\n\n return { commitHash };\n}\n\n/**\n * @public\n */\nexport async function commitAndPushRepo(input: {\n dir: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger: Logger;\n commitMessage: string;\n gitAuthorInfo?: { name?: string; email?: string };\n branch?: string;\n remoteRef?: string;\n}): Promise<{ commitHash: string }> {\n const {\n dir,\n auth,\n logger,\n commitMessage,\n gitAuthorInfo,\n branch = 'master',\n remoteRef,\n } = input;\n\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.fetch({ dir });\n await git.checkout({ dir, ref: branch });\n await git.add({ dir, filepath: '.' });\n\n // use provided info if possible, otherwise use fallbacks\n const authorInfo = {\n name: gitAuthorInfo?.name ?? 'Scaffolder',\n email: gitAuthorInfo?.email ?? 'scaffolder@backstage.io',\n };\n\n const commitHash = await git.commit({\n dir,\n message: commitMessage,\n author: authorInfo,\n committer: authorInfo,\n });\n\n await git.push({\n dir,\n remote: 'origin',\n remoteRef: remoteRef ?? `refs/heads/${branch}`,\n });\n\n return { commitHash };\n}\n\n/**\n * @public\n */\nexport async function cloneRepo(options: {\n url: string;\n dir: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: Logger | undefined;\n ref?: string | undefined;\n depth?: number | undefined;\n noCheckout?: boolean | undefined;\n}): Promise<void> {\n const { url, dir, auth, logger, ref, depth, noCheckout } = options;\n\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.clone({ url, dir, ref, depth, noCheckout });\n}\n\n/**\n * @public\n */\nexport async function createBranch(options: {\n dir: string;\n ref: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: Logger | undefined;\n}): Promise<void> {\n const { dir, ref, auth, logger } = options;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.branch({ dir, ref });\n}\n\n/**\n * @public\n */\nexport async function addFiles(options: {\n dir: string;\n filepath: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: Logger | undefined;\n}): Promise<void> {\n const { dir, filepath, auth, logger } = options;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.add({ dir, filepath });\n}\n\n/**\n * @public\n */\nexport async function commitAndPushBranch(options: {\n dir: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger?: Logger | undefined;\n commitMessage: string;\n gitAuthorInfo?: { name?: string; email?: string };\n branch?: string;\n remoteRef?: string;\n remote?: string;\n}): Promise<{ commitHash: string }> {\n const {\n dir,\n auth,\n logger,\n commitMessage,\n gitAuthorInfo,\n branch = 'master',\n remoteRef,\n remote = 'origin',\n } = options;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n // use provided info if possible, otherwise use fallbacks\n const authorInfo = {\n name: gitAuthorInfo?.name ?? 'Scaffolder',\n email: gitAuthorInfo?.email ?? 'scaffolder@backstage.io',\n };\n\n const commitHash = await git.commit({\n dir,\n message: commitMessage,\n author: authorInfo,\n committer: authorInfo,\n });\n\n await git.push({\n dir,\n remote,\n remoteRef: remoteRef ?? `refs/heads/${branch}`,\n });\n\n return { commitHash };\n}\n"],"names":["git","Git"],"mappings":";;;;AAsBA,eAAsB,gBAAgB,KAWF,EAAA;AAClC,EAAM,MAAA;AAAA,IACJ,GAAA;AAAA,IACA,SAAA;AAAA,IACA,IAAA;AAAA,IACA,MAAA;AAAA,IACA,aAAgB,GAAA,QAAA;AAAA,IAChB,aAAgB,GAAA,gBAAA;AAAA,IAChB,aAAA;AAAA,GACE,GAAA,KAAA,CAAA;AACJ,EAAM,MAAAA,KAAA,GAAMC,QAAI,QAAS,CAAA;AAAA,IACvB,GAAG,IAAA;AAAA,IACH,MAAA;AAAA,GACD,CAAA,CAAA;AAED,EAAA,MAAMD,MAAI,IAAK,CAAA;AAAA,IACb,GAAA;AAAA,IACA,aAAA;AAAA,GACD,CAAA,CAAA;AAED,EAAA,MAAMA,MAAI,GAAI,CAAA,EAAE,GAAK,EAAA,QAAA,EAAU,KAAK,CAAA,CAAA;AAGpC,EAAA,MAAM,UAAa,GAAA;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87 @@
1
+ 'use strict';
2
+
3
+ var errors = require('@backstage/errors');
4
+ var backendPluginApi = require('@backstage/backend-plugin-api');
5
+ var path = require('path');
6
+
7
+ const getRepoSourceDirectory = (workspacePath, sourcePath) => {
8
+ if (sourcePath) {
9
+ const safeSuffix = path.normalize(sourcePath).replace(
10
+ /^(\.\.(\/|\\|$))+/,
11
+ ""
12
+ );
13
+ const path$1 = path.join(workspacePath, safeSuffix);
14
+ if (!backendPluginApi.isChildPath(workspacePath, path$1)) {
15
+ throw new Error("Invalid source path");
16
+ }
17
+ return path$1;
18
+ }
19
+ return workspacePath;
20
+ };
21
+ const parseRepoUrl = (repoUrl, integrations) => {
22
+ let parsed;
23
+ try {
24
+ parsed = new URL(`https://${repoUrl}`);
25
+ } catch (error) {
26
+ throw new errors.InputError(
27
+ `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`
28
+ );
29
+ }
30
+ const host = parsed.host;
31
+ const owner = parsed.searchParams.get("owner") ?? void 0;
32
+ const organization = parsed.searchParams.get("organization") ?? void 0;
33
+ const workspace = parsed.searchParams.get("workspace") ?? void 0;
34
+ const project = parsed.searchParams.get("project") ?? void 0;
35
+ const type = integrations.byHost(host)?.type;
36
+ if (!type) {
37
+ throw new errors.InputError(
38
+ `No matching integration configuration for host ${host}, please check your integrations config`
39
+ );
40
+ }
41
+ const repo = parsed.searchParams.get("repo");
42
+ switch (type) {
43
+ case "bitbucket": {
44
+ if (host === "www.bitbucket.org") {
45
+ checkRequiredParams(parsed, "workspace");
46
+ }
47
+ checkRequiredParams(parsed, "project", "repo");
48
+ break;
49
+ }
50
+ case "azure": {
51
+ checkRequiredParams(parsed, "project", "repo");
52
+ break;
53
+ }
54
+ case "gitlab": {
55
+ if (!project) {
56
+ checkRequiredParams(parsed, "owner", "repo");
57
+ }
58
+ break;
59
+ }
60
+ case "gitea": {
61
+ checkRequiredParams(parsed, "repo");
62
+ break;
63
+ }
64
+ case "gerrit": {
65
+ checkRequiredParams(parsed, "repo");
66
+ break;
67
+ }
68
+ default: {
69
+ checkRequiredParams(parsed, "repo", "owner");
70
+ break;
71
+ }
72
+ }
73
+ return { host, owner, repo, organization, workspace, project };
74
+ };
75
+ function checkRequiredParams(repoUrl, ...params) {
76
+ for (let i = 0; i < params.length; i++) {
77
+ if (!repoUrl.searchParams.get(params[i])) {
78
+ throw new errors.InputError(
79
+ `Invalid repo URL passed to publisher: ${repoUrl.toString()}, missing ${params[i]}`
80
+ );
81
+ }
82
+ }
83
+ }
84
+
85
+ exports.getRepoSourceDirectory = getRepoSourceDirectory;
86
+ exports.parseRepoUrl = parseRepoUrl;
87
+ //# sourceMappingURL=util.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.cjs.js","sources":["../../src/actions/util.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 { InputError } from '@backstage/errors';\nimport { isChildPath } from '@backstage/backend-plugin-api';\nimport { join as joinPath, normalize as normalizePath } from 'path';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\n\n/**\n * @public\n */\nexport const getRepoSourceDirectory = (\n workspacePath: string,\n sourcePath: string | undefined,\n) => {\n if (sourcePath) {\n const safeSuffix = normalizePath(sourcePath).replace(\n /^(\\.\\.(\\/|\\\\|$))+/,\n '',\n );\n const path = joinPath(workspacePath, safeSuffix);\n if (!isChildPath(workspacePath, path)) {\n throw new Error('Invalid source path');\n }\n return path;\n }\n return workspacePath;\n};\n\n/**\n * @public\n */\nexport const parseRepoUrl = (\n repoUrl: string,\n integrations: ScmIntegrationRegistry,\n): {\n repo: string;\n host: string;\n owner?: string;\n organization?: string;\n workspace?: string;\n project?: string;\n} => {\n let parsed;\n try {\n parsed = new URL(`https://${repoUrl}`);\n } catch (error) {\n throw new InputError(\n `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`,\n );\n }\n const host = parsed.host;\n const owner = parsed.searchParams.get('owner') ?? undefined;\n const organization = parsed.searchParams.get('organization') ?? undefined;\n const workspace = parsed.searchParams.get('workspace') ?? undefined;\n const project = parsed.searchParams.get('project') ?? undefined;\n\n const type = integrations.byHost(host)?.type;\n\n if (!type) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n const repo: string = parsed.searchParams.get('repo')!;\n switch (type) {\n case 'bitbucket': {\n if (host === 'www.bitbucket.org') {\n checkRequiredParams(parsed, 'workspace');\n }\n checkRequiredParams(parsed, 'project', 'repo');\n break;\n }\n case 'azure': {\n checkRequiredParams(parsed, 'project', 'repo');\n break;\n }\n case 'gitlab': {\n // project is the projectID, and if defined, owner and repo won't be needed.\n if (!project) {\n checkRequiredParams(parsed, 'owner', 'repo');\n }\n break;\n }\n case 'gitea': {\n checkRequiredParams(parsed, 'repo');\n break;\n }\n case 'gerrit': {\n checkRequiredParams(parsed, 'repo');\n break;\n }\n default: {\n checkRequiredParams(parsed, 'repo', 'owner');\n break;\n }\n }\n\n return { host, owner, repo, organization, workspace, project };\n};\n\nfunction checkRequiredParams(repoUrl: URL, ...params: string[]) {\n for (let i = 0; i < params.length; i++) {\n if (!repoUrl.searchParams.get(params[i])) {\n throw new InputError(\n `Invalid repo URL passed to publisher: ${repoUrl.toString()}, missing ${\n params[i]\n }`,\n );\n }\n }\n}\n"],"names":["normalizePath","path","joinPath","isChildPath","InputError"],"mappings":";;;;;;AAwBa,MAAA,sBAAA,GAAyB,CACpC,aAAA,EACA,UACG,KAAA;AACH,EAAA,IAAI,UAAY,EAAA;AACd,IAAM,MAAA,UAAA,GAAaA,cAAc,CAAA,UAAU,CAAE,CAAA,OAAA;AAAA,MA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AoB,YAAiB,MAAkB,EAAA;AAC9D,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,MAAA,CAAO,QAAQ,CAAK,EAAA,EAAA;AACtC,IAAA,IAAI,CAAC,OAAQ,CAAA,YAAA,CAAa,IAAI,MAAO,CAAA,CAAC,CAAC,CAAG,EAAA;AACxC,MAAA,MAAM,IAAIA,iBAAA;AAAA,QACR,yCAAyC,OAAQ,CAAA,QAAA,EAAU,CACzD,UAAA,EAAA,MAAA,CAAO,CAAC,CACV,CAAA,CAAA;AAAA,OACF,CAAA;AAAA,KACF;AAAA,GACF;AACF;;;;;"}
package/dist/alpha.cjs.js CHANGED
@@ -1,38 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var backendPluginApi = require('@backstage/backend-plugin-api');
4
- var tar = require('tar');
5
- var concatStream = require('concat-stream');
6
- var util = require('util');
7
- var stream = require('stream');
8
-
9
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
10
-
11
- var tar__default = /*#__PURE__*/_interopDefaultCompat(tar);
12
- var concatStream__default = /*#__PURE__*/_interopDefaultCompat(concatStream);
13
-
14
- const pipeline = util.promisify(stream.pipeline);
15
- const serializeWorkspace = async (opts) => {
16
- return new Promise(async (resolve) => {
17
- await pipeline(
18
- tar__default.default.create({ cwd: opts.path }, [""]),
19
- concatStream__default.default((buffer) => {
20
- return resolve({ contents: buffer });
21
- })
22
- );
23
- });
24
- };
25
- const restoreWorkspace = async (opts) => {
26
- const { buffer, path } = opts;
27
- if (buffer) {
28
- await pipeline(
29
- stream.Readable.from(buffer),
30
- tar__default.default.extract({
31
- C: path
32
- })
33
- );
34
- }
35
- };
4
+ var serializer = require('./tasks/serializer.cjs.js');
36
5
 
37
6
  const scaffolderActionsExtensionPoint = backendPluginApi.createExtensionPoint({
38
7
  id: "scaffolder.actions"
@@ -50,11 +19,11 @@ const scaffolderWorkspaceProviderExtensionPoint = backendPluginApi.createExtensi
50
19
  id: "scaffolder.workspace.provider"
51
20
  });
52
21
 
53
- exports.restoreWorkspace = restoreWorkspace;
22
+ exports.restoreWorkspace = serializer.restoreWorkspace;
23
+ exports.serializeWorkspace = serializer.serializeWorkspace;
54
24
  exports.scaffolderActionsExtensionPoint = scaffolderActionsExtensionPoint;
55
25
  exports.scaffolderAutocompleteExtensionPoint = scaffolderAutocompleteExtensionPoint;
56
26
  exports.scaffolderTaskBrokerExtensionPoint = scaffolderTaskBrokerExtensionPoint;
57
27
  exports.scaffolderTemplatingExtensionPoint = scaffolderTemplatingExtensionPoint;
58
28
  exports.scaffolderWorkspaceProviderExtensionPoint = scaffolderWorkspaceProviderExtensionPoint;
59
- exports.serializeWorkspace = serializeWorkspace;
60
29
  //# sourceMappingURL=alpha.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"alpha.cjs.js","sources":["../src/tasks/serializer.ts","../src/alpha.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 tar from 'tar';\nimport concatStream from 'concat-stream';\nimport { promisify } from 'util';\nimport { pipeline as pipelineCb, Readable } from 'stream';\n\nconst pipeline = promisify(pipelineCb);\n/**\n * Serializes provided path into tar archive\n *\n * @alpha\n */\nexport const serializeWorkspace = async (opts: {\n path: string;\n}): Promise<{ contents: Buffer }> => {\n return new Promise<{ contents: Buffer }>(async resolve => {\n await pipeline(\n tar.create({ cwd: opts.path }, ['']),\n concatStream(buffer => {\n return resolve({ contents: buffer });\n }),\n );\n });\n};\n\n/**\n * Rehydrates the provided buffer of tar archive into the provide destination path\n *\n * @alpha\n */\nexport const restoreWorkspace = async (opts: {\n path: string;\n buffer?: Buffer;\n}): Promise<void> => {\n const { buffer, path } = opts;\n if (buffer) {\n await pipeline(\n Readable.from(buffer),\n tar.extract({\n C: path,\n }),\n );\n }\n};\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createExtensionPoint } from '@backstage/backend-plugin-api';\nimport {\n TemplateAction,\n TemplateFilter,\n TemplateGlobal,\n TaskBroker,\n} from '@backstage/plugin-scaffolder-node';\n\nexport * from './tasks/alpha';\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\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\n/**\n * Autocomplete handler for the scaffolder.\n * @alpha\n */\nexport type AutocompleteHandler = ({\n resource,\n token,\n context,\n}: {\n resource: string;\n token: string;\n context: Record<string, string>;\n}) => Promise<{ results: { title: string }[] }>;\n\n/**\n * Extension point for adding autocomplete handler providers\n * @alpha\n */\nexport interface ScaffolderAutocompleteExtensionPoint {\n addAutocompleteProvider({\n id,\n handler,\n }: {\n id: string;\n handler: AutocompleteHandler;\n }): void;\n}\n\n/**\n * Extension point for adding autocomplete handlers.\n *\n * @alpha\n */\nexport const scaffolderAutocompleteExtensionPoint =\n createExtensionPoint<ScaffolderAutocompleteExtensionPoint>({\n id: 'scaffolder.autocomplete',\n });\n\n/**\n * This provider has to be implemented to make it possible to serialize/deserialize scaffolder workspace.\n *\n * @alpha\n */\nexport interface WorkspaceProvider {\n serializeWorkspace({\n path,\n taskId,\n }: {\n path: string;\n taskId: string;\n }): Promise<void>;\n\n cleanWorkspace(options: { taskId: string }): Promise<void>;\n\n rehydrateWorkspace(options: {\n taskId: string;\n targetPath: string;\n }): Promise<void>;\n}\n\n/**\n * Extension point for adding workspace providers.\n *\n * @alpha\n */\nexport interface ScaffolderWorkspaceProviderExtensionPoint {\n addProviders(providers: Record<string, WorkspaceProvider>): void;\n}\n\n/**\n * Extension point for adding workspace providers.\n *\n * @alpha\n */\nexport const scaffolderWorkspaceProviderExtensionPoint =\n createExtensionPoint<ScaffolderWorkspaceProviderExtensionPoint>({\n id: 'scaffolder.workspace.provider',\n });\n"],"names":["promisify","pipelineCb","tar","concatStream","Readable","createExtensionPoint"],"mappings":";;;;;;;;;;;;;AAqBA,MAAM,QAAA,GAAWA,eAAUC,eAAU,CAAA,CAAA;AAMxB,MAAA,kBAAA,GAAqB,OAAO,IAEJ,KAAA;AACnC,EAAO,OAAA,IAAI,OAA8B,CAAA,OAAM,OAAW,KAAA;AACxD,IAAM,MAAA,QAAA;AAAA,MACJC,oBAAA,CAAI,OAAO,EAAE,GAAA,EAAK,KAAK,IAAK,EAAA,EAAG,CAAC,EAAE,CAAC,CAAA;AAAA,MACnCC,8BAAa,CAAU,MAAA,KAAA;AACrB,QAAA,OAAO,OAAQ,CAAA,EAAE,QAAU,EAAA,MAAA,EAAQ,CAAA,CAAA;AAAA,OACpC,CAAA;AAAA,KACH,CAAA;AAAA,GACD,CAAA,CAAA;AACH,EAAA;AAOa,MAAA,gBAAA,GAAmB,OAAO,IAGlB,KAAA;AACnB,EAAM,MAAA,EAAE,MAAQ,EAAA,IAAA,EAAS,GAAA,IAAA,CAAA;AACzB,EAAA,IAAI,MAAQ,EAAA;AACV,IAAM,MAAA,QAAA;AAAA,MACJC,eAAA,CAAS,KAAK,MAAM,CAAA;AAAA,MACpBF,qBAAI,OAAQ,CAAA;AAAA,QACV,CAAG,EAAA,IAAA;AAAA,OACJ,CAAA;AAAA,KACH,CAAA;AAAA,GACF;AACF;;AClBO,MAAM,kCACXG,qCAAsD,CAAA;AAAA,EACpD,EAAI,EAAA,oBAAA;AACN,CAAC,EAAA;AAgBI,MAAM,qCACXA,qCAAyD,CAAA;AAAA,EACvD,EAAI,EAAA,uBAAA;AACN,CAAC,EAAA;AAkBI,MAAM,qCACXA,qCAAyD,CAAA;AAAA,EACvD,EAAI,EAAA,uBAAA;AACN,CAAC,EAAA;AAmCI,MAAM,uCACXA,qCAA2D,CAAA;AAAA,EACzD,EAAI,EAAA,yBAAA;AACN,CAAC,EAAA;AAsCI,MAAM,4CACXA,qCAAgE,CAAA;AAAA,EAC9D,EAAI,EAAA,+BAAA;AACN,CAAC;;;;;;;;;;"}
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\nexport * from './tasks/alpha';\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\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\n/**\n * Autocomplete handler for the scaffolder.\n * @alpha\n */\nexport type AutocompleteHandler = ({\n resource,\n token,\n context,\n}: {\n resource: string;\n token: string;\n context: Record<string, string>;\n}) => Promise<{ results: { title: string }[] }>;\n\n/**\n * Extension point for adding autocomplete handler providers\n * @alpha\n */\nexport interface ScaffolderAutocompleteExtensionPoint {\n addAutocompleteProvider({\n id,\n handler,\n }: {\n id: string;\n handler: AutocompleteHandler;\n }): void;\n}\n\n/**\n * Extension point for adding autocomplete handlers.\n *\n * @alpha\n */\nexport const scaffolderAutocompleteExtensionPoint =\n createExtensionPoint<ScaffolderAutocompleteExtensionPoint>({\n id: 'scaffolder.autocomplete',\n });\n\n/**\n * This provider has to be implemented to make it possible to serialize/deserialize scaffolder workspace.\n *\n * @alpha\n */\nexport interface WorkspaceProvider {\n serializeWorkspace({\n path,\n taskId,\n }: {\n path: string;\n taskId: string;\n }): Promise<void>;\n\n cleanWorkspace(options: { taskId: string }): Promise<void>;\n\n rehydrateWorkspace(options: {\n taskId: string;\n targetPath: string;\n }): Promise<void>;\n}\n\n/**\n * Extension point for adding workspace providers.\n *\n * @alpha\n */\nexport interface ScaffolderWorkspaceProviderExtensionPoint {\n addProviders(providers: Record<string, WorkspaceProvider>): void;\n}\n\n/**\n * Extension point for adding workspace providers.\n *\n * @alpha\n */\nexport const scaffolderWorkspaceProviderExtensionPoint =\n createExtensionPoint<ScaffolderWorkspaceProviderExtensionPoint>({\n id: 'scaffolder.workspace.provider',\n });\n"],"names":["createExtensionPoint"],"mappings":";;;;;AAwCO,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;AAkBI,MAAM,qCACXA,qCAAyD,CAAA;AAAA,EACvD,EAAI,EAAA,uBAAA;AACN,CAAC,EAAA;AAmCI,MAAM,uCACXA,qCAA2D,CAAA;AAAA,EACzD,EAAI,EAAA,yBAAA;AACN,CAAC,EAAA;AAsCI,MAAM,4CACXA,qCAAgE,CAAA;AAAA,EAC9D,EAAI,EAAA,+BAAA;AACN,CAAC;;;;;;;;;;"}
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ var fs = require('fs-extra');
4
+ var path = require('path');
5
+ var backendPluginApi = require('@backstage/backend-plugin-api');
6
+
7
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
8
+
9
+ var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
10
+
11
+ async function deserializeDirectoryContents(targetPath, files) {
12
+ for (const file of files) {
13
+ const filePath = backendPluginApi.resolveSafeChildPath(targetPath, file.path);
14
+ await fs__default.default.ensureDir(path.dirname(filePath));
15
+ await fs__default.default.writeFile(filePath, file.content);
16
+ }
17
+ }
18
+
19
+ exports.deserializeDirectoryContents = deserializeDirectoryContents;
20
+ //# sourceMappingURL=deserializeDirectoryContents.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deserializeDirectoryContents.cjs.js","sources":["../../src/files/deserializeDirectoryContents.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 fs from 'fs-extra';\nimport { dirname } from 'path';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { SerializedFile } from './types';\n\n/**\n * Deserializes a list of serialized files into the target directory.\n *\n * This method uses `resolveSafeChildPath` to make sure that files are\n * not written outside of the target directory.\n *\n * @public\n */\nexport async function deserializeDirectoryContents(\n targetPath: string,\n files: SerializedFile[],\n): Promise<void> {\n for (const file of files) {\n const filePath = resolveSafeChildPath(targetPath, file.path);\n await fs.ensureDir(dirname(filePath));\n await fs.writeFile(filePath, file.content); // Ignore file mode\n }\n}\n"],"names":["resolveSafeChildPath","fs","dirname"],"mappings":";;;;;;;;;;AA6BsB,eAAA,4BAAA,CACpB,YACA,KACe,EAAA;AACf,EAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AACxB,IAAA,MAAM,QAAW,GAAAA,qCAAA,CAAqB,UAAY,EAAA,IAAA,CAAK,IAAI,CAAA,CAAA;AAC3D,IAAA,MAAMC,mBAAG,CAAA,SAAA,CAAUC,YAAQ,CAAA,QAAQ,CAAC,CAAA,CAAA;AACpC,IAAA,MAAMD,mBAAG,CAAA,SAAA,CAAU,QAAU,EAAA,IAAA,CAAK,OAAO,CAAA,CAAA;AAAA,GAC3C;AACF;;;;"}