From 158f574b2abf2c5735467d6c4badb733df241249 Mon Sep 17 00:00:00 2001 From: Jordan Knott Date: Thu, 16 Jul 2020 22:58:46 -0500 Subject: [PATCH] change: add LICENSE & basic compile instructions --- .gitignore | 3 ++- LICENSE | 21 ++++++++++++++++++ README.md | 27 +++++++++++++++++++++++ cmd/mage/main.go | 10 +++++++++ conf/{app.toml => app.example.toml} | 2 +- magefile.go | 34 ++++++++++++++++++++++------- 6 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 LICENSE create mode 100644 cmd/mage/main.go rename conf/{app.toml => app.example.toml} (94%) diff --git a/.gitignore b/.gitignore index 08280a0..df6a79e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ node_modules +dist/ uploads/* !uploads/.keep - internal/frontend/frontend_generated.go citadel +conf/app.toml diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8aa2645 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) [year] [fullname] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 8caab83..b70f659 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,32 @@ Currently you can do the following to tasks: ## Installation +### From Source + +You'll need [Golang](https://golang.org/dl/) installed on your machine. + +Next, clone the repository: + +``` bash +git clone https://github.com/JordanKnott/project-citadel && cd project-citadel +``` + +Next we need to build the binary. This project uses [Mage](https://magefile.org/) for its build tool. + +``` bash +go run cmd/mage/main.go build +``` + +This will: + +- Install all yarn packages for the frontend +- Build the React frontend +- Embed the React frontend in the binary +- Compile the final exectuable binary + +The newly created `citadel` binary can be found in the __dist__ folder. + +It contains everything neccessary to run except the config file. An example config file can be found in `conf/app.example.toml` ## Roadmap @@ -43,4 +69,5 @@ This is a list of features that will eventually be added to Citadel in no partic ## License +[MIT License](LICENSE) diff --git a/cmd/mage/main.go b/cmd/mage/main.go new file mode 100644 index 0000000..4273031 --- /dev/null +++ b/cmd/mage/main.go @@ -0,0 +1,10 @@ +// +build ignore + +package main + +import ( + "github.com/magefile/mage/mage" + "os" +) + +func main() { os.Exit(mage.Main()) } diff --git a/conf/app.toml b/conf/app.example.toml similarity index 94% rename from conf/app.toml rename to conf/app.example.toml index 1741aad..5a3030a 100644 --- a/conf/app.toml +++ b/conf/app.example.toml @@ -12,7 +12,7 @@ upload_dir_path = 'uploads' [database] host = '0.0.0.0' -name = 'citadel_test' +name = 'citadel' user = 'postgres' password = 'test' diff --git a/magefile.go b/magefile.go index 3fb34eb..fe483d2 100644 --- a/magefile.go +++ b/magefile.go @@ -4,19 +4,33 @@ package main import ( "fmt" - "github.com/magefile/mage/sh" - "github.com/shurcooL/vfsgen" "io/ioutil" "net/http" "os" "strings" + + "github.com/magefile/mage/mg" + "github.com/magefile/mage/sh" + "github.com/shurcooL/vfsgen" ) var Aliases = map[string]interface{}{ - "g": Generate, + "s": Backend.Schema, } -func Vfs() error { +type Frontend mg.Namespace + +func (Frontend) Install() error { + return sh.Run("yarn", "install", "--cwd", "frontend") +} + +func (Frontend) Build() error { + return sh.Run("yarn", "build", "--cwd", "frontend") +} + +type Backend mg.Namespace + +func (Backend) GenFrontend() error { var fs http.FileSystem = http.Dir("frontend/build") err := vfsgen.Generate(fs, vfsgen.Options{ Filename: "internal/frontend/frontend_generated.go", @@ -29,9 +43,11 @@ func Vfs() error { return nil } -// Runs go mod download and then installs the binary. -func Generate() error { +func (Backend) Build() error { + return sh.Run("go", "build", "-o", "dist/citadel", "cmd/citadel/main.go") +} +func (Backend) Schema() error { files, err := ioutil.ReadDir("internal/graph/schema/") if err != nil { panic(err) @@ -50,11 +66,13 @@ func Generate() error { } fmt.Fprintln(&schema, string(content)) } - // return sh.Run("go", "install", "./...") - // fmt.Println(schema.String()) err = ioutil.WriteFile("internal/graph/schema.graphqls", []byte(schema.String()), os.FileMode(0755)) if err != nil { panic(err) } return sh.Run("gqlgen") } + +func Build() { + mg.SerialDeps(Frontend.Install, Frontend.Build, Backend.GenFrontend, Backend.Build) +}