Add adds imports to "importmap" script
()
| 65 | |
| 66 | // Add adds imports to "importmap" script |
| 67 | func Add() { |
| 68 | all := flag.Bool("all", false, "add all modules of the import") |
| 69 | a := flag.Bool("a", false, "add all modules of the import") |
| 70 | noPrompt := flag.Bool("no-prompt", false, "add imports without prompt") |
| 71 | noSRI := flag.Bool("no-sri", false, "do not generate SRI for the import") |
| 72 | specifiers, help := parseCommandFlags() |
| 73 | |
| 74 | if help || len(specifiers) == 0 { |
| 75 | fmt.Print(addHelpMessage) |
| 76 | return |
| 77 | } |
| 78 | |
| 79 | err := updateImportMap(set.New(specifiers...).Values(), *all || *a, *noPrompt, *noSRI) |
| 80 | if err != nil { |
| 81 | fmt.Println(term.Red("✖︎"), "Failed to add imports: "+err.Error()) |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | func updateImportMap(specifiers []string, all bool, noPrompt bool, noSRI bool) (err error) { |
| 86 | indexHtml, exists, err := lookupClosestFile("index.html") |
no test coverage detected