@@ -2,9 +2,6 @@ package cmd
2
2
3
3
import (
4
4
"bufio"
5
- "encoding/xml"
6
- "fmt"
7
- "io/ioutil"
8
5
"os"
9
6
"os/exec"
10
7
"path/filepath"
@@ -16,15 +13,6 @@ import (
16
13
"github.com/go-flutter-desktop/hover/internal/build"
17
14
"github.com/go-flutter-desktop/hover/internal/log"
18
15
"github.com/go-flutter-desktop/hover/internal/pubspec"
19
- homedir "github.com/mitchellh/go-homedir"
20
- "github.com/pkg/errors"
21
- )
22
-
23
- var (
24
- goBin string
25
- flutterBin string
26
- dockerBin string
27
- gitBin string
28
16
)
29
17
30
18
// initBinaries is used to ensure go and flutter exec are found in the
@@ -131,134 +119,3 @@ func askForConfirmation() bool {
131
119
}
132
120
return false
133
121
}
134
-
135
- // AndroidManifest is a file that describes the essential information about
136
- // an android app.
137
- type AndroidManifest struct {
138
- Package string `xml:"package,attr"`
139
- }
140
-
141
- // androidOrganizationName fetch the android package name (default:
142
- // 'com.example').
143
- // Can by set upon flutter create (--org flag)
144
- //
145
- // If errors occurs when reading the android package name, the string value
146
- // will correspond to 'hover.failed.to.retrieve.package.name'
147
- func androidOrganizationName () string {
148
- // Default value
149
- androidManifestFile := "android/app/src/main/AndroidManifest.xml"
150
-
151
- // Open AndroidManifest file
152
- xmlFile , err := os .Open (androidManifestFile )
153
- if err != nil {
154
- log .Errorf ("Failed to retrieve the organization name: %v" , err )
155
- return "hover.failed.to.retrieve.package.name"
156
- }
157
- defer xmlFile .Close ()
158
-
159
- byteXMLValue , err := ioutil .ReadAll (xmlFile )
160
- if err != nil {
161
- log .Errorf ("Failed to retrieve the organization name: %v" , err )
162
- return "hover.failed.to.retrieve.package.name"
163
- }
164
-
165
- var androidManifest AndroidManifest
166
- err = xml .Unmarshal (byteXMLValue , & androidManifest )
167
- if err != nil {
168
- log .Errorf ("Failed to retrieve the organization name: %v" , err )
169
- return "hover.failed.to.retrieve.package.name"
170
- }
171
- javaPackage := strings .Split (androidManifest .Package , "." )
172
- orgName := strings .Join (javaPackage [:len (javaPackage )- 1 ], "." )
173
- if orgName == "" {
174
- return "hover.failed.to.retrieve.package.name"
175
- }
176
- return orgName
177
- }
178
-
179
- var camelcaseRegex = regexp .MustCompile ("(^[A-Za-z])|_([A-Za-z])" )
180
-
181
- // toCamelCase take a snake_case string and converts it to camelcase
182
- func toCamelCase (str string ) string {
183
- return camelcaseRegex .ReplaceAllStringFunc (str , func (s string ) string {
184
- return strings .ToUpper (strings .Replace (s , "_" , "" , - 1 ))
185
- })
186
- }
187
-
188
- // initializeGoModule uses the golang binary to initialize the go module
189
- func initializeGoModule (projectPath string ) {
190
- wd , err := os .Getwd ()
191
- if err != nil {
192
- log .Errorf ("Failed to get working dir: %v\n " , err )
193
- os .Exit (1 )
194
- }
195
-
196
- cmdGoModInit := exec .Command (goBin , "mod" , "init" , projectPath + "/" + build .BuildPath )
197
- cmdGoModInit .Dir = filepath .Join (wd , build .BuildPath )
198
- cmdGoModInit .Env = append (os .Environ (),
199
- "GO111MODULE=on" ,
200
- )
201
- cmdGoModInit .Stderr = os .Stderr
202
- cmdGoModInit .Stdout = os .Stdout
203
- err = cmdGoModInit .Run ()
204
- if err != nil {
205
- log .Errorf ("Go mod init failed: %v\n " , err )
206
- os .Exit (1 )
207
- }
208
-
209
- cmdGoModTidy := exec .Command (goBin , "mod" , "tidy" )
210
- cmdGoModTidy .Dir = filepath .Join (wd , build .BuildPath )
211
- log .Infof ("You can add the '%s' directory to git." , cmdGoModTidy .Dir )
212
- cmdGoModTidy .Env = append (os .Environ (),
213
- "GO111MODULE=on" ,
214
- )
215
- cmdGoModTidy .Stderr = os .Stderr
216
- cmdGoModTidy .Stdout = os .Stdout
217
- err = cmdGoModTidy .Run ()
218
- if err != nil {
219
- log .Errorf ("Go mod tidy failed: %v\n " , err )
220
- os .Exit (1 )
221
- }
222
- }
223
-
224
- // findPubcachePath returns the absolute path for the pub-cache or an error.
225
- func findPubcachePath () (string , error ) {
226
- var path string
227
- switch runtime .GOOS {
228
- case "darwin" , "linux" :
229
- home , err := homedir .Dir ()
230
- if err != nil {
231
- return "" , errors .Wrap (err , "failed to resolve user home dir" )
232
- }
233
- path = filepath .Join (home , ".pub-cache" )
234
- case "windows" :
235
- path = filepath .Join (os .Getenv ("APPDATA" ), "Pub" , "Cache" )
236
- }
237
- return path , nil
238
- }
239
-
240
- // shouldRunPluginGet checks if the pubspec.yaml file is older than the
241
- // .packages file, if it is the case, prompt the user for a hover plugin get.
242
- func shouldRunPluginGet () (bool , error ) {
243
- file1Info , err := os .Stat ("pubspec.yaml" )
244
- if err != nil {
245
- return false , err
246
- }
247
-
248
- file2Info , err := os .Stat (".packages" )
249
- if err != nil {
250
- if os .IsNotExist (err ) {
251
- return true , nil
252
- }
253
- return false , err
254
- }
255
- modTime1 := file1Info .ModTime ()
256
- modTime2 := file2Info .ModTime ()
257
-
258
- diff := modTime1 .Sub (modTime2 )
259
-
260
- if diff > (time .Duration (0 ) * time .Second ) {
261
- return true , nil
262
- }
263
- return false , nil
264
- }
0 commit comments