Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/breezy-wings-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@platacard/backstage-plugin-scaffolder-backend-module-yaml-merge-actions': minor
'@platacard/backstage-plugin-scaffolder-backend-module-json-merge-action': minor
---

Add README
69 changes: 65 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,71 @@
# [Backstage](https://backstage.io)
# Backstage Plugins Collection

This is your newly scaffolded Backstage App, Good Luck!
A collection of custom Backstage plugins developed by Platacard.

To start the app, run:
## Development

```sh
### Project Structure

```
├── plugins/
│ ├── scaffolder-backend-module-json-merge-action/
│ └── scaffolder-backend-module-yaml-merge-actions/
├── examples/
│ └── template/
├── scripts/
├── package.json
└── README.md
```

## Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Run tests and linting
5. Submit a pull request

### Development Workflow

```bash
# Install dependencies
yarn install

# Start development
yarn start

# Make changes and test
yarn test

# Ensure code quality
yarn lint
yarn prettier:check
```

## Versioning

This project uses [Changesets](https://github.com/changesets/changesets) for
version management and publishing.

To create a changeset:

```bash
yarn changeset
```

## License

Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for
details.

## Support

For issues and questions:

- Open an issue in this repository
- Check the [Backstage documentation](https://backstage.io/docs)
- Review plugin-specific README files in the `plugins/` directory

---

Built with ❤️ for the Backstage community by Platacard.
119 changes: 116 additions & 3 deletions plugins/scaffolder-backend-module-json-merge-action/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,118 @@
# @internal/backstage-plugin-scaffolder-backend-module-json-merge-action
# backstage-plugin-scaffolder-backend-module-json-merge-action

The json-merge-action backend module for the scaffolder plugin.
A Backstage Scaffolder backend module that provides custom actions for merging
JSON files during the scaffolding process.

_This plugin was created through the Backstage CLI_
## Overview

This plugin adds two powerful JSON merging actions to your Backstage Scaffolder:

- `json:merge-file` - Merges a single JSON file with inline data
- `json:merge-files` - Merges multiple JSON files together

These actions are particularly useful when you need to combine configuration
files, merge API responses, or consolidate JSON data during template execution.

## Installation

Add the plugin to your backend:

```bash
# From your Backstage root directory
yarn add --cwd packages/backend @platacard/backstage-plugin-scaffolder-backend-module-json-merge-action
```

## Configuration

Add the module to your backend in `packages/backend/src/index.ts`:

```typescript
import { createBackend } from '@backstage/backend-defaults';

const backend = createBackend();

// ... other modules

backend.add(
import(
'@platacard/backstage-plugin-scaffolder-backend-module-json-merge-action'
),
);

