Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,30 @@ jobs:
cache: true
- run: make smoke

templates:
name: built-in templates build and pass their tests
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
cache: true
- uses: actions/setup-node@v4
with:
node-version: 22
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Rust
run: rustup toolchain install stable --profile minimal && rustup default stable
- run: make templates

# Required status check: one name to protect in the branch rules.
ci-ok:
if: always()
needs: [test, lint, vulncheck, cross-build, smoke]
needs: [test, lint, vulncheck, cross-build, smoke, templates]
runs-on: ubuntu-latest
steps:
- name: All jobs must have succeeded
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ and versions follow [Semantic Versioning](https://semver.org/).

## [Unreleased]

## [0.3.0] - 2026-10-16

### Added
- **Built-in templates** that ship inside the binary: `go-basic`, `go-http`, `node-basic`, `node-http`,
`typescript-basic`, `python-basic`, `python-http`, `rust-basic`, `static-site` and `blank`. `foundry new` works
right after installing; `--language` uses the built-in template of that language unless you set another.
- `foundry template export <name> <folder>` copies a built-in template so you can change it.
- `foundry template list --builtin` and `--saved`; built-in templates can be the default of a language.
- `scripts/test-templates.sh` and a CI job that create a project from every built-in template and run its
own build and tests.

### Changed
- `foundry template list` shows built-in and saved templates (before: only saved ones). A template you saved
hides a built-in one with the same name.
- The example templates under `examples/` became built-in templates.

## [0.2.0] - 2026-10-16

### Security
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo none)
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -s -w -X $(MODULE)/internal/cli.version=$(VERSION) -X $(MODULE)/internal/cli.commit=$(COMMIT) -X $(MODULE)/internal/cli.date=$(DATE)

.PHONY: all build test race cover vet fmt fmt-check check lint vuln smoke dist install clean
.PHONY: all build test race cover vet fmt fmt-check check lint vuln smoke templates dist install clean

all: check build

Expand Down Expand Up @@ -44,6 +44,10 @@ vuln:
smoke: build
FOUNDRY_BIN=$(CURDIR)/foundry scripts/smoke-test.sh

# Creates a project from every built-in template and runs that language's own tests on it.
templates: build
FOUNDRY_BIN=$(CURDIR)/foundry scripts/test-templates.sh

# Cross-compiled archives and checksums in dist/ (see scripts/dist.sh).
dist:
VERSION=$(VERSION) COMMIT=$(COMMIT) DATE=$(DATE) scripts/dist.sh
Expand Down
60 changes: 40 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ Foundry turns any directory into a reusable project template. Create a new proje
name, author and license filled in, setup commands run and a first git commit made.

```console
$ foundry template add go-cli ./examples/go-cli
✓ Template "go-cli" saved

$ foundry config Go go-cli # make it the default for Go
$ foundry new my-api --language Go
Creating project "my-api" from go-cli
✓ Created 3 files in my-api
Creating project "my-api" from go-basic (built-in)
✓ Created 5 files in my-api
✓ Initialised a git repository.
✓ Added a .gitignore for Go.
✓ Created the first commit.
Expand Down Expand Up @@ -73,24 +69,47 @@ cd Foundry
make build # produces ./foundry
```

## Built-in templates

Foundry comes with templates for common starts, so `foundry new` works the moment it is installed. Each one
builds and passes its own tests, and uses only the language's standard tooling (no frameworks).

| Template | Language | What you get |
| --- | --- | --- |
| `go-basic` | Go | Command line program with flags and tests |
| `go-http` | Go | HTTP service with health check, graceful shutdown and tests |
| `node-basic` | JavaScript | Node.js program, ES modules, built-in test runner |
| `node-http` | JavaScript | Node.js HTTP service with health check and tests |
| `typescript-basic` | TypeScript | TypeScript program compiled with `tsc`, built-in test runner |
| `python-basic` | Python | Command line program with `pyproject.toml` and `unittest` |
| `python-http` | Python | HTTP service with health check and `unittest`, standard library only |
| `rust-basic` | Rust | Command line program with a unit test |
| `static-site` | HTML | Plain HTML and CSS site |
| `blank` | any | An empty project: README and editor settings |

`foundry new my-app --language Go` uses the built-in template of that language (marked as default in
`foundry template list`) unless you chose another. Want to change one? `foundry template export go-basic ./my-go`
copies it to a folder; edit it and save it as your own with `foundry template add`. Your own templates win when a
name is the same.

## Quick start

```console
# 1. Save a directory as a template (the language is detected)
foundry template add go-cli ./examples/go-cli --description "Go CLI starter"
foundry template add node-cli ./examples/node-cli
# 1. Create a project from a built-in template
foundry new my-api --language Go # the default template of a language
foundry new my-tool --template node-basic # a specific template
foundry new my-app # choose from menus
foundry template list # see what is available

# 2. Optional: pick a default template per language
foundry config Go go-cli
# 2. Preview first: nothing is written
foundry new my-api --template go-http --dry-run

# 3. Create a project
foundry new my-api --language Go # default template of a language
foundry new my-tool --template node-cli # a specific template
foundry new my-app # choose from menus
foundry new my-site --git https://github.com/you/template # a repository as template
# 3. Make your own templates and defaults
foundry template add my-go ./path/to/directory # save any directory as a template
foundry config Go my-go # make it the default for Go

# 4. See what would happen without writing anything
foundry new my-api --template go-cli --dry-run
# 4. Other sources
foundry new my-site --git https://github.com/you/template # a repository as template
```

On the first run Foundry creates `~/.foundry/config.yaml`, detects the tools on your machine and
Expand All @@ -117,14 +136,15 @@ Details, ignore rules and tips: [docs/templates.md](docs/templates.md).
| --- | --- |
| `foundry new <name>` | Create a project. Flags: `--template`, `--language`, `--git`, `--branch`, `--path`, `--var KEY=VALUE`, `--dry-run`, `--json` (with `--dry-run`), `--no-git`, `--no-post`, `--no-open`, `--non-interactive` |
| `foundry template add <name> <path>` | Save a directory as a template (`--description`, `--language`) |
| `foundry template list` | List templates (`--sort name\|language`, `--quiet`, `--json`) |
| `foundry template list` | List built-in and saved templates (`--saved`, `--builtin`, `--sort name\|language`, `--quiet`, `--json`) |
| `foundry template show <name>` | Show details and files (`--files-only`, `--summary`, `--json`) |
| `foundry template update [name...]` | Rescan templates so file lists stay current |
| `foundry template edit <name>` | Change description, language, path or name |
| `foundry template vars <name>` | List the placeholders a template uses |
| `foundry template export <name> <folder>` | Copy a built-in template to a folder so you can change it |
| `foundry template remove <name>` | Forget a template (`--force` if it is a default); files stay |
| `foundry config` | Show settings; set with `--user`, `--license`, `--default-language`, `--docker`, `--interactive`; `--json`, `--path` |
| `foundry config <language> <template>` | Set the default template of a language (`""` clears it) |
| `foundry config <language> <template>` | Set the default template of a language, built-in or your own (`""` clears it) |
| `foundry detect` | Detect languages, package managers and tools (`--json`, `--yes`) |
| `foundry completion <shell>` | Shell completion for bash, zsh, fish and PowerShell |
| `foundry version` | Print version information |
Expand Down
16 changes: 16 additions & 0 deletions docs/templates.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Writing templates

Foundry ships with built-in templates (`foundry template list --builtin`); everything below applies to them too,
and to your own. To start from a built-in one, run `foundry template export go-basic ./my-go`.

A Foundry template is an ordinary directory. Everything in it is copied into the new project, with
placeholders filled in.

Expand Down Expand Up @@ -62,3 +65,16 @@ JavaScript, TypeScript, React and Vue) and the hints shown at the end.
`foundry new my-app --git https://github.com/you/template [--branch main]` fetches a shallow clone,
uses it like a template (placeholders, `.foundryignore`) and starts a fresh history. The history of
the template is not copied.

## Built-in templates in the source

The built-in templates live in `templates/_builtin/<name>/` and are embedded in the binary. They are listed,
with a language and a description, in `templates/_builtin/catalog.json`. Two details:

- The directory starts with an underscore so that the Go tools ignore it: the Go sources of the templates are
not compiled as part of Foundry.
- A `go.mod` would make a directory a separate module that cannot be embedded, so templates keep it as
`go.mod.txt`; Foundry gives it its real name when it writes a project.

To add a template: create the directory, add it to `catalog.json`, add a line to `scripts/test-templates.sh`
that builds and tests the generated project, and run `make templates`.
9 changes: 0 additions & 9 deletions examples/go-cli/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions examples/go-cli/go.mod

This file was deleted.

7 changes: 0 additions & 7 deletions examples/go-cli/main.go

This file was deleted.

9 changes: 0 additions & 9 deletions examples/node-cli/README.md

This file was deleted.

9 changes: 0 additions & 9 deletions examples/node-cli/package.json

This file was deleted.

1 change: 0 additions & 1 deletion examples/node-cli/src/index.js

This file was deleted.

4 changes: 0 additions & 4 deletions examples/python-cli/.foundryignore

This file was deleted.

8 changes: 0 additions & 8 deletions examples/python-cli/README.md

This file was deleted.

1 change: 0 additions & 1 deletion examples/python-cli/requirements.txt

This file was deleted.

9 changes: 0 additions & 9 deletions examples/python-cli/src/{{PROJECT_NAME_SNAKE}}.py

This file was deleted.

3 changes: 0 additions & 3 deletions examples/static-site/README.md

This file was deleted.

97 changes: 97 additions & 0 deletions internal/cli/builtin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package cli

import (
"fmt"
"os"
"sort"
"strings"

"github.com/SandSoftwareSolutions/Foundry/internal/config"
"github.com/SandSoftwareSolutions/Foundry/templates"
)

// entry is a template the user can pick: one they saved, or one that ships with Foundry.
type entry struct {
config.Template
Builtin bool
}

// lookup finds a template by name. Templates the user saved win over built-in ones with the same name.
func lookup(cfg *config.Config, name string) (entry, bool) {
if t, ok := cfg.FindTemplate(name); ok {
return entry{Template: *t}, true
}
if b, ok := templates.Get(name); ok {
return entry{Template: config.Template{Name: b.Name, Language: b.Language, Description: b.Description}, Builtin: true}, true
}
return entry{}, false
}

// everyTemplate returns the saved and the built-in templates, sorted by name; a saved template hides a
// built-in one with the same name.
func everyTemplate(cfg *config.Config) []entry {
saved := map[string]bool{}
var out []entry
for _, t := range cfg.Templates {
saved[strings.ToLower(t.Name)] = true
out = append(out, entry{Template: t})
}
for _, b := range templates.Catalog() {
if saved[strings.ToLower(b.Name)] {
continue
}
out = append(out, entry{Template: config.Template{Name: b.Name, Language: b.Language, Description: b.Description}, Builtin: true})
}
sort.Slice(out, func(i, j int) bool { return out[i].Name < out[j].Name })
return out
}

func everyName(cfg *config.Config) []string {
list := everyTemplate(cfg)
names := make([]string, len(list))
for i, e := range list {
names[i] = e.Name
}
return names
}

func languagesOf(list []entry) []string {
set := map[string]bool{}
for _, e := range list {
if e.Language != "" {
set[e.Language] = true
}
}
out := make([]string, 0, len(set))
for l := range set {
out = append(out, l)
}
sort.Strings(out)
return out
}

// materialize makes sure the template exists as a directory. A built-in template is written to a
// temporary directory; the returned function removes it again.
func materialize(e entry) (config.Template, func(), error) {
noop := func() {}
if !e.Builtin {
return e.Template, noop, nil
}
dir, err := os.MkdirTemp("", "foundry-builtin-*")
if err != nil {
return config.Template{}, noop, err
}
cleanup := func() { _ = os.RemoveAll(dir) }
if err := templates.Extract(e.Name, dir); err != nil {
cleanup()
return config.Template{}, noop, fmt.Errorf("cannot unpack the built-in template %q: %w", e.Name, err)
}
t := e.Template
t.Path = dir
return t, cleanup, nil
}

// builtinChangeError explains why a built-in template cannot be edited or removed.
func builtinChangeError(name string) error {
return usagef("%q is a built-in template and cannot be changed or removed.\nMake a copy you can edit with: foundry template export %s <folder>, then: foundry template add <name> <folder>", name, name)
}
Loading
Loading