DEV Community

Cover image for How to create an npm package + CI/CD in 10 minutes
Luiz Gabriel
Luiz Gabriel

Posted on

How to create an npm package + CI/CD in 10 minutes

In this article we will create a template library for react native, after this tutorial you will know how to create any package.

Requirements

Step 1 - Create your project

npx create-expo-app name-template --template
Enter fullscreen mode Exit fullscreen mode
  • go to project folder
cd nameOfProject
Enter fullscreen mode Exit fullscreen mode

Step 2 - NPM Config

  • run the command
npm init
Enter fullscreen mode Exit fullscreen mode
  • after run command, you nesse answer some questions about your package
package name: (app-template)
version: (1.0.0)
description:
git repository:
keywords:
author:
license: (ISC)
Enter fullscreen mode Exit fullscreen mode
  • now you need authenticate your user
npm adduser
Enter fullscreen mode Exit fullscreen mode
  • after that you need to remove the line 'private: true' inside the file package.json, with this action you package become public

Step 3 - Config CI/CD

Image description

  • Go to your github repository
  • actions -> new workflow
  • insert the codes below
// name of project
name: Publish Npm Package

// any update or pull request directed to the master will activateo workflow
on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    // machine that will run
    runs-on: ubuntu-latest

    steps: 
      // go to repo
      - name: Checkout repository
        uses: actions/checkout@v2

       // Install version node.js
      - name: setup version node.js
        uses: actions/setup-node@v2
        with:
          node-version: '18.20.2'

      - name: Install dependencies
        run: npm install --force

        // Authenticate to npm before publish
      - name: Authenticate to npm
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc

        // Publish your package npm
      - name: Publish to npm
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: npm publish --access public
Enter fullscreen mode Exit fullscreen mode

repo github: https://github.com/Luizrebelatto/template-reactnative-setup
Linkedin: https://www.linkedin.com/in/luizgabrielrebelatto/
Github: https://github.com/Luizrebelatto

Top comments (0)