Skip to content

TypeScript/JavaScript Config

You can configure your projects programmatically with TypeScript or JavaScript.
The config filename can be any of the following:

  • likec4.config.js
  • likec4.config.mjs
  • likec4.config.ts
  • likec4.config.mts

Example:

likec4.config.ts
import { defineConfig } from '@likec4/config'
export default defineConfig({
name: 'my-project',
title: 'My Project',
exclude: ["**/node_modules/**", "**/.cache/**"],
imageAliases: {
"@": "./images",
"@root": "../../some-more-images"
}
})

LikeC4 CLI has a generate command to generate files from your model.
You can define custom generators in your project config:

likec4.config.ts
import { defineConfig } from '@likec4/config'
export default defineConfig({
name: 'my-project',
title: 'My Project',
generators: {
'hello': async ({ likec4model, ctx }) => {
await ctx.write({
path: 'hello.txt', // relative to the project root
content: `Project: ${likec4model.project.id}`,
})
},
},
})

Now you can run your generator with CLI:

Terminal window
likec4 gen hello

In multi-project workspace use:

Terminal window
likec4 gen hello --project my-project
# Other options
likec4 gen hello --project my-project --use-dot

There is also helper function defineGenerators to define reusable generators:

example
// shared_generators.ts
import { defineGenerators } from '@likec4/config'
export default defineGenerators({
'hello': async ({ likec4model, ctx }) => {
await ctx.write({
path: 'hello.txt', // relative to the project root
content: `Project: ${likec4model.project.id}`,
})
},
})
// likec4.config.ts
import { defineConfig } from '@likec4/config'
import generators from './shared_generators'
export default defineConfig({
name: 'my-project',
title: 'My Project',
generators,
})