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:
import { defineConfig } from '@likec4/config'
export default defineConfig({ name: 'my-project', title: 'My Project', exclude: ["**/node_modules/**", "**/.cache/**"], imageAliases: { "@": "./images", "@root": "../../some-more-images" }})
Custom Generators
Section titled “Custom Generators”LikeC4 CLI has a generate
command to generate files from your model.
You can define custom generators in your project config:
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:
likec4 gen hello
In multi-project workspace use:
likec4 gen hello --project my-project# Other optionslikec4 gen hello --project my-project --use-dot
Reusable Generators
Section titled “Reusable Generators”There is also helper function defineGenerators
to define reusable generators:
// shared_generators.tsimport { 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.tsimport { defineConfig } from '@likec4/config'import generators from './shared_generators'
export default defineConfig({ name: 'my-project', title: 'My Project', generators,})