Skip to content

Commit

Permalink
Merge pull request #244 from kool-dev/hugo
Browse files Browse the repository at this point in the history
Hugo + update kool create
  • Loading branch information
fabriciojs committed Jan 28, 2021
2 parents 715028e + 0e52a55 commit 150bc69
Show file tree
Hide file tree
Showing 18 changed files with 184 additions and 32 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Out current presets:
- [NestJS](docs/2-Presets/NestJS.md)
- [NextJS](docs/2-Presets/NextJS.md)
- [NuxtJS](docs/2-Presets/NuxtJS.md)
- [Hugo](docs/2-Presets/Hugo.md)

## Demo

Expand Down
21 changes: 13 additions & 8 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"kool-dev/kool/cmd/builder"
"kool-dev/kool/cmd/presets"
"kool-dev/kool/environment"
"os"

"github.com/spf13/cobra"
Expand All @@ -13,6 +14,7 @@ import (
type KoolCreate struct {
DefaultKoolService
parser presets.Parser
env environment.EnvStorage
createCommand builder.Command
KoolPreset
}
Expand All @@ -31,21 +33,24 @@ func NewKoolCreate() *KoolCreate {
return &KoolCreate{
*newDefaultKoolService(),
presets.NewParser(),
environment.NewEnvStorage(),
&builder.DefaultCommand{},
*NewKoolPreset(),
}
}

// Execute runs the create logic with incoming arguments.
func (c *KoolCreate) Execute(originalArgs []string) (err error) {
func (c *KoolCreate) Execute(args []string) (err error) {
var (
presetConfig *presets.PresetConfig
createCmds []string
ok bool
presetConfig *presets.PresetConfig
createCmds []string
ok bool
preset = args[0]
createDirectory = args[1]
)

preset := originalArgs[0]
dir := originalArgs[1]
// sets env variable CREATE_DIRECTORY that aims to tell
c.env.Set("CREATE_DIRECTORY", createDirectory)

c.parser.LoadPresets(presets.GetAll())
c.parser.LoadConfigs(presets.GetConfigs())
Expand All @@ -70,12 +75,12 @@ func (c *KoolCreate) Execute(originalArgs []string) (err error) {
return
}

if err = c.Interactive(c.createCommand, dir); err != nil {
if err = c.Interactive(c.createCommand); err != nil {
return
}
}

_ = os.Chdir(dir)
_ = os.Chdir(createDirectory)

err = c.KoolPreset.Execute([]string{preset})

Expand Down
2 changes: 2 additions & 0 deletions cmd/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (
"kool-dev/kool/cmd/builder"
"kool-dev/kool/cmd/presets"
"kool-dev/kool/cmd/shell"
"kool-dev/kool/environment"
"testing"
)

func newFakeKoolCreate() *KoolCreate {
return &KoolCreate{
*newFakeKoolService(),
&presets.FakeParser{},
environment.NewFakeEnvStorage(),
&builder.FakeCommand{},
*newFakeKoolPreset(),
}
Expand Down
36 changes: 28 additions & 8 deletions cmd/presets/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,34 @@ func GetConfigs() map[string]string {
configs["adonis"] = `language: javascript
commands:
create:
- kool docker kooldev/node:14-adonis adonis new
- kool docker kooldev/node:14-adonis adonis new $CREATE_DIRECTORY
`
configs["golang-cli"] = `language: golang
`
configs["hugo"] = `language: static
commands:
create:
- kool docker klakegg/hugo new site $CREATE_DIRECTORY
# questions:
# compose:
# - key: app
# template: hugo.yml
# - key: comments
# default_answer: none
# message: What comments service do you want to use
# options:
# - name: Commento
# template: commento.yml
# - name: none
# template: none
# templates:
# - key: scripts
# template: hugo.yml
`
configs["laravel"] = `language: php
commands:
create:
- kool docker kooldev/php:7.4 composer create-project --prefer-dist laravel/laravel
- kool docker kooldev/php:7.4 composer create-project --prefer-dist laravel/laravel $CREATE_DIRECTORY
questions:
compose:
- key: app
Expand Down Expand Up @@ -72,37 +92,37 @@ templates:
configs["nestjs"] = `language: javascript
commands:
create:
- kool docker kooldev/node:14-nest nest new
- kool docker kooldev/node:14-nest nest new $CREATE_DIRECTORY
`
configs["nextjs"] = `language: javascript
commands:
create:
- kool docker kooldev/node:14 yarn create next-app
- kool docker kooldev/node:14 yarn create next-app $CREATE_DIRECTORY
`
configs["nextjs-static"] = `language: javascript
commands:
create:
- kool docker kooldev/node:14 yarn create next-app
- kool docker kooldev/node:14 yarn create next-app $CREATE_DIRECTORY
`
configs["nuxtjs"] = `language: javascript
commands:
create:
- kool docker kooldev/node:14 yarn create nuxt-app
- kool docker kooldev/node:14 yarn create nuxt-app $CREATE_DIRECTORY
`
configs["nuxtjs-static"] = `language: javascript
commands:
create:
- kool docker kooldev/node:14 yarn create nuxt-app
- kool docker kooldev/node:14 yarn create nuxt-app $CREATE_DIRECTORY
`
configs["symfony"] = `language: php
commands:
create:
- kool docker kooldev/php:7.4 composer create-project --prefer-dist symfony/website-skeleton
- kool docker kooldev/php:7.4 composer create-project --prefer-dist symfony/website-skeleton $CREATE_DIRECTORY
questions:
compose:
- key: app
Expand Down
32 changes: 32 additions & 0 deletions cmd/presets/presets.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,38 @@ networks:
- mv my-cli /usr/local/bin/my-cli
fmt: kool run go fmt ./...
lint: kool docker --volume=gopath:/go golangci/golangci-lint:v1.31.0 golangci-lint run -v
`,
}
presets["hugo"] = map[string]string{
"docker-compose.yml": `version: "3.8"
services:
app:
image: klakegg/hugo
command: ["server", "-p", "80", "-D"]
working_dir: /app
ports:
- "${KOOL_APP_PORT:-80}:80"
volumes:
- .:/app:delegated
networks:
- kool_local
- kool_global
static:
image: kooldev/nginx:static
volumes:
- .:/app:delegated
networks:
- kool_local
- kool_global
networks:
kool_local:
kool_global:
external: true
name: "${KOOL_GLOBAL_NETWORK:-kool_global}"
`,
"kool.yml": `scripts:
hugo: kool docker -p 1313:1313 klakegg/hugo
dev: kool run hugo server -D
`,
}
presets["laravel"] = map[string]string{
Expand Down
43 changes: 43 additions & 0 deletions docs/2-Presets/Hugo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
### Using Hugo preset

#### Creating a new Hugo website

To make things easier we will use **kool** to install it for you.

```console
$ kool create hugo my-website

$ cd my-website
```
- **kool create** already executes **kool preset** internally so you can skip the command in the next step.

#### Adding kool to an existing Hugo website

Go to the project folder and run:

```console
$ cd my-website/
$ kool preset hugo
```

**kool preset** will create a few configuration files in order to enable you to configure / extend it. You don't need to execute it if you created the project with `kool create`.

### Using kool for Hugo development

- To start the container to serve your Hugo website:

```console
$ kool start
```

Then check out your site at `http://localhost`. If you wanna stop the container just run `kool stop`.

- To create some new content:

```console
$ kool run hugo new posts/my-super-post.md
```

---

Check your **kool.yml** to see what scripts you can run and add more.
18 changes: 10 additions & 8 deletions kool.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@ scripts:
dev:
- kool run compile
- kool run install
# Runs go CLI with proper version for kool development
# Runs go CLI with proper version for kool development (targets host OS passing down GOOS)
go: kool docker --volume=kool_gopath:/go --env='GOOS=$GOOS' golang:1.15.0 go
# Runs go CLI with Linux, independent of host OS
go:linux: kool docker --volume=kool_gopath:/go golang:1.15.0 go
# Compiling kool itself. In case you are on MacOS make sure to have your .env
# file properly setting GOOS=darwin so you will be able to use the binary.
compile:
- kool run fmt
- kool run go build -o kool
install:
- mv kool /usr/local/bin/kool
fmt: kool run go fmt ./...
fmt: kool run go:linux fmt ./...
lint: kool docker --volume=kool_gopath:/go golangci/golangci-lint:v1.31.0 golangci-lint run -v
test: kool docker --volume=kool_gopath:/go golang:1.15.0 go test ./...
test-coverage: kool docker --volume=kool_gopath:/go golang:1.15.0 go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
test: kool run go:linux test ./...
test-coverage: kool run go:linux test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
# Generate documentation for kool commands
make-docs:
- rm -f docs/4-Commands/*.md
- kool docker --volume=kool_gopath:/go golang:1.15.0 go run docs.go
- kool run go:linux run docs.go
# Parsing the preset files onto Go code in an automated fashion.
parse-presets:
- rm -f cmd/presets/presets.go
- rm -f cmd/presets/templates.go
- rm -f cmd/presets/configs.go
- kool docker --volume=kool_gopath:/go golang:1.15.0 go run parse_presets.go
- kool docker --volume=kool_gopath:/go golang:1.15.0 go run parse_templates.go
- kool docker --volume=kool_gopath:/go golang:1.15.0 go run parse_presets_configs.go
- kool run go:linux run parse_presets.go
- kool run go:linux run parse_templates.go
- kool run go:linux run parse_presets_configs.go
- kool run fmt
2 changes: 1 addition & 1 deletion presets/adonis/preset-config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: javascript
commands:
create:
- kool docker kooldev/node:14-adonis adonis new
- kool docker kooldev/node:14-adonis adonis new $CREATE_DIRECTORY
25 changes: 25 additions & 0 deletions presets/hugo/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3.8"
services:
app:
image: klakegg/hugo
command: ["server", "-p", "80", "-D"]
working_dir: /app
ports:
- "${KOOL_APP_PORT:-80}:80"
volumes:
- .:/app:delegated
networks:
- kool_local
- kool_global
static:
image: kooldev/nginx:static
volumes:
- .:/app:delegated
networks:
- kool_local
- kool_global
networks:
kool_local:
kool_global:
external: true
name: "${KOOL_GLOBAL_NETWORK:-kool_global}"
3 changes: 3 additions & 0 deletions presets/hugo/kool.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
scripts:
hugo: kool docker -p 1313:1313 klakegg/hugo
dev: kool run hugo server -D
19 changes: 19 additions & 0 deletions presets/hugo/preset-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: static
commands:
create:
- kool docker klakegg/hugo new site $CREATE_DIRECTORY
# questions:
# compose:
# - key: app
# template: hugo.yml
# - key: comments
# default_answer: none
# message: What comments service do you want to use
# options:
# - name: Commento
# template: commento.yml
# - name: none
# template: none
# templates:
# - key: scripts
# template: hugo.yml
2 changes: 1 addition & 1 deletion presets/laravel/preset-config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: php
commands:
create:
- kool docker kooldev/php:7.4 composer create-project --prefer-dist laravel/laravel
- kool docker kooldev/php:7.4 composer create-project --prefer-dist laravel/laravel $CREATE_DIRECTORY
questions:
compose:
- key: app
Expand Down
2 changes: 1 addition & 1 deletion presets/nestjs/preset-config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: javascript
commands:
create:
- kool docker kooldev/node:14-nest nest new
- kool docker kooldev/node:14-nest nest new $CREATE_DIRECTORY

2 changes: 1 addition & 1 deletion presets/nextjs-static/preset-config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: javascript
commands:
create:
- kool docker kooldev/node:14 yarn create next-app
- kool docker kooldev/node:14 yarn create next-app $CREATE_DIRECTORY

2 changes: 1 addition & 1 deletion presets/nextjs/preset-config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: javascript
commands:
create:
- kool docker kooldev/node:14 yarn create next-app
- kool docker kooldev/node:14 yarn create next-app $CREATE_DIRECTORY

2 changes: 1 addition & 1 deletion presets/nuxtjs-static/preset-config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: javascript
commands:
create:
- kool docker kooldev/node:14 yarn create nuxt-app
- kool docker kooldev/node:14 yarn create nuxt-app $CREATE_DIRECTORY

2 changes: 1 addition & 1 deletion presets/nuxtjs/preset-config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: javascript
commands:
create:
- kool docker kooldev/node:14 yarn create nuxt-app
- kool docker kooldev/node:14 yarn create nuxt-app $CREATE_DIRECTORY

2 changes: 1 addition & 1 deletion presets/symfony/preset-config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: php
commands:
create:
- kool docker kooldev/php:7.4 composer create-project --prefer-dist symfony/website-skeleton
- kool docker kooldev/php:7.4 composer create-project --prefer-dist symfony/website-skeleton $CREATE_DIRECTORY
questions:
compose:
- key: app
Expand Down

0 comments on commit 150bc69

Please sign in to comment.