Skip to content

Commit

Permalink
[v1.1.14]: LSP language server, better migration. (#43)
Browse files Browse the repository at this point in the history
* Correct binary address on cli

* Easier new project generation with fireback
  • Loading branch information
torabian authored Jun 2, 2024
1 parent 3c5771f commit 26fc4ca
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 8 deletions.
6 changes: 5 additions & 1 deletion modules/workspaces/UserCli.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"log"
"os"
"strings"
"time"

Expand Down Expand Up @@ -484,7 +485,10 @@ func InteractiveUserAdmin(query QueryDSL) error {
}

cfg := GetAppConfig()
fmt.Println("Workspace changed to :::", workspaceAs, " run `f ws view` to see the access scope")
exePath, err4 := os.Executable()
if err4 == nil {
fmt.Println("Workspace changed to :::", workspaceAs, " run `"+exePath+" ws view` to see the access scope")
}

cfg.WorkspaceAs = workspaceAs
cfg.Token = *session.Token
Expand Down
11 changes: 10 additions & 1 deletion modules/workspaces/cli-code-gen-tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ var fbGoModuleFlags = []cli.Flag{
Name: "dir",
Usage: "The directory which will the module be created - if not set, the name of module will be used",
},
&cli.StringFlag{
Name: "auto-import",
Usage: "It would add the module, into a server or desktop main app file in fireback if file path is given, also the magic comment exists as well",
},
}

var reconfigFlag = []cli.Flag{
Expand Down Expand Up @@ -555,6 +559,7 @@ func CodeGenTools(xapp *XWebServer) cli.Command {
Action: func(c *cli.Context) error {
var dirname string
var moduleName string
var autoImport string

if c.IsSet("name") {
moduleName = c.String("name")
Expand All @@ -566,7 +571,11 @@ func CodeGenTools(xapp *XWebServer) cli.Command {
dirname = strings.ToLower(moduleName)
}

return NewGoNativeModule(moduleName, dirname)
if c.IsSet("auto-import") {
autoImport = c.String("auto-import")
}

return NewGoNativeModule(moduleName, dirname, autoImport)

},
},
Expand Down
61 changes: 60 additions & 1 deletion modules/workspaces/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package workspaces

import (
"bufio"
"bytes"
"crypto/md5"
"embed"
Expand Down Expand Up @@ -885,10 +886,35 @@ func GetOpenAPiXServer(ctx *CodeGenContext) (*XWebServer, []*Module2) {
return app, modules
}

func extractModuleName(goModFilePath string) (string, error) {
file, err := os.Open(goModFilePath)
if err != nil {
return "", err
}
defer file.Close()

scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "module ") {
parts := strings.Fields(line)
if len(parts) >= 2 {
return parts[1], nil
}
}
}

if err := scanner.Err(); err != nil {
return "", err
}

return "", fmt.Errorf("module name not found in %s", goModFilePath)
}

/*
* Creates a yml, and also a golang module file in modules directory
*/
func NewGoNativeModule(name string, dist string) error {
func NewGoNativeModule(name string, dist string, autoImport string) error {

folderName := strings.ToLower(dist)
args := gin.H{
Expand Down Expand Up @@ -921,6 +947,39 @@ func NewGoNativeModule(name string, dist string) error {
return err
}

MAGIC_LINE := "// do not remove this comment line - it's used by fireback to append new modules"

if autoImport != "" {

if !Exists("go.mod") {
return nil
}

moduleName, err0 := extractModuleName("go.mod")
if err0 != nil {
return nil
}

fmt.Println(autoImport)
if data, err := os.ReadFile(autoImport); err != nil {
return err
} else {
j := string(data)
m := strings.ReplaceAll(
j,
MAGIC_LINE,
MAGIC_LINE+"\r\n\t\t"+name+"."+ToUpper(name)+"ModuleSetup(),",
)

m = strings.ReplaceAll(
m,
"import (",
"import ("+"\r\n\t\""+moduleName+"/modules/"+name+"\"\r\n",
)
os.WriteFile(autoImport, []byte(m), 0644)
}
}

return nil
}

Expand Down
2 changes: 2 additions & 0 deletions modules/workspaces/codegen/firebackgo/.gitignore.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Artifacts folder is ignore, we make binaries there
artifacts
7 changes: 6 additions & 1 deletion modules/workspaces/codegen/firebackgo/GoModule.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ func {{ .Name }}ModuleSetup() *workspaces.ModuleProvider {
Name: "{{ .name }}",
Definitions: &Module2Definitions,
EntityBundles: []workspaces.EntityBundle{
// Do not remove this comment, aef0
// Insert the NameEntityBundle here.
// each entity, has multiple features, such as permissions, events, translations
// *EntityBundle objects are a list of them which are auto generated,
// and by adding them here it will be automatically added.
// we cannot add them automatically upon saving yaml for you,
// when you add a new entity in yaml, add it manually here.
},
}

Expand Down
2 changes: 1 addition & 1 deletion modules/workspaces/codegen/firebackgo/GoModuleDef.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: {{ .name }}

entities:
# This is a sample entity. You can delete it and write your own
- name: book
- name: {{ .name }}
fields:
- name: title
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"problemMatcher": [],
"label": "Generate new module",
"type": "shell",
"command": "fireback gen module --name ${input:modulename}",
"command": "fireback gen module --name ${input:modulename} --auto-import cmd/{{ .ctx.Name}}-server/main.go",
"group": "test",
"presentation": {
"reveal": "always",
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ func BookModuleSetup() *workspaces.ModuleProvider {
Definitions: &Module2Definitions,
EntityBundles: []workspaces.EntityBundle{
BookEntityBundle,
// Do not remove this comment, aef0
},
}

Expand Down
2 changes: 1 addition & 1 deletion modules/workspaces/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package workspaces

// Do not change the structure of this versioning.
// a 'v' will be prefixed for go packages
var FIREBACK_VERSION = "1.1.13"
var FIREBACK_VERSION = "1.1.14"

0 comments on commit 26fc4ca

Please sign in to comment.