In this article we will create a template library for react native, after this tutorial you will know how to create any package.
Requirements
Have an npm account, if not create one https://www.npmjs.com
Have an github account, if not create one https://github.com
Step 1 – Create your project
go to project folder
Step 2 – NPM Config
run the command
after run command, you nesse answer some questions about your package
version: (1.0.0)
description:
git repository:
keywords:
author:
license: (ISC)
now you need authenticate your user
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
Go to your github repository
actions -> new workflow
insert the codes below
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
repo github: https://github.com/Luizrebelatto/template-reactnative-setup
Linkedin: https://www.linkedin.com/in/luizgabrielrebelatto/
Github: https://github.com/Luizrebelatto