Skip to content

Commit

Permalink
feat: add js support
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jul 19, 2019
1 parent cbc11b2 commit 5155115
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -86,9 +86,9 @@ COMMANDS:
help, h Shows a list of commands or help for one command

GLOBAL OPTIONS:
--format value, -f value output format ("json", "yaml", "jsonp") (default: "json")
--format value, -f value output format ("json", "yaml", "jsonp", "js") (default: "json")
--indent, -i use indented output (only for "json" format) (default: false)
--callback value, -c value jsonp callback name (default: "callback")
--callback value, -c value jsonp/js callback name (default: "callback")
--help, -h show help (default: false)
--version, -v print the version (default: false)
```
Expand Down
12 changes: 9 additions & 3 deletions main.go
Expand Up @@ -30,14 +30,14 @@ func main() {
app := &cli.App{
Name: "fs-bundler",
Flags: []cli.Flag{
&cli.StringFlag{Name: "format", Aliases: []string{"f"}, Value: "json", Usage: `output format ("json", "yaml", "jsonp")`},
&cli.StringFlag{Name: "format", Aliases: []string{"f"}, Value: "json", Usage: `output format ("json", "yaml", "jsonp", "js")`},
&cli.BoolFlag{Name: "indent", Aliases: []string{"i"}, Usage: `use indented output (only for "json" format)`},
&cli.StringFlag{Name: "callback", Aliases: []string{"c"}, Value: "callback", Usage: `jsonp callback name`},
&cli.StringFlag{Name: "callback", Aliases: []string{"c"}, Value: "callback", Usage: `jsonp/js callback name`},
// compress
},
Action: func(c *cli.Context) error {
switch c.String("format") {
case "json", "yaml", "jsonp":
case "json", "yaml", "jsonp", "js":
default:
return fmt.Errorf("unsupported output format %q", c.String("format"))
}
Expand Down Expand Up @@ -94,6 +94,12 @@ func main() {
return err
}
fmt.Printf("%s(%s)", c.String("callback"), string(out))
case "js":
out, err := json.Marshal(dump)
if err != nil {
return err
}
fmt.Printf("var %s = %s", c.String("callback"), string(out))
case "yaml":
out, err := yaml.Marshal(dump)
if err != nil {
Expand Down

0 comments on commit 5155115

Please sign in to comment.