home

Simple make file with CUE

// make_tool.cue
package main

import (
  "tool/file"
)

files: {}

command: make: {
  for k, v in files {
    "\(k)": file.Create & {
      filename: k
      contents: v.contents
    }
  }
}

This is a quick boilerplate for Cue lang to start producing (text) files.

That way one can create many (consistent!) files from a single Cue file/package by using cue cmd make. As an example - I use it to generate Pikchr diagrams wrapped in Markdown:

#MdPikchr: {
  pikchr: string
  contents: "```pikchr\n\(pikchr)\n```"
}
files: {
  "my_diagram.md": {
    #MdPikchr
    pikchr: """
        box "Hello"
        arrow
        circle "World"
        """
  }
}

Which becomes my_diagram.md with the following contents:

```pikchr
box "Hello"
arrow
circle "World"
```

…and live refreshes in Obsidian :)

Przemysław Alexander Kamiński
vel xlii vel exlee

cb | gl | gh | li | rss

Powered by hugo and hugo-theme-nostyleplease.