Skip to content

Commit aa17f50

Browse files
committed
feat: allow templating
1 parent 5fe56d4 commit aa17f50

File tree

7 files changed

+495
-0
lines changed

7 files changed

+495
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,14 @@ backend/*.xcframework
6060
# IDEs
6161
.vscode/
6262
.idea/
63+
.claude/
6364
*.swp
6465
*.swo
6566
*~
6667

68+
# CLI template (generated before npm publish)
69+
cli/template/
70+
6771
# Testing
6872
coverage/
6973
*.log

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ This project showcases how to build a fast mobile application where:
2626
- iOS: Xcode 15+, CocoaPods
2727
- Android: Android Studio, JDK 17+
2828

29+
## Create a New Project
30+
31+
```bash
32+
npx create-react-native-go my-app --bundleId com.mycompany.myapp --goModule mycompany.com/my-app
33+
cd my-app
34+
make setup
35+
make ios # or: make android
36+
```
37+
38+
The CLI scaffolds a new project with your app name, bundle ID, and Go module — fully configured and ready to build.
39+
2940
## Quick Start
3041

3142
### Setup

cli/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# create-react-native-go
2+
3+
Scaffold a React Native + Go mobile app in seconds. Go runs as an embedded HTTP server providing JSON-RPC APIs, while React Native handles the UI with the New Architecture (Fabric + TurboModules).
4+
5+
## Usage
6+
7+
```bash
8+
npx create-react-native-go my-app --bundleId com.mycompany.myapp --goModule mycompany.com/my-app
9+
cd my-app
10+
make setup
11+
make ios # or: make android
12+
```
13+
14+
If you omit any flags, the CLI will prompt you interactively.
15+
16+
## What You Get
17+
18+
```
19+
my-app/
20+
├── Makefile # Root orchestrator
21+
├── backend/
22+
│ ├── Makefile # Go build targets
23+
│ ├── mobile_api.go # Mobile API for server lifecycle
24+
│ └── http_server.go # JSON-RPC HTTP server
25+
└── mobile-app/
26+
├── Makefile # Mobile build targets
27+
├── src/
28+
│ ├── NativeGoServerBridge.ts # TurboModule spec
29+
│ ├── GoServerBridgeJSI.ts # JSI wrapper
30+
│ └── JsonRpcClient.ts # JSON-RPC client
31+
├── android/ # Android native code
32+
└── ios/ # iOS native code
33+
```
34+
35+
## Prerequisites
36+
37+
- Node.js 18+
38+
- Go 1.25+
39+
- iOS: Xcode 15+, CocoaPods
40+
- Android: Android Studio, JDK 17+
41+
42+
## Options
43+
44+
| Flag | Description | Example |
45+
|------|-------------|---------|
46+
| `--bundleId` | App bundle identifier | `com.mycompany.myapp` |
47+
| `--goModule` | Go module path | `mycompany.com/my-app` |
48+
49+
The first positional argument is the app name (e.g. `my-app`).
50+
51+
## How It Works
52+
53+
The CLI copies a pre-built template and replaces all identifiers (app name, bundle ID, Go module path, iOS project name, Android package directories) to match your configuration. It then initializes a fresh git repo.
54+
55+
## Links
56+
57+
- [GitHub Repository](https://github.com/siddarthkay/react-native-go)
58+
- [Issues](https://github.com/siddarthkay/react-native-go/issues)
59+
60+
## License
61+
62+
MIT

cli/bin.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
const { run } = require("./src/index");
3+
run();

cli/build-template.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
# Copies project template files into cli/template/ for npm publishing.
3+
# Run this before `npm publish` in the cli/ directory.
4+
set -e
5+
6+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
7+
REPO_ROOT="$(dirname "$SCRIPT_DIR")"
8+
TEMPLATE_DIR="$SCRIPT_DIR/template"
9+
10+
echo "Building template from repo..."
11+
12+
rm -rf "$TEMPLATE_DIR"
13+
mkdir -p "$TEMPLATE_DIR"
14+
15+
# Use rsync to copy while excluding build artifacts and dependencies
16+
rsync -a \
17+
--exclude='.git' \
18+
--exclude='node_modules' \
19+
--exclude='Pods' \
20+
--exclude='Podfile.lock' \
21+
--exclude='*.xcworkspace' \
22+
--exclude='build' \
23+
--exclude='.gradle' \
24+
--exclude='gradle/' \
25+
--exclude='.yarn/cache' \
26+
--exclude='.yarn/install-state.gz' \
27+
--exclude='gobridge.aar' \
28+
--exclude='Gobridge.xcframework' \
29+
--exclude='go.sum' \
30+
--exclude='.expo' \
31+
--exclude='.cxx' \
32+
--exclude='local.properties' \
33+
"$REPO_ROOT/backend" "$TEMPLATE_DIR/"
34+
35+
rsync -a \
36+
--exclude='.git' \
37+
--exclude='node_modules' \
38+
--exclude='Pods' \
39+
--exclude='Podfile.lock' \
40+
--exclude='*.xcworkspace' \
41+
--exclude='build' \
42+
--exclude='.gradle' \
43+
--exclude='.yarn/cache' \
44+
--exclude='.yarn/install-state.gz' \
45+
--exclude='gobridge.aar' \
46+
--exclude='Gobridge.xcframework' \
47+
--exclude='.expo' \
48+
--exclude='.cxx' \
49+
--exclude='.claude' \
50+
--exclude='local.properties' \
51+
"$REPO_ROOT/mobile-app" "$TEMPLATE_DIR/"
52+
53+
cp "$REPO_ROOT/Makefile" "$TEMPLATE_DIR/Makefile"
54+
cp "$REPO_ROOT/.gitignore" "$TEMPLATE_DIR/.gitignore"
55+
56+
echo "Template built at: $TEMPLATE_DIR"

cli/package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "create-react-native-go",
3+
"version": "1.0.1",
4+
"description": "Create a React Native + Go mobile app",
5+
"bin": {
6+
"create-react-native-go": "./bin.js"
7+
},
8+
"scripts": {
9+
"prepublishOnly": "./build-template.sh"
10+
},
11+
"files": [
12+
"bin.js",
13+
"src/",
14+
"template/"
15+
],
16+
"keywords": [
17+
"react-native",
18+
"golang",
19+
"go",
20+
"mobile",
21+
"template",
22+
"gomobile",
23+
"jsi",
24+
"turbomodules"
25+
],
26+
"author": "siddarthkay",
27+
"license": "MIT",
28+
"repository": {
29+
"type": "git",
30+
"url": "https://github.com/siddarthkay/react-native-go"
31+
}
32+
}

0 commit comments

Comments
 (0)