Skip to content

Commit 792e1c1

Browse files
committed
Merge branch 'plugins'
# Conflicts: # cmd_publish.go
2 parents bfe944d + ba616c5 commit 792e1c1

File tree

6 files changed

+668
-34
lines changed

6 files changed

+668
-34
lines changed

build.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package yaakcli
2+
3+
import (
4+
"github.com/evanw/esbuild/pkg/api"
5+
"github.com/pterm/pterm"
6+
"path/filepath"
7+
)
8+
9+
func ESLintBuildOptions(pluginDir string) api.BuildOptions {
10+
srcPath := filepath.Join(pluginDir, "src", "index.ts")
11+
outPath := filepath.Join(pluginDir, "build", "index.js")
12+
return api.BuildOptions{
13+
EntryPoints: []string{srcPath},
14+
Outfile: outPath,
15+
Platform: api.PlatformNode,
16+
Bundle: true, // Inline dependencies
17+
Write: true, // Write to disk
18+
Format: api.FormatCommonJS,
19+
LogLevel: api.LogLevelInfo,
20+
}
21+
}
22+
23+
func BuildPlugin(dir string) {
24+
if !fileExists(filepath.Join(dir, "package.json")) {
25+
ExitError("./package.json does not exist. Ensure that you are in a plugin directory.")
26+
}
27+
28+
pterm.Info.Printf("Building plugin %s...\n", dir)
29+
30+
api.Build(ESLintBuildOptions(dir))
31+
}

cmd_build.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
package yaakcli
22

33
import (
4-
"fmt"
5-
"github.com/evanw/esbuild/pkg/api"
64
"github.com/spf13/cobra"
5+
"os"
6+
"path/filepath"
77
)
88

99
var buildCmd = &cobra.Command{
1010
Use: "build entrypoint",
1111
Short: "Transpile code into a runnable plugin bundle",
12+
Args: cobra.MaximumNArgs(1),
1213
Run: func(cmd *cobra.Command, args []string) {
13-
if !fileExists("./package.json") {
14-
ExitError("./package.json does not exist. Ensure that you are in a plugin directory?")
15-
}
16-
17-
srcPath := "./src/index.ts"
18-
fmt.Printf("Building %s...\n", srcPath)
14+
pluginDir, err := os.Getwd()
15+
CheckError(err)
1916

20-
result := api.Build(ESLintBuildOptions([]string{srcPath}))
21-
for _, o := range result.OutputFiles {
22-
fmt.Printf("Compiled to: %s\n", o.Path)
17+
if len(args) > 0 {
18+
pluginDir, err = filepath.Abs(args[0])
19+
CheckError(err)
2320
}
21+
22+
BuildPlugin(pluginDir)
2423
},
2524
}

cmd_dev.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/evanw/esbuild/pkg/api"
66
"github.com/spf13/cobra"
77
"os"
8+
"path/filepath"
89
)
910

1011
var devCmd = &cobra.Command{
@@ -16,16 +17,23 @@ var devCmd = &cobra.Command{
1617
ExitError("./package.json does not exist. Ensure that you are in a plugin directory?")
1718
}
1819

19-
srcPath := "./src/index.ts"
20-
ctx, errors := api.Context(ESLintBuildOptions([]string{srcPath}))
20+
pluginDir, err := os.Getwd()
21+
CheckError(err)
22+
23+
if len(args) > 0 {
24+
pluginDir, err = filepath.Abs(args[0])
25+
CheckError(err)
26+
}
27+
28+
fmt.Printf("Watching %s...\n", pluginDir)
29+
30+
ctx, errors := api.Context(ESLintBuildOptions(pluginDir))
2131
if errors != nil {
2232
println("Failed to create esbuild context")
2333
os.Exit(1)
2434
}
2535

26-
fmt.Printf("Watching %s...\n", srcPath)
27-
28-
err := ctx.Watch(api.WatchOptions{})
36+
err = ctx.Watch(api.WatchOptions{})
2937
CheckError(err)
3038

3139
// Returning from main() exits immediately in Go.

cmd_publish.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var publishCmd = &cobra.Command{
1616
Short: "Publish a Yaak plugin version to the plugin registry",
1717
Args: cobra.MaximumNArgs(1),
1818
Run: func(cmd *cobra.Command, args []string) {
19-
spinner, _ := pterm.DefaultSpinner.WithDelay(1 * time.Second).Start("Publishing plugin...")
19+
pterm.Info.Println("Building plugin...")
2020

2121
pluginDir, err := os.Getwd()
2222
CheckError(err)
@@ -26,6 +26,10 @@ var publishCmd = &cobra.Command{
2626
CheckError(err)
2727
}
2828

29+
BuildPlugin(pluginDir)
30+
31+
spinner, _ := pterm.DefaultSpinner.WithDelay(1 * time.Second).Start("Publishing plugin...")
32+
2933
zipPipeReader, zipPipeWriter := io.Pipe()
3034

3135
zipWriter := zip.NewWriter(zipPipeWriter)

esbuild.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)