mirror of
https://github.com/kataras/iris.git
synced 2026-01-20 10:26:01 +00:00
Version 3.0.0-beta cleaned
This commit is contained in:
52
iris/README.md
Normal file
52
iris/README.md
Normal file
@@ -0,0 +1,52 @@
|
||||
## Package information
|
||||
|
||||
This package is the command line tool for [../](https://github.com/kataras/iris).
|
||||
|
||||
|
||||
## Install
|
||||
Current version: 0.0.1
|
||||
```sh
|
||||
|
||||
go get -u github.com/kataras/iris/iris
|
||||
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
```sh
|
||||
$ iris [command] [-flags]
|
||||
```
|
||||
|
||||
> Note that you must have $GOPATH/bin to your $PATH system/environment variable.
|
||||
|
||||
|
||||
## Create
|
||||
|
||||
|
||||
**The create command** creates for you a start project in a directory
|
||||
|
||||
```sh
|
||||
iris create
|
||||
```
|
||||
|
||||
Will create the starter/basic project structure to the current working directory and run the app.
|
||||
|
||||
```sh
|
||||
iris create -d C:\Users\kataras\Desktop\test1
|
||||
```
|
||||
|
||||
Will create the starter/basic project structure to the C:\Users\kataras\Desktop\test1 folder and run the app.
|
||||
|
||||
|
||||
## Version
|
||||
|
||||
```sh
|
||||
iris version
|
||||
```
|
||||
|
||||
Will print the current iris' installed version to your machine
|
||||
|
||||
## TODO
|
||||
|
||||
A lot more
|
||||
12
iris/doc.go
Normal file
12
iris/doc.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
/*
|
||||
|
||||
go get -u github.com/kataras/iris/iris
|
||||
|
||||
|
||||
create an empty folder, open the command prompt/terminal there, type and press enter:
|
||||
|
||||
iris create
|
||||
|
||||
*/
|
||||
116
iris/main.go
Normal file
116
iris/main.go
Normal file
@@ -0,0 +1,116 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"strings"
|
||||
|
||||
"runtime"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/kataras/cli"
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
PackagesURL = "https://github.com/iris-contrib/iris-command-assets/archive/master.zip"
|
||||
PackagesExportedName = "iris-command-assets-master"
|
||||
)
|
||||
|
||||
var (
|
||||
app *cli.App
|
||||
SuccessPrint = color.New(color.FgGreen).Add(color.Bold).PrintfFunc()
|
||||
InfoPrint = color.New(color.FgHiCyan).Add(color.Bold).PrintfFunc()
|
||||
packagesInstallDir = os.Getenv("GOPATH") + utils.PathSeparator + "src" + utils.PathSeparator + "github.com" + utils.PathSeparator + "kataras" + utils.PathSeparator + "iris" + utils.PathSeparator + "iris" + utils.PathSeparator
|
||||
packagesDir = packagesInstallDir + PackagesExportedName + utils.PathSeparator
|
||||
)
|
||||
|
||||
func init() {
|
||||
app = cli.NewApp("iris", "Command line tool for Iris web framework", "0.0.1")
|
||||
app.Command(cli.Command("version", "\t prints your iris version").Action(func(cli.Flags) error { app.Printf("%s", iris.Version); return nil }))
|
||||
|
||||
createCmd := cli.Command("create", "create a project to a given directory").
|
||||
Flag("dir", "./", "-d ./ creates an iris starter kit to the current directory").
|
||||
Flag("type", "basic", "-t basic creates the project based on the t 'package'").
|
||||
Action(create)
|
||||
|
||||
app.Command(createCmd)
|
||||
}
|
||||
|
||||
func main() {
|
||||
app.Run(func(cli.Flags) error { return nil })
|
||||
}
|
||||
|
||||
func create(flags cli.Flags) (err error) {
|
||||
|
||||
if !utils.DirectoryExists(packagesDir) {
|
||||
downloadPackages()
|
||||
}
|
||||
|
||||
targetDir := flags.String("dir")
|
||||
|
||||
if strings.HasPrefix(targetDir, "./") || strings.HasPrefix(targetDir, "."+utils.PathSeparator) {
|
||||
currentWdir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
targetDir = currentWdir + utils.PathSeparator + targetDir[2:]
|
||||
}
|
||||
|
||||
createPackage(flags.String("type"), targetDir)
|
||||
return
|
||||
}
|
||||
|
||||
func downloadPackages() {
|
||||
_, err := utils.Install("https://github.com/iris-contrib/iris-command-assets/archive/master.zip", packagesInstallDir)
|
||||
if err != nil {
|
||||
app.Printf("\nProblem while downloading the assets from the internet for the first time. Trace: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func createPackage(packageName string, targetDir string) error {
|
||||
basicDir := packagesDir + packageName
|
||||
err := utils.CopyDir(basicDir, targetDir)
|
||||
if err != nil {
|
||||
app.Printf("\nProblem while copying the %s package to the %s. Trace: %s", packageName, targetDir, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
InfoPrint("\n%s package was installed successfully", packageName)
|
||||
|
||||
//run the server
|
||||
|
||||
// go build
|
||||
buildCmd := utils.CommandBuilder("go", "build")
|
||||
if targetDir[len(targetDir)-1] != os.PathSeparator || targetDir[len(targetDir)-1] != '/' {
|
||||
targetDir += utils.PathSeparator
|
||||
}
|
||||
buildCmd.Dir = targetDir + "backend"
|
||||
buildCmd.Stderr = os.Stderr
|
||||
err = buildCmd.Start()
|
||||
if err != nil {
|
||||
app.Printf("\n Failed to build the %s package. Trace: %s", packageName, err.Error())
|
||||
}
|
||||
buildCmd.Wait()
|
||||
println("\n")
|
||||
// run backend/backend.exe
|
||||
|
||||
executable := "backend"
|
||||
if runtime.GOOS == "windows" {
|
||||
executable += ".exe"
|
||||
}
|
||||
|
||||
runCmd := utils.CommandBuilder("." + utils.PathSeparator + executable)
|
||||
runCmd.Dir = buildCmd.Dir
|
||||
runCmd.Stdout = os.Stdout
|
||||
runCmd.Stderr = os.Stderr
|
||||
|
||||
err = runCmd.Start()
|
||||
if err != nil {
|
||||
app.Printf("\n Failed to run the %s package. Trace: %s", packageName, err.Error())
|
||||
}
|
||||
runCmd.Wait()
|
||||
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user