summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/api/api.go18
-rw-r--r--cmd/frontend/frontend.go68
2 files changed, 84 insertions, 2 deletions
diff --git a/cmd/api/api.go b/cmd/api/api.go
index ed0cb98..7c31593 100644
--- a/cmd/api/api.go
+++ b/cmd/api/api.go
@@ -1,8 +1,11 @@
package api
import (
+ "github.com/labstack/echo/v4"
+ "github.com/labstack/echo/v4/middleware"
"github.com/urfave/cli/v2"
- "gitrepo.ru/neonxp/idecnode/pkg/api"
+ "gitrepo.ru/neonxp/idecnode/pkg/apiv1"
+ "gitrepo.ru/neonxp/idecnode/pkg/apiv2"
"gitrepo.ru/neonxp/idecnode/pkg/config"
"gitrepo.ru/neonxp/idecnode/pkg/idec"
)
@@ -22,8 +25,19 @@ var APICommand *cli.Command = &cli.Command{
return err
}
defer idecApi.Close()
+ e := echo.New()
- return api.New(idecApi, cfg).Run(c.Context)
+ e.Use(
+ middleware.Recover(),
+ middleware.Logger(),
+ )
+ apiv1.New(idecApi, cfg).Register(e)
+
+ apiv2.New(idecApi, cfg).Register(e)
+
+ e.Static("/", "./web/dist")
+
+ return e.Start(cfg.Listen)
},
Flags: []cli.Flag{
&cli.StringFlag{
diff --git a/cmd/frontend/frontend.go b/cmd/frontend/frontend.go
new file mode 100644
index 0000000..9679d6f
--- /dev/null
+++ b/cmd/frontend/frontend.go
@@ -0,0 +1,68 @@
+package frontend
+
+import (
+ "errors"
+ "log"
+
+ "github.com/evanw/esbuild/pkg/api"
+ "github.com/urfave/cli/v2"
+)
+
+var FrontendCommand *cli.Command = &cli.Command{
+ Name: "frontend",
+ Description: "Build/watch frontend",
+ Action: func(c *cli.Context) error {
+ dev := c.Bool("dev")
+ watch := c.Bool("watch")
+ buildOpts := api.BuildOptions{
+ EntryPoints: []string{
+ "./web/src/index.js",
+ "./web/src/index.css",
+ "./web/src/index.html",
+ },
+ Outdir: "./web/dist",
+ Bundle: true,
+ Write: true,
+ MinifyWhitespace: !dev,
+ MinifyIdentifiers: !dev,
+ MinifySyntax: !dev,
+ JSX: api.JSXAutomatic,
+ Loader: map[string]api.Loader{
+ ".js": api.LoaderJSX,
+ ".css": api.LoaderCSS,
+ ".html": api.LoaderCopy,
+ },
+ }
+ if watch {
+ ctx, err := api.Context(buildOpts)
+ if err != nil {
+ return err
+ }
+ if err := ctx.Watch(api.WatchOptions{}); err != nil {
+ return err
+ }
+ log.Println("watching frontend")
+ <-c.Done()
+ } else {
+ if br := api.Build(buildOpts); br.Errors != nil {
+ for _, e := range br.Errors {
+ log.Println(e.Location, e.Detail, e.Text)
+ }
+
+ return errors.New("build failed")
+ }
+ }
+
+ return nil
+ },
+ Flags: []cli.Flag{
+ &cli.BoolFlag{
+ Name: "dev",
+ Value: false,
+ },
+ &cli.BoolFlag{
+ Name: "watch",
+ Value: false,
+ },
+ },
+}