All Projects → palmerhq → Monorepo Starter

palmerhq / Monorepo Starter

Monorepo starter project for Kotlin, Python, TypeScript x React

Programming Languages

python
139335 projects - #7 most used programming language
typescript
32286 projects
kotlin
9241 projects

Projects that are alternatives of or similar to Monorepo Starter

Vitamin Web
Decathlon Design System libraries for web applications
Stars: ✭ 70 (-72.55%)
Mutual labels:  lerna, yarn
Eslint Plugin Monorepo
ESLint Plugin for monorepos
Stars: ✭ 56 (-78.04%)
Mutual labels:  lerna, yarn
Syncpack
Manage multiple package.json files, such as in Lerna Monorepos and Yarn/Pnpm Workspaces
Stars: ✭ 356 (+39.61%)
Mutual labels:  lerna, yarn
manager
OVHcloud Control Panel
Stars: ✭ 153 (-40%)
Mutual labels:  yarn, lerna
monorepo-utils
A collection of utilities for monorepo/lerna. Tools for TypeScript project references etc..
Stars: ✭ 143 (-43.92%)
Mutual labels:  yarn, lerna
Flow Mono Cli
A command line interface that aims to solve a few issues while working with flow typed codebases in a mono-repo.
Stars: ✭ 84 (-67.06%)
Mutual labels:  lerna, yarn
Lerna Yarn Workspaces Example
How to build TypeScript mono-repo project with yarn and lerna
Stars: ✭ 787 (+208.63%)
Mutual labels:  lerna, yarn
Yerna
A Lerna-like tool for managing Javascript monorepos using Yarn
Stars: ✭ 140 (-45.1%)
Mutual labels:  lerna, yarn
yarn-workspaces-example
Sample monorepo project using new Yarn feature called Workspaces
Stars: ✭ 39 (-84.71%)
Mutual labels:  yarn, lerna
monopack
A JavaScript bundler for node.js monorepo-codebased applications.
Stars: ✭ 52 (-79.61%)
Mutual labels:  yarn, lerna
gulp-yarn
Automatically install node modules using Yarn. 😻
Stars: ✭ 22 (-91.37%)
Mutual labels:  yarn
lagom-samples
developer.lightbend.com/start/?group=lagom
Stars: ✭ 85 (-66.67%)
Mutual labels:  jvm
arquillian-container-was
Arquillian WebSphere Containers
Stars: ✭ 18 (-92.94%)
Mutual labels:  jvm
JBWAPI
Pure Java BWAPI Client implementation for JVM languages
Stars: ✭ 16 (-93.73%)
Mutual labels:  jvm
twitch-chat-visualizer
A Node.js Project. Would you like to see your chat stream with a custom design? This is for you!
Stars: ✭ 14 (-94.51%)
Mutual labels:  yarn
supabase-schema
Secured & Simple Supabase Schema Visualizer
Stars: ✭ 216 (-15.29%)
Mutual labels:  yarn
KotlinSchool
Kotlin School with Kotlin Programming Tutorial
Stars: ✭ 26 (-89.8%)
Mutual labels:  jvm
lambda-string
Lambda-string (LS) is a helping java agent that inject configurable toString method into lambdas with some useful meta-information.
Stars: ✭ 34 (-86.67%)
Mutual labels:  jvm
monoreact
📦 React workspaces implementation
Stars: ✭ 13 (-94.9%)
Mutual labels:  yarn
mono.ts
A minimal example of a typescript mono repo with pre-build support (tests, vscode).
Stars: ✭ 58 (-77.25%)
Mutual labels:  lerna

Monorepo Starter

This is a polyglot monorepo boilerplate for The Palmer Group. It is a starter monorepo comprised of TypeScript apps/packages, placeholder JVM and Python apps and an example deployment workflow.

Overview

The repository is powered by Lerna and Yarn. Lerna is responsible for bootstrapping, installing, symlinking all of the packages/apps together.

What's inside

This repo includes multiple packages and applications for a hypothetical project called mono. Here's a rundown of the folders:

  • mono-common: Shared utilities (TypeScript)
  • mono-ui: Component library (TypeScript x Storybook) (depends on mono-common)
  • mono-cra: Create React App x TypeScript (depends on mono-common + mono-ui)
  • mono-razzle: Razzle x TypeScript (depends on mono-common + mono-ui)
  • mono-jvm: Dropwizard x Kotlin
  • .circle: Some example CircleCI v2 workflows for various monorepo setups (including polyglot)

Tweaking for your project

You should run a search and replace on the word mono and replace with your project name. Rename folders from mono-xxx as well. Lastly, -razzle and -cra are just placeholders. You should carefully replace them with their proper names as well like -web,-admin, -api, or -whatever-makes-sense.

TypeScript

Referencing packages from other packages/apps

Each package can be referenced within other packages/app files by importing from @<name>/<folder> (kind of like an npm scoped package).

import * as React from 'react';
import './App.css';
import { Button } from '@mono/ui';

