turbo icon indicating copy to clipboard operation
turbo copied to clipboard

Docs: document `turbo.*` generator variables

Open moltar opened this issue 1 year ago • 3 comments

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 avatar Jul 10 '24 13:07 moltar

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
    }
  ]
}

moltar avatar Jul 10 '24 13:07 moltar

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:

  • cwd: I assume "current workspace directory", the path of the workspace that turbo gen was executed in (not the actual location inside that workspace)
  • root: Monorepo/Project root path
  • workspace: Path of the workspace that the selected generator config is in (For a generator that is in a workspace folder it was "C:\Development\monorepo\libs\core\turbo\generators", though the path ended at the project root for @moltar for some reason)

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.

RaisRichard avatar Jul 19 '24 09:07 RaisRichard

Hey all, a little details here - these are intended to be public, so you can use them without fear that we'll break it without notice. We'll add it to the list to document!

tknickman avatar Nov 08 '24 02:11 tknickman