backend.start();
```

## Actions

### json:merge-file

Merges a JSON file with inline data using the
[json-merger](https://www.npmjs.com/package/json-merger) library.

#### Input Schema

| Parameter | Type | Required | Description |
| ------------------ | ------ | -------- | ------------------------------------------------------------------------ |
| `inputFile` | string | Yes | The file in the working directory to merge |
| `outputFileName` | string | Yes | The name of the file to write to |
| `outputFilePath` | string | No | The path to output the file to. Defaults to the task's working directory |
| `jsonMergeOptions` | object | No | Options to pass to the JSON merge function |

#### Example Usage

```yaml
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
name: json-merge-example
title: JSON Merge Example
spec:
steps:
- id: merge-config
name: Merge Configuration
action: json:merge-file
input:
inputFile: base-config.json
outputFileName: merged-config.json
outputFilePath: config
```

### json:merge-files

Merges multiple JSON files together into a single output file.

#### Input Schema

| Parameter | Type | Required | Description |
| ------------------ | -------- | -------- | ------------------------------------------------------------------------ |
| `inputFiles` | string[] | Yes | Array of files in the working directory to merge |
| `outputFileName` | string | Yes | The name of the file to write to |
| `outputFilePath` | string | No | The path to output the file to. Defaults to the task's working directory |
| `jsonMergeOptions` | object | No | Options to pass to the JSON merge function |

#### Example Usage

```yaml
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
name: multi-json-merge-example
title: Multiple JSON Merge Example
spec:
steps:
- id: merge-configs
name: Merge Multiple Configurations
action: json:merge-files
input:
inputFiles:
- defaults.json
- environment.json
- overrides.json
outputFileName: final-config.json
outputFilePath: dist
```

## JSON Merge Options

The `jsonMergeOptions` parameter accepts configuration options from the
[json-merger](https://www.npmjs.com/package/json-merger) library.
160 changes: 157 additions & 3 deletions plugins/scaffolder-backend-module-yaml-merge-actions/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,159 @@
# @internal/backstage-plugin-scaffolder-backend-module-yaml-merge-actions
# backstage-plugin-scaffolder-backend-module-yaml-merge-actions

The yaml-merge-actions backend module for the scaffolder plugin.
A Backstage Scaffolder backend module that provides a custom action for merging
YAML files with configurable merge strategies.

_This plugin was created through the Backstage CLI_
## Overview

This plugin adds a `yaml:merge` action to your Backstage Scaffolder that allows
you to merge YAML files during the scaffolding process. It supports different
merge strategies for arrays and preserves YAML structure and comments.

## Features

- **Deep merging** of YAML structures
- **Configurable array merge strategies**: concat, replace, or unique
- **Comment preservation** in YAML files
- **Dry run support** for testing
- **Flexible output paths** for generated files

## Installation

Add the plugin to your backend:

```bash
# From your Backstage root directory
yarn add --cwd packages/backend @platacard/backstage-plugin-scaffolder-backend-module-yaml-merge-actions
```

## Configuration

Add the module to your backend in `packages/backend/src/index.ts`:

```typescript
import { createBackend } from '@backstage/backend-defaults';

const backend = createBackend();

// ... other modules

backend.add(
import(
'@platacard/backstage-plugin-scaffolder-backend-module-yaml-merge-actions'
),
);

backend.start();
```

## Action: yaml:merge

Merges two YAML files with customizable merge strategies.

### Input Schema

| Parameter | Type | Required | Description |
| ------------------ | ------ | -------- | ------------------------------------------------------------------------ |
| `inputFile` | string | Yes | The file in the working directory to merge |
| `overlayFile` | string | Yes | The file containing data to merge into the input file |
| `outputFileName` | string | Yes | The name of the file to write to |
| `outputFilePath` | string | No | The path to output the file to. Defaults to the task's working directory |
| `yamlMergeOptions` | object | No | Options to control how YAML files are merged |

#### yamlMergeOptions

| Option | Type | Default | Description |
| -------------------- | ------- | -------- | -------------------------------------------------------------------- |
| `arrayMergeStrategy` | string | `concat` | How to merge arrays: `concat`, `replace`, or `unique` |
| `prependOnConcat` | boolean | `false` | When using concat strategy, prepend overlay arrays instead of append |

### Output Schema

| Parameter | Type | Description |
| ------------ | ------ | ------------------------------------------------------ |
| `outputFile` | string | Path to the merged output file (relative to workspace) |

### Example Usage

```yaml
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
name: yaml-merge-example
title: YAML Merge Example
spec:
steps:
- id: merge-kubernetes-configs
name: Merge Kubernetes Configurations
action: yaml:merge
input:
inputFile: base-deployment.yaml
overlayFile: production-overrides.yaml
outputFileName: final-deployment.yaml
outputFilePath: k8s
yamlMergeOptions:
arrayMergeStrategy: unique
```

## Merge Strategies

### Object Merging

Objects are deeply merged. Keys from the overlay file override or add to the
input file.

```yaml
# Input file
config:
database:
host: localhost
port: 5432

# Overlay file
config:
database:
port: 5433
cache:
enabled: true

# Result
config:
database:
host: localhost
port: 5433
cache:
enabled: true
```

### Array Merge Strategies

#### concat (default)

Concatenates arrays from both files.

```yaml
# Input: [a, b]
# Overlay: [c, d]
# Result: [a, b, c, d]
# With prependOnConcat: [c, d, a, b]
```

#### replace

Replaces the entire array with the overlay array.

```yaml
# Input: [a, b]
# Overlay: [c, d]
# Result: [c, d]
```

#### unique

Merges arrays keeping only unique values.

```yaml
# Input: [a, b, c]
# Overlay: [b, c, d]
# Result: [a, b, c, d]
```