Skip to content

Commit 943c355

Browse files
authored
Merge pull request #4 from LunarEclipse363/main
Small fixes (updated bootstrap, fixed mismatched HTML tags, etc)
2 parents 0dea50f + b084412 commit 943c355

File tree

12 files changed

+1888
-506
lines changed

12 files changed

+1888
-506
lines changed

.gitignore

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
# Output of the go coverage tool, specifically when used with LiteIDE
1212
*.out
1313

14-
# Dependency directories (remove the comment below to include it)
15-
# vendor/
14+
# Dependency directories
15+
/vendor/
16+
17+
# (P)NPM
18+
/node_modules/
1619

1720
# Output
18-
static/age.wasm
19-
static/wasm_exec.js
21+
/dist/

Makefile

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,79 @@
1-
.PHOHY: import build deploy-gcp
1+
.PHOHY: import build-wasm npm-install build clean zip deploy-gcp help
2+
3+
go-sources = go.mod go.sum *.go
4+
web-sources = package.json pnpm-lock.yaml vite.config.js src/*
25

36
GOROOT:=$(shell go env GOROOT)
47

5-
import:
6-
cp "$(GOROOT)/misc/wasm/wasm_exec.js" static/
8+
# The below code utilizes make's file change tracking
9+
# (i.e. not rebuilding targets unnecessarily)
10+
# while still allowing human-readable target names.
11+
#
12+
# First we set a variable named foo that holds
13+
# all the actual output filenames.
14+
# Then we use $(foo) anywhere we need
15+
# to reference that target as a prerequisite.
16+
# Finally we create a target foo which
17+
# has $(foo) as a prerequisite.
18+
19+
# make import: copy the required wasm_exec.js file from the Go toolchain (output in vendor/)
20+
import = vendor/wasm_exec.js
21+
22+
$(import): $(GOROOT)/misc/wasm/wasm_exec.js
23+
mkdir -p vendor
24+
cp "$(GOROOT)/misc/wasm/wasm_exec.js" vendor/
25+
26+
import: $(import)
27+
28+
# make build-wasm: build the WebAssembly module (output in vendor/)
29+
build-wasm = vendor/age.wasm
30+
31+
$(build-wasm): $(go-sources)
32+
mkdir -p vendor
33+
GOOS=js GOARCH=wasm go build -mod=mod -o vendor/age.wasm
34+
35+
build-wasm: $(build-wasm)
36+
37+
# make npm-install: installs tools and dependencies from npm (output in node_modules/)
38+
#
39+
# This uses an empty target file to track when it needs to be re-ran
40+
npm-install = node_modules/.make-sentinel
41+
42+
$(npm-install): package.json pnpm-lock.yaml
43+
pnpm install
44+
touch $(npm-install)
45+
46+
npm-install: $(npm-install)
47+
48+
# make build: build the complete static website (output in dist/)
49+
#
50+
# If dist/ doesn't exist $(build) will evaluate to 'dist/*'
51+
# but that's fine here because it means the target will run.
52+
build = dist/*
53+
54+
$(build): $(import) $(build-wasm) $(npm-install) $(web-sources)
55+
pnpm run build
56+
57+
build: $(build)
58+
59+
# make clean: delete all existing build files (deletes vendor/* dist/*)
60+
clean:
61+
rm -rf vendor/ dist/
762

8-
build:
9-
GOOS=js GOARCH=wasm go build -o static/age.wasm
63+
# make zip: create a zip archive with the output static website (outputs agewasm.zip)
64+
zip = agewasm.zip
65+
$(zip): $(build)
66+
cd dist && zip -r ../$(zip) .
67+
zip: $(zip)
1068

11-
zip:
12-
cd static && zip -r ../agewasm.zip .
69+
# make deploy-gcp: deploys to google cloud
70+
deploy-gcp: build
71+
gcloud app deploy
1372

14-
deploy-gcp:
15-
gcloud app deploy
73+
# make help: print this help page
74+
help:
75+
@echo "agewasm Makefile"
76+
@echo "Usage: make <TARGET>"
77+
@echo ""
78+
@echo "Available targets:"
79+
@grep -P '^# make [[:alnum:]_-]+:' Makefile | sed -e 's/^# / /'

README.md

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,34 @@ View online [here](https://age-wasm.ey.r.appspot.com/)
66

77
## Building
88

9-
You will need `Go` and `wasm_exec.js` (which is included with Go)
9+
You will need:
10+
- [Go](https://go.dev/) and `wasm_exec.js` (included with Go)
11+
- [PNPM](https://pnpm.io/)
1012

11-
### Supporting wasm_exec.js
13+
Use the provided `Makefile` and execute `make build`.
1214

13-
The JavaScript file can be found in the GOROOT folder. To copy it to the static directory use the following command:
15+
See `make help` for descriptions of other targets.
1416

15-
```sh
16-
cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" ./static
17-
```
17+
The final static website will be placed in `dist/`
1818

19-
or use provided `Makefile` and execute `make import`
19+
## Usage
2020

21-
### Compile it to a .wasm file
22-
23-
```sh
24-
GOOS=js GOARCH=wasm go build -o static/age.wasm
25-
```
26-
27-
or use provided `Makefile` and execute `make build`
28-
29-
Now you should have `age.wasm` and `wasm_exec.js` in static folder.
30-
31-
## Using
32-
33-
Put the static folder on your favorite web server server or open `index.html`.
21+
Put the `dist` folder on your favorite web server server or open `index.html`.
3422
There is no binary to run :)
3523

3624
---
3725

3826
**Prebuilt files?**
3927

40-
You can grab generated zip file which includes `age.wasm` and `wasm_exec.js` on [release page](https://github.com/MarinX/agewasm/releases).
28+
You can grab a generated zip file on the [release page](https://github.com/MarinX/agewasm/releases).
4129

4230
---
4331

32+
## Developement
33+
You can run a developement Vite server with live-reload using `pnpm run dev` (this will not auto-rebuild the WASM).
34+
35+
Please format the source files before commiting with `pnpm run format`
36+
4437
## License
4538

4639
This project is licensed under the MIT License. See the LICENSE file for the full license text.

app.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ threadsafe: true
44

55
handlers:
66
- url: /
7-
static_files: static/index.html
8-
upload: static/index.html
7+
static_files: dist/index.html
8+
upload: dist/index.html
99

1010
- url: /(.*)
11-
static_files: static/\1
12-
upload: static/(.*)
11+
static_files: dist/\1
12+
upload: dist/(.*)

package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "agewasm",
3+
"version": "1.1.0",
4+
"description": "A simple and secure online client-side Age key generator, encryption and decryption tool built using wasm.",
5+
"scripts": {
6+
"dev": "vite",
7+
"build": "vite build --emptyOutDir",
8+
"preview": "vite preview",
9+
"format": "prettier --write src/*.html src/*.js src/*.scss"
10+
},
11+
"keywords": [
12+
"encryption",
13+
"age-encryption"
14+
],
15+
"author": "Marin Basic (marin-basic.com)",
16+
"license": "MIT",
17+
"dependencies": {
18+
"@popperjs/core": "^2.11.8",
19+
"bootstrap": "^5.3.3"
20+
},
21+
"devDependencies": {
22+
"prettier": "^3.5.0",
23+
"sass-embedded": "^1.83.4",
24+
"vite": "^6.1.0"
25+
}
26+
}

0 commit comments

Comments
 (0)