Skip to content

Commit 307533e

Browse files
author
Norman Meier
committed
feat: module creation cli
Signed-off-by: Norman Meier <[email protected]>
1 parent 47d9543 commit 307533e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2444
-1354
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ all:
55
clean.gen:
66
for api in $$(ls api); do rm -fr \
77
go/pkg/$${api}/$${api}_grpc.pb.go \
8-
go/pkg/$${api}/ipfsman.pb.go \
8+
go/pkg/$${api}/$${api}.pb.go \
99
rn/src/api/$${api} \
1010
; done
11+
rm -f go/bind/labs/modules.go
1112
rm -f rn/src/api/index.ts
1213
.PHONY: clean-gen
1314

@@ -29,6 +30,7 @@ generate:
2930
echo "export * as $${api} from './$${api}/v1'" >> rn/src/api/index.ts; \
3031
done
3132
$(MAKE) -C rn lint.fix
33+
cd rn && npx ts-node src/create-mod/gen-go-modules-list
3234
.PHONY: generate
3335

3436
regen: clean.gen

README.md

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,80 @@ TODO
2828

2929
## Getting Started
3030

31-
TODO
31+
See [Modules](#modules) if you don't want to dive into the code
3232

3333
### Troubleshooting
3434

3535
_(please use [issues](https://github.com/berty/REPLACEME))_
3636

3737
## Development
3838

39-
TODO
39+
If you want to quickly try native mobile IPFS without writing any go, make an [HTML module](#html-module)
4040

4141
### Architecture
4242

43-
TODO
43+
TODO: Explain modules architecture
44+
45+
## Modules<a id='modules'></a>
46+
47+
Modules are automatically added to the home tool list in the app
48+
49+
They allow you to run custom Go or JavaScript and programatically access a Gomobile-IPFS backed IPFS shell on mobile very quickly
50+
51+
You don't need to know JavaScript to create or run a Go module and you don't need to know Go to create or run a JavaScript module
52+
53+
### HTML<a id='html-module'></a>
54+
55+
HTML modules in a nutshell:
56+
- Living at `rn/html-mods/`
57+
- Statically served at the root of a Go `http.FileServer` started automatically by the Labs bridge
58+
- Accessed with a `react-native-webview` pointed at the embedded static server (the `rn/src/screens/HTMLModule.tsx` screen)
59+
- If the build of an HTML module fails, it will be skipped and building the app will continue
60+
61+
Create a new Labs HTML module by running
62+
63+
```sh
64+
cd rn
65+
make create-module
66+
```
67+
68+
And choosing one of `bare`, `git` or `react`
69+
70+
It will ask you a few questions and create the module boilerplate, every step is logged so you can understand what is going on
71+
72+
If you choose the `react` preset, you can use the dev-server from mobile with the `Browser` Labs tool
73+
74+
Or:
75+
- Create a directory at `rn/html-mods/<your-module-name>`
76+
- Add a Makefile at `rn/html-mods/<your-module-name>/Makefile` with the first rule creating:
77+
- The `rn/html-mods.bundle/<your-module-name>/index.html` root site file
78+
- The `rn/html-mods.bundle/<your-module-name>/info.json` file containing a JSON representation of the `blmod.ModuleInfo` type
79+
80+
### Go
81+
82+
Go modules in a nutshell:
83+
- Living at `go/mod/`
84+
- Need to be registered in `go/bind/labs/modules.go` which can be done automatically by running `make generate`
85+
- Accessed with a generic UI that allows to run them, cancel runs and view their output (the `rn/src/screens/GoModule.tsx` screen)
86+
- If the build of a registered Go module fails, it will abort building the app
87+
88+
Create a new Labs Go module by running
89+
90+
```sh
91+
cd rn
92+
make create-module
93+
```
94+
95+
And choosing `go` as preset
96+
97+
Or:
98+
- Create a Go module at `go/mod/<your-module-name>`
99+
- Implement the `berty.tech/labs/go/pkg/blmod.Module` interface
100+
- Register the module in `go/bind/labs/modules.go`
101+
102+
To develop a Go module faster, you can:
103+
- `go run ./go/cmd/daemon` to spawn a CLI Labs instance
104+
- `go run ./go/cmd/client` to access the modules with a CLI
44105

45106
### Testing
46107

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/ipfs/go-ds-flatfs v0.5.1
1313
github.com/ipfs/go-ds-leveldb v0.5.0
1414
github.com/ipfs/go-ds-sql v0.3.0
15+
github.com/ipfs/go-ipfs-api v0.3.0
1516
github.com/ipfs/go-ipfs-chunker v0.0.5
1617
github.com/ipfs/go-ipfs-config v0.18.0
1718
github.com/multiformats/go-multiaddr v0.5.0
@@ -91,7 +92,6 @@ require (
9192
github.com/ipfs/go-fs-lock v0.0.7 // indirect
9293
github.com/ipfs/go-graphsync v0.11.0 // indirect
9394
github.com/ipfs/go-ipfs v0.11.0 // indirect
94-
github.com/ipfs/go-ipfs-api v0.3.0 // indirect
9595
github.com/ipfs/go-ipfs-blockstore v0.2.1 // indirect
9696
github.com/ipfs/go-ipfs-cmds v0.6.0 // indirect
9797
github.com/ipfs/go-ipfs-delay v0.0.1 // indirect
@@ -256,3 +256,5 @@ require (
256256
lukechampine.com/blake3 v1.1.6 // indirect
257257
nhooyr.io/websocket v1.8.6 // indirect
258258
)
259+
260+
replace golang.org/x/mobile => github.com/aeddi/mobile v0.0.3-silicon

go.sum

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ github.com/Stebalien/go-bitfield v0.0.1 h1:X3kbSSPUaJK60wV2hjOPZwmpljr6VGCqdq4cB
6060
github.com/Stebalien/go-bitfield v0.0.1/go.mod h1:GNjFpasyUVkHMsfEOk8EFLJ9syQ6SI+XWrX9Wf2XH0s=
6161
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
6262
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
63+
github.com/aeddi/mobile v0.0.3-silicon h1:wOm6xG8FinN1kQW8aQNZAS9QWMUOPstVU6WV1iIEI4A=
64+
github.com/aeddi/mobile v0.0.3-silicon/go.mod h1:jFTmtFYCV0MFtXBU+J5V/+5AUeVS0ON/0WkE/KSrl6E=
6365
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
6466
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
6567
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
@@ -1570,7 +1572,6 @@ golang.org/x/crypto v0.0.0-20210813211128-0a44fdfbc16e/go.mod h1:GvvjBRRGRdwPK5y
15701572
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
15711573
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
15721574
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
1573-
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
15741575
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
15751576
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
15761577
golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek=
@@ -1595,10 +1596,6 @@ golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRu
15951596
golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
15961597
golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k=
15971598
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
1598-
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
1599-
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
1600-
golang.org/x/mobile v0.0.0-20220112015953-858099ff7816 h1:jhDgkcu3yQ4tasBZ+1YwDmK7eFmuVf1w1k+NGGGxfmE=
1601-
golang.org/x/mobile v0.0.0-20220112015953-858099ff7816/go.mod h1:pe2sM7Uk+2Su1y7u/6Z8KJ24D7lepUjFZbhFOrmDfuQ=
16021599
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
16031600
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
16041601
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
@@ -1852,6 +1849,7 @@ golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4f
18521849
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
18531850
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
18541851
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
1852+
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
18551853
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
18561854
golang.org/x/tools v0.1.8-0.20211022200916-316ba0b74098/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
18571855
golang.org/x/tools v0.1.9 h1:j9KsMiaP1c3B0OTQGth0/k+miLGTgLsAFUCrF2vLcF8=

go/bind/labs/labs.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,3 @@ func (b *Labs) Close() error {
151151
}
152152
return nil
153153
}
154-
155-
func safeLogger(l *zap.Logger) *zap.Logger {
156-
if l == nil {
157-
l = zap.NewNop()
158-
}
159-
return l
160-
}

go/bind/labs/modules.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package labs
22

33
import (
4-
"berty.tech/labs/go/mod/datastorebench"
54
"berty.tech/labs/go/pkg/blmod"
5+
6+
"berty.tech/labs/go/mod/datastorebench"
67
)
78

89
var modules = []blmod.ModuleFactory{

rn/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,6 @@ android/app/gradlew.bat
7373
/gomobile-ipfs/
7474
/ios/vendored_pods/
7575
/react-native-labs-bridge/ios/Labsbridge.xcframework
76-
/html-mods.bundle
76+
/html-mods.bundle
77+
/html-mods/*/repo
78+
.gomobile-cache

rn/Makefile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ html-mods=$(wildcard html-mods/*)
2424

2525
html-mods.all:
2626
mkdir -p html-mods.bundle
27-
@for mod in $(html-mods); do echo "--- Making HTML module $$(basename $$mod) ---"; make -C $$mod; done
27+
@for mod in $(html-mods); do echo "--- Making HTML module $$(basename $$mod) ---"; SKIP_PREFLIGHT_CHECK=true make -C $$mod; done
2828
@echo --- Done making HTML modules ---
2929
.PHONY: html-mods.all
3030

@@ -38,11 +38,14 @@ ios: node_modules/.mkt ios/Pods/.mkt html-mods.all
3838
$(IOS_RN_FLAGS)
3939

4040
$(IOS_CORE): ../go.mod ../go.sum $(shell find ../go -name '*.go')
41-
$(GO) mod download
42-
$(GO) install golang.org/x/mobile/cmd/gomobile
43-
$(GO) install golang.org/x/mobile/cmd/gobind
4441
$(GO) run golang.org/x/mobile/cmd/gomobile init -v
45-
$(GO) run golang.org/x/mobile/cmd/gomobile bind $(GOMOBILE_OPT) -v -target=ios,iossimulator -o $(IOS_CORE) $(CORE_PACKAGE)
42+
CGO_CPPFLAGS=-DHAVE_GETHOSTUUID=0 $(GO) run golang.org/x/mobile/cmd/gomobile bind \
43+
$(GOMOBILE_OPT) \
44+
-v \
45+
-target=ios \
46+
-o $(IOS_CORE) \
47+
-cache "$(PWD)/ios/.gomobile-cache/labs" \
48+
$(CORE_PACKAGE)
4649

4750
.link:
4851
cd react-native-labs-bridge && yarn link
@@ -96,6 +99,11 @@ lint.fix: node_modules/.mkt
9699
metro.start: node_modules/.mkt
97100
npx react-native start --port=$(METRO_RN_PORT)
98101

102+
103+
.PHONY: create-module
104+
create-module: node_modules/.mkt
105+
SKIP_PREFLIGHT_CHECK=true npx ts-node -TH --files ./src/create-mod
106+
99107
.PHONY: clean
100108
clean:
101109
$(MAKE) unlink

rn/html-mods/ipfs-upload-file/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ DIST_DIR=$(REPO_ROOT)/dist
1111
$(INDEX_HTML): $(REPO_TARGET) $(NODE_MODULES_TARGET) info.json
1212
rm -fr $(DIST_DIR)
1313
cd $(REPO_ROOT) && npm run build
14+
1415
rm -fr $(BUILD_TARGET)
16+
mkdir -p $(BUNDLE_ROOT)
1517
cp -r $(DIST_DIR) $(BUILD_TARGET)
1618
cp info.json $(BUILD_TARGET)/info.json
1719

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"displayName": "IPFS File Upload",
33
"shortDescription": "Upload a file to IPFS",
4-
"iconKind": "UTF",
5-
"iconUTF": "⬆️"
4+
"iconKind": 1,
5+
"iconData": "4qyG77iP"
66
}

0 commit comments

Comments
 (0)