vercel / turborepo

Build system optimized for JavaScript and TypeScript, written in Rust
https://turbo.build/repo/docs
MIT License
26k stars 1.79k forks source link

Docs: document `turbo.*` generator variables #8708

Open moltar opened 2 months ago

moltar commented 2 months ago

What is the improvement or update you wish to see?

Code generator comes with built-in variables, e.g. {{ turbo.paths.root }}, but they are not documented anywhere.

Is there any context that might help us understand?

https://turbo.build/repo/docs/guides/generating-code

Does the docs page already exist? Please link to it.

https://turbo.build/repo/docs/guides/generating-code

moltar commented 2 months ago

Dumping turbo object, it seems to have the following shape, but not sure what is public there:

{
  "paths": {
    "cwd": "/Users/foo/my-project/apps/dir",
    "root": "/Users/foo/my-project",
    "workspace": "/Users/foo/my-project"
  },
  "configs": [
    {
      "config": {},
      "turboConfigPath": "/Users/foo/my-project/turbo.json",
      "workspacePath": "/Users/foo/my-project",
      "isRootConfig": true
    }
  ]
}
RaisRichard commented 1 month ago

Hi, I stumbled across this feature and was also wondering about this. I did some digging and I'm just going to leave this for anyone else that is currently looking:

My turbo object dump looks like this:

{
  paths: {
    cwd: 'C:\\Development\\monorepo\\libs\\core',
    root: 'C:\\Development\\monorepo',
    workspace: 'C:\\Development\\monorepo\\libs\\core\\turbo\\generators'
  },
  configs: [
    {
      config: [Object],
      turboConfigPath: 'C:\\Development\\monorepo\\turbo.json',
      workspacePath: 'C:\\Development\\monorepo',
      isRootConfig: true
    },
    {
      config: [Object],
      turboConfigPath: 'C:\\Development\\monorepo\\apps\\dev-storybook\\turbo.json',
      workspacePath: 'C:\\Development\\monorepo\\apps\\dev-storybook',
      isRootConfig: false
    },
    {
      config: [Object],
      turboConfigPath: 'C:\\Development\\monorepo\\apps\\docs\\turbo.json',
      workspacePath: 'C:\\Development\\monorepo\\apps\\docs',
      isRootConfig: false
    }
  ]
}

paths:

configs is an array of every config that turbo knows about.

Custom plop action functions also have access to this turbo object as a prop of the answers object.

By the way, it would be awesome if paths could list every known workspace so that you can do something in all of them or select one of them. I was originally looking at this feature to automatically generate TS types in a library workspace, based on its src/components contents.