@backstage/plugin-scaffolder-backend-module-yeoman 0.0.0-nightly-202192322437
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 +9 -0
- package/README.md +156 -0
- package/dist/index.cjs.js +54 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/package.json +36 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @backstage/plugin-scaffolder-backend-module-yeoman
|
|
2
|
+
|
|
3
|
+
## 0.0.0-nightly-202192322437
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
- 10615525f3: Switch to use the json and observable types from `@backstage/types`
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @backstage/plugin-scaffolder-backend@0.0.0-nightly-202192322437
|
|
9
|
+
- @backstage/config@0.0.0-nightly-202192322437
|
package/README.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# scaffolder-backend-module-yeoman
|
|
2
|
+
|
|
3
|
+
Welcome to the `run:yeoman` action for the `scaffolder-backend`.
|
|
4
|
+
|
|
5
|
+
## Getting started
|
|
6
|
+
|
|
7
|
+
You need to configure the action in your backend:
|
|
8
|
+
|
|
9
|
+
## From your Backstage root directory
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
cd packages/backend
|
|
13
|
+
yarn add @backstage/plugin-scaffolder-backend-module-yeoman
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Configure the action:
|
|
17
|
+
(you can check the [docs](https://backstage.io/docs/features/software-templates/writing-custom-actions#registering-custom-actions) to see all options):
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
// packages/backend/src/plugins/scaffolder.ts
|
|
21
|
+
|
|
22
|
+
const actions = [
|
|
23
|
+
createRunYeomanAction(),
|
|
24
|
+
...createBuiltInActions({
|
|
25
|
+
containerRunner,
|
|
26
|
+
integrations,
|
|
27
|
+
config,
|
|
28
|
+
catalogClient,
|
|
29
|
+
reader,
|
|
30
|
+
}),
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
return await createRouter({
|
|
34
|
+
containerRunner,
|
|
35
|
+
logger,
|
|
36
|
+
config,
|
|
37
|
+
database,
|
|
38
|
+
catalogClient,
|
|
39
|
+
reader,
|
|
40
|
+
actions,
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
After that you can use the action in your template:
|
|
45
|
+
|
|
46
|
+
```yaml
|
|
47
|
+
apiVersion: backstage.io/v1beta2
|
|
48
|
+
kind: Template
|
|
49
|
+
metadata:
|
|
50
|
+
name: yeoman-demo
|
|
51
|
+
title: Yeoman Test
|
|
52
|
+
description: Cookiecutter example
|
|
53
|
+
spec:
|
|
54
|
+
owner: backstage/techdocs-core
|
|
55
|
+
type: service
|
|
56
|
+
|
|
57
|
+
parameters:
|
|
58
|
+
- title: Fill in some steps
|
|
59
|
+
required:
|
|
60
|
+
- name
|
|
61
|
+
- owner
|
|
62
|
+
properties:
|
|
63
|
+
name:
|
|
64
|
+
title: Name
|
|
65
|
+
type: string
|
|
66
|
+
description: Unique name of the component
|
|
67
|
+
ui:autofocus: true
|
|
68
|
+
ui:options:
|
|
69
|
+
rows: 5
|
|
70
|
+
owner:
|
|
71
|
+
title: Owner
|
|
72
|
+
type: string
|
|
73
|
+
description: Owner of the component
|
|
74
|
+
ui:field: OwnerPicker
|
|
75
|
+
ui:options:
|
|
76
|
+
allowedKinds:
|
|
77
|
+
- Group
|
|
78
|
+
system:
|
|
79
|
+
title: System
|
|
80
|
+
type: string
|
|
81
|
+
description: System of the component
|
|
82
|
+
ui:field: EntityPicker
|
|
83
|
+
ui:options:
|
|
84
|
+
allowedKinds:
|
|
85
|
+
- System
|
|
86
|
+
defaultKind: System
|
|
87
|
+
|
|
88
|
+
- title: Choose a location
|
|
89
|
+
required:
|
|
90
|
+
- repoUrl
|
|
91
|
+
- dryRun
|
|
92
|
+
properties:
|
|
93
|
+
repoUrl:
|
|
94
|
+
title: Repository Location
|
|
95
|
+
type: string
|
|
96
|
+
ui:field: RepoUrlPicker
|
|
97
|
+
ui:options:
|
|
98
|
+
allowedHosts:
|
|
99
|
+
- github.com
|
|
100
|
+
dryRun:
|
|
101
|
+
title: Only perform a dry run, don't publish anything
|
|
102
|
+
type: boolean
|
|
103
|
+
default: false
|
|
104
|
+
|
|
105
|
+
steps:
|
|
106
|
+
- id: yeoman
|
|
107
|
+
name: Yeoman
|
|
108
|
+
action: run:yeoman
|
|
109
|
+
input:
|
|
110
|
+
namespace: 'org:codeowners'
|
|
111
|
+
options:
|
|
112
|
+
codeowners: '@{{ parameters.owner }}'
|
|
113
|
+
|
|
114
|
+
- id: publish
|
|
115
|
+
if: '{{ not parameters.dryRun }}'
|
|
116
|
+
name: Publish
|
|
117
|
+
action: publish:github
|
|
118
|
+
input:
|
|
119
|
+
allowedHosts: ['github.com']
|
|
120
|
+
description: 'This is {{ parameters.name }}'
|
|
121
|
+
repoUrl: '{{ parameters.repoUrl }}'
|
|
122
|
+
|
|
123
|
+
- id: register
|
|
124
|
+
if: '{{ not parameters.dryRun }}'
|
|
125
|
+
name: Register
|
|
126
|
+
action: catalog:register
|
|
127
|
+
input:
|
|
128
|
+
repoContentsUrl: '{{ steps.publish.output.repoContentsUrl }}'
|
|
129
|
+
catalogInfoPath: '/catalog-info.yaml'
|
|
130
|
+
|
|
131
|
+
- name: Results
|
|
132
|
+
if: '{{ parameters.dryRun }}'
|
|
133
|
+
action: debug:log
|
|
134
|
+
input:
|
|
135
|
+
listWorkspace: true
|
|
136
|
+
|
|
137
|
+
output:
|
|
138
|
+
links:
|
|
139
|
+
- title: Repository
|
|
140
|
+
url: '{{ steps.publish.output.remoteUrl }}'
|
|
141
|
+
- title: Open in catalog
|
|
142
|
+
icon: 'catalog'
|
|
143
|
+
entityRef: '{{ steps.register.output.entityRef }}'
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
You can also visit the `/create/actions` route in your Backstage application to find out more about the parameters this action accepts when it's installed to configure how you like.
|
|
147
|
+
|
|
148
|
+
### Yeoman Generators setup
|
|
149
|
+
|
|
150
|
+
Yeoman generator should be installed a dependency of your `backstage/packages/backend` in `package.json`
|
|
151
|
+
|
|
152
|
+
```package.json
|
|
153
|
+
"generator-name": "^1.2.3"
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Alternatively it can be installed globally in the environment using, e.g.: `npm install -g generator-name`.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var pluginScaffolderBackend = require('@backstage/plugin-scaffolder-backend');
|
|
6
|
+
|
|
7
|
+
async function yeomanRun(workspace, namespace, args, opts) {
|
|
8
|
+
const yeoman = require("yeoman-environment");
|
|
9
|
+
const generator = yeoman.lookupGenerator(namespace);
|
|
10
|
+
const env = yeoman.createEnv(void 0, {cwd: workspace});
|
|
11
|
+
env.register(generator, namespace);
|
|
12
|
+
const yeomanArgs = [namespace, ...args != null ? args : []];
|
|
13
|
+
await env.run(yeomanArgs, opts);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function createRunYeomanAction() {
|
|
17
|
+
return pluginScaffolderBackend.createTemplateAction({
|
|
18
|
+
id: "run:yeoman",
|
|
19
|
+
description: "Runs Yeoman on an installed Yeoman generator",
|
|
20
|
+
schema: {
|
|
21
|
+
input: {
|
|
22
|
+
type: "object",
|
|
23
|
+
required: ["namespace"],
|
|
24
|
+
properties: {
|
|
25
|
+
namespace: {
|
|
26
|
+
title: "Generator Namespace",
|
|
27
|
+
description: "Yeoman generator namespace, e.g: node:app",
|
|
28
|
+
type: "string"
|
|
29
|
+
},
|
|
30
|
+
args: {
|
|
31
|
+
title: "Generator Arguments",
|
|
32
|
+
description: "Arguments to pass on to Yeoman for templating",
|
|
33
|
+
type: "array",
|
|
34
|
+
items: {
|
|
35
|
+
type: "string"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
options: {
|
|
39
|
+
title: "Generator Options",
|
|
40
|
+
description: "Options to pass on to Yeoman for templating",
|
|
41
|
+
type: "object"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
async handler(ctx) {
|
|
47
|
+
ctx.logger.info(`Templating using Yeoman generator: ${ctx.input.namespace}`);
|
|
48
|
+
await yeomanRun(ctx.workspacePath, ctx.input.namespace, ctx.input.args, ctx.input.options);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
exports.createRunYeomanAction = createRunYeomanAction;
|
|
54
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/actions/run/yeomanRun.ts","../src/actions/run/yeoman.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 { JsonObject } from '@backstage/types';\n\n/*\n * This module should use '@types/yeoman-environment' eventually as soon as '@types/yeoman-environment' supports\n * the latest version of Yeoman -> 3.x. Then it will be possible to test this module with jest.\n */\n\nexport async function yeomanRun(\n workspace: string,\n namespace: string,\n args?: string[],\n opts?: JsonObject,\n) {\n const yeoman = require('yeoman-environment');\n const generator = yeoman.lookupGenerator(namespace);\n const env = yeoman.createEnv(undefined, { cwd: workspace });\n env.register(generator, namespace);\n const yeomanArgs = [namespace, ...(args ?? [])];\n await env.run(yeomanArgs, opts);\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 { JsonObject } from '@backstage/types';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-backend';\nimport { yeomanRun } from './yeomanRun';\n\nexport function createRunYeomanAction() {\n return createTemplateAction<{\n namespace: string;\n args?: string[];\n options?: JsonObject;\n }>({\n id: 'run:yeoman',\n description: 'Runs Yeoman on an installed Yeoman generator',\n schema: {\n input: {\n type: 'object',\n required: ['namespace'],\n properties: {\n namespace: {\n title: 'Generator Namespace',\n description: 'Yeoman generator namespace, e.g: node:app',\n type: 'string',\n },\n args: {\n title: 'Generator Arguments',\n description: 'Arguments to pass on to Yeoman for templating',\n type: 'array',\n items: {\n type: 'string',\n },\n },\n options: {\n title: 'Generator Options',\n description: 'Options to pass on to Yeoman for templating',\n type: 'object',\n },\n },\n },\n },\n async handler(ctx) {\n ctx.logger.info(\n `Templating using Yeoman generator: ${ctx.input.namespace}`,\n );\n await yeomanRun(\n ctx.workspacePath,\n ctx.input.namespace,\n ctx.input.args,\n ctx.input.options,\n );\n },\n });\n}\n"],"names":["createTemplateAction"],"mappings":";;;;;;yBAwBE,WACA,WACA,MACA,MACA;AACA,QAAM,SAAS,QAAQ;AACvB,QAAM,YAAY,OAAO,gBAAgB;AACzC,QAAM,MAAM,OAAO,UAAU,QAAW,CAAE,KAAK;AAC/C,MAAI,SAAS,WAAW;AACxB,QAAM,aAAa,CAAC,WAAW,GAAI,sBAAQ;AAC3C,QAAM,IAAI,IAAI,YAAY;AAAA;;iCCdY;AACtC,SAAOA,6CAIJ;AAAA,IACD,IAAI;AAAA,IACJ,aAAa;AAAA,IACb,QAAQ;AAAA,MACN,OAAO;AAAA,QACL,MAAM;AAAA,QACN,UAAU,CAAC;AAAA,QACX,YAAY;AAAA,UACV,WAAW;AAAA,YACT,OAAO;AAAA,YACP,aAAa;AAAA,YACb,MAAM;AAAA;AAAA,UAER,MAAM;AAAA,YACJ,OAAO;AAAA,YACP,aAAa;AAAA,YACb,MAAM;AAAA,YACN,OAAO;AAAA,cACL,MAAM;AAAA;AAAA;AAAA,UAGV,SAAS;AAAA,YACP,OAAO;AAAA,YACP,aAAa;AAAA,YACb,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,UAKR,QAAQ,KAAK;AACjB,UAAI,OAAO,KACT,sCAAsC,IAAI,MAAM;AAElD,YAAM,UACJ,IAAI,eACJ,IAAI,MAAM,WACV,IAAI,MAAM,MACV,IAAI,MAAM;AAAA;AAAA;AAAA;;;;"}
|
package/dist/index.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@backstage/plugin-scaffolder-backend-module-yeoman",
|
|
3
|
+
"version": "0.0.0-nightly-202192322437",
|
|
4
|
+
"main": "dist/index.cjs.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"private": false,
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public",
|
|
10
|
+
"main": "dist/index.cjs.js",
|
|
11
|
+
"types": "dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"start": "backstage-cli backend:dev",
|
|
15
|
+
"build": "backstage-cli backend:build",
|
|
16
|
+
"lint": "backstage-cli lint",
|
|
17
|
+
"test": "backstage-cli test",
|
|
18
|
+
"prepack": "backstage-cli prepack",
|
|
19
|
+
"postpack": "backstage-cli postpack",
|
|
20
|
+
"clean": "backstage-cli clean"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@backstage/config": "^0.0.0-nightly-202192322437",
|
|
24
|
+
"@backstage/plugin-scaffolder-backend": "^0.0.0-nightly-202192322437",
|
|
25
|
+
"@backstage/types": "^0.1.1",
|
|
26
|
+
"winston": "^3.2.1",
|
|
27
|
+
"yeoman-environment": "^3.6.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@backstage/backend-common": "^0.0.0-nightly-202192322437",
|
|
31
|
+
"@types/jest": "^26.0.7"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
]
|
|
36
|
+
}
|