Skip to content

Commit

Permalink
Merge pull request #15 from zwoo-hq/release/v1.0.0
Browse files Browse the repository at this point in the history
release: v1.0.0
  • Loading branch information
fabiankachlock committed Mar 14, 2024
2 parents 9171545 + 5605835 commit 66b2232
Show file tree
Hide file tree
Showing 18 changed files with 252 additions and 28 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Fabian Kachlock
Copyright (c) 2024-present Fabian Kachlock

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
98 changes: 86 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,90 @@

# zwooc

The official build system for [zwoo](https://github.com/fabiankachlock/zwoo)!
🚀 The official meta build tool for [zwoo](https://github.com/fabiankachlock/zwoo)!

`zwooc` is a **_meta_** built tool, which means it only leverages and orchestrates exiting build tools in order to produce outputs. zwooc aims to unify and simplify build tool configuration tailored to the use cases of zwoo.

---

## Install
## Installation

You can install zwooc from the
- [GitHub Releases](https://github.com/zwoo-hq/zwooc/releases) or
- via `go install github.com/zwoo-hq/zwooc/cmd/zwooc@latest` (go 1.21 is needed).

### Setting up auto completion

zwooc currently supports auto completion for `bash` & `zsh`, just add:

`source <(zwooc complete-bash)` into you `.bashrc` or

`source <(zwooc complete-zsh)` into your `.zshrc`

On bash completion on windows (for example in the git bash) will also provide completions for `zwooc.exe`

## Usage

### Get Started

`$ zwooc init` will initialize a new zwooc workspace. This creates a new `zwooc.config.json` with some example content.

### Basics

Your every day use commands will be:

`$ zwooc build|run|watch <key>` - execute a profile in the given run mode.

`$ zwooc exec <key>` - executes a fragment

`$ zwooc launch <key>` - launch a compound configuration.

Often used options are:

`$ zwooc exec -to` `-t` will disable TTY mode and `-o` will enable command output in static mode. These options are enable in CI by default.

If you want to pass some extra arguments to an command you can do this always behind the key, like:

`$ zwooc run dev --host` - in this case `dev` being a `vite-x` profile this will expose your dev server to the local network.

You can install zwooc from the [GitHub Releases](https://github.com/zwoo-hq/zwooc/releases) or via `go install github.com/zwoo-hq/zwooc/cmd/zwooc@latest` (go 1.20 is needed).
The drawback of this it, that all arguments targeted at zwooc must be passed before the key of the configuration to execute:

## Concepts
```diff
- zwooc run dev -to // does not work
+ zwooc run -to dev // does work
```

### Debugging Configuration

zwooc provides a handy tool for debugging the configuration.

`$ zwooc graph exec|build|run|watch|launch <key>` will print a tree will all tasks and their dependencies into the terminal. Adding the `--dry-run` flag to on of those commands will do the same.


### More Information

`$ zwooc h|help|-h|--help` prints an overview of all available commands including a short description.

`$ zwooc -v|--version` will print the version of zwooc.

## Using The Interactive Runner

> [!WARNING]
> The interactive runner is still in early stage of development and may contain bugs.
The interactive runner as a TUI for running zwooc tasks.

It currently supports:
- a help view by pressing `h`
- a full screen view by pressing `f`
- multi tabs command output view
- switching tabs via `tab` `shift+tab` or mouse click (yes it has mouse support!)
- status indicator for pre and post tasks
- `esc` will close the full screen or help view
- `q` or `ctrl+c` will stop the runner gracefully (running al post tasks) pressing it a second time will cancel all running post tasks


## Concepts & Configuration

This is a rough overview about all concepts, for a full documentation see [`docs/concept.md`](https://github.com/zwoo-hq/zwooc/blob/main/docs/concept.md)

Expand All @@ -22,30 +97,29 @@ There a 3 available run modes: `run`, `watch`, `build`

Define a sub-project with an adapter. The adapter will handle how commands are build. A project contains a number of profiles which can be run. The name of the project must equal the subpath.

Available adapters are
- `vite-yarn`, `vite-npm`, `vite-pnpm`
- `tauri-yarn`, `tauri-npm`, `tauri-pnpm`
- `dotnet`
- `custom`

#### Profiles

A profile is a run configuration for running a project in a certain run mode.

Profiles can be run via `zwoo <run|watch|build> <profile name>`

### Fragments

Fragments are individual commands that can be run before/with/after profiles. They are not bound to the adapter und are run with the folder of the project they are defined in. Fragments can adapt teh current run mode and profile.

Fragments can be run via `zwoo exec <fragment:configuration>`

### Compounds

Compounds are a combination of profiles that can be run together. They are defined in root scope.

Compounds can be started via `zwoo launch <compound name>`

### Genral Concepts

All runnable entities can define pre and post actions via `$pre` and `$post`


## Example
## Example Configuration

```json
{
Expand Down
Empty file added docs/adapter/custom.md
Empty file.
Empty file added docs/adapter/dotnet.md
Empty file.
Empty file added docs/adapter/tauri.md
Empty file.
Empty file added docs/adapter/vite.md
Empty file.
23 changes: 10 additions & 13 deletions docs/concept.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ The key of a compound shall not contain any `$COMP_WORDBREAKS` characters except

Compounds shall contain at least one profile or fragments. To configure a compound an object `profiles` with the profile key as the key and run desired run mode as value. Other options from profiles, like `base` and `includeFragments` apply here too.

| concept | status |
| ------------------------------- | :----------------: |
| define compounds | :white_check_mark: |
| execute compounds | :x: |
| execute compounds (interactive) | :white_check_mark: |
| execute hooks | :question: |
| execute included fragments | :white_check_mark: |
| concept | status |
| ------------------------------- | :------------------------------------------------: |
| define compounds | :white_check_mark: |
| execute compounds | :white_check_mark: |
| execute compounds (interactive) | :white_check_mark: |
| execute hooks | :question: (hooks laufen, aber zu falschen Zeiten) |
| execute included fragments | :white_check_mark: |

## Utilities and options

Expand All @@ -138,7 +138,9 @@ Along the core functionality, `zwooc` should provide additional utilities.
| version | :white_check_mark: |
| help | :white_check_mark: |
| bash completion | :white_check_mark: |
| zsh completion | :white_check_mark: |
| dependency/execution graph (dry run) | :white_check_mark: |
| init helper | :white_check_mark: |

Furthermore, `zwooc` should provide global options in order to provide flexibility whilst executing tasks.

Expand All @@ -150,7 +152,7 @@ Furthermore, `zwooc` should provide global options in order to provide flexibili
| set a max concurrency | :white_check_mark: |
| loose (tolerant errors) | :x: |
| skip hooks | :white_check_mark: |
| exclude fragments | :x: |
| exclude fragments | :white_check_mark: |
| force disable TTY | :white_check_mark: |
| inline output (static mode) | :white_check_mark: |
| disable output (interactive mode) | :x: |
Expand All @@ -170,8 +172,3 @@ Since this UI is currently under heavy construction the following table only out
| allow scheduling tasks dynamically | :question: |
| kill tasks | :question: |
| handle errors in tasks | :question: |


# TODOs:

- :x: handle colons in bash completion better (https://stackoverflow.com/questions/10528695/how-to-reset-comp-wordbreaks-without-affecting-other-completion-script)
Empty file added docs/configuration.md
Empty file.
Empty file added docs/runner.md
Empty file.
30 changes: 30 additions & 0 deletions pkg/adapter/custom/custom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package custom

import (
"strings"

"github.com/zwoo-hq/zwooc/pkg/adapter/shared"
"github.com/zwoo-hq/zwooc/pkg/helper"
"github.com/zwoo-hq/zwooc/pkg/model"
"github.com/zwoo-hq/zwooc/pkg/tasks"
)

type customAdapter struct{}

var _ model.Adapter = (*customAdapter)(nil)

func NewAdapter() model.Adapter {
return &customAdapter{}
}

func (a *customAdapter) CreateTask(c model.ProfileWrapper, extraArgs []string) tasks.Task {
opts := c.GetOptions()
data := helper.MapToStruct(opts, model.CustomOptions{})
commandParts := strings.Split(data.Command, " ")

cmd, additionalArgs := shared.CreateBaseCommand(commandParts[0], c, extraArgs)
cmd.Args = append(cmd.Args, commandParts[1:]...)
cmd.Args = append(cmd.Args, additionalArgs...)

return tasks.NewCommandTask(c.GetName(), cmd)
}
3 changes: 3 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"github.com/zwoo-hq/zwooc/pkg/adapter/custom"
"github.com/zwoo-hq/zwooc/pkg/adapter/dotnet"
"github.com/zwoo-hq/zwooc/pkg/adapter/tauri"
"github.com/zwoo-hq/zwooc/pkg/adapter/vite"
Expand Down Expand Up @@ -89,6 +90,8 @@ func GetAdapter(adapter string) model.Adapter {
return tauri.NewPnpmAdapter()
case model.AdapterDotnet:
return dotnet.NewCliAdapter()
case model.AdapterCustom:
return custom.NewAdapter()
}
return nil
}
2 changes: 1 addition & 1 deletion pkg/config/load_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func (c Config) LoadProfile(key, mode string, ctx loadingContext) (tasks.Collect
}

name := helper.BuildName(key, mode)
ctx = ctx.withCaller(name)
mainTask, err := config.GetTask(ctx.getArgs())
ctx = ctx.withCaller(name)
if err != nil {
return nil, err
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/zwoo-hq/zwooc/pkg/helper"
"github.com/zwoo-hq/zwooc/pkg/model"
)

type Profile struct {
Expand All @@ -27,6 +28,11 @@ func (p Profile) ResolveConfig(mode string) (ResolvedProfile, error) {
return ResolvedProfile{}, fmt.Errorf("profile '%s' disabled mode '%s'", p.name, mode)
}

if command, ok := options.(string); ok && p.adapter == model.AdapterCustom {
// support custom profiles
options = map[string]interface{}{"command": command}
}

config := ResolvedProfile{
Name: p.name,
Adapter: p.adapter,
Expand Down
1 change: 1 addition & 0 deletions pkg/model/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
AdapterTauriNpm = "tauri-npm"
AdapterTauriPnpm = "tauri-pnpm"
AdapterDotnet = "dotnet"
AdapterCustom = "custom"
)

const (
Expand Down
4 changes: 4 additions & 0 deletions pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ type (
Project string `json:"project"`
}

CustomOptions struct {
Command string `json:"command"`
}

CompoundOptions struct {
Profiles map[string]string `json:"profiles"`
IncludeFragments []string `json:"includeFragments"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/zwooc/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

var (
VERSION = "1.0.0-beta.5"
VERSION = "1.0.0"
)

var (
Expand Down
10 changes: 10 additions & 0 deletions zwooc.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@
"project": "a.b"
}
},
"ex3": {
"$adapter": "custom",
"$dir": ".",
"ex3": {
"run": {
"command": "echo 'build'"
},
"build": "echo 'run'"
}
},
"$fragments": {
"print2": "echo $PWD && sleep 3",
"print3": "git status",
Expand Down
Loading

0 comments on commit 66b2232

Please sign in to comment.