-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
169 lines (141 loc) · 4.22 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"os/exec"
"strings"
"github.com/dstotijn/go-notion"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// App struct
type App struct {
ctx context.Context
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
// Create the app table
CreateApplicationTable(ctx)
// Create the setting table
CreateSettingTable(ctx)
// Insert setting if it doesn't exist
if !SettingExists(ctx, "notion_api_key") {
AddSetting(ctx, Setting{Name: "notion_api_key", Value: ""})
}
}
// CheckNodeJS checks if Node.js is installed and returns its version or an error.
func (a *App) CheckNodeJS() (string, error) {
// The command to check Node.js version
cmd := exec.Command("node", "-v")
// Run the command and capture the output
output, err := cmd.Output()
if err != nil {
// Node.js might not be installed or another error occurred
return "", err
}
// Trim the output to get a clean version string
version := strings.TrimSpace(string(output))
return version, nil
}
func (a *App) GenerateApplication(applicationJsonString string) {
var application Application
err := json.Unmarshal([]byte(applicationJsonString), &application)
if err != nil {
log.Fatal(err)
}
log.Println(application)
// Check if NestJS is installed
cmdNestJS := exec.Command("nest", "-v")
_, errNestJS := cmdNestJS.Output()
if errNestJS != nil {
// NestJS is not installed
fmt.Println("NestJS is not installed. Please install it using the following command:")
fmt.Println("npm install -g @nestjs/cli")
// Install NestJS
cmdInstallNestJS := exec.Command("npm", "install", "-g", "@nestjs/cli")
_, errInstallNestJS := cmdInstallNestJS.Output()
if errInstallNestJS != nil {
// An error occurred
fmt.Println("Error installing NestJS:", errInstallNestJS)
return
}
}
// Change to the selected folder
err = os.Chdir(application.Path)
if err != nil {
fmt.Println("Error changing directory:", err)
return
}
// The command to generate a NestJS app
// nest new backend --skip-git --package-manager=npm --no-interactive
cmd := exec.Command("nest", "new", application.Name, "--skip-git", "--package-manager=npm")
// Run the command and capture the output
output, err := cmd.CombinedOutput()
if err != nil {
// An error occurred
fmt.Println("Error generating app:", err)
fmt.Println(string(output))
return
}
// Success
fmt.Println("Application generated successfully!")
}
func (a *App) GenerateCSVFromNotionDatabase(databaseJsonString string) {
var database notion.Database
err := json.Unmarshal([]byte(databaseJsonString), &database)
if err != nil {
log.Fatal(err)
}
GenerateCSVFromNotionDatabase(a.ctx, database)
}
func (a *App) GetApplications() []Application {
return GetApplications(a.ctx)
}
func (a *App) GetNotionDatabase(secretKey string, databaseId string) notion.Database {
return GetNotionDatabase(a.ctx, secretKey, databaseId)
}
func (a *App) GetSelectedApplication() Application {
return GetSelectedApplication(a.ctx)
}
func (a *App) ImportCSVFileForNotionDB(fileData []byte, name string) {
ImportCSVFileForNotionDB(a.ctx, fileData, name)
}
func (a *App) InsertApplication(applicationJsonString string) {
var application Application
err := json.Unmarshal([]byte(applicationJsonString), &application)
if err != nil {
log.Fatal(err)
}
AddApplication(a.ctx, application)
}
func (a *App) SelectApplication(id int) {
UpdateSelectedApplication(a.ctx, id)
}
func (a *App) SelectFolder() string {
// This will open a folder selection dialog and return the selected path
// Note: This is a placeholder. You'll need to implement the dialog functionality depending on your OS.
folderPath, err := runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{
Title: "Select Folder",
})
if err != nil {
fmt.Println("Error selecting folder:", err)
return ""
}
return folderPath
}
func (a *App) UpdateSetting(settingsJsonString string) {
var setting Setting
err := json.Unmarshal([]byte(settingsJsonString), &setting)
if err != nil {
log.Fatal(err)
}
UpdateSetting(a.ctx, setting)
}