@shawncheng888/plugin-scaffolder-backend-module-markdown-merge 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +250 -0
- package/dist/actions/markdownMerge.cjs.js +99 -0
- package/dist/actions/markdownMerge.cjs.js.map +1 -0
- package/dist/actions/merge.cjs.js +65 -0
- package/dist/actions/merge.cjs.js.map +1 -0
- package/dist/index.cjs.js +12 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +65 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
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 tracking or otherwise improving the Work,
|
|
59
|
+
but excludes 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, attribution and other
|
|
102
|
+
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 describing the origin of the Work and
|
|
141
|
+
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 Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Shawn Cheng
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# Backstage Scaffolder Markdown Merge
|
|
2
|
+
|
|
3
|
+
[](https://github.com/joint-song/plugin-scaffolder-backend-module-markdown-merge/actions/workflows/ci.yml)
|
|
4
|
+
|
|
5
|
+
A [Backstage](https://backstage.io) scaffolder action that merges multiple Markdown fragments into a target document at named slot markers. Useful for composing `AGENTS.md`, `README.md`, `CONTRIBUTING.md`, and other Markdown files from reusable, independently-maintained fragments during Software Template execution.
|
|
6
|
+
|
|
7
|
+
The action id is `markdown:merge`.
|
|
8
|
+
|
|
9
|
+
## Slot Markers
|
|
10
|
+
|
|
11
|
+
The action looks for HTML-comment-style markers in the target file:
|
|
12
|
+
|
|
13
|
+
```markdown
|
|
14
|
+
<!-- MD_SLOT: NAME -->
|
|
15
|
+
... content to be replaced or appended to ...
|
|
16
|
+
<!-- /MD_SLOT: NAME -->
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
A single opening tag is also accepted; the closing tag is auto-generated on first merge:
|
|
20
|
+
|
|
21
|
+
```markdown
|
|
22
|
+
<!-- MD_SLOT: NAME -->
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The marker name `MD_SLOT` was chosen to avoid collision with HTML `<slot>` elements and common templating engines.
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
In your Backstage project, add this action to the backend:
|
|
30
|
+
|
|
31
|
+
```console
|
|
32
|
+
yarn workspace backend add @shawncheng888/plugin-scaffolder-backend-module-markdown-merge
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Then register the action in `packages/backend/src/index.ts`:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
// packages/backend/src/index.ts
|
|
39
|
+
import { createBackend } from '@backstage/backend-defaults';
|
|
40
|
+
|
|
41
|
+
const backend = createBackend();
|
|
42
|
+
// ... other backend.add(...) calls
|
|
43
|
+
backend.add(import('backstage-plugin-scaffolder-markdown-merge'));
|
|
44
|
+
|
|
45
|
+
backend.start();
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
Add a step to your Software Template:
|
|
51
|
+
|
|
52
|
+
```yaml
|
|
53
|
+
# template.yaml
|
|
54
|
+
spec:
|
|
55
|
+
type: markdown-merge
|
|
56
|
+
steps:
|
|
57
|
+
- id: merge-docs
|
|
58
|
+
action: markdown:merge
|
|
59
|
+
input:
|
|
60
|
+
path: AGENTS.md
|
|
61
|
+
slots:
|
|
62
|
+
- name: coding-standards
|
|
63
|
+
fragmentPath: fragments/coding-standards.md
|
|
64
|
+
- name: deployment
|
|
65
|
+
fragmentPath: fragments/deploy.md
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Input parameters
|
|
69
|
+
|
|
70
|
+
| Name | Type | Required | Default | Description |
|
|
71
|
+
| -------------------- | ------------------------------------------ | -------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
72
|
+
| `path` | `string` | Yes | — | Path to the target Markdown file, relative to the scaffolder workspace (e.g. `AGENTS.md`). |
|
|
73
|
+
| `slots` | `Array<{ name, fragmentPath }>` | Yes | — | Fragments to merge in. `name` is the slot marker name (matches `MD_SLOT: <name>`); `fragmentPath` is the path to the fragment file, relative to the workspace. |
|
|
74
|
+
| `mode` | `'replace' \| 'append'` | No | `replace` | How to merge into a paired slot. `replace` overwrites the existing content between the markers; `append` keeps it and inserts the fragment after it. Has no effect for the single-tag fallback. |
|
|
75
|
+
| `onFragmentMissing` | `'error' \| 'warn' \| 'ignore'` | No | `warn` | Behavior when a fragment file does not exist. `error` throws and fails the step; `warn` logs a warning and skips the slot; `ignore` skips silently. |
|
|
76
|
+
| `onSlotMissing` | `'error' \| 'warn' \| 'ignore'` | No | `warn` | Behavior when no slot marker is found in the target file. `error` throws and fails the step; `warn` logs a warning and continues with the next slot; `ignore` continues silently. |
|
|
77
|
+
|
|
78
|
+
The target file itself is always required; a missing target file fails the step regardless of these options.
|
|
79
|
+
|
|
80
|
+
### Examples
|
|
81
|
+
|
|
82
|
+
#### Replace mode (default)
|
|
83
|
+
|
|
84
|
+
Target file before merge (`AGENTS.md`):
|
|
85
|
+
|
|
86
|
+
```markdown
|
|
87
|
+
# Project
|
|
88
|
+
|
|
89
|
+
## Coding standards
|
|
90
|
+
<!-- MD_SLOT: coding-standards -->
|
|
91
|
+
PLACEHOLDER
|
|
92
|
+
<!-- /MD_SLOT: coding-standards -->
|
|
93
|
+
|
|
94
|
+
## Deployment
|
|
95
|
+
<!-- MD_SLOT: deployment -->
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Fragment file (`fragments/coding-standards.md`):
|
|
99
|
+
|
|
100
|
+
```markdown
|
|
101
|
+
- Use TypeScript
|
|
102
|
+
- Run `yarn lint` before committing
|
|
103
|
+
- Follow Conventional Commits for PR titles
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
After execution, `AGENTS.md` becomes:
|
|
107
|
+
|
|
108
|
+
```markdown
|
|
109
|
+
# Project
|
|
110
|
+
|
|
111
|
+
## Coding standards
|
|
112
|
+
<!-- MD_SLOT: coding-standards -->
|
|
113
|
+
- Use TypeScript
|
|
114
|
+
- Run `yarn lint` before committing
|
|
115
|
+
- Follow Conventional Commits for PR titles
|
|
116
|
+
<!-- /MD_SLOT: coding-standards -->
|
|
117
|
+
|
|
118
|
+
## Deployment
|
|
119
|
+
<!-- MD_SLOT: deployment -->
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### Append mode
|
|
123
|
+
|
|
124
|
+
With `mode: append`, the existing content between paired markers is preserved and the fragment is appended after it:
|
|
125
|
+
|
|
126
|
+
```yaml
|
|
127
|
+
- id: merge-docs
|
|
128
|
+
action: markdown:merge
|
|
129
|
+
input:
|
|
130
|
+
path: AGENTS.md
|
|
131
|
+
mode: append
|
|
132
|
+
slots:
|
|
133
|
+
- name: deployment
|
|
134
|
+
fragmentPath: fragments/deploy.md
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
If the target previously contained:
|
|
138
|
+
|
|
139
|
+
```markdown
|
|
140
|
+
<!-- MD_SLOT: deployment -->
|
|
141
|
+
Existing step 1
|
|
142
|
+
Existing step 2
|
|
143
|
+
<!-- /MD_SLOT: deployment -->
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
After append, it becomes:
|
|
147
|
+
|
|
148
|
+
```markdown
|
|
149
|
+
<!-- MD_SLOT: deployment -->
|
|
150
|
+
Existing step 1
|
|
151
|
+
Existing step 2
|
|
152
|
+
New fragment content
|
|
153
|
+
<!-- /MD_SLOT: deployment -->
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
#### Single-tag fallback
|
|
157
|
+
|
|
158
|
+
If the target contains only an opening tag:
|
|
159
|
+
|
|
160
|
+
```markdown
|
|
161
|
+
<!-- MD_SLOT: optional-section -->
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
After merge, the action auto-completes it:
|
|
165
|
+
|
|
166
|
+
```markdown
|
|
167
|
+
<!-- MD_SLOT: optional-section -->
|
|
168
|
+
<fragment content>
|
|
169
|
+
<!-- /MD_SLOT: optional-section -->
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
This is convenient for templates that minimize placeholder boilerplate.
|
|
173
|
+
|
|
174
|
+
#### Strict mode
|
|
175
|
+
|
|
176
|
+
To fail loudly on configuration mistakes:
|
|
177
|
+
|
|
178
|
+
```yaml
|
|
179
|
+
- id: merge-docs
|
|
180
|
+
action: markdown:merge
|
|
181
|
+
input:
|
|
182
|
+
path: AGENTS.md
|
|
183
|
+
onFragmentMissing: error
|
|
184
|
+
onSlotMissing: error
|
|
185
|
+
slots:
|
|
186
|
+
- name: coding-standards
|
|
187
|
+
fragmentPath: fragments/coding-standards.md
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Any missing fragment or unmatched slot marker will fail the step, surfacing typos and broken paths during template execution rather than silently producing a half-merged document.
|
|
191
|
+
|
|
192
|
+
## Development
|
|
193
|
+
|
|
194
|
+
### Build
|
|
195
|
+
|
|
196
|
+
```console
|
|
197
|
+
yarn install
|
|
198
|
+
yarn build
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Test
|
|
202
|
+
|
|
203
|
+
```console
|
|
204
|
+
yarn test
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Tests use Jest with `@swc/jest` for fast TypeScript transformation. The pure functions in `src/actions/merge.ts` (`mergeSlot`, `handleMissing`) are unit-tested directly without mocks.
|
|
208
|
+
|
|
209
|
+
### Project layout
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
src/
|
|
213
|
+
├── index.ts # Re-exports
|
|
214
|
+
└── actions/
|
|
215
|
+
├── merge.ts # Pure: mergeSlot, handleMissing
|
|
216
|
+
├── merge.test.ts # Unit tests
|
|
217
|
+
└── markdownMerge.ts # Backstage action factory + filesystem IO
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
The core merge logic is intentionally split from the Backstage action factory so it can be unit-tested without spinning up a scaffolder context.
|
|
221
|
+
|
|
222
|
+
## Releasing
|
|
223
|
+
|
|
224
|
+
Publishing is automated via GitHub Actions and **npm Trusted Publishing (OIDC)** — no long-lived npm token is stored as a repository secret.
|
|
225
|
+
|
|
226
|
+
### One-time setup
|
|
227
|
+
|
|
228
|
+
The package must exist on npm before Trusted Publishing can be configured against it. For the very first release:
|
|
229
|
+
|
|
230
|
+
1. Log in locally: `npm login`
|
|
231
|
+
2. Build and publish once with provenance enabled, which both creates the package and primes the provenance chain:
|
|
232
|
+
```console
|
|
233
|
+
yarn install
|
|
234
|
+
yarn build
|
|
235
|
+
yarn npm publish --provenance --access public
|
|
236
|
+
```
|
|
237
|
+
3. On [npmjs.com](https://www.npmjs.com/package/@shawncheng888/plugin-scaffolder-backend-module-markdown-merge) → Settings → **Trusted publishers** → Add a trusted publisher:
|
|
238
|
+
- Provider: **GitHub Actions**
|
|
239
|
+
- Repository owner: **joint-song**
|
|
240
|
+
- Repository name: **backstage-plugin-scaffolder-markdown-merge**
|
|
241
|
+
- Workflow filename: **release.yml**
|
|
242
|
+
- Environment name: **npm** (must match the `environment` block in the workflow, or leave blank if you remove it)
|
|
243
|
+
|
|
244
|
+
### Cutting a release
|
|
245
|
+
|
|
246
|
+
1. Bump the version locally: `yarn version --new-version <patch|minor|major>` (or edit `package.json` by hand).
|
|
247
|
+
2. Commit and push: `git push && git push --tags`.
|
|
248
|
+
3. On GitHub, go to **Releases** → **Draft a new release** → pick the tag (`v0.1.1` etc.) → **Publish**.
|
|
249
|
+
|
|
250
|
+
The `Release` workflow runs, attaches a signed provenance attestation, and the new version appears on npm within ~30 seconds.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
4
|
+
var promises = require('node:fs/promises');
|
|
5
|
+
var path = require('node:path');
|
|
6
|
+
var merge = require('./merge.cjs.js');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
11
|
+
|
|
12
|
+
const createMarkdownMergeAction = () => {
|
|
13
|
+
return pluginScaffolderNode.createTemplateAction({
|
|
14
|
+
id: "markdown:merge",
|
|
15
|
+
description: "Markdown Slot Injector - Merges multiple fragments into defined slots.",
|
|
16
|
+
schema: {
|
|
17
|
+
input: (z) => z.object({
|
|
18
|
+
path: z.string().describe("Target File Path, e.g., AGENTS.md"),
|
|
19
|
+
slots: z.array(
|
|
20
|
+
z.object({
|
|
21
|
+
name: z.string().describe("Slot Name"),
|
|
22
|
+
fragmentPath: z.string().describe("Path to Fragment File")
|
|
23
|
+
})
|
|
24
|
+
),
|
|
25
|
+
mode: z.enum(["replace", "append"]).optional().describe(
|
|
26
|
+
'How to merge the fragment into an existing paired slot. "replace" (default) overwrites the existing content. "append" keeps the existing content and inserts the fragment after it. Has no effect for single-tag (auto-completed) markers.'
|
|
27
|
+
),
|
|
28
|
+
onFragmentMissing: z.enum(["error", "warn", "ignore"]).optional().describe(
|
|
29
|
+
'Behavior when a fragment file is not found. Default: "warn" (log a warning and skip the slot).'
|
|
30
|
+
),
|
|
31
|
+
onSlotMissing: z.enum(["error", "warn", "ignore"]).optional().describe(
|
|
32
|
+
'Behavior when no slot marker is found in the target file. Default: "warn" (log a warning and continue).'
|
|
33
|
+
)
|
|
34
|
+
})
|
|
35
|
+
},
|
|
36
|
+
async handler(ctx) {
|
|
37
|
+
const {
|
|
38
|
+
path: targetRelPath,
|
|
39
|
+
slots,
|
|
40
|
+
mode = "replace",
|
|
41
|
+
onFragmentMissing = "warn",
|
|
42
|
+
onSlotMissing = "warn"
|
|
43
|
+
} = ctx.input;
|
|
44
|
+
const targetPath = path__default.default.resolve(ctx.workspacePath, targetRelPath);
|
|
45
|
+
let content;
|
|
46
|
+
try {
|
|
47
|
+
content = await promises.readFile(targetPath, "utf-8");
|
|
48
|
+
} catch (e) {
|
|
49
|
+
if (e?.code === "ENOENT") {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Target file ${targetRelPath} not found.`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
throw e;
|
|
55
|
+
}
|
|
56
|
+
for (const slot of slots) {
|
|
57
|
+
const fragPath = path__default.default.resolve(
|
|
58
|
+
ctx.workspacePath,
|
|
59
|
+
slot.fragmentPath
|
|
60
|
+
);
|
|
61
|
+
let fragmentContent;
|
|
62
|
+
try {
|
|
63
|
+
fragmentContent = await promises.readFile(fragPath, "utf-8");
|
|
64
|
+
} catch (e) {
|
|
65
|
+
if (e?.code === "ENOENT") {
|
|
66
|
+
merge.handleMissing(
|
|
67
|
+
onFragmentMissing,
|
|
68
|
+
ctx,
|
|
69
|
+
`Fragment file ${slot.fragmentPath} not found, skipping slot "${slot.name}".`
|
|
70
|
+
);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
throw e;
|
|
74
|
+
}
|
|
75
|
+
const result = merge.mergeSlot(
|
|
76
|
+
content,
|
|
77
|
+
slot.name,
|
|
78
|
+
fragmentContent,
|
|
79
|
+
mode
|
|
80
|
+
);
|
|
81
|
+
content = result.content;
|
|
82
|
+
if (result.match.kind === "none") {
|
|
83
|
+
merge.handleMissing(
|
|
84
|
+
onSlotMissing,
|
|
85
|
+
ctx,
|
|
86
|
+
`Slot "${slot.name}" not found in ${targetRelPath}.`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
await promises.writeFile(targetPath, content, "utf-8");
|
|
91
|
+
ctx.logger.info(
|
|
92
|
+
`Successfully injected fragments into ${targetRelPath}`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
exports.createMarkdownMergeAction = createMarkdownMergeAction;
|
|
99
|
+
//# sourceMappingURL=markdownMerge.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdownMerge.cjs.js","sources":["../../src/actions/markdownMerge.ts"],"sourcesContent":["import { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { readFile, writeFile } from 'node:fs/promises';\nimport path from 'node:path';\nimport { handleMissing, mergeSlot } from './merge';\n\nexport const createMarkdownMergeAction = () => {\n return createTemplateAction({\n id: 'markdown:merge',\n description:\n 'Markdown Slot Injector - Merges multiple fragments into defined slots.',\n schema: {\n input: z =>\n z.object({\n path: z\n .string()\n .describe('Target File Path, e.g., AGENTS.md'),\n slots: z.array(\n z.object({\n name: z.string().describe('Slot Name'),\n fragmentPath: z\n .string()\n .describe('Path to Fragment File'),\n }),\n ),\n mode: z\n .enum(['replace', 'append'])\n .optional()\n .describe(\n 'How to merge the fragment into an existing paired slot. ' +\n '\"replace\" (default) overwrites the existing content. ' +\n '\"append\" keeps the existing content and inserts the fragment after it. ' +\n 'Has no effect for single-tag (auto-completed) markers.',\n ),\n onFragmentMissing: z\n .enum(['error', 'warn', 'ignore'])\n .optional()\n .describe(\n 'Behavior when a fragment file is not found. ' +\n 'Default: \"warn\" (log a warning and skip the slot).',\n ),\n onSlotMissing: z\n .enum(['error', 'warn', 'ignore'])\n .optional()\n .describe(\n 'Behavior when no slot marker is found in the target file. ' +\n 'Default: \"warn\" (log a warning and continue).',\n ),\n }),\n },\n async handler(ctx) {\n const {\n path: targetRelPath,\n slots,\n mode = 'replace',\n onFragmentMissing = 'warn',\n onSlotMissing = 'warn',\n } = ctx.input;\n const targetPath = path.resolve(ctx.workspacePath, targetRelPath);\n\n // Target file: must exist; hard error otherwise.\n let content: string;\n try {\n content = await readFile(targetPath, 'utf-8');\n } catch (e: any) {\n if (e?.code === 'ENOENT') {\n throw new Error(\n `Target file ${targetRelPath} not found.`,\n );\n }\n throw e;\n }\n\n for (const slot of slots) {\n const fragPath = path.resolve(\n ctx.workspacePath,\n slot.fragmentPath,\n );\n\n // Fragment file: behavior on missing is configurable.\n let fragmentContent: string;\n try {\n fragmentContent = await readFile(fragPath, 'utf-8');\n } catch (e: any) {\n if (e?.code === 'ENOENT') {\n handleMissing(\n onFragmentMissing,\n ctx,\n `Fragment file ${slot.fragmentPath} not found, skipping slot \"${slot.name}\".`,\n );\n continue;\n }\n throw e;\n }\n\n const result = mergeSlot(\n content,\n slot.name,\n fragmentContent,\n mode,\n );\n content = result.content;\n\n if (result.match.kind === 'none') {\n handleMissing(\n onSlotMissing,\n ctx,\n `Slot \"${slot.name}\" not found in ${targetRelPath}.`,\n );\n }\n }\n\n await writeFile(targetPath, content, 'utf-8');\n ctx.logger.info(\n `Successfully injected fragments into ${targetRelPath}`,\n );\n },\n });\n};\n"],"names":["createTemplateAction","path","readFile","handleMissing","mergeSlot","writeFile"],"mappings":"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"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var escapeRegExp = require('lodash/escapeRegExp');
|
|
4
|
+
|
|
5
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
6
|
+
|
|
7
|
+
var escapeRegExp__default = /*#__PURE__*/_interopDefaultCompat(escapeRegExp);
|
|
8
|
+
|
|
9
|
+
const SLOT_TAG_NAME = "MD_SLOT";
|
|
10
|
+
function mergeSlot(content, slotName, fragmentContent, mode) {
|
|
11
|
+
const safeName = escapeRegExp__default.default(slotName);
|
|
12
|
+
const openTagRe = `<!--\\s*${SLOT_TAG_NAME}\\s*:\\s*${safeName}\\s*-->`;
|
|
13
|
+
const closeTagRe = `<!--\\s*/\\s*${SLOT_TAG_NAME}\\s*:\\s*${safeName}\\s*-->`;
|
|
14
|
+
const pairPattern = new RegExp(
|
|
15
|
+
`(${openTagRe})([\\s\\S]*?)(${closeTagRe})`
|
|
16
|
+
);
|
|
17
|
+
const singlePattern = new RegExp(openTagRe);
|
|
18
|
+
if (pairPattern.test(content)) {
|
|
19
|
+
if (mode === "append") {
|
|
20
|
+
const next = content.replace(
|
|
21
|
+
pairPattern,
|
|
22
|
+
(_match, open, existing, close) => `${open}${existing.replace(
|
|
23
|
+
/\s+$/,
|
|
24
|
+
""
|
|
25
|
+
)}
|
|
26
|
+
${fragmentContent}
|
|
27
|
+
${close}`
|
|
28
|
+
);
|
|
29
|
+
return { content: next, match: { kind: "pair" } };
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
content: content.replace(
|
|
33
|
+
pairPattern,
|
|
34
|
+
`$1
|
|
35
|
+
${fragmentContent}
|
|
36
|
+
$3`
|
|
37
|
+
),
|
|
38
|
+
match: { kind: "pair" }
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (singlePattern.test(content)) {
|
|
42
|
+
const openTagPlain = `<!-- ${SLOT_TAG_NAME}: ${slotName} -->`;
|
|
43
|
+
const closeTagPlain = `<!-- /${SLOT_TAG_NAME}: ${slotName} -->`;
|
|
44
|
+
return {
|
|
45
|
+
content: content.replace(
|
|
46
|
+
singlePattern,
|
|
47
|
+
`${openTagPlain}
|
|
48
|
+
${fragmentContent}
|
|
49
|
+
${closeTagPlain}`
|
|
50
|
+
),
|
|
51
|
+
match: { kind: "single" }
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return { content, match: { kind: "none" } };
|
|
55
|
+
}
|
|
56
|
+
function handleMissing(behavior, ctx, message) {
|
|
57
|
+
if (behavior === "ignore") return;
|
|
58
|
+
if (behavior === "error") throw new Error(message);
|
|
59
|
+
ctx.logger.warn(message);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
exports.SLOT_TAG_NAME = SLOT_TAG_NAME;
|
|
63
|
+
exports.handleMissing = handleMissing;
|
|
64
|
+
exports.mergeSlot = mergeSlot;
|
|
65
|
+
//# sourceMappingURL=merge.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.cjs.js","sources":["../../src/actions/merge.ts"],"sourcesContent":["import escapeRegExp from 'lodash/escapeRegExp';\n\nexport type MergeMode = 'replace' | 'append';\n\nexport type MissingBehavior = 'error' | 'warn' | 'ignore';\n\nexport type SlotMatch =\n | { kind: 'pair' }\n | { kind: 'single' }\n | { kind: 'none' };\n\nexport type MergeResult = {\n content: string;\n match: SlotMatch;\n};\n\n/**\n * Canonical slot tag name embedded in markdown markers.\n *\n * Paired: <!-- MD_SLOT: NAME -->...content...<!-- /MD_SLOT: NAME -->\n * Single: <!-- MD_SLOT: NAME --> (closing tag is auto-added)\n *\n * Exported so consumers and tests can refer to the same constant.\n */\nexport const SLOT_TAG_NAME = 'MD_SLOT';\n\n/**\n * Pure: merge a fragment into a slot marker in `content`.\n *\n * Pair pattern (preferred): <!-- MD_SLOT: NAME -->...existing...<!-- /MD_SLOT: NAME -->\n * Single pattern (fallback): <!-- MD_SLOT: NAME --> (closing tag is auto-added)\n *\n * - `mode: 'replace'` overwrites the existing content between paired markers.\n * - `mode: 'append'` keeps the existing content and inserts the fragment after it.\n * Has no effect for the single-tag fallback (no existing content to keep).\n *\n * No filesystem access. `slotName` is regex-escaped via lodash/escapeRegExp.\n */\nexport function mergeSlot(\n content: string,\n slotName: string,\n fragmentContent: string,\n mode: MergeMode,\n): MergeResult {\n const safeName = escapeRegExp(slotName);\n const openTagRe = `<!--\\\\s*${SLOT_TAG_NAME}\\\\s*:\\\\s*${safeName}\\\\s*-->`;\n const closeTagRe = `<!--\\\\s*/\\\\s*${SLOT_TAG_NAME}\\\\s*:\\\\s*${safeName}\\\\s*-->`;\n const pairPattern = new RegExp(\n `(${openTagRe})([\\\\s\\\\S]*?)(${closeTagRe})`,\n );\n const singlePattern = new RegExp(openTagRe);\n\n if (pairPattern.test(content)) {\n if (mode === 'append') {\n const next = content.replace(\n pairPattern,\n (_match, open: string, existing: string, close: string) =>\n `${open}${existing.replace(\n /\\s+$/,\n '',\n )}\\n${fragmentContent}\\n${close}`,\n );\n return { content: next, match: { kind: 'pair' } };\n }\n return {\n content: content.replace(\n pairPattern,\n `$1\\n${fragmentContent}\\n$3`,\n ),\n match: { kind: 'pair' },\n };\n }\n\n if (singlePattern.test(content)) {\n const openTagPlain = `<!-- ${SLOT_TAG_NAME}: ${slotName} -->`;\n const closeTagPlain = `<!-- /${SLOT_TAG_NAME}: ${slotName} -->`;\n return {\n content: content.replace(\n singlePattern,\n `${openTagPlain}\\n${fragmentContent}\\n${closeTagPlain}`,\n ),\n match: { kind: 'single' },\n };\n }\n\n return { content, match: { kind: 'none' } };\n}\n\nexport type LoggerLike = {\n warn: (msg: string) => void;\n};\n\n/**\n * Apply the configured behavior when a slot/fragment is missing.\n * - 'error' → throws an Error with the given message\n * - 'warn' → logs a warning and returns\n * - 'ignore' → returns silently\n */\nexport function handleMissing(\n behavior: MissingBehavior,\n ctx: { logger: LoggerLike },\n message: string,\n): void {\n if (behavior === 'ignore') return;\n if (behavior === 'error') throw new Error(message);\n ctx.logger.warn(message);\n}\n"],"names":["escapeRegExp"],"mappings":";;;;;;;;AAwBO,MAAM,aAAA,GAAgB;AActB,SAAS,SAAA,CACZ,OAAA,EACA,QAAA,EACA,eAAA,EACA,IAAA,EACW;AACX,EAAA,MAAM,QAAA,GAAWA,8BAAa,QAAQ,CAAA;AACtC,EAAA,MAAM,SAAA,GAAY,CAAA,QAAA,EAAW,aAAa,CAAA,SAAA,EAAY,QAAQ,CAAA,OAAA,CAAA;AAC9D,EAAA,MAAM,UAAA,GAAa,CAAA,aAAA,EAAgB,aAAa,CAAA,SAAA,EAAY,QAAQ,CAAA,OAAA,CAAA;AACpE,EAAA,MAAM,cAAc,IAAI,MAAA;AAAA,IACpB,CAAA,CAAA,EAAI,SAAS,CAAA,cAAA,EAAiB,UAAU,CAAA,CAAA;AAAA,GAC5C;AACA,EAAA,MAAM,aAAA,GAAgB,IAAI,MAAA,CAAO,SAAS,CAAA;AAE1C,EAAA,IAAI,WAAA,CAAY,IAAA,CAAK,OAAO,CAAA,EAAG;AAC3B,IAAA,IAAI,SAAS,QAAA,EAAU;AACnB,MAAA,MAAM,OAAO,OAAA,CAAQ,OAAA;AAAA,QACjB,WAAA;AAAA,QACA,CAAC,QAAQ,IAAA,EAAc,QAAA,EAAkB,UACrC,CAAA,EAAG,IAAI,GAAG,QAAA,CAAS,OAAA;AAAA,UACf,MAAA;AAAA,UACA;AAAA,SACH;AAAA,EAAK,eAAe;AAAA,EAAK,KAAK,CAAA;AAAA,OACvC;AACA,MAAA,OAAO,EAAE,OAAA,EAAS,IAAA,EAAM,OAAO,EAAE,IAAA,EAAM,QAAO,EAAE;AAAA,IACpD;AACA,IAAA,OAAO;AAAA,MACH,SAAS,OAAA,CAAQ,OAAA;AAAA,QACb,WAAA;AAAA,QACA,CAAA;AAAA,EAAO,eAAe;AAAA,EAAA;AAAA,OAC1B;AAAA,MACA,KAAA,EAAO,EAAE,IAAA,EAAM,MAAA;AAAO,KAC1B;AAAA,EACJ;AAEA,EAAA,IAAI,aAAA,CAAc,IAAA,CAAK,OAAO,CAAA,EAAG;AAC7B,IAAA,MAAM,YAAA,GAAe,CAAA,KAAA,EAAQ,aAAa,CAAA,EAAA,EAAK,QAAQ,CAAA,IAAA,CAAA;AACvD,IAAA,MAAM,aAAA,GAAgB,CAAA,MAAA,EAAS,aAAa,CAAA,EAAA,EAAK,QAAQ,CAAA,IAAA,CAAA;AACzD,IAAA,OAAO;AAAA,MACH,SAAS,OAAA,CAAQ,OAAA;AAAA,QACb,aAAA;AAAA,QACA,GAAG,YAAY;AAAA,EAAK,eAAe;AAAA,EAAK,aAAa,CAAA;AAAA,OACzD;AAAA,MACA,KAAA,EAAO,EAAE,IAAA,EAAM,QAAA;AAAS,KAC5B;AAAA,EACJ;AAEA,EAAA,OAAO,EAAE,OAAA,EAAS,KAAA,EAAO,EAAE,IAAA,EAAM,QAAO,EAAE;AAC9C;AAYO,SAAS,aAAA,CACZ,QAAA,EACA,GAAA,EACA,OAAA,EACI;AACJ,EAAA,IAAI,aAAa,QAAA,EAAU;AAC3B,EAAA,IAAI,QAAA,KAAa,OAAA,EAAS,MAAM,IAAI,MAAM,OAAO,CAAA;AACjD,EAAA,GAAA,CAAI,MAAA,CAAO,KAAK,OAAO,CAAA;AAC3B;;;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var merge = require('./actions/merge.cjs.js');
|
|
4
|
+
var markdownMerge = require('./actions/markdownMerge.cjs.js');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
exports.SLOT_TAG_NAME = merge.SLOT_TAG_NAME;
|
|
9
|
+
exports.handleMissing = merge.handleMissing;
|
|
10
|
+
exports.mergeSlot = merge.mergeSlot;
|
|
11
|
+
exports.createMarkdownMergeAction = markdownMerge.createMarkdownMergeAction;
|
|
12
|
+
//# 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,65 @@
|
|
|
1
|
+
import * as _backstage_plugin_scaffolder_node from '@backstage/plugin-scaffolder-node';
|
|
2
|
+
|
|
3
|
+
type MergeMode = 'replace' | 'append';
|
|
4
|
+
type MissingBehavior = 'error' | 'warn' | 'ignore';
|
|
5
|
+
type SlotMatch = {
|
|
6
|
+
kind: 'pair';
|
|
7
|
+
} | {
|
|
8
|
+
kind: 'single';
|
|
9
|
+
} | {
|
|
10
|
+
kind: 'none';
|
|
11
|
+
};
|
|
12
|
+
type MergeResult = {
|
|
13
|
+
content: string;
|
|
14
|
+
match: SlotMatch;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Canonical slot tag name embedded in markdown markers.
|
|
18
|
+
*
|
|
19
|
+
* Paired: <!-- MD_SLOT: NAME -->...content...<!-- /MD_SLOT: NAME -->
|
|
20
|
+
* Single: <!-- MD_SLOT: NAME --> (closing tag is auto-added)
|
|
21
|
+
*
|
|
22
|
+
* Exported so consumers and tests can refer to the same constant.
|
|
23
|
+
*/
|
|
24
|
+
declare const SLOT_TAG_NAME = "MD_SLOT";
|
|
25
|
+
/**
|
|
26
|
+
* Pure: merge a fragment into a slot marker in `content`.
|
|
27
|
+
*
|
|
28
|
+
* Pair pattern (preferred): <!-- MD_SLOT: NAME -->...existing...<!-- /MD_SLOT: NAME -->
|
|
29
|
+
* Single pattern (fallback): <!-- MD_SLOT: NAME --> (closing tag is auto-added)
|
|
30
|
+
*
|
|
31
|
+
* - `mode: 'replace'` overwrites the existing content between paired markers.
|
|
32
|
+
* - `mode: 'append'` keeps the existing content and inserts the fragment after it.
|
|
33
|
+
* Has no effect for the single-tag fallback (no existing content to keep).
|
|
34
|
+
*
|
|
35
|
+
* No filesystem access. `slotName` is regex-escaped via lodash/escapeRegExp.
|
|
36
|
+
*/
|
|
37
|
+
declare function mergeSlot(content: string, slotName: string, fragmentContent: string, mode: MergeMode): MergeResult;
|
|
38
|
+
type LoggerLike = {
|
|
39
|
+
warn: (msg: string) => void;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Apply the configured behavior when a slot/fragment is missing.
|
|
43
|
+
* - 'error' → throws an Error with the given message
|
|
44
|
+
* - 'warn' → logs a warning and returns
|
|
45
|
+
* - 'ignore' → returns silently
|
|
46
|
+
*/
|
|
47
|
+
declare function handleMissing(behavior: MissingBehavior, ctx: {
|
|
48
|
+
logger: LoggerLike;
|
|
49
|
+
}, message: string): void;
|
|
50
|
+
|
|
51
|
+
declare const createMarkdownMergeAction: () => _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
52
|
+
path: string;
|
|
53
|
+
slots: {
|
|
54
|
+
name: string;
|
|
55
|
+
fragmentPath: string;
|
|
56
|
+
}[];
|
|
57
|
+
mode?: "replace" | "append" | undefined;
|
|
58
|
+
onFragmentMissing?: "error" | "warn" | "ignore" | undefined;
|
|
59
|
+
onSlotMissing?: "error" | "warn" | "ignore" | undefined;
|
|
60
|
+
}, {
|
|
61
|
+
[x: string]: any;
|
|
62
|
+
}, "v2">;
|
|
63
|
+
|
|
64
|
+
export { SLOT_TAG_NAME, createMarkdownMergeAction, handleMissing, mergeSlot };
|
|
65
|
+
export type { LoggerLike, MergeMode, MergeResult, MissingBehavior, SlotMatch };
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shawncheng888/plugin-scaffolder-backend-module-markdown-merge",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Backstage scaffolder action that merges Markdown fragments into named slot markers in a target file.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"packageManager": "yarn@4.12.0",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20.0.0"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"backstage",
|
|
12
|
+
"scaffolder",
|
|
13
|
+
"scaffolder-action",
|
|
14
|
+
"markdown",
|
|
15
|
+
"scaffolder-backend-module"
|
|
16
|
+
],
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "Shawn Cheng",
|
|
19
|
+
"url": "https://github.com/joint-song"
|
|
20
|
+
},
|
|
21
|
+
"main": "dist/index.cjs.js",
|
|
22
|
+
"types": "dist/index.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public",
|
|
28
|
+
"main": "dist/index.cjs.js",
|
|
29
|
+
"types": "dist/index.d.ts"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/joint-song/plugin-scaffolder-backend-module-markdown-merge#readme",
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/joint-song/plugin-scaffolder-backend-module-markdown-merge.git"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/joint-song/plugin-scaffolder-backend-module-markdown-merge/issues"
|
|
38
|
+
},
|
|
39
|
+
"backstage": {
|
|
40
|
+
"role": "backend-plugin-module",
|
|
41
|
+
"pluginId": "scaffolder",
|
|
42
|
+
"pluginPackage": "@backstage/plugin-scaffolder-backend"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "yarn tsc && backstage-cli package build",
|
|
46
|
+
"tsc": "tsc -p tsconfig.build.json",
|
|
47
|
+
"clean": "backstage-cli package clean",
|
|
48
|
+
"prepack": "backstage-cli package prepack",
|
|
49
|
+
"postpack": "backstage-cli package postpack",
|
|
50
|
+
"lint": "backstage-cli package lint",
|
|
51
|
+
"test": "jest --passWithNoTests"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@backstage/cli": "^0.36.2",
|
|
55
|
+
"@backstage/plugin-scaffolder-node": "^0.13.3",
|
|
56
|
+
"lodash": "^4.17.21",
|
|
57
|
+
"zod": "4.4.3"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@swc/jest": "^0.2.0",
|
|
61
|
+
"@types/jest": "^30.0.0",
|
|
62
|
+
"@types/lodash": "^4",
|
|
63
|
+
"@types/node": "^25.9.2",
|
|
64
|
+
"jest": "^30.0.0",
|
|
65
|
+
"jest-environment-node": "^30.0.0",
|
|
66
|
+
"prettier": "^3.4.0",
|
|
67
|
+
"typescript": "^6.0.3"
|
|
68
|
+
},
|
|
69
|
+
"typesVersions": {
|
|
70
|
+
"*": {
|
|
71
|
+
"package.json": [
|
|
72
|
+
"package.json"
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|