Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Monorepo Generation

Once we have our settings (or not, if we want to use defaults), we can run

sketch ts monorepo

to create our new Typescript monorepo.

For example, if we use this config:

typescript:
  root_package:
    name: workspace

    package_json:
      license: Apache-2.0
      devDependencies:
        husky: latest

    # The tsconfig files to generate at the root.
    # If left empty, defaults will be used.
    ts_config:
      - output: tsconfig.options.json
        config:
          compilerOptions:
            verbatimModuleSyntax: true
            strict: true

      - output: tsconfig.json
        config:
          files: []

    # Literal oxlint configuration to generate at the root
    # of the workspace.
    # Can be set to `true` to use defaults.
    oxlint: |
      {
        "plugins": ["unicorn", "typescript", "oxc"]
      }

And the package.json file of the root package will be like this:

{
  "name": "workspace",
  "private": true,
  "version": "0.1.0",
  "type": "module",
  "license": "Apache-2.0",
  "packageManager": "pnpm",
  "scripts": {},
  "devDependencies": {
    "husky": "^9.1.7", 
    "oxlint": "^1.16.0", 
    "typescript": "^5.9.2"
  },
  "dependencies": {}
}

You can also use the generate_templates field to automatically generate a certain file structure when the monorepo is generated.

Let's say, for example, that every time that you create a new monorepo, you always want to create a docker directory with a basic dev.dockerfile inside of it, so that you can quickly create a dev environment using docker.

For the root package, you would do so like this:

    generate_templates:
      - output: docker/dev.dockerfile
        template:
          name: dev_dockerfile
          content: |
            FROM node:23-alpine

            COPY . .
            EXPOSE {{ docker_dev_port }}
            CMD ["npm", "run", "dev"]

vars:
  docker_dev_port: 5173

So the final tree structure of the output directory will look like this:

.
├── .oxlintrc.json
├── docker
│   └── dev.dockerfile
├── package.json
├── packages
├── pnpm-workspace.yaml
├── tsconfig.json
└── tsconfig.options.json

ℹ️ You can use the -i flag to install dependencies for the root package after creating the new monorepo.