-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
baseTypes.ts | ||
baseTypes.ts | ||
introspection.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,78 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/lmittmann/tint" | ||
"errors" | ||
"fmt" | ||
"github.com/briandowns/spinner" | ||
"github.com/simse/faster-graphql-codegen/internal" | ||
"log/slog" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
) | ||
|
||
func main() { | ||
// set up coloured logging | ||
w := os.Stderr | ||
|
||
// set global logger with custom options | ||
slog.SetDefault(slog.New( | ||
tint.NewHandler(w, &tint.Options{ | ||
Level: slog.LevelDebug, | ||
TimeFormat: time.TimeOnly, | ||
}), | ||
)) | ||
|
||
/*timeStart := time.Now() | ||
schema, err := internal.LoadSchema("examples/github/github.graphql") | ||
if err != nil { | ||
panic(err) | ||
} | ||
loadSchemaTime := time.Since(timeStart) | ||
convertTimeStart := time.Now() | ||
output := strings.Builder{} | ||
internal.ConvertSchema(schema, &output) | ||
convertSchemaTime := time.Since(convertTimeStart) | ||
writeTypesTimeStart := time.Now() | ||
outputFile, openErr := os.Create("output/github/baseTypes.ts") | ||
if openErr != nil { | ||
panic(err) | ||
} | ||
_, writeErr := outputFile.WriteString(output.String()) | ||
if writeErr != nil { | ||
panic(err) | ||
} | ||
writeTypesTime := time.Since(writeTypesTimeStart) | ||
outputFile.Close() | ||
slog.Info("finished codegen", "duration", time.Since(timeStart), "load_duration", loadSchemaTime, "convert_duration", convertSchemaTime, "write_duration", writeTypesTime)*/ | ||
timeStart := time.Now() | ||
projects := internal.FindProjects("./examples/projects/monorepo", filepath.WalkDir) | ||
slog.Info("search for packages using codegen complete", "found_projects", len(projects)) | ||
|
||
/*for _, project := range projects { | ||
internal.ExecuteProject(project) | ||
}*/ | ||
projects := findProjects() | ||
|
||
executionContext := internal.ExecutionContext{} | ||
executionContext.SetProjects(projects) | ||
executionContext.LoadSchemas() | ||
executionContext.Execute() | ||
slog.Info("finished all codegen tasks", "duration", time.Since(timeStart)) | ||
|
||
loadSchemas(&executionContext) | ||
execute(&executionContext, timeStart) | ||
} | ||
|
||
func findProjects() []internal.Project { | ||
// get input folder | ||
searchFolder := "." | ||
argsWithoutProg := os.Args[1:] | ||
|
||
if len(argsWithoutProg) > 0 { | ||
searchFolder = argsWithoutProg[0] | ||
} | ||
|
||
s := spinner.New(spinner.CharSets[14], 100*time.Millisecond, spinner.WithWriter(os.Stderr)) | ||
s.Suffix = " Finding projects using codegen" | ||
|
||
s.Start() | ||
projects, err := internal.FindProjects(searchFolder, filepath.WalkDir) | ||
|
||
if err != nil { | ||
if errors.Is(err, os.ErrNotExist) { | ||
s.FinalMSG = "✗ Input folder does not exist\n" | ||
s.Stop() | ||
} else { | ||
s.FinalMSG = "✗ Unknown error while searching for projects: " + err.Error() + "\n" | ||
s.Stop() | ||
} | ||
|
||
os.Exit(1) | ||
} else { | ||
s.FinalMSG = fmt.Sprintf("✓ Found %d projects\n", len(projects)) | ||
s.Stop() | ||
} | ||
|
||
return projects | ||
} | ||
|
||
func loadSchemas(e *internal.ExecutionContext) { | ||
s := spinner.New(spinner.CharSets[14], 100*time.Millisecond, spinner.WithWriter(os.Stderr)) | ||
s.Suffix = " Loading graphql schemas" | ||
|
||
s.Start() | ||
schemasLoaded := e.LoadSchemas() | ||
|
||
s.FinalMSG = fmt.Sprintf("✓ Loaded %d unique schemas\n", schemasLoaded) | ||
s.Stop() | ||
} | ||
|
||
func execute(e *internal.ExecutionContext, timeStart time.Time) { | ||
s := spinner.New(spinner.CharSets[14], 100*time.Millisecond, spinner.WithWriter(os.Stderr)) | ||
s.Suffix = " Executing codegen tasks" | ||
|
||
s.Start() | ||
e.Execute() | ||
|
||
s.FinalMSG = fmt.Sprintf("✓ Codegen completed in %s\n", time.Since(timeStart).String()) | ||
s.Stop() | ||
} |