Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added base applet structure. #3

Merged
merged 1 commit into from
Jan 5, 2022
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ clean:
rm -f ca-tools

build: clean
go build -o ca-tools tools/main.go
go build -v ./...

test:
go test -v -cover ./...
4 changes: 3 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
TODO(mark):
- Add issue and PR templates: https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests
- Add details either as config or as part of the starlark
- Add details either as config or as part of the starlark
- Make fuzzy clock a model citizen that includes good code structure and unit tests
- Add codegen so we can `make applet` and it will plop out a new applet.
16 changes: 16 additions & 0 deletions apps/apps.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Package apps provides a clean way for Tidbyt to be able to get a list of all
// community apps.
package apps

import (
"tidbyt.dev/community-apps/apps/community"
"tidbyt.dev/community-apps/apps/fuzzyclock"
)

// GetApps returns a list of all apps in the this repository. Add your applet
// below to include it in the Tidbyt Mobile app for all Tidbyt users.
func GetApps() []community.App {
return []community.App{
fuzzyclock.New(),
}
}
21 changes: 21 additions & 0 deletions apps/apps_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package apps_test

import (
"fmt"
"testing"

"tidbyt.dev/community-apps/apps"
)

// TODO(mark): add tests to validate all applet fields. We should check casing,
// spelling, and length.

// TODO(mark): add a test that tests the actual starlark

// TODO(mark): add the ability to use our unit test module.
func TestGetApps(t *testing.T) {
applets := apps.GetApps()
for _, app := range applets {
fmt.Println(app.Name)
}
}
20 changes: 20 additions & 0 deletions apps/community/community.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Package community provides structures and primitives to define apps.
package community

// App is a structure to define a starlark applet for Tidbyt in Go.
type App struct {
// Name is the name of the applet. Ex. "Fuzzy Clock"
Name string `json:"name"`
// Summary is the short form of what this applet does. Ex. "Human readable
// time".
Summary string `json:"summary"`
// Desc is the long form of what this applet does. Ex. "Display the time in
// a groovy, human-readable way."
Desc string `json:"desc"`
// Author is the person or organization who contributed this applet. Ex,
// "Max Timkovich"
Author string `json:"author"`
// Source is the starlark source code for this applet using the go `embed`
// module.
Source []byte `json:"-"`
}
27 changes: 27 additions & 0 deletions apps/community/community_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package community_test

import (
_ "embed"
"io/ioutil"
"testing"

"github.com/stretchr/testify/assert"
"tidbyt.dev/community-apps/apps/community"
)

//go:embed testdata/source.star
var source []byte

func TestApp(t *testing.T) {
app := community.App{
Name: "Foo Tracker",
Summary: "Track realtime foo",
Desc: "The foo tracker provides realtime feeds for foo.",
Author: "Tidbyt",
Source: source,
}

expected, err := ioutil.ReadFile("testdata/source.star")
assert.NoError(t, err)
assert.Equal(t, app.Source, expected)
}
6 changes: 6 additions & 0 deletions apps/community/testdata/source.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
load("render.star", "render")

def main():
return render.Root(
child = render.Text("Hello, World!"),
)
22 changes: 22 additions & 0 deletions apps/fuzzyclock/fuzzyclock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Package fuzzyclock provides details for the Fuzzy Clock applet.
package fuzzyclock

import (
_ "embed"

"tidbyt.dev/community-apps/apps/community"
)

//go:embed source.star
var source []byte

// New creates a new instance of the Fuzzy Clock applet.
func New() community.App {
return community.App{
Name: "Fuzzy Clock",
Author: "Max Timkovich",
Summary: "Human readable time",
Desc: "Display the time in a groovy, human-readable way.",
Source: source,
}
}
File renamed without changes.
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
module tidbyt.dev/community-apps

go 1.17

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.7.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=