@backstage-community/plugin-scaffolder-backend-module-annotator 2.2.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/CHANGELOG.md +84 -0
- package/README.md +109 -0
- package/dist/actions/annotator/annotator.cjs.js +133 -0
- package/dist/actions/annotator/annotator.cjs.js.map +1 -0
- package/dist/actions/customActions/createScaffoldedFromAction.cjs.js +21 -0
- package/dist/actions/customActions/createScaffoldedFromAction.cjs.js.map +1 -0
- package/dist/actions/customActions/createTimestampAction.cjs.js +20 -0
- package/dist/actions/customActions/createTimestampAction.cjs.js.map +1 -0
- package/dist/index.cjs.js +16 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +82 -0
- package/dist/module.cjs.js +27 -0
- package/dist/module.cjs.js.map +1 -0
- package/dist/utils/getCurrentTimestamp.cjs.js +11 -0
- package/dist/utils/getCurrentTimestamp.cjs.js.map +1 -0
- package/dist/utils/getObjectToAnnotate.cjs.js +40 -0
- package/dist/utils/getObjectToAnnotate.cjs.js.map +1 -0
- package/dist/utils/resolveSpec.cjs.js +21 -0
- package/dist/utils/resolveSpec.cjs.js.map +1 -0
- package/package.json +71 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
## @janus-idp/backstage-scaffolder-backend-module-annotator [1.3.0](https://github.com/janus-idp/backstage-plugins/compare/@janus-idp/backstage-scaffolder-backend-module-annotator@1.2.1...@janus-idp/backstage-scaffolder-backend-module-annotator@1.3.0) (2024-07-25)
|
|
2
|
+
|
|
3
|
+
## 2.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b6fe90f: The [scaffolder-backend-module-annotator](https://github.com/janus-idp/backstage-plugins/tree/main/plugins/scaffolder-annotator-action) plugin from the [janus-idp/backstage-plugins](https://github.com/janus-idp/backstage-plugins) repository was migrated to the [community plugins](https://github.com/backstage/community-plugins), based on commit `9671df5d`.
|
|
8
|
+
|
|
9
|
+
The migration was performed by following the manual migration steps outlined in the [Community Plugins CONTRIBUTING guide](https://github.com/backstage/community-plugins/blob/main/CONTRIBUTING.md#migrating-a-plugin).
|
|
10
|
+
|
|
11
|
+
## 2.2.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 0e6bfd3: feat: update Backstage to the latest version
|
|
16
|
+
|
|
17
|
+
Update to Backstage 1.32.5
|
|
18
|
+
|
|
19
|
+
## 2.2.0
|
|
20
|
+
|
|
21
|
+
### Minor Changes
|
|
22
|
+
|
|
23
|
+
- 8244f28: chore(deps): update to backstage 1.32
|
|
24
|
+
|
|
25
|
+
## 2.1.1
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- 7342e9b: chore: remove @janus-idp/cli dep and relink local packages
|
|
30
|
+
|
|
31
|
+
This update removes `@janus-idp/cli` from all plugins, as it’s no longer necessary. Additionally, packages are now correctly linked with a specified version.
|
|
32
|
+
|
|
33
|
+
## 2.1.0
|
|
34
|
+
|
|
35
|
+
### Minor Changes
|
|
36
|
+
|
|
37
|
+
- d9551ae: feat(deps): update to backstage 1.31
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- d9551ae: upgrade to yarn v3
|
|
42
|
+
- d9551ae: Change the export-dynamic script to no longer use any flags and remove the tracking of the dist-dynamic folder
|
|
43
|
+
|
|
44
|
+
### Features
|
|
45
|
+
|
|
46
|
+
- **deps:** update to backstage 1.29 ([#1900](https://github.com/janus-idp/backstage-plugins/issues/1900)) ([f53677f](https://github.com/janus-idp/backstage-plugins/commit/f53677fb02d6df43a9de98c43a9f101a6db76802))
|
|
47
|
+
|
|
48
|
+
## @janus-idp/backstage-scaffolder-backend-module-annotator [1.2.1](https://github.com/janus-idp/backstage-plugins/compare/@janus-idp/backstage-scaffolder-backend-module-annotator@1.2.0...@janus-idp/backstage-scaffolder-backend-module-annotator@1.2.1) (2024-07-24)
|
|
49
|
+
|
|
50
|
+
### Bug Fixes
|
|
51
|
+
|
|
52
|
+
- **deps:** rollback unreleased plugins ([#1951](https://github.com/janus-idp/backstage-plugins/issues/1951)) ([8b77969](https://github.com/janus-idp/backstage-plugins/commit/8b779694f02f8125587296305276b84cdfeeaebe))
|
|
53
|
+
|
|
54
|
+
## @janus-idp/backstage-scaffolder-backend-module-annotator [1.2.0](https://github.com/janus-idp/backstage-plugins/compare/@janus-idp/backstage-scaffolder-backend-module-annotator@1.1.0...@janus-idp/backstage-scaffolder-backend-module-annotator@1.2.0) (2024-07-22)
|
|
55
|
+
|
|
56
|
+
### Features
|
|
57
|
+
|
|
58
|
+
- **deps:** update to backstage 1.28 ([#1891](https://github.com/janus-idp/backstage-plugins/issues/1891)) ([1ba1108](https://github.com/janus-idp/backstage-plugins/commit/1ba11088e0de60e90d138944267b83600dc446e5))
|
|
59
|
+
|
|
60
|
+
## @janus-idp/backstage-scaffolder-backend-module-annotator [1.1.0](https://github.com/janus-idp/backstage-plugins/compare/@janus-idp/backstage-scaffolder-backend-module-annotator@1.0.3...@janus-idp/backstage-scaffolder-backend-module-annotator@1.1.0) (2024-06-13)
|
|
61
|
+
|
|
62
|
+
### Features
|
|
63
|
+
|
|
64
|
+
- **deps:** update to backstage 1.27 ([#1683](https://github.com/janus-idp/backstage-plugins/issues/1683)) ([a14869c](https://github.com/janus-idp/backstage-plugins/commit/a14869c3f4177049cb8d6552b36c3ffd17e7997d))
|
|
65
|
+
|
|
66
|
+
## @janus-idp/backstage-scaffolder-backend-module-annotator [1.0.3](https://github.com/janus-idp/backstage-plugins/compare/@janus-idp/backstage-scaffolder-backend-module-annotator@1.0.2...@janus-idp/backstage-scaffolder-backend-module-annotator@1.0.3) (2024-06-13)
|
|
67
|
+
|
|
68
|
+
### Bug Fixes
|
|
69
|
+
|
|
70
|
+
- missing postversion script is several plugins and missing turbo dependency ([#1811](https://github.com/janus-idp/backstage-plugins/issues/1811)) ([4dfe4f5](https://github.com/janus-idp/backstage-plugins/commit/4dfe4f533e21e79c928c66bfd68684243912be2c))
|
|
71
|
+
|
|
72
|
+
## @janus-idp/backstage-scaffolder-backend-module-annotator [1.0.2](https://github.com/janus-idp/backstage-plugins/compare/@janus-idp/backstage-scaffolder-backend-module-annotator@1.0.1...@janus-idp/backstage-scaffolder-backend-module-annotator@1.0.2) (2024-06-04)
|
|
73
|
+
|
|
74
|
+
## @janus-idp/backstage-scaffolder-backend-module-annotator [1.0.1](https://github.com/janus-idp/backstage-plugins/compare/@janus-idp/backstage-scaffolder-backend-module-annotator@1.0.0...@janus-idp/backstage-scaffolder-backend-module-annotator@1.0.1) (2024-05-31)
|
|
75
|
+
|
|
76
|
+
### Bug Fixes
|
|
77
|
+
|
|
78
|
+
- **scaffolder:** update annotator action readme ([#1638](https://github.com/janus-idp/backstage-plugins/issues/1638)) ([8e3af1b](https://github.com/janus-idp/backstage-plugins/commit/8e3af1b91b1cc874d4e867717eef1dc9eca592fc))
|
|
79
|
+
|
|
80
|
+
## @janus-idp/backstage-scaffolder-backend-module-annotator 1.0.0 (2024-05-09)
|
|
81
|
+
|
|
82
|
+
### Features
|
|
83
|
+
|
|
84
|
+
- **scaffolder:** create custom action for scaffolder templates ([#1567](https://github.com/janus-idp/backstage-plugins/issues/1567)) ([e30701e](https://github.com/janus-idp/backstage-plugins/commit/e30701ec9c0ba09ad56cbc23fb7f8a8cb9c561c9))
|
package/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Annotator custom action for Scaffolder Backstage
|
|
2
|
+
|
|
3
|
+
The annotator module for [@backstage/plugin-scaffolder-backend](https://www.npmjs.com/package/@backstage/plugin-scaffolder-backend).
|
|
4
|
+
|
|
5
|
+
This module allows users to create custom actions for annotating their entity objects. Additionally, it enables users to utilize existing custom actions provided by the module for annotating entities with timestamps and scaffolder entity references.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
### Available custom actions
|
|
10
|
+
|
|
11
|
+
| Action | Description |
|
|
12
|
+
| ------------------------- | :-----------------------------------------------------------------------------------------------------: |
|
|
13
|
+
| `catalog:timestamping` | Adds the `backstage.io/createdAt` annotation containing the current timestamp to your entity object |
|
|
14
|
+
| `catalog:scaffolded-from` | Adds `scaffoldedFrom` spec containing the template entityRef to your entity object |
|
|
15
|
+
| `catalog:annotate` | Allows you to annotate your entity object with specified label(s), annotation(s) and spec property(ies) |
|
|
16
|
+
|
|
17
|
+
To begin, install the module package into the backend workspace of your backstage instance:
|
|
18
|
+
|
|
19
|
+
```console
|
|
20
|
+
yarn workspace backend add @backstage-community/plugin-scaffolder-backend-module-annotator
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Registering the annotator action plugin with the backend system
|
|
24
|
+
|
|
25
|
+
To install the module into the [backend system](https://backstage.io/docs/backend-system/), add the following into the `packages/backend/src/index.ts` file:
|
|
26
|
+
|
|
27
|
+
```ts title="packages/backend/src/index.ts
|
|
28
|
+
const backend = createBackend();
|
|
29
|
+
|
|
30
|
+
// highlight-add-start
|
|
31
|
+
backend.add(
|
|
32
|
+
import('@backstage-community/plugin-scaffolder-backend-module-annotator'),
|
|
33
|
+
);
|
|
34
|
+
// highlight-add-end
|
|
35
|
+
|
|
36
|
+
backend.start();
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Creating custom actions for your templates using the annotator module
|
|
40
|
+
|
|
41
|
+
### Create the custom action
|
|
42
|
+
|
|
43
|
+
#### The `createAnnotatorAction` action accepts the following parameters:
|
|
44
|
+
|
|
45
|
+
| Parameter Name | Type | Required | Description |
|
|
46
|
+
| ---------------------------------- | :------: | :------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
47
|
+
| `actionId` | `string` | Yes | A unique id for the action. Default: `catalog:annotate`, please provide one or else it may conflict with the generic `catalog:annotate` custom action that is provided by this module. |
|
|
48
|
+
| `actionDescription` | `string` | No | A description of what the action accomplishes. Default: "Creates a new scaffolder action to annotate the entity object with specified label(s), annotation(s) and spec property(ies)." |
|
|
49
|
+
| `loggerInfoMsg` | `string` | No | A message that will be logged upon the execution of the action. Default: "Annotating your object" |
|
|
50
|
+
| `annotateEntityObject.labels` | `object` | No | Key-value pairs to be added to the `metadata.labels` of the entity |
|
|
51
|
+
| `annotateEntityObject.annotations` | `object` | No | Key-value pairs to be added to the `metadata.annotations` of the entity |
|
|
52
|
+
| `annotateEntityObject.spec` | `object` | No | Key-value pairs to be added to the `spec` of the entity. The value for each key can either be a string or an object with the key `readFromContext`, enabling users to specify the path in the context from which the value should be retrieved. |
|
|
53
|
+
|
|
54
|
+
1. Create your [custom action](https://backstage.io/docs/features/software-templates/writing-custom-actions#writing-your-custom-action)
|
|
55
|
+
|
|
56
|
+
2. Add the annotator module package `@backstage-community/plugin-scaffolder-backend-module-annotator` into your module's `package.json`
|
|
57
|
+
|
|
58
|
+
3. In the action file, add the following snippet to it:
|
|
59
|
+
|
|
60
|
+
```ts createAddCompanyTitleAction.ts
|
|
61
|
+
// highlight-add-start
|
|
62
|
+
import { createAnnotatorAction } from '@backstage-community/plugin-scaffolder-backend-module-annotator';
|
|
63
|
+
|
|
64
|
+
export const createAddCompanyTitleAction = () => {
|
|
65
|
+
return createAnnotatorAction(
|
|
66
|
+
'catalog:company-title',
|
|
67
|
+
'Creates a new `catalog:company-title` Scaffolder action to annotate scaffolded entities with the company title.',
|
|
68
|
+
'Annotating catalog-info.yaml with the company title',
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
// highlight-add-end
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
4. Install the custom action into your backstage instance following steps similar to the [installation instructions above](#installation)
|
|
75
|
+
|
|
76
|
+
### Use your custom action in your desired template(s)
|
|
77
|
+
|
|
78
|
+
#### The annotator template action accepts the following inputs
|
|
79
|
+
|
|
80
|
+
#### Input
|
|
81
|
+
|
|
82
|
+
| Parameter Name | Type | Required | Description |
|
|
83
|
+
| ---------------- | :------: | :------: | ------------------------------------------------------------------------------------------------------------------ |
|
|
84
|
+
| `labels` | `object` | No | Key-value pairs to be added to the `metadata.labels` of the entity |
|
|
85
|
+
| `annotations` | `object` | No | Key-value pairs to be added to the `metadata.annotations` of the entity |
|
|
86
|
+
| `spec` | `object` | No | Key-value pairs to be added to the `spec` of the entity |
|
|
87
|
+
| `entityFilePath` | `string` | No | The file path from which the YAML representation of the entity should be read |
|
|
88
|
+
| `objectYaml` | `object` | No | The YAML representation of the object/entity |
|
|
89
|
+
| `writeToFile` | `string` | No | The file path where the YAML representation of the entity should be stored. Default value is './catalog-info.yaml' |
|
|
90
|
+
|
|
91
|
+
#### Output
|
|
92
|
+
|
|
93
|
+
| Name | Type | Description |
|
|
94
|
+
| ----------------- | :------: | -------------------------------------------------------------------------------------------- |
|
|
95
|
+
| `annotatedObject` | `object` | The entity object marked with your specified annotation(s), label(s), and spec property(ies) |
|
|
96
|
+
|
|
97
|
+
To annotate the entity file, add your custom action to your template file after `Fetch Skeleton + Template` step. Please note that your custom action needs to be installed into the backstage instance running the software template.
|
|
98
|
+
|
|
99
|
+
```yaml
|
|
100
|
+
// highlight-add-start
|
|
101
|
+
- id: company-title
|
|
102
|
+
name: Add company title to catalog-info.yaml
|
|
103
|
+
action: catalog:company-title
|
|
104
|
+
input:
|
|
105
|
+
labels: {
|
|
106
|
+
company: 'My Company'
|
|
107
|
+
}
|
|
108
|
+
// highlight-add-end
|
|
109
|
+
```
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
4
|
+
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
5
|
+
var fs = require('fs-extra');
|
|
6
|
+
var yaml = require('yaml');
|
|
7
|
+
var getObjectToAnnotate = require('../../utils/getObjectToAnnotate.cjs.js');
|
|
8
|
+
var resolveSpec = require('../../utils/resolveSpec.cjs.js');
|
|
9
|
+
|
|
10
|
+
function _interopNamespaceCompat(e) {
|
|
11
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n.default = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var fs__namespace = /*#__PURE__*/_interopNamespaceCompat(fs);
|
|
29
|
+
var yaml__namespace = /*#__PURE__*/_interopNamespaceCompat(yaml);
|
|
30
|
+
|
|
31
|
+
const createAnnotatorAction = (actionId = "catalog:annotate", actionDescription, loggerInfoMsg, annotateEntityObjectProvider) => {
|
|
32
|
+
return pluginScaffolderNode.createTemplateAction({
|
|
33
|
+
id: actionId,
|
|
34
|
+
description: actionDescription || "Creates a new scaffolder action to annotate the entity object with specified label(s), annotation(s) and spec property(ies).",
|
|
35
|
+
schema: {
|
|
36
|
+
input: {
|
|
37
|
+
type: "object",
|
|
38
|
+
properties: {
|
|
39
|
+
labels: {
|
|
40
|
+
title: "Labels",
|
|
41
|
+
description: "Labels that will be applied to the `metadata.labels` of the entity object",
|
|
42
|
+
type: "object"
|
|
43
|
+
},
|
|
44
|
+
annotations: {
|
|
45
|
+
title: "Annotations",
|
|
46
|
+
description: "Annotations that will be applied to the `metadata.annotations` of the entity object",
|
|
47
|
+
type: "object"
|
|
48
|
+
},
|
|
49
|
+
spec: {
|
|
50
|
+
title: "Spec",
|
|
51
|
+
description: "Key-Value pair(s) that will be applied to the `spec` of the entity object",
|
|
52
|
+
type: "object"
|
|
53
|
+
},
|
|
54
|
+
entityFilePath: {
|
|
55
|
+
title: "Entity File Path",
|
|
56
|
+
description: "Path to the entity yaml you want to annotate",
|
|
57
|
+
type: "string"
|
|
58
|
+
},
|
|
59
|
+
objectYaml: {
|
|
60
|
+
title: "Object Yaml",
|
|
61
|
+
description: "Entity object yaml you want to annotate",
|
|
62
|
+
type: "object"
|
|
63
|
+
},
|
|
64
|
+
writeToFile: {
|
|
65
|
+
title: "Write To File",
|
|
66
|
+
description: "Path to the file you want to write. Default path `./catalog-info.yaml`",
|
|
67
|
+
type: "string"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
output: {
|
|
72
|
+
type: "object",
|
|
73
|
+
properties: {
|
|
74
|
+
annotatedObject: {
|
|
75
|
+
type: "object",
|
|
76
|
+
title: "The entity object annotated with your desired annotation(s), label(s) and spec property(ies)"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
async handler(ctx) {
|
|
82
|
+
const annotateEntityObject = annotateEntityObjectProvider?.();
|
|
83
|
+
let objToAnnotate;
|
|
84
|
+
if (ctx.input?.objectYaml) {
|
|
85
|
+
objToAnnotate = { ...ctx.input?.objectYaml };
|
|
86
|
+
} else {
|
|
87
|
+
objToAnnotate = await getObjectToAnnotate.getObjectToAnnotate(
|
|
88
|
+
ctx.workspacePath,
|
|
89
|
+
ctx.input?.entityFilePath
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
const annotatedObj = {
|
|
93
|
+
...objToAnnotate,
|
|
94
|
+
metadata: {
|
|
95
|
+
...objToAnnotate.metadata,
|
|
96
|
+
annotations: {
|
|
97
|
+
...objToAnnotate.metadata.annotations || {},
|
|
98
|
+
...annotateEntityObject?.annotations || {},
|
|
99
|
+
...ctx.input?.annotations || {}
|
|
100
|
+
},
|
|
101
|
+
labels: {
|
|
102
|
+
...objToAnnotate.metadata.labels || {},
|
|
103
|
+
...annotateEntityObject?.labels || {},
|
|
104
|
+
...ctx.input?.labels || {}
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
spec: {
|
|
108
|
+
...objToAnnotate.spec || {},
|
|
109
|
+
...resolveSpec.resolveSpec(annotateEntityObject?.spec, ctx),
|
|
110
|
+
...ctx.input?.spec || {}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const result = yaml__namespace.stringify(annotatedObj);
|
|
114
|
+
if (Object.keys(
|
|
115
|
+
annotateEntityObject?.labels || annotateEntityObject?.annotations || annotateEntityObject?.spec || ctx.input?.labels || ctx.input?.annotations || ctx.input?.spec || {}
|
|
116
|
+
).length > 0) {
|
|
117
|
+
ctx.logger.info(loggerInfoMsg || "Annotating your object");
|
|
118
|
+
await fs__namespace.writeFile(
|
|
119
|
+
backendPluginApi.resolveSafeChildPath(
|
|
120
|
+
ctx.workspacePath,
|
|
121
|
+
ctx.input?.writeToFile || "./catalog-info.yaml"
|
|
122
|
+
),
|
|
123
|
+
result,
|
|
124
|
+
"utf8"
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
ctx.output("annotatedObject", result);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
exports.createAnnotatorAction = createAnnotatorAction;
|
|
133
|
+
//# sourceMappingURL=annotator.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotator.cjs.js","sources":["../../../src/actions/annotator/annotator.ts"],"sourcesContent":["/*\n * Copyright 2024 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 */\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\n\nimport * as fs from 'fs-extra';\nimport * as yaml from 'yaml';\n\nimport { getObjectToAnnotate } from '../../utils/getObjectToAnnotate';\nimport { resolveSpec, Value } from '../../utils/resolveSpec';\n\n/**\n * Creates a new Scaffolder action to annotate an entity object with specified label(s), annotation(s) and spec property(ies).\n *\n */\n\nexport const createAnnotatorAction = (\n actionId: string = 'catalog:annotate',\n actionDescription?: string,\n loggerInfoMsg?: string,\n annotateEntityObjectProvider?: () => {\n annotations?: { [key: string]: string };\n labels?: { [key: string]: string };\n spec?: { [key: string]: Value };\n },\n) => {\n return createTemplateAction<{\n labels?: { [key: string]: string };\n annotations?: { [key: string]: string };\n spec?: { [key: string]: string };\n entityFilePath?: string;\n objectYaml?: { [key: string]: string };\n writeToFile?: string;\n }>({\n id: actionId,\n description:\n actionDescription ||\n 'Creates a new scaffolder action to annotate the entity object with specified label(s), annotation(s) and spec property(ies).',\n schema: {\n input: {\n type: 'object',\n properties: {\n labels: {\n title: 'Labels',\n description:\n 'Labels that will be applied to the `metadata.labels` of the entity object',\n type: 'object',\n },\n annotations: {\n title: 'Annotations',\n description:\n 'Annotations that will be applied to the `metadata.annotations` of the entity object',\n type: 'object',\n },\n spec: {\n title: 'Spec',\n description:\n 'Key-Value pair(s) that will be applied to the `spec` of the entity object',\n type: 'object',\n },\n entityFilePath: {\n title: 'Entity File Path',\n description: 'Path to the entity yaml you want to annotate',\n type: 'string',\n },\n objectYaml: {\n title: 'Object Yaml',\n description: 'Entity object yaml you want to annotate',\n type: 'object',\n },\n writeToFile: {\n title: 'Write To File',\n description:\n 'Path to the file you want to write. Default path `./catalog-info.yaml`',\n type: 'string',\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n annotatedObject: {\n type: 'object',\n title:\n 'The entity object annotated with your desired annotation(s), label(s) and spec property(ies)',\n },\n },\n },\n },\n async handler(ctx) {\n const annotateEntityObject = annotateEntityObjectProvider?.();\n let objToAnnotate: { [key: string]: any };\n\n if (ctx.input?.objectYaml) {\n objToAnnotate = { ...ctx.input?.objectYaml };\n } else {\n objToAnnotate = await getObjectToAnnotate(\n ctx.workspacePath,\n ctx.input?.entityFilePath,\n );\n }\n const annotatedObj = {\n ...objToAnnotate,\n metadata: {\n ...objToAnnotate.metadata,\n annotations: {\n ...(objToAnnotate.metadata.annotations || {}),\n ...(annotateEntityObject?.annotations || {}),\n ...(ctx.input?.annotations || {}),\n },\n labels: {\n ...(objToAnnotate.metadata.labels || {}),\n ...(annotateEntityObject?.labels || {}),\n ...(ctx.input?.labels || {}),\n },\n },\n spec: {\n ...(objToAnnotate.spec || {}),\n ...resolveSpec(annotateEntityObject?.spec, ctx),\n ...(ctx.input?.spec || {}),\n },\n };\n\n const result = yaml.stringify(annotatedObj);\n if (\n Object.keys(\n annotateEntityObject?.labels ||\n annotateEntityObject?.annotations ||\n annotateEntityObject?.spec ||\n ctx.input?.labels ||\n ctx.input?.annotations ||\n ctx.input?.spec ||\n {},\n ).length > 0\n ) {\n ctx.logger.info(loggerInfoMsg || 'Annotating your object');\n\n await fs.writeFile(\n resolveSafeChildPath(\n ctx.workspacePath,\n ctx.input?.writeToFile || './catalog-info.yaml',\n ),\n result,\n 'utf8',\n );\n }\n\n ctx.output('annotatedObject', result);\n },\n });\n};\n"],"names":["createTemplateAction","getObjectToAnnotate","resolveSpec","yaml","fs","resolveSafeChildPath"],"mappings":"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"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var annotator = require('../annotator/annotator.cjs.js');
|
|
4
|
+
|
|
5
|
+
const createScaffoldedFromAction = () => {
|
|
6
|
+
return annotator.createAnnotatorAction(
|
|
7
|
+
"catalog:scaffolded-from",
|
|
8
|
+
"Creates a new `catalog:scaffolded-from` scaffolder action to update a catalog-info.yaml with the entityRef of the template that created it.",
|
|
9
|
+
"Annotating catalog-info.yaml with template entityRef",
|
|
10
|
+
() => {
|
|
11
|
+
return {
|
|
12
|
+
spec: {
|
|
13
|
+
scaffoldedFrom: { readFromContext: "templateInfo.entityRef" }
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.createScaffoldedFromAction = createScaffoldedFromAction;
|
|
21
|
+
//# sourceMappingURL=createScaffoldedFromAction.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createScaffoldedFromAction.cjs.js","sources":["../../../src/actions/customActions/createScaffoldedFromAction.ts"],"sourcesContent":["/*\n * Copyright 2024 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 */\nimport { createAnnotatorAction } from '../annotator/annotator';\n\nexport const createScaffoldedFromAction = () => {\n return createAnnotatorAction(\n 'catalog:scaffolded-from',\n 'Creates a new `catalog:scaffolded-from` scaffolder action to update a catalog-info.yaml with the entityRef of the template that created it.',\n 'Annotating catalog-info.yaml with template entityRef',\n () => {\n return {\n spec: {\n scaffoldedFrom: { readFromContext: 'templateInfo.entityRef' },\n },\n };\n },\n );\n};\n"],"names":["createAnnotatorAction"],"mappings":";;;;AAiBO,MAAM,6BAA6B,MAAM;AAC9C,EAAO,OAAAA,+BAAA;AAAA,IACL,yBAAA;AAAA,IACA,6IAAA;AAAA,IACA,sDAAA;AAAA,IACA,MAAM;AACJ,MAAO,OAAA;AAAA,QACL,IAAM,EAAA;AAAA,UACJ,cAAA,EAAgB,EAAE,eAAA,EAAiB,wBAAyB;AAAA;AAC9D,OACF;AAAA;AACF,GACF;AACF;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var getCurrentTimestamp = require('../../utils/getCurrentTimestamp.cjs.js');
|
|
4
|
+
var annotator = require('../annotator/annotator.cjs.js');
|
|
5
|
+
|
|
6
|
+
const createTimestampAction = () => {
|
|
7
|
+
return annotator.createAnnotatorAction(
|
|
8
|
+
"catalog:timestamping",
|
|
9
|
+
"Creates a new `catalog:timestamping` Scaffolder action to annotate scaffolded entities with creation timestamp.",
|
|
10
|
+
"Annotating catalog-info.yaml with current timestamp",
|
|
11
|
+
() => {
|
|
12
|
+
return {
|
|
13
|
+
annotations: { "backstage.io/createdAt": getCurrentTimestamp.getCurrentTimestamp() }
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.createTimestampAction = createTimestampAction;
|
|
20
|
+
//# sourceMappingURL=createTimestampAction.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTimestampAction.cjs.js","sources":["../../../src/actions/customActions/createTimestampAction.ts"],"sourcesContent":["/*\n * Copyright 2024 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 */\nimport { getCurrentTimestamp } from '../../utils/getCurrentTimestamp';\nimport { createAnnotatorAction } from '../annotator/annotator';\n\nexport const createTimestampAction = () => {\n return createAnnotatorAction(\n 'catalog:timestamping',\n 'Creates a new `catalog:timestamping` Scaffolder action to annotate scaffolded entities with creation timestamp.',\n 'Annotating catalog-info.yaml with current timestamp',\n () => {\n return {\n annotations: { 'backstage.io/createdAt': getCurrentTimestamp() },\n };\n },\n );\n};\n"],"names":["createAnnotatorAction","getCurrentTimestamp"],"mappings":";;;;;AAkBO,MAAM,wBAAwB,MAAM;AACzC,EAAO,OAAAA,+BAAA;AAAA,IACL,sBAAA;AAAA,IACA,iHAAA;AAAA,IACA,qDAAA;AAAA,IACA,MAAM;AACJ,MAAO,OAAA;AAAA,QACL,WAAa,EAAA,EAAE,wBAA0B,EAAAC,uCAAA,EAAsB;AAAA,OACjE;AAAA;AACF,GACF;AACF;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var annotator = require('./actions/annotator/annotator.cjs.js');
|
|
6
|
+
var createTimestampAction = require('./actions/customActions/createTimestampAction.cjs.js');
|
|
7
|
+
var createScaffoldedFromAction = require('./actions/customActions/createScaffoldedFromAction.cjs.js');
|
|
8
|
+
var module$1 = require('./module.cjs.js');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.createAnnotatorAction = annotator.createAnnotatorAction;
|
|
13
|
+
exports.createTimestampAction = createTimestampAction.createTimestampAction;
|
|
14
|
+
exports.createScaffoldedFromAction = createScaffoldedFromAction.createScaffoldedFromAction;
|
|
15
|
+
exports.default = module$1.scaffolderCustomActionsScaffolderModule;
|
|
16
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import * as _backstage_plugin_scaffolder_node from '@backstage/plugin-scaffolder-node';
|
|
2
|
+
import * as _backstage_types_index from '@backstage/types/index';
|
|
3
|
+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
4
|
+
|
|
5
|
+
type Value = string | {
|
|
6
|
+
readFromContext: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new Scaffolder action to annotate an entity object with specified label(s), annotation(s) and spec property(ies).
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
declare const createAnnotatorAction: (actionId?: string, actionDescription?: string, loggerInfoMsg?: string, annotateEntityObjectProvider?: (() => {
|
|
14
|
+
annotations?: {
|
|
15
|
+
[key: string]: string;
|
|
16
|
+
} | undefined;
|
|
17
|
+
labels?: {
|
|
18
|
+
[key: string]: string;
|
|
19
|
+
} | undefined;
|
|
20
|
+
spec?: {
|
|
21
|
+
[key: string]: Value;
|
|
22
|
+
} | undefined;
|
|
23
|
+
}) | undefined) => _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
24
|
+
labels?: {
|
|
25
|
+
[key: string]: string;
|
|
26
|
+
} | undefined;
|
|
27
|
+
annotations?: {
|
|
28
|
+
[key: string]: string;
|
|
29
|
+
} | undefined;
|
|
30
|
+
spec?: {
|
|
31
|
+
[key: string]: string;
|
|
32
|
+
} | undefined;
|
|
33
|
+
entityFilePath?: string | undefined;
|
|
34
|
+
objectYaml?: {
|
|
35
|
+
[key: string]: string;
|
|
36
|
+
} | undefined;
|
|
37
|
+
writeToFile?: string | undefined;
|
|
38
|
+
}, _backstage_types_index.JsonObject>;
|
|
39
|
+
|
|
40
|
+
declare const createTimestampAction: () => _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
41
|
+
labels?: {
|
|
42
|
+
[key: string]: string;
|
|
43
|
+
} | undefined;
|
|
44
|
+
annotations?: {
|
|
45
|
+
[key: string]: string;
|
|
46
|
+
} | undefined;
|
|
47
|
+
spec?: {
|
|
48
|
+
[key: string]: string;
|
|
49
|
+
} | undefined;
|
|
50
|
+
entityFilePath?: string | undefined;
|
|
51
|
+
objectYaml?: {
|
|
52
|
+
[key: string]: string;
|
|
53
|
+
} | undefined;
|
|
54
|
+
writeToFile?: string | undefined;
|
|
55
|
+
}, _backstage_types_index.JsonObject>;
|
|
56
|
+
|
|
57
|
+
declare const createScaffoldedFromAction: () => _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
58
|
+
labels?: {
|
|
59
|
+
[key: string]: string;
|
|
60
|
+
} | undefined;
|
|
61
|
+
annotations?: {
|
|
62
|
+
[key: string]: string;
|
|
63
|
+
} | undefined;
|
|
64
|
+
spec?: {
|
|
65
|
+
[key: string]: string;
|
|
66
|
+
} | undefined;
|
|
67
|
+
entityFilePath?: string | undefined;
|
|
68
|
+
objectYaml?: {
|
|
69
|
+
[key: string]: string;
|
|
70
|
+
} | undefined;
|
|
71
|
+
writeToFile?: string | undefined;
|
|
72
|
+
}, _backstage_types_index.JsonObject>;
|
|
73
|
+
|
|
74
|
+
/***/
|
|
75
|
+
/**
|
|
76
|
+
* The annotator module for @backstage/plugin-scaffolder-backend.
|
|
77
|
+
*
|
|
78
|
+
* @alpha
|
|
79
|
+
*/
|
|
80
|
+
declare const scaffolderCustomActionsScaffolderModule: _backstage_backend_plugin_api.BackendFeature;
|
|
81
|
+
|
|
82
|
+
export { createAnnotatorAction, createScaffoldedFromAction, createTimestampAction, scaffolderCustomActionsScaffolderModule as default };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
4
|
+
var alpha = require('@backstage/plugin-scaffolder-node/alpha');
|
|
5
|
+
var annotator = require('./actions/annotator/annotator.cjs.js');
|
|
6
|
+
var createTimestampAction = require('./actions/customActions/createTimestampAction.cjs.js');
|
|
7
|
+
var createScaffoldedFromAction = require('./actions/customActions/createScaffoldedFromAction.cjs.js');
|
|
8
|
+
|
|
9
|
+
const scaffolderCustomActionsScaffolderModule = backendPluginApi.createBackendModule({
|
|
10
|
+
moduleId: "scaffolder-backend-scaffolder-annotator",
|
|
11
|
+
pluginId: "scaffolder",
|
|
12
|
+
register(env) {
|
|
13
|
+
env.registerInit({
|
|
14
|
+
deps: {
|
|
15
|
+
scaffolder: alpha.scaffolderActionsExtensionPoint
|
|
16
|
+
},
|
|
17
|
+
async init({ scaffolder }) {
|
|
18
|
+
scaffolder.addActions(createScaffoldedFromAction.createScaffoldedFromAction());
|
|
19
|
+
scaffolder.addActions(createTimestampAction.createTimestampAction());
|
|
20
|
+
scaffolder.addActions(annotator.createAnnotatorAction());
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
exports.scaffolderCustomActionsScaffolderModule = scaffolderCustomActionsScaffolderModule;
|
|
27
|
+
//# sourceMappingURL=module.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.cjs.js","sources":["../src/module.ts"],"sourcesContent":["/*\n * Copyright 2024 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 */\nimport { createBackendModule } from '@backstage/backend-plugin-api';\nimport { scaffolderActionsExtensionPoint } from '@backstage/plugin-scaffolder-node/alpha';\n\nimport {\n createAnnotatorAction,\n createScaffoldedFromAction,\n createTimestampAction,\n} from './actions';\n\n/***/\n/**\n * The annotator module for @backstage/plugin-scaffolder-backend.\n *\n * @alpha\n */\nexport const scaffolderCustomActionsScaffolderModule = createBackendModule({\n moduleId: 'scaffolder-backend-scaffolder-annotator',\n pluginId: 'scaffolder',\n register(env) {\n env.registerInit({\n deps: {\n scaffolder: scaffolderActionsExtensionPoint,\n },\n async init({ scaffolder }) {\n scaffolder.addActions(createScaffoldedFromAction());\n scaffolder.addActions(createTimestampAction());\n scaffolder.addActions(createAnnotatorAction());\n },\n });\n },\n});\n"],"names":["createBackendModule","scaffolderActionsExtensionPoint","createScaffoldedFromAction","createTimestampAction","createAnnotatorAction"],"mappings":";;;;;;;;AA8BO,MAAM,0CAA0CA,oCAAoB,CAAA;AAAA,EACzE,QAAU,EAAA,yCAAA;AAAA,EACV,QAAU,EAAA,YAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,UAAY,EAAAC;AAAA,OACd;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,UAAA,EAAc,EAAA;AACzB,QAAW,UAAA,CAAA,UAAA,CAAWC,uDAA4B,CAAA;AAClD,QAAW,UAAA,CAAA,UAAA,CAAWC,6CAAuB,CAAA;AAC7C,QAAW,UAAA,CAAA,UAAA,CAAWC,iCAAuB,CAAA;AAAA;AAC/C,KACD,CAAA;AAAA;AAEL,CAAC;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const getCurrentTimestamp = (date) => {
|
|
4
|
+
const dateObj = new Date(Date.now());
|
|
5
|
+
return `${dateObj.toLocaleDateString()}, ${dateObj.toLocaleTimeString(
|
|
6
|
+
"en-US"
|
|
7
|
+
)}`;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
exports.getCurrentTimestamp = getCurrentTimestamp;
|
|
11
|
+
//# sourceMappingURL=getCurrentTimestamp.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCurrentTimestamp.cjs.js","sources":["../../src/utils/getCurrentTimestamp.ts"],"sourcesContent":["/*\n * Copyright 2024 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 */\nexport const getCurrentTimestamp = (date?: Date) => {\n const dateObj = date || new Date(Date.now());\n return `${dateObj.toLocaleDateString()}, ${dateObj.toLocaleTimeString(\n 'en-US',\n )}`;\n};\n"],"names":[],"mappings":";;AAea,MAAA,mBAAA,GAAsB,CAAC,IAAgB,KAAA;AAClD,EAAA,MAAM,UAAkB,IAAI,IAAK,CAAA,IAAA,CAAK,KAAK,CAAA;AAC3C,EAAA,OAAO,CAAG,EAAA,OAAA,CAAQ,kBAAmB,EAAC,KAAK,OAAQ,CAAA,kBAAA;AAAA,IACjD;AAAA,GACD,CAAA,CAAA;AACH;;;;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
4
|
+
var fs = require('fs-extra');
|
|
5
|
+
var yaml = require('yaml');
|
|
6
|
+
|
|
7
|
+
function _interopNamespaceCompat(e) {
|
|
8
|
+
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
9
|
+
var n = Object.create(null);
|
|
10
|
+
if (e) {
|
|
11
|
+
Object.keys(e).forEach(function (k) {
|
|
12
|
+
if (k !== 'default') {
|
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return e[k]; }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var fs__namespace = /*#__PURE__*/_interopNamespaceCompat(fs);
|
|
26
|
+
var yaml__namespace = /*#__PURE__*/_interopNamespaceCompat(yaml);
|
|
27
|
+
|
|
28
|
+
const getObjectToAnnotate = async (workspacePath, objectFilePath) => {
|
|
29
|
+
const obj = await fs__namespace.readFile(
|
|
30
|
+
backendPluginApi.resolveSafeChildPath(
|
|
31
|
+
workspacePath,
|
|
32
|
+
objectFilePath || "./catalog-info.yaml"
|
|
33
|
+
),
|
|
34
|
+
"utf8"
|
|
35
|
+
);
|
|
36
|
+
return yaml__namespace.parse(obj);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
exports.getObjectToAnnotate = getObjectToAnnotate;
|
|
40
|
+
//# sourceMappingURL=getObjectToAnnotate.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getObjectToAnnotate.cjs.js","sources":["../../src/utils/getObjectToAnnotate.ts"],"sourcesContent":["/*\n * Copyright 2024 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 */\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\n\nimport * as fs from 'fs-extra';\nimport * as yaml from 'yaml';\n\nexport const getObjectToAnnotate = async (\n workspacePath: string,\n objectFilePath: string | undefined,\n): Promise<{ [key: string]: any }> => {\n const obj = await fs.readFile(\n resolveSafeChildPath(\n workspacePath,\n objectFilePath || './catalog-info.yaml',\n ),\n 'utf8',\n );\n\n return yaml.parse(obj);\n};\n"],"names":["fs","resolveSafeChildPath","yaml"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBa,MAAA,mBAAA,GAAsB,OACjC,aAAA,EACA,cACoC,KAAA;AACpC,EAAM,MAAA,GAAA,GAAM,MAAMA,aAAG,CAAA,QAAA;AAAA,IACnBC,qCAAA;AAAA,MACE,aAAA;AAAA,MACA,cAAkB,IAAA;AAAA,KACpB;AAAA,IACA;AAAA,GACF;AAEA,EAAO,OAAAC,eAAA,CAAK,MAAM,GAAG,CAAA;AACvB;;;;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var lodash = require('lodash');
|
|
4
|
+
|
|
5
|
+
const resolveSpec = (spec, ctx) => {
|
|
6
|
+
if (!spec || Object.keys(spec).length === 0) {
|
|
7
|
+
return {};
|
|
8
|
+
}
|
|
9
|
+
return Object.keys(spec).reduce((acc, s) => {
|
|
10
|
+
const val = spec[s];
|
|
11
|
+
return {
|
|
12
|
+
...acc,
|
|
13
|
+
...{
|
|
14
|
+
[`${s}`]: typeof val === "string" ? spec[s] : lodash.get(ctx, val.readFromContext)
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}, {});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.resolveSpec = resolveSpec;
|
|
21
|
+
//# sourceMappingURL=resolveSpec.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveSpec.cjs.js","sources":["../../src/utils/resolveSpec.ts"],"sourcesContent":["/*\n * Copyright 2024 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 */\nimport type { ActionContext } from '@backstage/plugin-scaffolder-node';\n\nimport { get } from 'lodash';\n\nexport type Value = string | { readFromContext: string };\n\nexport const resolveSpec = (\n spec: { [key: string]: Value } | undefined,\n ctx: ActionContext<any>,\n) => {\n if (!spec || Object.keys(spec).length === 0) {\n return {};\n }\n return Object.keys(spec).reduce((acc, s) => {\n const val = spec[s];\n return {\n ...acc,\n ...{\n [`${s}`]:\n typeof val === 'string' ? spec[s] : get(ctx, val.readFromContext),\n },\n };\n }, {});\n};\n"],"names":["get"],"mappings":";;;;AAqBa,MAAA,WAAA,GAAc,CACzB,IAAA,EACA,GACG,KAAA;AACH,EAAA,IAAI,CAAC,IAAQ,IAAA,MAAA,CAAO,KAAK,IAAI,CAAA,CAAE,WAAW,CAAG,EAAA;AAC3C,IAAA,OAAO,EAAC;AAAA;AAEV,EAAA,OAAO,OAAO,IAAK,CAAA,IAAI,EAAE,MAAO,CAAA,CAAC,KAAK,CAAM,KAAA;AAC1C,IAAM,MAAA,GAAA,GAAM,KAAK,CAAC,CAAA;AAClB,IAAO,OAAA;AAAA,MACL,GAAG,GAAA;AAAA,MACH,GAAG;AAAA,QACD,CAAC,CAAA,EAAG,CAAC,CAAA,CAAE,GACL,OAAO,GAAA,KAAQ,QAAW,GAAA,IAAA,CAAK,CAAC,CAAA,GAAIA,UAAI,CAAA,GAAA,EAAK,IAAI,eAAe;AAAA;AACpE,KACF;AAAA,GACF,EAAG,EAAE,CAAA;AACP;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@backstage-community/plugin-scaffolder-backend-module-annotator",
|
|
3
|
+
"description": "The annotator module for @backstage/plugin-scaffolder-backend",
|
|
4
|
+
"version": "2.2.2",
|
|
5
|
+
"main": "./dist/index.cjs.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"backstage": {
|
|
12
|
+
"role": "backend-plugin-module",
|
|
13
|
+
"supported-versions": "1.32.5",
|
|
14
|
+
"pluginId": "scaffolder",
|
|
15
|
+
"pluginPackage": "@backstage/plugin-scaffolder-backend"
|
|
16
|
+
},
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"backstage": "@backstage/BackendFeature",
|
|
20
|
+
"require": "./dist/index.cjs.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.cjs.js"
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"start": "backstage-cli package start",
|
|
28
|
+
"build": "backstage-cli package build",
|
|
29
|
+
"lint:check": "backstage-cli package lint",
|
|
30
|
+
"lint:fix": "backstage-cli package lint --fix",
|
|
31
|
+
"test": "backstage-cli package test --passWithNoTests --coverage",
|
|
32
|
+
"clean": "backstage-cli package clean",
|
|
33
|
+
"prepack": "backstage-cli package prepack",
|
|
34
|
+
"postpack": "backstage-cli package postpack",
|
|
35
|
+
"lodash": "^4.17.21",
|
|
36
|
+
"tsc": "tsc",
|
|
37
|
+
"prettier:check": "prettier --ignore-unknown --check .",
|
|
38
|
+
"prettier:fix": "prettier --ignore-unknown --write ."
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@backstage/backend-plugin-api": "^1.0.1",
|
|
42
|
+
"@backstage/plugin-scaffolder-node": "^0.5.0",
|
|
43
|
+
"fs-extra": "^11.2.0",
|
|
44
|
+
"lodash": "^4.17.21",
|
|
45
|
+
"yaml": "^2.0.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@backstage/backend-test-utils": "1.0.2",
|
|
49
|
+
"@backstage/cli": "0.28.2",
|
|
50
|
+
"@types/fs-extra": "^11.0.4",
|
|
51
|
+
"@types/lodash": "^4.17.13",
|
|
52
|
+
"prettier": "3.3.3"
|
|
53
|
+
},
|
|
54
|
+
"files": [
|
|
55
|
+
"dist",
|
|
56
|
+
"config.d.ts"
|
|
57
|
+
],
|
|
58
|
+
"repository": {
|
|
59
|
+
"type": "git",
|
|
60
|
+
"url": "https://github.com/backstage/community-plugins",
|
|
61
|
+
"directory": "workspaces/scaffolder-backend-module-annotator/plugins/scaffolder-backend-module-annotator"
|
|
62
|
+
},
|
|
63
|
+
"keywords": [
|
|
64
|
+
"support:tech-preview",
|
|
65
|
+
"lifecycle:active",
|
|
66
|
+
"backstage",
|
|
67
|
+
"plugin"
|
|
68
|
+
],
|
|
69
|
+
"bugs": "https://github.com/backstage/community-plugins/issues",
|
|
70
|
+
"author": "The Backstage Community"
|
|
71
|
+
}
|