Skip to content

Commit 757ff58

Browse files
committed
creates importmap, sample app and deno.json files
1 parent deccf87 commit 757ff58

9 files changed

Lines changed: 89 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ tmp
22
bin
33
pkg
44
obj
5+
.vscode

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"deno.enable": true
3+
}

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
all: demo
2+
3+
demo: build
4+
emerald-esbuild
5+
6+
build:
7+
go build -ldflags "-s -w" -o /usr/local/bin/emerald-esbuild .
8+
9+
run:
10+
go run .

app/main.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Alpine from "alpinejs";
2+
3+
// const Alpine = window.Alpine;
4+
5+
/// --- DEFINE ALL OUR COMPONENTS AND PAGES ---
6+
Alpine.data('content', () => ({}));
7+
8+
/// START ALPINE
9+
Alpine.start();

deno.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
importmap.json

dist/main.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

esbuild/esbuild.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,22 @@ import (
1616
func BuildApp() {
1717
var dir = "app"
1818
if _, err := os.Stat(dir); os.IsNotExist(err) {
19-
fmt.Println("Skipping esbuild")
20-
return
19+
fmt.Println("No app dir, creating...")
20+
WriteApp()
21+
}
22+
if _, err := os.Stat(dir + "main.tsx"); os.IsNotExist(err) {
23+
fmt.Println("No app main.tsx, creating...")
24+
WriteApp()
25+
}
26+
if _, err := os.Stat("./importmap.json"); os.IsNotExist(err) {
27+
fmt.Println("Cannot find importmap.json, creating...")
28+
WriteImportMap("./importmap.json")
29+
}
30+
if _, err := os.Stat("./deno.json"); os.IsNotExist(err) {
31+
fmt.Println("Cannot find deno.json, linking...")
32+
if err = os.Symlink("importmap.json", "deno.json"); err != nil {
33+
WriteImportMap("./deno.json")
34+
}
2135
}
2236
fmt.Println("Bundling with esbuild...")
2337
result := api.Build(api.BuildOptions{

esbuild/write_files.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package esbuild
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
func WriteImportMap(filepath string) error {
9+
return os.WriteFile(filepath, []byte(`{
10+
"imports": {
11+
"alpinejs": "https://esm.sh/alpinejs",
12+
"react": "https://esm.sh/react",
13+
"react-dom": "https://esm.sh/react-dom",
14+
"moment": "https://esm.sh/moment"
15+
}
16+
}`), os.FileMode(int(0777)))
17+
}
18+
19+
func WriteApp() {
20+
if err := os.MkdirAll("./app", os.FileMode(int(0777))); err != nil {
21+
fmt.Println("error: ", err)
22+
}
23+
err := os.WriteFile("./app/main.tsx", []byte(`import Alpine from "alpinejs";
24+
25+
// const Alpine = window.Alpine;
26+
27+
/// --- DEFINE ALL OUR COMPONENTS AND PAGES ---
28+
Alpine.data('content', () => ({}));
29+
30+
/// START ALPINE
31+
Alpine.start();
32+
`), os.FileMode(int(0777)))
33+
34+
if err != nil {
35+
fmt.Println("error: ", err)
36+
}
37+
}

importmap.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"imports": {
3+
"react": "https://esm.sh/react",
4+
"react-dom": "https://esm.sh/react-dom",
5+
"alpinejs": "https://esm.sh/alpinejs"
6+
}
7+
}

0 commit comments

Comments
 (0)