@roadiehq/scaffolder-backend-module-utils 0.1.2

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,194 @@
1
+ # scaffolder-backend-module-utils actions package
2
+
3
+ Welcome to the roadie `utils` actions for the `scaffolder-backend`.
4
+
5
+ This contains a collection of actions:
6
+ - `roadiehq:utils:zip`
7
+ - `roadiehq:utils:sleep`
8
+ - `roadiehq:utils:fs:write`
9
+ - `roadiehq:utils:fs:append`
10
+
11
+ ## Getting started
12
+
13
+ Create your Backstage application using the Backstage CLI as described here:
14
+ https://backstage.io/docs/getting-started/create-an-app
15
+
16
+ > Note: If you are using this plugin in a Backstage monorepo that contains the code for `@backstage/plugin-scaffolder-backend`, you need to modify your internal build processes to transpile files from the `node_modules` folder as well.
17
+
18
+ You need to configure the action in your backend:
19
+
20
+ ## From your Backstage root directory
21
+
22
+ ```
23
+ cd packages/backend
24
+ yarn add @roadiehq/scaffolder-backend-module-utils
25
+ ```
26
+
27
+ Configure the action:
28
+ (you can check the [docs](https://backstage.io/docs/features/software-templates/writing-custom-actions#registering-custom-actions) to see all options):
29
+
30
+ Here you can pick the actions that you'd like to register to your backstage instance.
31
+
32
+ ```typescript
33
+ // packages/backend/src/plugins/scaffolder.ts
34
+ import { createZipAction, createWriteFileAction, createAppendFileAction, createSleepAction } from '@roadiehq/scaffolder-backend-module-utils';
35
+ ...
36
+
37
+ const actions = [
38
+ createFileAction(),
39
+ createSleepAction(),
40
+ createZipAction(),
41
+ createAppendFileAction(),
42
+ ...createBuiltinActions({
43
+ containerRunner,
44
+ integrations,
45
+ config,
46
+ catalogClient,
47
+ reader,
48
+ }),
49
+ ];
50
+
51
+ return await createRouter({
52
+ containerRunner,
53
+ logger,
54
+ config,
55
+ database,
56
+ catalogClient,
57
+ reader,
58
+ actions,
59
+ });
60
+ ```
61
+
62
+ ### Example of using zip action
63
+
64
+ ```yaml
65
+ ---
66
+ apiVersion: scaffolder.backstage.io/v1beta3
67
+ kind: Template
68
+ metadata:
69
+ name: zip-dummy
70
+ title: My custom zip action
71
+ description: scaffolder action to zip the current context?
72
+ spec:
73
+ owner: roadie
74
+ type: service
75
+
76
+ parameters:
77
+ - title: Zip
78
+ properties:
79
+ path:
80
+ title: Path
81
+ type: string
82
+ description: Workspace path to zip
83
+ outputPath:
84
+ title: Path
85
+ type: string
86
+ description: The path of the zip file
87
+
88
+ steps:
89
+ - id: zip
90
+ name: Zip
91
+ action: roadiehq:utils:zip
92
+ input:
93
+ path: ${{ parameters.path }}
94
+ outputPath: ${{ parameters.outputPath }}
95
+
96
+ output:
97
+ path: ${{ steps.zip.output.path }}
98
+ ```
99
+ ### Example of using sleep action
100
+
101
+ ```yaml
102
+ ---
103
+ apiVersion: scaffolder.backstage.io/v1beta3
104
+ kind: Template
105
+ metadata:
106
+ name: sleep-dummy
107
+ title: Sleep template
108
+ description: A template with only one sleep example action that will ask for a user input for the amount of seconds it should sleep
109
+ spec:
110
+ owner: roadie
111
+ type: service
112
+
113
+ parameters:
114
+ - title: Sleep
115
+ properties:
116
+ amount:
117
+ title: Amount to sleep
118
+ type: number
119
+ description: Will sleep for this amount of seconds
120
+
121
+ steps:
122
+ - id: sleep
123
+ name: sleep
124
+ action: roadiehq:utils:sleep
125
+ input:
126
+ path: ${{ parameters.amount }}
127
+ ```
128
+ ### Example of using writeFile action
129
+
130
+ ```yaml
131
+ ---
132
+ apiVersion: scaffolder.backstage.io/v1beta3
133
+ kind: Template
134
+ metadata:
135
+ name: create-file-template
136
+ title: Create File template
137
+ description: Example temaplte to create a file with on the given path with the given content in the workspace.
138
+ spec:
139
+ owner: roadie
140
+ type: service
141
+
142
+ parameters:
143
+ - title: Create File
144
+ properties:
145
+ path:
146
+ title: Path
147
+ type: string
148
+ description: The path to the desired new file
149
+ content:
150
+ title: Content
151
+ type: string
152
+ description: The content of the newly created file
153
+ steps:
154
+ - id: writeFile
155
+ name: Create File
156
+ action: roadiehq:utils:fs:write
157
+ input:
158
+ path: ${{ parameters.path }}
159
+ content: ${{ parameters.content }}
160
+ ```
161
+ ### Example of using appendFile action
162
+
163
+ ```yaml
164
+ ---
165
+ apiVersion: scaffolder.backstage.io/v1beta3
166
+ kind: Template
167
+ metadata:
168
+ name: append-file-template
169
+ title: Append To File template
170
+ description: Example temaplte to append to a file with on the given path with the given content in the workspace.
171
+ spec:
172
+ owner: roadie
173
+ type: service
174
+
175
+ parameters:
176
+ - title: Append To File
177
+ properties:
178
+ path:
179
+ title: Path
180
+ type: string
181
+ description: The path to the file
182
+ content:
183
+ title: Content
184
+ type: string
185
+ description: The content to append to the file
186
+ steps:
187
+ - id: appendFile
188
+ name: Append To File
189
+ action: roadiehq:utils:fs:append
190
+ input:
191
+ path: ${{ parameters.path }}
192
+ content: ${{ parameters.content }}
193
+ ```
194
+
@@ -0,0 +1,179 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var backendCommon = require('@backstage/backend-common');
6
+ var pluginScaffolderBackend = require('@backstage/plugin-scaffolder-backend');
7
+ var errors = require('@backstage/errors');
8
+ var AdmZip = require('adm-zip');
9
+ var fs = require('fs-extra');
10
+
11
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
+
13
+ var AdmZip__default = /*#__PURE__*/_interopDefaultLegacy(AdmZip);
14
+ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
15
+
16
+ function createZipAction() {
17
+ return pluginScaffolderBackend.createTemplateAction({
18
+ id: "roadiehq:utils:zip",
19
+ description: "Zips the content of the path",
20
+ schema: {
21
+ input: {
22
+ required: ["path"],
23
+ type: "object",
24
+ properties: {
25
+ path: {
26
+ title: "Path",
27
+ description: "Relative path you would like to zip",
28
+ type: "string"
29
+ },
30
+ outputPath: {
31
+ title: "Output Path",
32
+ description: "The name of the result of the zip command",
33
+ type: "string"
34
+ }
35
+ }
36
+ },
37
+ output: {
38
+ type: "object",
39
+ properties: {
40
+ outputPath: {
41
+ title: "Zip Path",
42
+ type: "string"
43
+ }
44
+ }
45
+ }
46
+ },
47
+ async handler(ctx) {
48
+ const zip = new AdmZip__default["default"]();
49
+ const sourceFilepath = backendCommon.resolveSafeChildPath(ctx.workspacePath, ctx.input.path);
50
+ const destFilepath = backendCommon.resolveSafeChildPath(ctx.workspacePath, ctx.input.outputPath);
51
+ if (!fs__default["default"].existsSync(sourceFilepath)) {
52
+ throw new errors.InputError(`File ${ctx.input.path} does not exist. Can't zip it.`);
53
+ }
54
+ if (fs__default["default"].lstatSync(sourceFilepath).isDirectory()) {
55
+ zip.addLocalFolder(sourceFilepath);
56
+ } else if (fs__default["default"].lstatSync(sourceFilepath).isFile()) {
57
+ zip.addLocalFile(sourceFilepath);
58
+ }
59
+ zip.writeZip(destFilepath);
60
+ ctx.output("outputPath", ctx.input.outputPath);
61
+ }
62
+ });
63
+ }
64
+
65
+ function createWriteFileAction() {
66
+ return pluginScaffolderBackend.createTemplateAction({
67
+ id: "roadiehq:utils:fs:write",
68
+ description: "Creates a file with the content on the given path",
69
+ schema: {
70
+ input: {
71
+ required: ["path", "content"],
72
+ type: "object",
73
+ properties: {
74
+ path: {
75
+ title: "Path",
76
+ description: "Relative path",
77
+ type: "string"
78
+ },
79
+ content: {
80
+ title: "Content",
81
+ description: "This will be the content of the file",
82
+ type: "string"
83
+ }
84
+ }
85
+ },
86
+ output: {
87
+ type: "object",
88
+ properties: {
89
+ path: {
90
+ title: "Path",
91
+ type: "string"
92
+ }
93
+ }
94
+ }
95
+ },
96
+ async handler(ctx) {
97
+ const destFilepath = backendCommon.resolveSafeChildPath(ctx.workspacePath, ctx.input.path);
98
+ fs__default["default"].outputFileSync(destFilepath, ctx.input.content);
99
+ ctx.output("path", destFilepath);
100
+ }
101
+ });
102
+ }
103
+
104
+ function createAppendFileAction() {
105
+ return pluginScaffolderBackend.createTemplateAction({
106
+ id: "roadiehq:utils:fs:append",
107
+ description: "Append content to the end of the given file, it will create the file if it does not exist.",
108
+ schema: {
109
+ input: {
110
+ type: "object",
111
+ required: ["content", "path"],
112
+ properties: {
113
+ path: {
114
+ title: "Path",
115
+ description: "Path to existing file to append.",
116
+ type: "string"
117
+ },
118
+ content: {
119
+ title: "Content",
120
+ description: "This will be appended to the file",
121
+ type: "string"
122
+ }
123
+ }
124
+ },
125
+ output: {
126
+ type: "object",
127
+ properties: {
128
+ path: {
129
+ title: "Path",
130
+ type: "string"
131
+ }
132
+ }
133
+ }
134
+ },
135
+ async handler(ctx) {
136
+ const sourceFilepath = backendCommon.resolveSafeChildPath(ctx.workspacePath, ctx.input.path);
137
+ fs__default["default"].appendFileSync(sourceFilepath, ctx.input.content);
138
+ ctx.output("path", sourceFilepath);
139
+ }
140
+ });
141
+ }
142
+
143
+ function createSleepAction(options) {
144
+ return pluginScaffolderBackend.createTemplateAction({
145
+ id: "roadiehq:utils:sleep",
146
+ description: "Halts the scaffolding for the given amount of seconds",
147
+ schema: {
148
+ input: {
149
+ type: "object",
150
+ required: ["amount"],
151
+ properties: {
152
+ amount: {
153
+ title: "Sleep Amount",
154
+ description: "How much seconds should this step take.",
155
+ type: "number"
156
+ }
157
+ }
158
+ }
159
+ },
160
+ async handler(ctx) {
161
+ var _a;
162
+ if (isNaN((_a = ctx.input) == null ? void 0 : _a.amount)) {
163
+ throw new errors.InputError("amount must be a number");
164
+ } else if ((options == null ? void 0 : options.maxSleep) && ctx.input.amount > options.maxSleep) {
165
+ throw new errors.InputError(`sleep amount can not be greater than maxSleep. amount: ${ctx.input.amount}, maxSleep: ${options.maxSleep}`);
166
+ }
167
+ ctx.logger.info(`Waiting ${ctx.input.amount} seconds`);
168
+ await new Promise((resolve) => {
169
+ setTimeout(resolve, ctx.input.amount * 1e3);
170
+ });
171
+ }
172
+ });
173
+ }
174
+
175
+ exports.createAppendFileAction = createAppendFileAction;
176
+ exports.createSleepAction = createSleepAction;
177
+ exports.createWriteFileAction = createWriteFileAction;
178
+ exports.createZipAction = createZipAction;
179
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/actions/zip.ts","../src/actions/fs/writeFile.ts","../src/actions/fs/appendFile.ts","../src/actions/sleep.ts"],"sourcesContent":["/*\n * Copyright 2021 Larder Software Limited\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 } from '@backstage/backend-common';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-backend';\nimport { InputError } from '@backstage/errors';\nimport AdmZip from 'adm-zip';\nimport fs from 'fs-extra';\n\nexport function createZipAction() {\n return createTemplateAction<{ path: string; outputPath: string }>({\n id: 'roadiehq:utils:zip',\n description: 'Zips the content of the path',\n schema: {\n input: {\n required: ['path'],\n type: 'object',\n properties: {\n path: {\n title: 'Path',\n description: 'Relative path you would like to zip',\n type: 'string',\n },\n\n outputPath: {\n title: 'Output Path',\n description: 'The name of the result of the zip command',\n type: 'string',\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n outputPath: {\n title: 'Zip Path',\n type: 'string',\n },\n },\n },\n },\n async handler(ctx) {\n const zip = new AdmZip();\n const sourceFilepath = resolveSafeChildPath(\n ctx.workspacePath,\n ctx.input.path,\n );\n const destFilepath = resolveSafeChildPath(\n ctx.workspacePath,\n ctx.input.outputPath,\n );\n\n if (!fs.existsSync(sourceFilepath)) {\n throw new InputError(\n `File ${ctx.input.path} does not exist. Can't zip it.`,\n );\n }\n if (fs.lstatSync(sourceFilepath).isDirectory()) {\n zip.addLocalFolder(sourceFilepath);\n } else if (fs.lstatSync(sourceFilepath).isFile()) {\n zip.addLocalFile(sourceFilepath);\n }\n zip.writeZip(destFilepath);\n ctx.output('outputPath', ctx.input.outputPath);\n },\n });\n}\n","/*\n * Copyright 2021 Larder Software Limited\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 { createTemplateAction } from '@backstage/plugin-scaffolder-backend';\nimport { resolveSafeChildPath } from '@backstage/backend-common';\nimport fs from 'fs-extra';\n\nexport function createWriteFileAction() {\n return createTemplateAction<{ path: string; content: string }>({\n id: 'roadiehq:utils:fs:write',\n description: 'Creates a file with the content on the given path',\n schema: {\n input: {\n required: ['path', 'content'],\n type: 'object',\n properties: {\n path: {\n title: 'Path',\n description: 'Relative path',\n type: 'string',\n },\n content: {\n title: 'Content',\n description: 'This will be the content of the file',\n type: 'string',\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n path: {\n title: 'Path',\n type: 'string',\n },\n },\n },\n },\n async handler(ctx) {\n const destFilepath = resolveSafeChildPath(\n ctx.workspacePath,\n ctx.input.path,\n );\n\n fs.outputFileSync(destFilepath, ctx.input.content);\n ctx.output('path', destFilepath);\n },\n });\n}\n","/*\n * Copyright 2021 Larder Software Limited\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 { createTemplateAction } from '@backstage/plugin-scaffolder-backend';\nimport { resolveSafeChildPath } from '@backstage/backend-common';\nimport fs from 'fs-extra';\n\nexport function createAppendFileAction() {\n return createTemplateAction<{ path: string; content: string }>({\n id: 'roadiehq:utils:fs:append',\n description:\n 'Append content to the end of the given file, it will create the file if it does not exist.',\n schema: {\n input: {\n type: 'object',\n required: ['content', 'path'],\n properties: {\n path: {\n title: 'Path',\n description: 'Path to existing file to append.',\n type: 'string',\n },\n content: {\n title: 'Content',\n description: 'This will be appended to the file',\n type: 'string',\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n path: {\n title: 'Path',\n type: 'string',\n },\n },\n },\n },\n async handler(ctx) {\n const sourceFilepath = resolveSafeChildPath(\n ctx.workspacePath,\n ctx.input.path,\n );\n\n fs.appendFileSync(sourceFilepath, ctx.input.content);\n ctx.output('path', sourceFilepath);\n },\n });\n}\n","/*\n * Copyright 2021 Larder Software Limited\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 { createTemplateAction } from '@backstage/plugin-scaffolder-backend';\nimport { InputError } from '@backstage/errors';\n\nexport function createSleepAction(options?: { maxSleep?: number }) {\n return createTemplateAction<{ amount: number }>({\n id: 'roadiehq:utils:sleep',\n description: 'Halts the scaffolding for the given amount of seconds',\n schema: {\n input: {\n type: 'object',\n required: ['amount'],\n properties: {\n amount: {\n title: 'Sleep Amount',\n description: 'How much seconds should this step take.',\n type: 'number',\n },\n },\n },\n },\n async handler(ctx) {\n if (isNaN(ctx.input?.amount)) {\n throw new InputError('amount must be a number');\n } else if (options?.maxSleep && ctx.input.amount > options.maxSleep) {\n throw new InputError(\n `sleep amount can not be greater than maxSleep. amount: ${ctx.input.amount}, maxSleep: ${options.maxSleep}`,\n );\n }\n ctx.logger.info(`Waiting ${ctx.input.amount} seconds`);\n\n await new Promise(resolve => {\n setTimeout(resolve, ctx.input.amount * 1000);\n });\n },\n });\n}\n"],"names":["createTemplateAction","AdmZip","resolveSafeChildPath","fs","InputError"],"mappings":"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"}
@@ -0,0 +1,24 @@
1
+ import * as _backstage_plugin_scaffolder_backend from '@backstage/plugin-scaffolder-backend';
2
+
3
+ declare function createZipAction(): _backstage_plugin_scaffolder_backend.TemplateAction<{
4
+ path: string;
5
+ outputPath: string;
6
+ }>;
7
+
8
+ declare function createWriteFileAction(): _backstage_plugin_scaffolder_backend.TemplateAction<{
9
+ path: string;
10
+ content: string;
11
+ }>;
12
+
13
+ declare function createAppendFileAction(): _backstage_plugin_scaffolder_backend.TemplateAction<{
14
+ path: string;
15
+ content: string;
16
+ }>;
17
+
18
+ declare function createSleepAction(options?: {
19
+ maxSleep?: number;
20
+ }): _backstage_plugin_scaffolder_backend.TemplateAction<{
21
+ amount: number;
22
+ }>;
23
+
24
+ export { createAppendFileAction, createSleepAction, createWriteFileAction, createZipAction };
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@roadiehq/scaffolder-backend-module-utils",
3
+ "version": "0.1.2",
4
+ "main": "dist/index.cjs.js",
5
+ "types": "dist/index.d.ts",
6
+ "license": "Apache-2.0",
7
+ "publishConfig": {
8
+ "access": "public",
9
+ "main": "dist/index.cjs.js",
10
+ "types": "dist/index.d.ts"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "github:RoadieHQ/roadie-backstage-plugins",
15
+ "directory": "plugins/scaffolder-actions/scaffolder-backend-module-utils"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/RoadieHQ/roadie-backstage-plugins/issues",
19
+ "email": "support@roadie.io"
20
+ },
21
+ "scripts": {
22
+ "start": "backstage-cli backend:dev",
23
+ "build": "backstage-cli backend:build",
24
+ "lint": "backstage-cli lint",
25
+ "test": "backstage-cli test",
26
+ "prepack": "backstage-cli prepack",
27
+ "postpack": "backstage-cli postpack",
28
+ "clean": "backstage-cli clean"
29
+ },
30
+ "dependencies": {
31
+ "@backstage/backend-common": "^0.10.1",
32
+ "@backstage/config": "^0.1.8",
33
+ "@backstage/errors": "^0.2.0",
34
+ "@backstage/plugin-scaffolder-backend": "^0.16.1",
35
+ "adm-zip": "^0.5.9",
36
+ "cross-fetch": "^3.1.4",
37
+ "fs-extra": "^10.0.0",
38
+ "winston": "^3.2.1"
39
+ },
40
+ "devDependencies": {
41
+ "@backstage/cli": "^0.14.0",
42
+ "@types/adm-zip": "^0.4.34",
43
+ "@types/fs-extra": "^9.0.13",
44
+ "@types/jest": "^26.0.7",
45
+ "@types/mock-fs": "^4.13.1",
46
+ "mock-fs": "^5.1.2"
47
+ },
48
+ "files": [
49
+ "dist"
50
+ ],
51
+ "gitHead": "ed592176aa1cb9ee324ae7948103480ca9e2a9c9"
52
+ }