class App extends React.Component<any> {
  render() {
    return (
      <div className="App">
        <header className="App-header">
          <h1 className="App-title">Welcome to React</h1>
        </header>
        <Button>Hello</Button>
        <p className="App-intro">
          To get started, edit <code>src/App.tsx</code> and save to reload.
        </p>
      </div>
    );
  }
}

export default App;

IMPORTANT: YOU DO NOT NEED TO CREATE/OWN THE NPM ORGANIZATION OF YOUR PROJECT NAME BECAUSE NOTHING IS EVER PUBLISHED TO NPM.

For more info, see the section on package versioning

Installing

Install lerna globally.

npm i -g lerna
git clone [email protected]:palmerhq/typescript-monorepo-starter.git
cd typescript-monorepo-starter
rm -rf .git
yarn install

Development

Lerna allows some pretty nifty development stuff. Here's a quick rundown of stuff you can do:

  • yarn start: Run's the yarn start command in every project and pipe output to the console. This will do the following:
    • mono-cra: Starts the app in dev mode on port 3000
    • mono-razzle: Starts the app in dev mode on port 8082
    • mono-ui: Starts TypeScript watch task, and also launches react-storybook on port 6006
    • mono-common: Starts TypeScript watch task
  • yarn test: Run's the yarn test command in every project and pipe output to the console. Because of how jest works, this cannot be run in watch mode...womp.womp.
  • yarn build: Build all projects
  • lerna clean: Clean up all node_modules
  • lerna bootstrap: Rerun lerna's bootstrap command

Package Management

**IF you run yarn add <module> or npm install <module> from inside a project folder, you will break your symlinks.** To manage package modules, please refer to the following instructions:

Installing a module from Yarn

To add a new npm module to ALL packages, run

lerna add <module>

To add a new npm module(s) to just one package

lerna add <module> --scope=<package-name> <other yarn-flags>

# Examples (if your project name was `mono`)
lerna add classnames --scope=@mono/ui
lerna add @types/classnames @types/jest --scope=@mono/ui --dev

Uninstalling a module from a package

Unfortunately, there is no lerna remove or lerna uninstall command. Instead, you should remove the target module from the relevant package or packages' package.json and then run lerna bootstrap again.

Reference issue: https://github.com/lerna/lerna/issues/1229#issuecomment-359508643

Package Versioning and TS Paths

None of the packages in this setup are ever published to NPM. Instead, each shared packages' (like mono-common and mono-ui) have build steps (which are run via yarn prepare) and get built locally and then symlinked. This symlinking solves some problems often faced with monorepos:

  • All projects/apps are always on the latest version of other packages in the monorepo
  • You don't actually need to version things (unless you actually want to publish to NPM)
  • You don't need to do special stuff in the CI or Cloud to work with private NPM packages

Somewhat confusingly, (and amazingly), the TypeScript setup for this thing for both mono-cra and mono-razzle directly reference source code (<name>/src/**) of mono-ui and mono-common by messing with paths in tsconfig.json.

{
  "extends": "./tsconfig.base.json",
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@mono/common/*": ["./mono/common/src"],
      "@mono/ui/*": ["./mono/ui/src"]
    }
  }
}

Long story short, this means that you can open up this whole thing at the root directory and VSCode will understand what is going on.

You are welcome.

Altering paths and package names

If you don't like the @mono/<folder> you can change it to whatever you want to. For example, you may want to change it to mono-<folder> so it exactly matches the folder names.

To do this, you need to (search and replace @mono/ with mono-). Or in other words:

  • Edit ./tsconfig.json's paths
  • Edit each package's name in package.json
  • Update references to related packages in dependencies in each package.json
  • Update references in code in each package.

Again, search and replace will work.

Important: If you do this, then your Lerna installation scoping will also change because it uses the package name.

# old
lerna add axios --scope=@mono/common

# new (changed to mono-common)
lerna add axios --scope=mono-common

JVM

Kotlin

Refer to internal Palmer Group documentation. Deployment workflow for the mono-jvm folder is a stub.

Python

Inside of the mono-python folder is a "Hello World" Flask application and Docker setup.

Running locally

Set up Python environment:

pipenv install

To create a virtual environment you just execute the $ pipenv shell.

Run a development server:

FLASK_APP=helloworld flask run

Docker image

Build the docker image:

docker build -t flask-pipenv-helloworld .

Run the Docker Container:

docker run -p 8000:8000 flask-pipenv-helloworld

You can find the container runtime details as shown below:

docker ps
# ...
CONTAINER ID        IMAGE                             COMMAND                  CREATED             STATUS              PORTS                      NAMES
80af0bce64c7        flask-pipenv-helloworld           "gunicorn -b0.0.0.0:…"   1 second ago        Up Less than a second   0.0.0.0:8000->8000/tcp     silly_goldstine

Running the tests

Install the prerequisites:

pipenv install --dev

Runs tests:

pipenv run python -m pytest

Inspiration

A LOT of this has been shameless taken from Quramy/lerna-yarn-workspaces-example. So much so, in fact, you can read the original README.md in WORKSPACES.md

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].