forked from gopherjs/gopherjs
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compiler/prelude: format .js files using prettier (#4)
This PR introduces automatic formatting of the prelude's now separate .js files. Using prettier has the same argument as using gofmt on .go source code. As part of this we make the go generate step for the prelude include a formatpreludejs.go step. The resulting prelude_min.go file is slightly different now, but post gopherjs#791 we can see these differences are entirely and solely attributable to prettier's adjusting of the .js files.
- Loading branch information
Showing
11 changed files
with
1,069 additions
and
812 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// +build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"go/build" | ||
"io/ioutil" | ||
"log" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
func main() { | ||
if err := run(); err != nil { | ||
log.Fatalln(err) | ||
} | ||
} | ||
|
||
func run() error { | ||
bpkg, err := build.Import("github.com/gopherjs/gopherjs", "", build.FindOnly) | ||
if err != nil { | ||
return fmt.Errorf("failed to locate path for github.com/gopherjs/gopherjs/compiler/prelude: %v", err) | ||
} | ||
|
||
preludeDir := filepath.Join(bpkg.Dir, "compiler", "prelude") | ||
|
||
args := []string{ | ||
filepath.Join(bpkg.Dir, "node_modules", ".bin", "prettier"), | ||
"--config", | ||
filepath.Join(preludeDir, "prettier_options.json"), | ||
"--write", | ||
} | ||
|
||
fis, err := ioutil.ReadDir(preludeDir) | ||
if err != nil { | ||
return fmt.Errorf("failed to list contents of %v: %v", preludeDir, err) | ||
} | ||
for _, fi := range fis { | ||
fn := fi.Name() | ||
if !strings.HasSuffix(fn, ".js") || strings.HasSuffix(fn, ".min.js") { | ||
continue | ||
} | ||
args = append(args, fn) | ||
} | ||
|
||
cmd := exec.Command(args[0], args[1:]...) | ||
|
||
out, err := cmd.CombinedOutput() | ||
if err != nil { | ||
return fmt.Errorf("failed to run %v: %v\n%s", strings.Join(args, " "), err, string(out)) | ||
} | ||
|
||
return nil | ||
} |
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,3 +1,4 @@ | ||
package prelude | ||
|
||
//go:generate go run formatpreludejs.go | ||
//go:generate go run genprelude.go |
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
Oops, something went wrong.