open-index/open-npm huggingface dataset:
npm package: @mdude2314/backstage-plugin-scaffolder-json-merge-actions
Description: The json-merge actions module for @backstage/plugin-scaffolder-backend
Latest version: 1.2.1

# backstage-plugin-scaffolder-json-merge-actions

This is a `json-merge` actions plugin for the `scaffolder-backend` in Backstage.

This contains a collection of actions for using with the [JSON Merger npm package](https://www.npmjs.com/package/json-merger):

- json:merge-files - [JSON Merger doc](https://www.npmjs.com/package/json-merger#mergefilesfiles-string-config-config)
- json:merge-file - [JSON Merger doc](https://www.npmjs.com/package/json-merger#mergefilefile-string-config-config)

## Prerequisites

- Node must be installed in the environment your Backstage instance is running in, but it will most likely already be there since your Backstage instance runs in Node.

- Additionally, these actions use the [JSON Merger npm package](https://www.npmjs.com/package/json-merger). It will be useful to understand how it functions as well as what options are available in the configuration.

## Getting started

In the root directory of your Backstage project:

```
yarn add --cwd packages/backend @mdude2314/backstage-plugin-scaffolder-json-merge-actions
```

Add the actions you'd like to the scaffolder:

```typescript
// packages/backend/src/plugins/scaffolder.ts

import {
  createJsonMergeFileAction,
  createJsonMergeFilesAction
} from '@mdude2314/backstage-plugin-scaffolder-json-merge-actions';
import { ScmIntegrations } from '@backstage/integration';
import { createBuiltinActions, createRouter } from '@backstage/plugin-scaffolder-backend';

...

const integrations = ScmIntegrations.fromConfig(env.config);
const builtInActions = createBuiltinActions({
  catalogClient,
  integrations,
  config: env.config,
  reader: env.reader
});

const actions = [
    createJsonMergeFileAction(),
    createJsonMergeFilesAction(),
  ...builtInActions
];

return await createRouter({
  logger: env.logger,
  config: env.config,
  database: env.database,
  reader: env.reader,
  catalogClient,
  actions
});
```

## Example of using the JSON merge:

```json
/// files/file-1.json
{ "hello": "world", "foo": ["bar", "baz"] }

/// files/file-2.json
{ "goodbye": "world", "foo": ["rab", "zab"] }
```

```yaml
---
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
  name: json-merge-demo
  title: My json merge template
  description: Merge JSON files in the working directory of the task
spec:
  owner: mdude2314
  type: service

  steps:
    - id: fetch-files
      name: Fetch files
      action: fetch:plain
      input:
        url: ./files # files should contain the JSON files you want to merge

    - id: merge-files
      name: Merge files
      action: json:merge
      input:
        inputFiles: ["file-1.json", "file-2.json"]
        outputFilePath: results
        outputFileName: results.json
        jsonMergeOptions: # options passed directly to the mergeFiles function
          defaultArrayMergeOperation: "concat"
```

Output:

```json
/// results/results.json
{ "hello": "world", "foo": ["bar", "baz", "rab", "zab"], "goodbye": "world" }
```
npm package: @mdude2314/backstage-plugin-scaffolder-npm-actions
Description: The npm-actions module for @backstage/plugin-scaffolder-backend
Latest version: 1.1.1

# backstage-plugin-scaffolder-npm-actions package

This is a `npm` actions plugin for the `scaffolder-backend` in Backstage.

This contains a collection of actions for using with npm:

- npm:init
- npm:install
- npm:exec
- npm:config

## Prerequisites

- Node and NPM must be installed in the environment your Backstage instance is running in, but it will most likely already be there since your Backstage instance runs in Node.

## Getting started

In the root directory of your Backstage project:

```
yarn add --cwd packages/backend @mdude2314/backstage-plugin-scaffolder-npm-actions
```

Add the actions you'd like to the scaffolder:

```typescript
// packages/backend/src/plugins/scaffolder.ts

import {
  createNpmExecAction,
  createNpmInitAction,
  createNpmInstallAction,
  createNpmConfigAction,
} from '@mdude2314/backstage-plugin-scaffolder-npm-actions';
import { ScmIntegrations } from '@backstage/integration';
import { createBuiltinActions, createRouter } from '@backstage/plugin-scaffolder-backend';

...

const integrations = ScmIntegrations.fromConfig(env.config);
const builtInActions = createBuiltinActions({
  catalogClient,
  integrations,
  config: env.config,
  reader: env.reader
});

const actions = [
    createNpmExecAction(),
    createNpmInitAction(),
    createNpmInstallAction(),
    createNpmConfigAction(),
  ...builtInActions
];

return await createRouter({
  logger: env.logger,
  config: env.config,
  database: env.database,
  reader: env.reader,
  catalogClient,
  actions
});
```

## Example of using each of the three actions:

```yaml
---
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
  name: npm-demo
  title: My npm demo template
  description: Run npm commands in the task's working directory
spec:
  owner: mdude2314
  type: service

  parameters:
    - title: Npm init
      properties:
        packageToInstall:
          title: Package to install
          type: string
          description: The name of the npm package to install
        execArgs:
          title: Args for exec
          type: array
          description: Arguments to pass to the exec command

  steps:
    - id: npm-init
      name: init
      action: npm:init

    - id: npm-install
      name: install
      action: npm:install
      input:
        packageToInstall: ${{ parameters.packageToInstall }}

    - id: npm-config
      name: config
      action: npm:config
      input:
        args: ${{ parameters.execArgs }}

    - id: npm-exec
      name: exec
      action: npm:exec
      input:
        args: ${{ parameters.execArgs }}
```