Initialize NPM Project

Action ID: npm:init
NPM Package:

@mdude2314/backstage-plugin-scaffolder-npm-actions

Description

Runs npm init with defaults set in the task workspace directory

Input Schema

No input schema defined for this action.

Output Schema

No output schema defined for this action.

Usage Examples

Initialize package.json in the project root after fetching a template

Use this when you want a default package.json created at the workspace root right after fetching a template with fetch:template. This prepares the project for later steps like publishing with publish:github.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: https://github.com/my-org/templates/node-service/skeleton.zip
      targetPath: .
      values:
        name: ${{ parameters.serviceName }}
        owner: ${{ parameters.owner }}
        description: ${{ parameters.description }}

  - id: npm-init-root
    action: npm:init

  - id: publish-to-github
    action: publish:github
    input:
      repoUrl: "github.com?owner=${{ parameters.owner }}&repo=${{ parameters.repoName }}"
      defaultBranch: main

Initialize package.json for multiple packages in a monorepo

Use this to create default package.json files in multiple subpackages of a monorepo. It runs npm init in each package directory using workingDirectory, following a fetch with fetch:template, and then publishes with publish:github.

Copy
steps:
  - id: fetch-monorepo-skeleton
    action: fetch:template
    input:
      url: https://github.com/my-org/templates/monorepo/skeleton.zip
      targetPath: .
      values:
        repoName: ${{ parameters.repoName }}
        owner: ${{ parameters.owner }}

  - id: npm-init-api
    action: npm:init
    workingDirectory: packages/api

  - id: npm-init-web
    action: npm:init
    workingDirectory: packages/web

  - id: publish-monorepo
    action: publish:github
    input:
      repoUrl: "github.com?owner=${{ parameters.owner }}&repo=${{ parameters.repoName }}"
      defaultBranch: main