Skip to content

Commit 2abf144

Browse files
committed
Refactor ACUL scaffolding and error messages
1 parent 81c6bec commit 2abf144

File tree

3 files changed

+30
-27
lines changed

3 files changed

+30
-27
lines changed

internal/cli/acul_app_scaffolding.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ func getLatestReleaseTag() (string, error) {
111111
return "", fmt.Errorf("no tags found in repository")
112112
}
113113

114-
// TODO: return tags[0].Name, nil.
115-
return "main", nil
114+
return tags[0].Name, nil
116115
}
117116

118117
var (
@@ -343,13 +342,12 @@ func getDestDir(args []string) string {
343342
}
344343

345344
func downloadAndUnzipSampleRepo() (string, error) {
346-
_, err := getLatestReleaseTag()
345+
latestTag, err := getLatestReleaseTag()
347346
if err != nil {
348347
return "", fmt.Errorf("failed to get latest release tag: %w", err)
349348
}
350349

351-
// TODO: repoURL := fmt.Sprintf("https://github.com/auth0-samples/auth0-acul-samples/archive/refs/tags/%s.zip", latestTag).
352-
repoURL := "https://github.com/auth0-samples/auth0-acul-samples/archive/refs/heads/main.zip"
350+
repoURL := fmt.Sprintf("https://github.com/auth0-samples/auth0-acul-samples/archive/refs/tags/%s.zip", latestTag)
353351
tempZipFile, err := downloadFile(repoURL)
354352
if err != nil {
355353
return "", fmt.Errorf("error downloading sample repo: %w", err)

internal/cli/acul_dev.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,8 @@ func applyPromptRenderings(ctx context.Context, cli *cli, screenTagMap map[strin
611611
cli.renderer.Errorf("%s batch %d-%d failed: %v", debugPrefix, i+1, end, err)
612612
cli.renderer.Infof("%s rollback starting for screens 1-%d...", debugPrefix, i)
613613
} else {
614-
cli.renderer.Errorf("patch failed; rolling back...")
614+
// Removed the redundant log: cli.renderer.Errorf("patch failed; rolling back...").
615+
cli.renderer.Warnf("Patch failed. Attempting rollback...")
615616
}
616617

617618
// Rollback all fully-applied previous batches.
@@ -625,7 +626,7 @@ func applyPromptRenderings(ctx context.Context, cli *cli, screenTagMap map[strin
625626
if cli.debug {
626627
cli.renderer.Warnf("%s rollback failed for screens %d-%d: %v", debugPrefix, r+1, rEnd, rbErr)
627628
} else {
628-
cli.renderer.Warnf("rollback failed")
629+
cli.renderer.Warnf("Partial rollback failed for screens %d-%d.", r+1, rEnd)
629630
}
630631
} else {
631632
if cli.debug {
@@ -634,7 +635,7 @@ func applyPromptRenderings(ctx context.Context, cli *cli, screenTagMap map[strin
634635
}
635636
}
636637

637-
cli.renderer.Infof("rolled back for all screens")
638+
cli.renderer.Infof("Rollback complete for all applied batches.")
638639

639640
if cli.debug {
640641
return fmt.Errorf("%s update failed at batch %d-%d: %w", debugPrefix, i+1, end, err)
@@ -650,12 +651,12 @@ func applyPromptRenderings(ctx context.Context, cli *cli, screenTagMap map[strin
650651
func watchAndPatch(ctx context.Context, cli *cli, assetsURL, distPath string, screensToWatch []string, originalHeadTags map[string][]interface{}) error {
651652
watcher, err := fsnotify.NewWatcher()
652653
if err != nil {
653-
return fmt.Errorf("failed to create watcher: %w", err)
654+
return fmt.Errorf("failed to create file system watcher: %w", err)
654655
}
655656
defer watcher.Close()
656657

657658
if err := watcher.Add(distPath); err != nil {
658-
return fmt.Errorf("failed to watch %s: %w", distPath, err)
659+
return fmt.Errorf("failed to watch distribution path %s: %w", distPath, err)
659660
}
660661

661662
fmt.Println("👀 Watching: " + ansi.Yellow(strings.Join(screensToWatch, ", ")))
@@ -677,25 +678,26 @@ func watchAndPatch(ctx context.Context, cli *cli, assetsURL, distPath string, sc
677678
time.Sleep(1 * time.Second)
678679
fmt.Fprintln(os.Stderr, ansi.Yellow("\nShutting down ACUL connected mode..."))
679680
if len(originalHeadTags) > 0 {
680-
restore := prompt.Confirm(
681-
"Would you like to restore your original rendering settings?",
682-
)
681+
restore := prompt.Confirm("Would you like to restore your original rendering settings?")
683682

684683
if restore {
685-
fmt.Fprintln(os.Stdout, ansi.Cyan("Restoring original rendering settings..."))
684+
fmt.Fprintln(os.Stderr, ansi.Cyan("Restoring original rendering settings..."))
686685

687686
if err := applyPromptRenderings(ctx, cli, originalHeadTags, "Restoring"); err != nil {
688-
fmt.Fprintln(os.Stdout, ansi.Yellow(fmt.Sprintf("Failed to restore previous settings: %v", err)))
687+
fmt.Fprintln(os.Stderr, ansi.Yellow(fmt.Sprintf("Restoration failed: %v", err)))
689688
} else {
690-
fmt.Fprintln(os.Stdout, ansi.Green(fmt.Sprintf("Successfully restored rendering settings for %d screen(s).", len(originalHeadTags))))
689+
fmt.Fprintln(os.Stderr, ansi.Green(fmt.Sprintf("Successfully restored rendering settings for %d screen(s).", len(originalHeadTags))))
691690
}
692691
} else {
693-
fmt.Fprintln(os.Stdout, ansi.Yellow("Restoration skipped. The patched assets will continue to remain active in your Auth0 tenant."))
692+
fmt.Fprintln(os.Stderr, ansi.Yellow("Restoration skipped. The patched assets will continue to remain active in your Auth0 tenant."))
694693
}
695694
}
696695

697696
fmt.Println()
698-
fmt.Fprintln(os.Stdout, ansi.Green("👋 ACUL connected mode stopped."))
697+
fmt.Fprintln(os.Stderr, ansi.Green("👋 ACUL connected mode stopped."))
698+
699+
fmt.Fprintf(os.Stderr, "%s Use %s to see all available commands\n\n",
700+
ansi.Yellow("💡 Tip:"), ansi.Cyan("auth0 acul --help"))
699701
}
700702

701703
for {
@@ -725,7 +727,7 @@ func watchAndPatch(ctx context.Context, cli *cli, assetsURL, distPath string, sc
725727
headTags, err := buildHeadTagsFromDirs(distPath, assetsURL, screen)
726728
if err != nil {
727729
if cli.debug {
728-
cli.renderer.Warnf(ansi.Yellow(fmt.Sprintf("Skipping '%s': %v", screen, err)))
730+
cli.renderer.Warnf(ansi.Yellow(fmt.Sprintf("Skipping '%s': failed to build head tags: %v", screen, err)))
729731
}
730732
continue
731733
}
@@ -742,7 +744,7 @@ func watchAndPatch(ctx context.Context, cli *cli, assetsURL, distPath string, sc
742744

743745
if len(changedScreens) == 0 {
744746
if cli.debug {
745-
fmt.Println(ansi.Yellow("No effective asset changes detected and skipping patch."))
747+
fmt.Println(ansi.Yellow("No effective asset changes detected, skipping patch."))
746748
}
747749
continue
748750
}
@@ -755,7 +757,7 @@ func watchAndPatch(ctx context.Context, cli *cli, assetsURL, distPath string, sc
755757
}
756758

757759
if err = applyPromptRenderings(ctx, cli, newHeadTags, "Patching"); err != nil {
758-
cli.renderer.Errorf("Patch failed: %v", err)
760+
cli.renderer.Errorf("Patching assets failed: %v", err)
759761
} else {
760762
fmt.Println(ansi.Green("✅ Assets patched successfully!"))
761763
for screen, headTags := range newHeadTags {
@@ -764,16 +766,14 @@ func watchAndPatch(ctx context.Context, cli *cli, assetsURL, distPath string, sc
764766
}
765767

766768
case err := <-watcher.Errors:
767-
cli.renderer.Warnf("Watcher error: %v", err)
769+
cli.renderer.Warnf("File watcher internal error: %v", err)
768770

769771
case <-sigChan:
770772
cleanup()
771-
printAvailableCommands()
772773
return nil
773774

774775
case <-ctx.Done():
775776
cleanup()
776-
printAvailableCommands()
777777
return ctx.Err()
778778
}
779779
}

internal/cli/acul_screen_scaffolding.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,13 @@ func addScreensToProject(cli *cli, destDir, chosenTemplate string, selectedScree
171171
}
172172
defer os.RemoveAll(tempUnzipDir) // Clean up the entire temp directory.
173173

174-
var sourcePrefix = "auth0-acul-samples-main/" + chosenTemplate
175-
var sourceRoot = filepath.Join(tempUnzipDir, sourcePrefix)
174+
extractedDir, err := findExtractedRepoDir(tempUnzipDir)
175+
if err != nil {
176+
return fmt.Errorf("failed to find extracted directory: %w", err)
177+
}
178+
179+
sourcePathPrefix := filepath.Join(extractedDir, chosenTemplate)
180+
var sourceRoot = filepath.Join(tempUnzipDir, sourcePathPrefix)
176181
var destRoot = destDir
177182

178183
missingFiles, editedFiles, err := processFiles(cli, selectedTemplate.BaseFiles, sourceRoot, destRoot)
@@ -196,7 +201,7 @@ func addScreensToProject(cli *cli, destDir, chosenTemplate string, selectedScree
196201
return fmt.Errorf("error during backup/overwrite: %w", err)
197202
}
198203

199-
err = handleMissingFiles(cli, missingFiles, tempUnzipDir, sourcePrefix, destDir)
204+
err = handleMissingFiles(cli, missingFiles, tempUnzipDir, sourcePathPrefix, destDir)
200205
if err != nil {
201206
return fmt.Errorf("error copying missing files: %w", err)
202207
}

0 commit comments

Comments
 (0)