Module Layout



CUE modules have a specific set of files and directories that make up the layout.

cue.mod

Both cue and hof will look for this directory and file, by walking up the directory tree until it finds them.

The cue.mod directory has a few important subdirectories

cue.mod directory

cue.mod/
	module.cue  // indicates a CUE module
	sums.cue    // hashes for integrity
  /pkg        // where dependencies go
	/gen        // where `cue import` puts code
	/usr        // for extending or correcting /gen

module.cue

The module.cue file is how cue knows the current module name and how hof records dependencies.

cue.mod/module.cue

module: "github.com/hofstadter-io/hof"
cue: "0.5.0"

// Direct dependencies (managed by hof)
require: {
	"github.com/hofstadter-io/ghacue": "v0.2.0"
	"github.com/hofstadter-io/hofmod-cli": "v0.8.4"
}

// Indirect dependencies (managed by hof)
indirect: { ... }

// Replace dependencies with remote or local, useful for co-development
replace: {
  "github.com/hofstadter-io/ghacue": "github.com/myorg/ghacue": "v0.2.1"
  "github.com/hofstadter-io/hofmod-cli": "../mods/cli"
}

packages

A CUE module is a collection of packages. These are similar to Go packages, and if you use them the same, then they will behave the same. However, CUE modules have several extensions. We recommend sticking to the Go style packages and imports, as this style is much easier for non-experts to understand. If you want to learn about the other variations, check out our page on cuetorials.com - modules & packages.

The Go style of packages and imports:

  • use lowercase and underscores
  • have only one package per directory
  • name should be the same as the directory
  • use <module-path>/<package-path> for all imports

For example, in the github.com/hofstadter-io/hof module, we have imports like:

github.com/hofstadter-io/hof - hof.cue

package hof

import (
	// CUE stdlib
	"strings"

	// dependency import
	"github.com/hofstadter-io/hofmod-cli/gen"

	// module-local import
	"github.com/hofstadter-io/hof/design"
)

Cli: gen.#Generator & {
	@gen(cli,hof)
	Outdir: "./"
	Cli:    design.#CLI
	WatchGlobs: ["./design/**/*"]
}