Skip to content

About

๐Ÿ› ๏ธ A tool to build and publish packages (Typescript or Javascript) on npm for projects based on mono repository (lerna).

Topics

Resources

Code of conduct

Contributing

Stars

4 stars

Watchers

4 watching

Forks

Latest commit

ย 

History

333 Commits

Folders and files

Repository files navigation

Ts.ED logo

MonoRepo Utils

A tool to build and publish packages (TypeScript or JavaSript) on NPM registry (or any other compliant registry) for all projects based on mono repository lerna.

Features

  • Publishing packages on NPM, Github packages or any NPM private registries.
  • Publishing Docker Image on Docker HUB.
  • Deploy Docker Image on heroku.
  • Apply Tags and create release note on Github (with semantic-release)
  • Publish documentation on Github Pages.
  • Update projects example from external repository.

Workspaces

MonoRepoUtils use Lerna to manage scripts between package. By default, MonoRepoUtils use Yarn as workspaces manager. You can try with NPM 7. But isn't officially supported right now.

Supported CI

  • GithubActions,
  • Travis CI,
  • Circle CI,
  • GitLab

Installation

Run:

npm install --save-dev @tsed/monorepo-utils

Configuration

MonoRepoUtils support semantic-release versioning tools and publishing Release note on Github. By the way, it's not mandatory. You can manage manage versioning by you own way.

Prerequisite configuration

Add the following configuration to your ``package.json:

{
  "scripts": {
     "configure": "monorepo ci configure",
     "build": "monorepo build"
  }, 
  "monorepo": {
    "productionBranch": "main",
    "developBranch": "main",
    "npmAccess": "public",
    "trustedPublishing": true
  }
}

Configuration without Semantic-release

Add these tasks to your package.json:

{
  "scripts": {
    "test": "",
    "version:patch": "monorepo version patch", // update version
    "version:minor": "monorepo version minor",
    "version:major": "monorepo version major",
    "build": "monorepo build packages", // build packages
    "test:e2e: "",
    "publish": "monorepo publish packages" // publish on NPM
    "docs:build": "vuepress build",
    "docs:publish": "yarn docs:build && monorepo publish ghpages",
    "heroku:publish": ""
  }
}

Configuration with Semantic-release

Install semantic-release and add release.config.js file and add these lines:

module.exports = {
  branch: 'master',
  verifyConditions: ['@semantic-release/github', '@semantic-release/npm', '@tsed/monorepo-utils/semantic-release'],
  analyzeCommits: ['@semantic-release/commit-analyzer'],
  verifyRelease: [],
  generateNotes: ['@semantic-release/release-notes-generator'],
  prepare: ['@semantic-release/npm', '@tsed/monorepo-utils/semantic-release'],
  publish: ['@tsed/monorepo-utils/semantic-release', '@semantic-release/github'],
  success: ['@semantic-release/github', '@tsed/monorepo-utils/semantic-release'],
  fail: ['@semantic-release/github'],
  npmPublish: false
}

Add these tasks to your package.json:

{
  "scripts": {
    "release": "semantic-release"
  }
}

CI Configuration

To publish to npm with OIDC trusted publishing, set monorepo.trustedPublishing to true (or configure the semantic-release plugin with {trustedPublishing: true}). This omits the npm authentication token from generated .npmrc files so npm can use the CI provider's OIDC credentials. It only applies to npmjs registries; GitHub Packages and private registries still use their configured tokens.

export default {
  verifyConditions: [["@tsed/monorepo-utils/semantic-release", {trustedPublishing: true}]]
};

When trusted publishing is enabled, CI blocks a release if a public workspace package does not yet exist on npm. Bootstrap those packages locally, then complete the 2FA prompt required by npm:

NPM_TOKEN=... monorepo trust bootstrap
monorepo trust migrate

monorepo trust bootstrap publishes only packages that do not exist on npm with NPM_TOKEN, always using the temporary version 0.0.1, then configures npm trust github for each package. It restores the generated manifest afterwards. It asks which workflow in .github/workflows/ is allowed to publish; pass --file workflow.yml to skip the prompt. --repository owner/repository defaults to the repository URL in package.json.

monorepo trust migrate configures trusted publishing for packages already on npm. It does not publish packages and skips any package that already has a trusted publisher, preventing an existing configuration from being replaced.

Use monorepo packages status to list every workspace package and its status: private, unpublished, untrusted, or trusted. If npm requires authentication to read trusted publishers, it reports authentication-required instead. This command makes no changes.

To deploy with your favority CI, you have to create these environments variables to allow publishing on your NPM registries,

commit push and docker image deployment.

Variable Description
EMAIL User mail to sign the commit produced by MonoRepo
USER User name to sign the commit produced by MonoRepo
PROJECT_NAME The project to publish artifact on docker
GH_TOKEN A GitHub personal access token.
DOCKER_HUB_ID The docker hub id
DOCKER_HUB_PWD The docker password account
HEROKU_APP Enable deployment on heroku. Note: You have to configure HEROKU_API_KEY token on your CI

Github actions example

name: Build & Release
on:
  push:
  pull_request:
    branches:
      - main
jobs:     
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [ 14.x ]

    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: Install dependencies
        run: yarn install --frozen-lockfile --network-timeout 500000
      - name: Run build
        run: yarn build
        
# DEPLOY PACKAGES on NPM
deploy-packages:
    runs-on: ubuntu-latest
    needs: [build] # add depend job here
    if: ${{ github.event_name != 'pull_request' && contains(github.ref, 'main') }}

    strategy:
      matrix:
        node-version: [ 14.x ]

    steps:
      - uses: actions/checkout@v2
      - uses: actions/download-artifact@v2
        with:
          name: benchmarks
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: Install dependencies
        run: yarn install --frozen-lockfile --network-timeout 500000
      - name: Release packages
        env:
          CI: true
          GH_TOKEN: ${{ secrets.GH_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: yarn release

Contributors

Please read contributing guidelines here.

Backers

Thank you to all our backers! ๐Ÿ™ [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

License

The MIT License (MIT)

Copyright (c) 2016 - 2021 Romain Lenzotti

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

๐Ÿ› ๏ธ A tool to build and publish packages (Typescript or Javascript) on npm for projects based on mono repository (lerna).

Topics

Resources

Code of conduct

Contributing

Stars

4 stars

Watchers

4 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages