Skip to content

Commit

Permalink
Merge pull request #19 from davidovich/add-scaffolding
Browse files Browse the repository at this point in the history
Add scaffolding
  • Loading branch information
davidovich authored Mar 21, 2019
2 parents 1a6d034 + c16d94c commit 4bf8875
Show file tree
Hide file tree
Showing 19 changed files with 519 additions and 443 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
steps:
- checkout

- run: go test -cover -v ./...
- run: make
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
SHELL=/bin/bash

HAS_PACKR2 := $(shell command -v packr2)

export GO111MODULE := on

SCAFFOLD_BIN := bin/scaffold
PACKR_FILE := pkg/scaffold/scaffold-packr.go

ASSETS := $(shell find templates/scaffold)

all: test $(PACK_FILE) $(SCAFFOLD_BIN)

.PHONY: $(SCAFFOLD_BIN)
$(SCAFFOLD_BIN): $(PACKR_FILE)
@mkdir -p bin
go build -o $@ $(@F)/$(@F).go

$(PACKR_FILE): $(ASSETS)
ifndef HAS_PACKR2
go get -u github.com/gobuffalo/packr/v2/packr2
endif
packr2

.PHONY: test
test:
go test -cover -v ./...

.PHONY: clean
clean:
packr2 clean
rm -r bin
73 changes: 56 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Summon
======

Summon is used to manage a central location of data or
go executable references, and distribute them to any go-enabled environment.
go executable references, allowing distribution to any go-enabled environment.

It solves the maintenance problem of mutliple copies of same
It solves the maintenance problem of multiple copies of same
code snippets distributed in many repos, leveraging go modules and version
management.

Expand Down Expand Up @@ -35,30 +35,29 @@ which you then bootstrap at destination using standard go get or [gobin](https:/
Configuration
-------------

Create a data repository with this structure (summon-cli will allow bootstrapping this structure in the future):
### Data repository

Create a data repository with this structure

```
.
├── Makefile
├── assets
│ ├── text.txt
│ └── summon.config.yaml
├── boxer
│ └── box.go
├── go.mod
├── go.sum
└── summon
├── go.mod
└── summon.go
```

You just need to populate the `assets` directory with your own data.
There is an example setup at https://github.com/davidovich/summon-example-assets. Use this structure to bootstrap your own data provider. This is now automated using `github.com/davidovich/summon/scaffold init [module name]`.

The `boxer/` directory is used to provide Boxes to be found by [packr2](https://github.com/gobuffalo/packr/tree/master/v2).
The `summon/` directory is the entry point to the summon library, and creates the main executable.
You just need to populate the `assets` directory with your own data.

There is an example setup at https://github.com/davidovich/summon-example-assets.
The `summon/` directory is the entry point to the summon library, and creates the main executable. This directory will also host
[packr2](https://github.com/gobuffalo/packr/tree/master/v2) which encodes data into go files.

The `assets/summon.config.yaml` contains a configuration file to customize summon. You can define:
The `assets/summon.config.yaml` contains an (optional) configuration file to customize summon. You can define:

* aliases
* default output-dir
Expand Down Expand Up @@ -96,13 +95,15 @@ This will install gohack and forward the arguments that you provide.
Build
-----

In an asset data repository:
In an empty asset data repository:

0) (Comming soon) invoke summon-cli create
0) invoke `go run github.com/davidovich/summon/scaffold init [repo host (module name)]`
This will create code template similar as above
1) Use the provided Makefile to invoke the packr2 process: make
2) Commit the resulting -packr files so clients can go get the data repo
3) Tag the repo with semantic version (with the `v`) prefix
1) add assets that need to be shared amongst consumers
2) Use the provided Makefile to invoke the packr2 process: `make`
3) Commit the resulting -packr files so clients can go get the data repo
4) Tag the repo with semantic version (with the `v`) prefix


Install
-------
Expand Down Expand Up @@ -135,6 +136,44 @@ include $(shell summon version.mk)

By default, summon will put summoned scripts at the `.summoned/` directory at root of the current directory.

### Templating

Files in the asset directory can contain go templates. This allows customization using json data.

For example, consider this file in an asset provider:

```
/assets
template.file
```
With this content:

```
Hello {{ .Name }}!
```

`summon template.file --json '{ "Name": "David" }'`

You will get a summoned `template.file` file with this result:

```
Hello David!
```

Templates can also be used in the filenames given in the data hierarchy. This can be usefull to scaffold simple projects.

```
/assets
/template
{{.FileName}}
```

Then you can summon this file by introducing a FileName in json parameter.

In a comming update, you will be able to leverage this filename templating functionality by summoning a whole asset hierarchy:

`summon assets/template/* --json '{ "FileName": "myRenderedFileName" }'

### Running a go binary

`summon run [executable]` allows to run executables declared in the config file
Expand Down
14 changes: 3 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
module github.com/davidovich/summon

require (
github.com/gobuffalo/buffalo-plugins v1.13.0 // indirect
github.com/gobuffalo/envy v1.6.15 // indirect
github.com/gobuffalo/flect v0.1.0 // indirect
github.com/gobuffalo/meta v0.0.0-20190207205153-50a99e08b8cf // indirect
github.com/gobuffalo/packr/v2 v2.0.1
github.com/gobuffalo/packr/v2 v2.0.7
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/lithammer/dedent v1.1.0
github.com/pkg/errors v0.8.1
github.com/rogpeppe/go-internal v1.2.1 // indirect
github.com/spf13/afero v1.2.1
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3 // indirect
github.com/stretchr/testify v1.3.0
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 // indirect
golang.org/x/sys v0.0.0-20190213121743-983097b1a8a3 // indirect
golang.org/x/tools v0.0.0-20190213042836-0e66cc6fab8b // indirect
gopkg.in/yaml.v2 v2.2.2
)

// replace github.com/gobuffalo/packr/v2 => ../github.com/gobuffalo/packr/v2
Loading

0 comments on commit 4bf8875

Please sign in to comment.