@backstage/plugin-scaffolder-node 0.2.9-next.2 → 0.2.9-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/alpha/package.json +1 -1
- package/dist/index.cjs.js +223 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +91 -2
- package/package.json +7 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @backstage/plugin-scaffolder-node
|
|
2
2
|
|
|
3
|
+
## 0.2.9-next.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 219d7f0: Refactor some methods to `-node` instead and use the new external modules
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/backend-common@0.20.0-next.3
|
|
10
|
+
- @backstage/backend-plugin-api@0.6.8-next.3
|
|
11
|
+
- @backstage/catalog-model@1.4.3
|
|
12
|
+
- @backstage/errors@1.2.3
|
|
13
|
+
- @backstage/integration@1.8.0-next.1
|
|
14
|
+
- @backstage/types@1.1.1
|
|
15
|
+
- @backstage/plugin-scaffolder-common@1.4.3
|
|
16
|
+
|
|
3
17
|
## 0.2.9-next.2
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/alpha/package.json
CHANGED
package/dist/index.cjs.js
CHANGED
|
@@ -9,12 +9,17 @@ 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 fs$1 = require('fs');
|
|
13
|
+
var globby = require('globby');
|
|
14
|
+
var limiterFactory = require('p-limit');
|
|
12
15
|
|
|
13
16
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
17
|
|
|
15
18
|
var zodToJsonSchema__default = /*#__PURE__*/_interopDefaultLegacy(zodToJsonSchema);
|
|
16
19
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
17
20
|
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
21
|
+
var globby__default = /*#__PURE__*/_interopDefaultLegacy(globby);
|
|
22
|
+
var limiterFactory__default = /*#__PURE__*/_interopDefaultLegacy(limiterFactory);
|
|
18
23
|
|
|
19
24
|
const createTemplateAction = (action) => {
|
|
20
25
|
var _a, _b, _c, _d;
|
|
@@ -115,8 +120,226 @@ function getReadUrl(fetchUrl, baseUrl, integrations) {
|
|
|
115
120
|
);
|
|
116
121
|
}
|
|
117
122
|
|
|
123
|
+
async function initRepoAndPush(input) {
|
|
124
|
+
var _a, _b;
|
|
125
|
+
const {
|
|
126
|
+
dir,
|
|
127
|
+
remoteUrl,
|
|
128
|
+
auth,
|
|
129
|
+
logger,
|
|
130
|
+
defaultBranch = "master",
|
|
131
|
+
commitMessage = "Initial commit",
|
|
132
|
+
gitAuthorInfo
|
|
133
|
+
} = input;
|
|
134
|
+
const git = backendCommon.Git.fromAuth({
|
|
135
|
+
...auth,
|
|
136
|
+
logger
|
|
137
|
+
});
|
|
138
|
+
await git.init({
|
|
139
|
+
dir,
|
|
140
|
+
defaultBranch
|
|
141
|
+
});
|
|
142
|
+
await git.add({ dir, filepath: "." });
|
|
143
|
+
const authorInfo = {
|
|
144
|
+
name: (_a = gitAuthorInfo == null ? void 0 : gitAuthorInfo.name) != null ? _a : "Scaffolder",
|
|
145
|
+
email: (_b = gitAuthorInfo == null ? void 0 : gitAuthorInfo.email) != null ? _b : "scaffolder@backstage.io"
|
|
146
|
+
};
|
|
147
|
+
const commitHash = await git.commit({
|
|
148
|
+
dir,
|
|
149
|
+
message: commitMessage,
|
|
150
|
+
author: authorInfo,
|
|
151
|
+
committer: authorInfo
|
|
152
|
+
});
|
|
153
|
+
await git.addRemote({
|
|
154
|
+
dir,
|
|
155
|
+
url: remoteUrl,
|
|
156
|
+
remote: "origin"
|
|
157
|
+
});
|
|
158
|
+
await git.push({
|
|
159
|
+
dir,
|
|
160
|
+
remote: "origin"
|
|
161
|
+
});
|
|
162
|
+
return { commitHash };
|
|
163
|
+
}
|
|
164
|
+
async function commitAndPushRepo(input) {
|
|
165
|
+
var _a, _b;
|
|
166
|
+
const {
|
|
167
|
+
dir,
|
|
168
|
+
auth,
|
|
169
|
+
logger,
|
|
170
|
+
commitMessage,
|
|
171
|
+
gitAuthorInfo,
|
|
172
|
+
branch = "master",
|
|
173
|
+
remoteRef
|
|
174
|
+
} = input;
|
|
175
|
+
const git = backendCommon.Git.fromAuth({
|
|
176
|
+
...auth,
|
|
177
|
+
logger
|
|
178
|
+
});
|
|
179
|
+
await git.fetch({ dir });
|
|
180
|
+
await git.checkout({ dir, ref: branch });
|
|
181
|
+
await git.add({ dir, filepath: "." });
|
|
182
|
+
const authorInfo = {
|
|
183
|
+
name: (_a = gitAuthorInfo == null ? void 0 : gitAuthorInfo.name) != null ? _a : "Scaffolder",
|
|
184
|
+
email: (_b = gitAuthorInfo == null ? void 0 : gitAuthorInfo.email) != null ? _b : "scaffolder@backstage.io"
|
|
185
|
+
};
|
|
186
|
+
const commitHash = await git.commit({
|
|
187
|
+
dir,
|
|
188
|
+
message: commitMessage,
|
|
189
|
+
author: authorInfo,
|
|
190
|
+
committer: authorInfo
|
|
191
|
+
});
|
|
192
|
+
await git.push({
|
|
193
|
+
dir,
|
|
194
|
+
remote: "origin",
|
|
195
|
+
remoteRef: remoteRef != null ? remoteRef : `refs/heads/${branch}`
|
|
196
|
+
});
|
|
197
|
+
return { commitHash };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const getRepoSourceDirectory = (workspacePath, sourcePath) => {
|
|
201
|
+
if (sourcePath) {
|
|
202
|
+
const safeSuffix = path.normalize(sourcePath).replace(
|
|
203
|
+
/^(\.\.(\/|\\|$))+/,
|
|
204
|
+
""
|
|
205
|
+
);
|
|
206
|
+
const path$1 = path.join(workspacePath, safeSuffix);
|
|
207
|
+
if (!backendCommon.isChildPath(workspacePath, path$1)) {
|
|
208
|
+
throw new Error("Invalid source path");
|
|
209
|
+
}
|
|
210
|
+
return path$1;
|
|
211
|
+
}
|
|
212
|
+
return workspacePath;
|
|
213
|
+
};
|
|
214
|
+
const parseRepoUrl = (repoUrl, integrations) => {
|
|
215
|
+
var _a, _b, _c, _d, _e;
|
|
216
|
+
let parsed;
|
|
217
|
+
try {
|
|
218
|
+
parsed = new URL(`https://${repoUrl}`);
|
|
219
|
+
} catch (error) {
|
|
220
|
+
throw new errors.InputError(
|
|
221
|
+
`Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
const host = parsed.host;
|
|
225
|
+
const owner = (_a = parsed.searchParams.get("owner")) != null ? _a : void 0;
|
|
226
|
+
const organization = (_b = parsed.searchParams.get("organization")) != null ? _b : void 0;
|
|
227
|
+
const workspace = (_c = parsed.searchParams.get("workspace")) != null ? _c : void 0;
|
|
228
|
+
const project = (_d = parsed.searchParams.get("project")) != null ? _d : void 0;
|
|
229
|
+
const type = (_e = integrations.byHost(host)) == null ? void 0 : _e.type;
|
|
230
|
+
if (!type) {
|
|
231
|
+
throw new errors.InputError(
|
|
232
|
+
`No matching integration configuration for host ${host}, please check your integrations config`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
const repo = parsed.searchParams.get("repo");
|
|
236
|
+
switch (type) {
|
|
237
|
+
case "bitbucket": {
|
|
238
|
+
if (host === "www.bitbucket.org") {
|
|
239
|
+
checkRequiredParams(parsed, "workspace");
|
|
240
|
+
}
|
|
241
|
+
checkRequiredParams(parsed, "project", "repo");
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
case "gitlab": {
|
|
245
|
+
if (!project) {
|
|
246
|
+
checkRequiredParams(parsed, "owner", "repo");
|
|
247
|
+
}
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
case "gerrit": {
|
|
251
|
+
checkRequiredParams(parsed, "repo");
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
default: {
|
|
255
|
+
checkRequiredParams(parsed, "repo", "owner");
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return { host, owner, repo, organization, workspace, project };
|
|
260
|
+
};
|
|
261
|
+
function checkRequiredParams(repoUrl, ...params) {
|
|
262
|
+
for (let i = 0; i < params.length; i++) {
|
|
263
|
+
if (!repoUrl.searchParams.get(params[i])) {
|
|
264
|
+
throw new errors.InputError(
|
|
265
|
+
`Invalid repo URL passed to publisher: ${repoUrl.toString()}, missing ${params[i]}`
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const DEFAULT_GLOB_PATTERNS = ["./**", "!.git"];
|
|
272
|
+
const isExecutable = (fileMode) => {
|
|
273
|
+
if (!fileMode) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
const executeBitMask = 73;
|
|
277
|
+
const res = fileMode & executeBitMask;
|
|
278
|
+
return res > 0;
|
|
279
|
+
};
|
|
280
|
+
async function asyncFilter(array, callback) {
|
|
281
|
+
const filterMap = await Promise.all(array.map(callback));
|
|
282
|
+
return array.filter((_value, index) => filterMap[index]);
|
|
283
|
+
}
|
|
284
|
+
async function serializeDirectoryContents(sourcePath, options) {
|
|
285
|
+
var _a;
|
|
286
|
+
const paths = await globby__default["default"]((_a = options == null ? void 0 : options.globPatterns) != null ? _a : DEFAULT_GLOB_PATTERNS, {
|
|
287
|
+
cwd: sourcePath,
|
|
288
|
+
dot: true,
|
|
289
|
+
gitignore: options == null ? void 0 : options.gitignore,
|
|
290
|
+
followSymbolicLinks: false,
|
|
291
|
+
// In order to pick up 'broken' symlinks, we oxymoronically request files AND folders yet we filter out folders
|
|
292
|
+
// This is because broken symlinks aren't classed as files so we need to glob everything
|
|
293
|
+
onlyFiles: false,
|
|
294
|
+
objectMode: true,
|
|
295
|
+
stats: true
|
|
296
|
+
});
|
|
297
|
+
const limiter = limiterFactory__default["default"](10);
|
|
298
|
+
const valid = await asyncFilter(paths, async ({ dirent, path }) => {
|
|
299
|
+
if (dirent.isDirectory())
|
|
300
|
+
return false;
|
|
301
|
+
if (!dirent.isSymbolicLink())
|
|
302
|
+
return true;
|
|
303
|
+
const safePath = backendCommon.resolveSafeChildPath(sourcePath, path);
|
|
304
|
+
try {
|
|
305
|
+
await fs$1.promises.stat(safePath);
|
|
306
|
+
return false;
|
|
307
|
+
} catch (e) {
|
|
308
|
+
return errors.isError(e) && e.code === "ENOENT";
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
return Promise.all(
|
|
312
|
+
valid.map(async ({ dirent, path, stats }) => ({
|
|
313
|
+
path,
|
|
314
|
+
content: await limiter(async () => {
|
|
315
|
+
const absFilePath = backendCommon.resolveSafeChildPath(sourcePath, path);
|
|
316
|
+
if (dirent.isSymbolicLink()) {
|
|
317
|
+
return fs$1.promises.readlink(absFilePath, "buffer");
|
|
318
|
+
}
|
|
319
|
+
return fs$1.promises.readFile(absFilePath);
|
|
320
|
+
}),
|
|
321
|
+
executable: isExecutable(stats == null ? void 0 : stats.mode),
|
|
322
|
+
symlink: dirent.isSymbolicLink()
|
|
323
|
+
}))
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
async function deserializeDirectoryContents(targetPath, files) {
|
|
328
|
+
for (const file of files) {
|
|
329
|
+
const filePath = backendCommon.resolveSafeChildPath(targetPath, file.path);
|
|
330
|
+
await fs__default["default"].ensureDir(path.dirname(filePath));
|
|
331
|
+
await fs__default["default"].writeFile(filePath, file.content);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
exports.commitAndPushRepo = commitAndPushRepo;
|
|
118
336
|
exports.createTemplateAction = createTemplateAction;
|
|
337
|
+
exports.deserializeDirectoryContents = deserializeDirectoryContents;
|
|
119
338
|
exports.executeShellCommand = executeShellCommand;
|
|
120
339
|
exports.fetchContents = fetchContents;
|
|
121
340
|
exports.fetchFile = fetchFile;
|
|
341
|
+
exports.getRepoSourceDirectory = getRepoSourceDirectory;
|
|
342
|
+
exports.initRepoAndPush = initRepoAndPush;
|
|
343
|
+
exports.parseRepoUrl = parseRepoUrl;
|
|
344
|
+
exports.serializeDirectoryContents = serializeDirectoryContents;
|
|
122
345
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/actions/createTemplateAction.ts","../src/actions/executeShellCommand.ts","../src/actions/fetch.ts"],"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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AAK,CAAA,OAAA,CAAQ,UAAU,CAAC,CAAA,CAAA;AAC3C,IAAM,MAAA,MAAA,GAAS,MAAM,GAAA,CAAI,MAAO,EAAA,CAAA;AAChC,IAAA,MAAMC,sBAAG,CAAA,UAAA,CAAW,UAAY,EAAA,MAAA,CAAO,UAAU,CAAA,CAAA;AAAA,GACnD;AACF,CAAA;AAEA,SAAS,mBAAmB,QAAkB,EAAA;AAC5C,EAAA,IAAI,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;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/actions/createTemplateAction.ts","../src/actions/executeShellCommand.ts","../src/actions/fetch.ts","../src/actions/gitHelpers.ts","../src/actions/util.ts","../src/files/serializeDirectoryContents.ts","../src/files/deserializeDirectoryContents.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ActionContext, TemplateAction } from './types';\nimport { z } from 'zod';\nimport { Schema } from 'jsonschema';\nimport zodToJsonSchema from 'zod-to-json-schema';\nimport { JsonObject } from '@backstage/types';\n\n/** @public */\nexport type TemplateExample = {\n description: string;\n example: string;\n};\n\n/** @public */\nexport type TemplateActionOptions<\n TActionInput extends JsonObject = {},\n TActionOutput extends JsonObject = {},\n TInputSchema extends Schema | z.ZodType = {},\n TOutputSchema extends Schema | z.ZodType = {},\n> = {\n id: string;\n description?: string;\n examples?: TemplateExample[];\n supportsDryRun?: boolean;\n schema?: {\n input?: TInputSchema;\n output?: TOutputSchema;\n };\n handler: (ctx: ActionContext<TActionInput, TActionOutput>) => Promise<void>;\n};\n\n/**\n * This function is used to create new template actions to get type safety.\n * Will convert zod schemas to json schemas for use throughout the system.\n * @public\n */\nexport const createTemplateAction = <\n TInputParams extends JsonObject = JsonObject,\n TOutputParams extends JsonObject = JsonObject,\n TInputSchema extends Schema | z.ZodType = {},\n TOutputSchema extends Schema | z.ZodType = {},\n TActionInput extends JsonObject = TInputSchema extends z.ZodType<\n any,\n any,\n infer IReturn\n >\n ? IReturn\n : TInputParams,\n TActionOutput extends JsonObject = TOutputSchema extends z.ZodType<\n any,\n any,\n infer IReturn\n >\n ? IReturn\n : TOutputParams,\n>(\n action: TemplateActionOptions<\n TActionInput,\n TActionOutput,\n TInputSchema,\n TOutputSchema\n >,\n): TemplateAction<TActionInput, TActionOutput> => {\n const inputSchema =\n action.schema?.input && 'safeParseAsync' in action.schema.input\n ? zodToJsonSchema(action.schema.input)\n : action.schema?.input;\n\n const outputSchema =\n action.schema?.output && 'safeParseAsync' in action.schema.output\n ? zodToJsonSchema(action.schema.output)\n : action.schema?.output;\n\n return {\n ...action,\n schema: {\n ...action.schema,\n input: inputSchema as TInputSchema,\n output: outputSchema as TOutputSchema,\n },\n };\n};\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { spawn, SpawnOptionsWithoutStdio } from 'child_process';\nimport { PassThrough, Writable } from 'stream';\n\n/**\n * Options for {@link executeShellCommand}.\n *\n * @public\n */\nexport type ExecuteShellCommandOptions = {\n /** command to run */\n command: string;\n /** arguments to pass the command */\n args: string[];\n /** options to pass to spawn */\n options?: SpawnOptionsWithoutStdio;\n /** stream to capture stdout and stderr output */\n logStream?: Writable;\n};\n\n/**\n * Run a command in a sub-process, normally a shell command.\n *\n * @public\n */\nexport async function executeShellCommand(\n options: ExecuteShellCommandOptions,\n): Promise<void> {\n const {\n command,\n args,\n options: spawnOptions,\n logStream = new PassThrough(),\n } = options;\n\n await new Promise<void>((resolve, reject) => {\n const process = spawn(command, args, spawnOptions);\n\n process.stdout.on('data', stream => {\n logStream.write(stream);\n });\n\n process.stderr.on('data', stream => {\n logStream.write(stream);\n });\n\n process.on('error', error => {\n return reject(error);\n });\n\n process.on('close', code => {\n if (code !== 0) {\n return reject(\n new Error(`Command ${command} failed, exit code: ${code}`),\n );\n }\n return resolve();\n });\n });\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { resolveSafeChildPath, UrlReader } from '@backstage/backend-common';\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrations } from '@backstage/integration';\nimport fs from 'fs-extra';\nimport path from 'path';\n\n/**\n * A helper function that reads the contents of a directory from the given URL.\n * Can be used in your own actions, and also used behind fetch:template and fetch:plain\n *\n * @public\n */\nexport async function fetchContents(options: {\n reader: UrlReader;\n integrations: ScmIntegrations;\n baseUrl?: string;\n fetchUrl?: string;\n outputPath: string;\n}) {\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 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Git } from '@backstage/backend-common';\nimport { Logger } from 'winston';\n\n/**\n * @public\n */\nexport async function initRepoAndPush(input: {\n dir: string;\n remoteUrl: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger: Logger;\n defaultBranch?: string;\n commitMessage?: string;\n gitAuthorInfo?: { name?: string; email?: string };\n}): Promise<{ commitHash: string }> {\n const {\n dir,\n remoteUrl,\n auth,\n logger,\n defaultBranch = 'master',\n commitMessage = 'Initial commit',\n gitAuthorInfo,\n } = input;\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.init({\n dir,\n defaultBranch,\n });\n\n await git.add({ dir, filepath: '.' });\n\n // use provided info if possible, otherwise use fallbacks\n const authorInfo = {\n name: gitAuthorInfo?.name ?? 'Scaffolder',\n email: gitAuthorInfo?.email ?? 'scaffolder@backstage.io',\n };\n\n const commitHash = await git.commit({\n dir,\n message: commitMessage,\n author: authorInfo,\n committer: authorInfo,\n });\n await git.addRemote({\n dir,\n url: remoteUrl,\n remote: 'origin',\n });\n\n await git.push({\n dir,\n remote: 'origin',\n });\n\n return { commitHash };\n}\n\n/**\n * @public\n */\nexport async function commitAndPushRepo(input: {\n dir: string;\n // For use cases where token has to be used with Basic Auth\n // it has to be provided as password together with a username\n // which may be a fixed value defined by the provider.\n auth: { username: string; password: string } | { token: string };\n logger: Logger;\n commitMessage: string;\n gitAuthorInfo?: { name?: string; email?: string };\n branch?: string;\n remoteRef?: string;\n}): Promise<{ commitHash: string }> {\n const {\n dir,\n auth,\n logger,\n commitMessage,\n gitAuthorInfo,\n branch = 'master',\n remoteRef,\n } = input;\n\n const git = Git.fromAuth({\n ...auth,\n logger,\n });\n\n await git.fetch({ dir });\n await git.checkout({ dir, ref: branch });\n await git.add({ dir, filepath: '.' });\n\n // use provided info if possible, otherwise use fallbacks\n const authorInfo = {\n name: gitAuthorInfo?.name ?? 'Scaffolder',\n email: gitAuthorInfo?.email ?? 'scaffolder@backstage.io',\n };\n\n const commitHash = await git.commit({\n dir,\n message: commitMessage,\n author: authorInfo,\n committer: authorInfo,\n });\n\n await git.push({\n dir,\n remote: 'origin',\n remoteRef: remoteRef ?? `refs/heads/${branch}`,\n });\n\n return { commitHash };\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { isChildPath } from '@backstage/backend-common';\nimport { join as joinPath, normalize as normalizePath } from 'path';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\n\n/**\n * @public\n */\nexport const getRepoSourceDirectory = (\n workspacePath: string,\n sourcePath: string | undefined,\n) => {\n if (sourcePath) {\n const safeSuffix = normalizePath(sourcePath).replace(\n /^(\\.\\.(\\/|\\\\|$))+/,\n '',\n );\n const path = joinPath(workspacePath, safeSuffix);\n if (!isChildPath(workspacePath, path)) {\n throw new Error('Invalid source path');\n }\n return path;\n }\n return workspacePath;\n};\n\n/**\n * @public\n */\nexport const parseRepoUrl = (\n repoUrl: string,\n integrations: ScmIntegrationRegistry,\n): {\n repo: string;\n host: string;\n owner?: string;\n organization?: string;\n workspace?: string;\n project?: string;\n} => {\n let parsed;\n try {\n parsed = new URL(`https://${repoUrl}`);\n } catch (error) {\n throw new InputError(\n `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`,\n );\n }\n const host = parsed.host;\n const owner = parsed.searchParams.get('owner') ?? undefined;\n const organization = parsed.searchParams.get('organization') ?? undefined;\n const workspace = parsed.searchParams.get('workspace') ?? undefined;\n const project = parsed.searchParams.get('project') ?? undefined;\n\n const type = integrations.byHost(host)?.type;\n\n if (!type) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n const repo: string = parsed.searchParams.get('repo')!;\n switch (type) {\n case 'bitbucket': {\n if (host === 'www.bitbucket.org') {\n checkRequiredParams(parsed, 'workspace');\n }\n checkRequiredParams(parsed, 'project', 'repo');\n break;\n }\n case 'gitlab': {\n // project is the projectID, and if defined, owner and repo won't be needed.\n if (!project) {\n checkRequiredParams(parsed, 'owner', 'repo');\n }\n break;\n }\n case 'gerrit': {\n checkRequiredParams(parsed, 'repo');\n break;\n }\n default: {\n checkRequiredParams(parsed, 'repo', 'owner');\n break;\n }\n }\n\n return { host, owner, repo, organization, workspace, project };\n};\n\nfunction checkRequiredParams(repoUrl: URL, ...params: string[]) {\n for (let i = 0; i < params.length; i++) {\n if (!repoUrl.searchParams.get(params[i])) {\n throw new InputError(\n `Invalid repo URL passed to publisher: ${repoUrl.toString()}, missing ${\n params[i]\n }`,\n );\n }\n }\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { promises as fs } from 'fs';\nimport globby from 'globby';\nimport limiterFactory from 'p-limit';\nimport { resolveSafeChildPath } from '@backstage/backend-common';\nimport { SerializedFile } from './types';\nimport { isError } from '@backstage/errors';\n\nconst DEFAULT_GLOB_PATTERNS = ['./**', '!.git'];\n\nexport const isExecutable = (fileMode: number | undefined) => {\n if (!fileMode) {\n return false;\n }\n\n const executeBitMask = 0o000111;\n const res = fileMode & executeBitMask;\n return res > 0;\n};\n\nasync function asyncFilter<T>(\n array: T[],\n callback: (value: T, index: number, array: T[]) => Promise<boolean>,\n): Promise<T[]> {\n const filterMap = await Promise.all(array.map(callback));\n return array.filter((_value, index) => filterMap[index]);\n}\n\n/**\n * @public\n */\nexport async function serializeDirectoryContents(\n sourcePath: string,\n options?: {\n gitignore?: boolean;\n globPatterns?: string[];\n },\n): Promise<SerializedFile[]> {\n const paths = await globby(options?.globPatterns ?? DEFAULT_GLOB_PATTERNS, {\n cwd: sourcePath,\n dot: true,\n gitignore: options?.gitignore,\n followSymbolicLinks: false,\n // In order to pick up 'broken' symlinks, we oxymoronically request files AND folders yet we filter out folders\n // This is because broken symlinks aren't classed as files so we need to glob everything\n onlyFiles: false,\n objectMode: true,\n stats: true,\n });\n\n const limiter = limiterFactory(10);\n\n const valid = await asyncFilter(paths, async ({ dirent, path }) => {\n if (dirent.isDirectory()) return false;\n if (!dirent.isSymbolicLink()) return true;\n\n const safePath = resolveSafeChildPath(sourcePath, path);\n\n // we only want files that don't exist\n try {\n await fs.stat(safePath);\n return false;\n } catch (e) {\n return isError(e) && e.code === 'ENOENT';\n }\n });\n\n return Promise.all(\n valid.map(async ({ dirent, path, stats }) => ({\n path,\n content: await limiter(async () => {\n const absFilePath = resolveSafeChildPath(sourcePath, path);\n if (dirent.isSymbolicLink()) {\n return fs.readlink(absFilePath, 'buffer');\n }\n return fs.readFile(absFilePath);\n }),\n executable: isExecutable(stats?.mode),\n symlink: dirent.isSymbolicLink(),\n })),\n );\n}\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fs from 'fs-extra';\nimport { dirname } from 'path';\nimport { resolveSafeChildPath } from '@backstage/backend-common';\nimport { SerializedFile } from './types';\n\n/**\n * Deserializes a list of serialized files into the target directory.\n *\n * This method uses `resolveSafeChildPath` to make sure that files are\n * not written outside of the target directory.\n *\n * @public\n */\nexport async function deserializeDirectoryContents(\n targetPath: string,\n files: SerializedFile[],\n): Promise<void> {\n for (const file of files) {\n const filePath = resolveSafeChildPath(targetPath, file.path);\n await fs.ensureDir(dirname(filePath));\n await fs.writeFile(filePath, file.content); // Ignore file mode\n }\n}\n"],"names":["zodToJsonSchema","PassThrough","spawn","resolveSafeChildPath","path","fs","InputError","Git","normalizePath","joinPath","isChildPath","globby","limiterFactory","isError","dirname"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmDa,MAAA,oBAAA,GAAuB,CAoBlC,MAMgD,KAAA;AA7ElD,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,CAAA;AA8EE,EAAA,MAAM,gBACJ,EAAO,GAAA,MAAA,CAAA,MAAA,KAAP,IAAe,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,KAAA,KAAS,oBAAoB,MAAO,CAAA,MAAA,CAAO,KACtD,GAAAA,mCAAA,CAAgB,OAAO,MAAO,CAAA,KAAK,CACnC,GAAA,CAAA,EAAA,GAAA,MAAA,CAAO,WAAP,IAAe,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,KAAA,CAAA;AAErB,EAAA,MAAM,iBACJ,EAAO,GAAA,MAAA,CAAA,MAAA,KAAP,IAAe,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,MAAA,KAAU,oBAAoB,MAAO,CAAA,MAAA,CAAO,MACvD,GAAAA,mCAAA,CAAgB,OAAO,MAAO,CAAA,MAAM,CACpC,GAAA,CAAA,EAAA,GAAA,MAAA,CAAO,WAAP,IAAe,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,MAAA,CAAA;AAErB,EAAO,OAAA;AAAA,IACL,GAAG,MAAA;AAAA,IACH,MAAQ,EAAA;AAAA,MACN,GAAG,MAAO,CAAA,MAAA;AAAA,MACV,KAAO,EAAA,WAAA;AAAA,MACP,MAAQ,EAAA,YAAA;AAAA,KACV;AAAA,GACF,CAAA;AACF;;ACxDA,eAAsB,oBACpB,OACe,EAAA;AACf,EAAM,MAAA;AAAA,IACJ,OAAA;AAAA,IACA,IAAA;AAAA,IACA,OAAS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AAA,CAAK,OAAO,CAAA,CAAA;AAAA,GAC3C;AACF;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { Schema } from 'jsonschema';
|
|
|
8
8
|
import { z } from 'zod';
|
|
9
9
|
import { SpawnOptionsWithoutStdio } from 'child_process';
|
|
10
10
|
import { UrlReader } from '@backstage/backend-common';
|
|
11
|
-
import { ScmIntegrations } from '@backstage/integration';
|
|
11
|
+
import { ScmIntegrations, ScmIntegrationRegistry } from '@backstage/integration';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* TaskSecrets
|
|
@@ -255,9 +255,98 @@ declare function fetchFile(options: {
|
|
|
255
255
|
outputPath: string;
|
|
256
256
|
}): Promise<void>;
|
|
257
257
|
|
|
258
|
+
/**
|
|
259
|
+
* @public
|
|
260
|
+
*/
|
|
261
|
+
declare function initRepoAndPush(input: {
|
|
262
|
+
dir: string;
|
|
263
|
+
remoteUrl: string;
|
|
264
|
+
auth: {
|
|
265
|
+
username: string;
|
|
266
|
+
password: string;
|
|
267
|
+
} | {
|
|
268
|
+
token: string;
|
|
269
|
+
};
|
|
270
|
+
logger: Logger;
|
|
271
|
+
defaultBranch?: string;
|
|
272
|
+
commitMessage?: string;
|
|
273
|
+
gitAuthorInfo?: {
|
|
274
|
+
name?: string;
|
|
275
|
+
email?: string;
|
|
276
|
+
};
|
|
277
|
+
}): Promise<{
|
|
278
|
+
commitHash: string;
|
|
279
|
+
}>;
|
|
280
|
+
/**
|
|
281
|
+
* @public
|
|
282
|
+
*/
|
|
283
|
+
declare function commitAndPushRepo(input: {
|
|
284
|
+
dir: string;
|
|
285
|
+
auth: {
|
|
286
|
+
username: string;
|
|
287
|
+
password: string;
|
|
288
|
+
} | {
|
|
289
|
+
token: string;
|
|
290
|
+
};
|
|
291
|
+
logger: Logger;
|
|
292
|
+
commitMessage: string;
|
|
293
|
+
gitAuthorInfo?: {
|
|
294
|
+
name?: string;
|
|
295
|
+
email?: string;
|
|
296
|
+
};
|
|
297
|
+
branch?: string;
|
|
298
|
+
remoteRef?: string;
|
|
299
|
+
}): Promise<{
|
|
300
|
+
commitHash: string;
|
|
301
|
+
}>;
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* @public
|
|
305
|
+
*/
|
|
306
|
+
declare const getRepoSourceDirectory: (workspacePath: string, sourcePath: string | undefined) => string;
|
|
307
|
+
/**
|
|
308
|
+
* @public
|
|
309
|
+
*/
|
|
310
|
+
declare const parseRepoUrl: (repoUrl: string, integrations: ScmIntegrationRegistry) => {
|
|
311
|
+
repo: string;
|
|
312
|
+
host: string;
|
|
313
|
+
owner?: string | undefined;
|
|
314
|
+
organization?: string | undefined;
|
|
315
|
+
workspace?: string | undefined;
|
|
316
|
+
project?: string | undefined;
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* @public
|
|
321
|
+
*/
|
|
322
|
+
interface SerializedFile {
|
|
323
|
+
path: string;
|
|
324
|
+
content: Buffer;
|
|
325
|
+
executable?: boolean;
|
|
326
|
+
symlink?: boolean;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* @public
|
|
331
|
+
*/
|
|
332
|
+
declare function serializeDirectoryContents(sourcePath: string, options?: {
|
|
333
|
+
gitignore?: boolean;
|
|
334
|
+
globPatterns?: string[];
|
|
335
|
+
}): Promise<SerializedFile[]>;
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Deserializes a list of serialized files into the target directory.
|
|
339
|
+
*
|
|
340
|
+
* This method uses `resolveSafeChildPath` to make sure that files are
|
|
341
|
+
* not written outside of the target directory.
|
|
342
|
+
*
|
|
343
|
+
* @public
|
|
344
|
+
*/
|
|
345
|
+
declare function deserializeDirectoryContents(targetPath: string, files: SerializedFile[]): Promise<void>;
|
|
346
|
+
|
|
258
347
|
/** @public */
|
|
259
348
|
type TemplateFilter = (...args: JsonValue[]) => JsonValue | undefined;
|
|
260
349
|
/** @public */
|
|
261
350
|
type TemplateGlobal = ((...args: JsonValue[]) => JsonValue | undefined) | JsonValue;
|
|
262
351
|
|
|
263
|
-
export { ActionContext, ExecuteShellCommandOptions, SerializedTask, SerializedTaskEvent, TaskBroker, TaskBrokerDispatchOptions, TaskBrokerDispatchResult, TaskCompletionState, TaskContext, TaskEventType, TaskSecrets, TaskStatus, TemplateAction, TemplateActionOptions, TemplateExample, TemplateFilter, TemplateGlobal, createTemplateAction, executeShellCommand, fetchContents, fetchFile };
|
|
352
|
+
export { ActionContext, ExecuteShellCommandOptions, SerializedFile, SerializedTask, SerializedTaskEvent, TaskBroker, TaskBrokerDispatchOptions, TaskBrokerDispatchResult, TaskCompletionState, TaskContext, TaskEventType, TaskSecrets, TaskStatus, TemplateAction, TemplateActionOptions, TemplateExample, TemplateFilter, TemplateGlobal, commitAndPushRepo, createTemplateAction, deserializeDirectoryContents, executeShellCommand, fetchContents, fetchFile, getRepoSourceDirectory, initRepoAndPush, parseRepoUrl, serializeDirectoryContents };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-scaffolder-node",
|
|
3
3
|
"description": "The plugin-scaffolder-node module for @backstage/plugin-scaffolder-backend",
|
|
4
|
-
"version": "0.2.9-next.
|
|
4
|
+
"version": "0.2.9-next.3",
|
|
5
5
|
"main": "./dist/index.cjs.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -40,21 +40,24 @@
|
|
|
40
40
|
"postpack": "backstage-cli package postpack"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@backstage/backend-common": "^0.20.0-next.
|
|
44
|
-
"@backstage/backend-plugin-api": "^0.6.8-next.
|
|
43
|
+
"@backstage/backend-common": "^0.20.0-next.3",
|
|
44
|
+
"@backstage/backend-plugin-api": "^0.6.8-next.3",
|
|
45
45
|
"@backstage/catalog-model": "^1.4.3",
|
|
46
46
|
"@backstage/errors": "^1.2.3",
|
|
47
47
|
"@backstage/integration": "^1.8.0-next.1",
|
|
48
48
|
"@backstage/plugin-scaffolder-common": "^1.4.3",
|
|
49
49
|
"@backstage/types": "^1.1.1",
|
|
50
50
|
"fs-extra": "10.1.0",
|
|
51
|
+
"globby": "^11.0.0",
|
|
51
52
|
"jsonschema": "^1.2.6",
|
|
53
|
+
"p-limit": "^3.1.0",
|
|
52
54
|
"winston": "^3.2.1",
|
|
53
55
|
"zod": "^3.21.4",
|
|
54
56
|
"zod-to-json-schema": "^3.20.4"
|
|
55
57
|
},
|
|
56
58
|
"devDependencies": {
|
|
57
|
-
"@backstage/
|
|
59
|
+
"@backstage/backend-test-utils": "^0.2.9-next.3",
|
|
60
|
+
"@backstage/cli": "^0.25.0-next.3",
|
|
58
61
|
"@backstage/config": "^1.1.1"
|
|
59
62
|
},
|
|
60
63
|
"files": [
|