solforge 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +441 -0
- package/package.json +71 -0
- package/scripts/postinstall.cjs +103 -0
- package/src/commands/add-program.ts +337 -0
- package/src/commands/init.ts +122 -0
- package/src/commands/list.ts +136 -0
- package/src/commands/start.ts +735 -0
- package/src/commands/status.ts +99 -0
- package/src/commands/stop.ts +389 -0
- package/src/commands/transfer.ts +259 -0
- package/src/config/manager.ts +157 -0
- package/src/index.ts +107 -0
- package/src/services/port-manager.ts +177 -0
- package/src/services/process-registry.ts +155 -0
- package/src/services/program-cloner.ts +317 -0
- package/src/services/token-cloner.ts +809 -0
- package/src/services/validator.ts +295 -0
- package/src/types/config.ts +110 -0
- package/src/utils/shell.ts +110 -0
- package/tsconfig.json +28 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 nitishxyz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
# SolForge
|
|
2
|
+
|
|
3
|
+
**SolForge** is a powerful Solana localnet orchestration tool that simplifies the process of setting up and managing local Solana development environments. It allows you to clone mainnet programs and tokens to your local validator, making it easy to develop and test Solana applications with real-world data.
|
|
4
|
+
|
|
5
|
+
## ✨ Features
|
|
6
|
+
|
|
7
|
+
- 🚀 **One-command setup** - Initialize and start a localnet with a single command
|
|
8
|
+
- 🔄 **Mainnet cloning** - Clone tokens and programs from Solana mainnet to your localnet
|
|
9
|
+
- 🎯 **Multi-validator support** - Run multiple validators simultaneously with different configurations
|
|
10
|
+
- 💰 **Token management** - Mint tokens with custom amounts and distribute to specific wallets
|
|
11
|
+
- 🔧 **Program deployment** - Deploy and manage Solana programs on your localnet
|
|
12
|
+
- 📊 **Process management** - Monitor, start, stop, and manage validator processes
|
|
13
|
+
- 🌐 **Port management** - Automatic port allocation and conflict resolution
|
|
14
|
+
- 📝 **Configuration-driven** - JSON-based configuration for reproducible environments
|
|
15
|
+
- 🎨 **Beautiful CLI** - Colorful, intuitive command-line interface
|
|
16
|
+
|
|
17
|
+
## 🚀 Quick Start
|
|
18
|
+
|
|
19
|
+
### Prerequisites
|
|
20
|
+
|
|
21
|
+
- [Bun](https://bun.sh) runtime
|
|
22
|
+
- [Solana CLI tools](https://docs.solana.com/cli/install-solana-cli-tools) installed and configured
|
|
23
|
+
- Node.js 18+ (for compatibility)
|
|
24
|
+
|
|
25
|
+
### Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Clone the repository
|
|
29
|
+
git clone <repository-url>
|
|
30
|
+
cd solforge
|
|
31
|
+
|
|
32
|
+
# Install dependencies
|
|
33
|
+
bun install
|
|
34
|
+
|
|
35
|
+
# Build the project
|
|
36
|
+
bun run build
|
|
37
|
+
|
|
38
|
+
# Install globally (optional)
|
|
39
|
+
bun run build:binary
|
|
40
|
+
bun run install:binary
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Basic Usage
|
|
44
|
+
|
|
45
|
+
1. **Initialize a new project**:
|
|
46
|
+
```bash
|
|
47
|
+
solforge init
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
2. **Start your localnet**:
|
|
51
|
+
```bash
|
|
52
|
+
solforge start
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
3. **Check status**:
|
|
56
|
+
```bash
|
|
57
|
+
solforge status
|
|
58
|
+
solforge list
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
4. **Stop when done**:
|
|
62
|
+
```bash
|
|
63
|
+
solforge stop --all
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## 📖 Documentation
|
|
67
|
+
|
|
68
|
+
### 📚 Additional Documentation
|
|
69
|
+
- [Configuration Guide](docs/CONFIGURATION.md) - Detailed configuration options and examples
|
|
70
|
+
- [Troubleshooting Guide](#-troubleshooting) - Common issues and solutions
|
|
71
|
+
|
|
72
|
+
### Commands
|
|
73
|
+
|
|
74
|
+
#### `solforge init`
|
|
75
|
+
Initialize a new `sf.config.json` configuration file in the current directory.
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
solforge init
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
This command will prompt you for:
|
|
82
|
+
- Project name
|
|
83
|
+
- Description
|
|
84
|
+
- RPC port (default: 8899)
|
|
85
|
+
- Whether to include USDC token
|
|
86
|
+
|
|
87
|
+
#### `solforge start [options]`
|
|
88
|
+
Start a localnet validator with the current configuration.
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
solforge start # Start with default settings
|
|
92
|
+
solforge start --debug # Start with debug logging
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Options:**
|
|
96
|
+
- `--debug` - Enable debug logging to see detailed command output
|
|
97
|
+
|
|
98
|
+
#### `solforge list`
|
|
99
|
+
List all running validators with detailed information.
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
solforge list
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Shows:
|
|
106
|
+
- Validator ID and name
|
|
107
|
+
- Process ID (PID)
|
|
108
|
+
- RPC and Faucet ports
|
|
109
|
+
- Uptime
|
|
110
|
+
- Status
|
|
111
|
+
- Connection URLs
|
|
112
|
+
|
|
113
|
+
#### `solforge stop [validator-id] [options]`
|
|
114
|
+
Stop running validators.
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
solforge stop # Interactive selection
|
|
118
|
+
solforge stop <validator-id> # Stop specific validator
|
|
119
|
+
solforge stop --all # Stop all validators
|
|
120
|
+
solforge stop --kill # Force kill (SIGKILL)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Options:**
|
|
124
|
+
- `--all` - Stop all running validators
|
|
125
|
+
- `--kill` - Force kill the validator (SIGKILL instead of SIGTERM)
|
|
126
|
+
|
|
127
|
+
#### `solforge kill [validator-id] [options]`
|
|
128
|
+
Force kill running validators with interactive selection.
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
solforge kill # Interactive selection with validator list
|
|
132
|
+
solforge kill <validator-id> # Kill specific validator
|
|
133
|
+
solforge kill --all # Kill all validators
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Interactive Mode:**
|
|
137
|
+
When run without arguments, `solforge kill` will:
|
|
138
|
+
- Display a table of all running validators
|
|
139
|
+
- Allow you to select which validator to kill using arrow keys
|
|
140
|
+
- Provide options to kill individual validators, all validators, or cancel
|
|
141
|
+
- No need to copy/paste validator IDs from `solforge list`
|
|
142
|
+
|
|
143
|
+
#### `solforge status`
|
|
144
|
+
Show overall localnet status and configuration summary.
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
solforge status
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
#### `solforge add-program [options]`
|
|
151
|
+
Add a program to your configuration.
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
solforge add-program # Interactive mode
|
|
155
|
+
solforge add-program --program-id <address> # Non-interactive
|
|
156
|
+
solforge add-program --program-id <address> --name <name>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Options:**
|
|
160
|
+
- `--program-id <address>` - Mainnet program ID to clone and deploy
|
|
161
|
+
- `--name <name>` - Friendly name for the program
|
|
162
|
+
- `--no-interactive` - Run in non-interactive mode
|
|
163
|
+
|
|
164
|
+
#### `solforge transfer [options]`
|
|
165
|
+
Interactively transfer tokens from mint authority to any address.
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
solforge transfer # Use default RPC
|
|
169
|
+
solforge transfer --rpc-url http://localhost:8899 # Custom RPC
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Options:**
|
|
173
|
+
- `--rpc-url <url>` - RPC URL to use (default: "http://127.0.0.1:8899")
|
|
174
|
+
|
|
175
|
+
#### `solforge reset`
|
|
176
|
+
Reset localnet ledger (coming soon).
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
solforge reset
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Configuration File (`sf.config.json`)
|
|
183
|
+
|
|
184
|
+
The configuration file defines your localnet setup. For detailed configuration options, see the [Configuration Guide](docs/CONFIGURATION.md).
|
|
185
|
+
|
|
186
|
+
Here's the complete schema:
|
|
187
|
+
|
|
188
|
+
```json
|
|
189
|
+
{
|
|
190
|
+
"name": "my-localnet",
|
|
191
|
+
"description": "Local Solana development environment",
|
|
192
|
+
"tokens": [
|
|
193
|
+
{
|
|
194
|
+
"symbol": "USDC",
|
|
195
|
+
"mainnetMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
196
|
+
"mintAuthority": "./keypairs/mint-authority.json",
|
|
197
|
+
"mintAmount": 1000000,
|
|
198
|
+
"cloneMetadata": true,
|
|
199
|
+
"recipients": [
|
|
200
|
+
{
|
|
201
|
+
"wallet": "YourWalletPublicKeyHere",
|
|
202
|
+
"amount": 1000000000
|
|
203
|
+
}
|
|
204
|
+
]
|
|
205
|
+
}
|
|
206
|
+
],
|
|
207
|
+
"programs": [
|
|
208
|
+
{
|
|
209
|
+
"name": "Token Metadata",
|
|
210
|
+
"mainnetProgramId": "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s",
|
|
211
|
+
"cluster": "mainnet-beta",
|
|
212
|
+
"upgradeable": false,
|
|
213
|
+
"dependencies": []
|
|
214
|
+
}
|
|
215
|
+
],
|
|
216
|
+
"localnet": {
|
|
217
|
+
"airdropAmount": 100,
|
|
218
|
+
"faucetAccounts": ["YourWalletPublicKeyHere"],
|
|
219
|
+
"port": 8899,
|
|
220
|
+
"faucetPort": 9900,
|
|
221
|
+
"reset": true,
|
|
222
|
+
"logLevel": "info",
|
|
223
|
+
"bindAddress": "127.0.0.1",
|
|
224
|
+
"limitLedgerSize": 100000,
|
|
225
|
+
"rpc": "https://api.mainnet-beta.solana.com"
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
#### Configuration Schema
|
|
231
|
+
|
|
232
|
+
For detailed configuration options and examples, see the [Configuration Guide](docs/CONFIGURATION.md).
|
|
233
|
+
|
|
234
|
+
**Quick Reference:**
|
|
235
|
+
- `name` - Project name
|
|
236
|
+
- `description` - Project description
|
|
237
|
+
- `tokens[]` - Tokens to clone from mainnet
|
|
238
|
+
- `programs[]` - Programs to clone from mainnet
|
|
239
|
+
- `localnet` - Validator settings (ports, logging, etc.)
|
|
240
|
+
|
|
241
|
+
## 🎯 Use Cases
|
|
242
|
+
|
|
243
|
+
### DeFi Development
|
|
244
|
+
Clone popular DeFi tokens and programs to test your application:
|
|
245
|
+
|
|
246
|
+
```json
|
|
247
|
+
{
|
|
248
|
+
"name": "defi-testing",
|
|
249
|
+
"tokens": [
|
|
250
|
+
{
|
|
251
|
+
"symbol": "USDC",
|
|
252
|
+
"mainnetMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
253
|
+
"mintAmount": 10000000
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
"symbol": "USDT",
|
|
257
|
+
"mainnetMint": "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
|
|
258
|
+
"mintAmount": 10000000
|
|
259
|
+
}
|
|
260
|
+
],
|
|
261
|
+
"programs": [
|
|
262
|
+
{
|
|
263
|
+
"name": "Jupiter",
|
|
264
|
+
"mainnetProgramId": "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"
|
|
265
|
+
}
|
|
266
|
+
]
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### NFT Development
|
|
271
|
+
Set up an environment for NFT projects:
|
|
272
|
+
|
|
273
|
+
```json
|
|
274
|
+
{
|
|
275
|
+
"name": "nft-development",
|
|
276
|
+
"programs": [
|
|
277
|
+
{
|
|
278
|
+
"name": "Token Metadata",
|
|
279
|
+
"mainnetProgramId": "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
"name": "Candy Machine",
|
|
283
|
+
"mainnetProgramId": "cndy3Z4yapfJBmL3ShUp5exZKqR3z33thTzeNMm2gRZ"
|
|
284
|
+
}
|
|
285
|
+
]
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Multi-Environment Testing
|
|
290
|
+
Run multiple validators for different test scenarios:
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
# Terminal 1 - DeFi environment
|
|
294
|
+
cd defi-project
|
|
295
|
+
solforge start
|
|
296
|
+
|
|
297
|
+
# Terminal 2 - NFT environment
|
|
298
|
+
cd nft-project
|
|
299
|
+
solforge start
|
|
300
|
+
|
|
301
|
+
# Check both
|
|
302
|
+
solforge list
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## 🔧 Development
|
|
306
|
+
|
|
307
|
+
### Project Structure
|
|
308
|
+
|
|
309
|
+
```
|
|
310
|
+
src/
|
|
311
|
+
├── commands/ # CLI command implementations
|
|
312
|
+
│ ├── init.ts # Initialize configuration
|
|
313
|
+
│ ├── start.ts # Start validator
|
|
314
|
+
│ ├── stop.ts # Stop validator
|
|
315
|
+
│ ├── list.ts # List validators
|
|
316
|
+
│ ├── status.ts # Show status
|
|
317
|
+
│ ├── add-program.ts # Add programs
|
|
318
|
+
│ └── transfer.ts # Transfer tokens
|
|
319
|
+
├── config/ # Configuration management
|
|
320
|
+
│ └── manager.ts # Config file operations
|
|
321
|
+
├── services/ # Core services
|
|
322
|
+
│ ├── validator.ts # Validator management
|
|
323
|
+
│ ├── token-cloner.ts # Token cloning logic
|
|
324
|
+
│ ├── program-cloner.ts # Program cloning logic
|
|
325
|
+
│ ├── port-manager.ts # Port allocation
|
|
326
|
+
│ └── process-registry.ts # Process tracking
|
|
327
|
+
├── types/ # TypeScript definitions
|
|
328
|
+
│ └── config.ts # Configuration schemas
|
|
329
|
+
├── utils/ # Utility functions
|
|
330
|
+
│ └── shell.ts # Shell command helpers
|
|
331
|
+
└── index.ts # CLI entry point
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### Build Commands
|
|
335
|
+
|
|
336
|
+
```bash
|
|
337
|
+
# Development
|
|
338
|
+
bun run dev # Watch mode development
|
|
339
|
+
|
|
340
|
+
# Building
|
|
341
|
+
bun run build # Build for Node.js
|
|
342
|
+
bun run build:binary # Build standalone binary
|
|
343
|
+
|
|
344
|
+
# Testing & Quality
|
|
345
|
+
bun test # Run tests
|
|
346
|
+
bun run lint # Lint code
|
|
347
|
+
bun run format # Format code
|
|
348
|
+
|
|
349
|
+
# Installation
|
|
350
|
+
bun run install:binary # Install binary to ~/.local/bin
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### Contributing
|
|
354
|
+
|
|
355
|
+
1. Fork the repository
|
|
356
|
+
2. Create a feature branch: `git checkout -b feature/amazing-feature`
|
|
357
|
+
3. Make your changes
|
|
358
|
+
4. Run tests and linting: `bun test && bun run lint`
|
|
359
|
+
5. Commit your changes: `git commit -m 'Add amazing feature'`
|
|
360
|
+
6. Push to the branch: `git push origin feature/amazing-feature`
|
|
361
|
+
7. Open a Pull Request
|
|
362
|
+
|
|
363
|
+
## 🐛 Troubleshooting
|
|
364
|
+
|
|
365
|
+
### Common Issues
|
|
366
|
+
|
|
367
|
+
**Port already in use**
|
|
368
|
+
```bash
|
|
369
|
+
# Check what's using the port
|
|
370
|
+
lsof -i :8899
|
|
371
|
+
|
|
372
|
+
# Use a different port in sf.config.json
|
|
373
|
+
{
|
|
374
|
+
"localnet": {
|
|
375
|
+
"port": 8900,
|
|
376
|
+
"faucetPort": 9901
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
**Validator won't start**
|
|
382
|
+
```bash
|
|
383
|
+
# Check Solana CLI is installed
|
|
384
|
+
solana --version
|
|
385
|
+
|
|
386
|
+
# Check configuration
|
|
387
|
+
solforge status
|
|
388
|
+
|
|
389
|
+
# Start with debug logging
|
|
390
|
+
solforge start --debug
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
**Token cloning fails**
|
|
394
|
+
- Ensure RPC URL in config is accessible
|
|
395
|
+
- Check mainnet mint address is correct
|
|
396
|
+
- Verify network connectivity
|
|
397
|
+
|
|
398
|
+
**Program deployment fails**
|
|
399
|
+
- Ensure program ID exists on specified cluster
|
|
400
|
+
- Check if program has dependencies that need to be deployed first
|
|
401
|
+
- Verify sufficient SOL for deployment
|
|
402
|
+
|
|
403
|
+
### Debug Mode
|
|
404
|
+
|
|
405
|
+
Use `--debug` flag to see detailed command output:
|
|
406
|
+
|
|
407
|
+
```bash
|
|
408
|
+
solforge start --debug
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
This shows:
|
|
412
|
+
- Exact solana-test-validator commands
|
|
413
|
+
- Program deployment steps
|
|
414
|
+
- Token cloning operations
|
|
415
|
+
- Error details
|
|
416
|
+
|
|
417
|
+
### Logs and Data
|
|
418
|
+
|
|
419
|
+
SolForge stores data in:
|
|
420
|
+
- `~/.solforge/` - Process registry and metadata
|
|
421
|
+
- `.solforge/` - Local working directory for current project
|
|
422
|
+
|
|
423
|
+
## 📄 License
|
|
424
|
+
|
|
425
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
426
|
+
|
|
427
|
+
## 🤝 Support
|
|
428
|
+
|
|
429
|
+
- 🐛 **Issues**: [GitHub Issues](https://github.com/your-repo/solforge/issues)
|
|
430
|
+
- 💬 **Discussions**: [GitHub Discussions](https://github.com/your-repo/solforge/discussions)
|
|
431
|
+
- 📧 **Email**: your-email@example.com
|
|
432
|
+
|
|
433
|
+
## 🙏 Acknowledgments
|
|
434
|
+
|
|
435
|
+
- [Solana Labs](https://solana.com) for the amazing blockchain platform
|
|
436
|
+
- [Bun](https://bun.sh) for the fast JavaScript runtime
|
|
437
|
+
- The Solana developer community for inspiration and feedback
|
|
438
|
+
|
|
439
|
+
---
|
|
440
|
+
|
|
441
|
+
**Happy building on Solana! 🚀**
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "solforge",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Solana localnet orchestration tool for cloning mainnet programs and tokens",
|
|
5
|
+
"module": "index.ts",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"private": false,
|
|
8
|
+
"bin": {
|
|
9
|
+
"solforge": "./bin/solforge"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"src/",
|
|
13
|
+
"scripts/",
|
|
14
|
+
"tsconfig.json",
|
|
15
|
+
"bin/",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"dev": "bun run --watch src/index.ts",
|
|
21
|
+
"build": "bun build src/index.ts --outdir ./dist --target bun",
|
|
22
|
+
"build:binary": "bun build src/index.ts --compile --outfile ./dist/solforge",
|
|
23
|
+
"build:npm": "mkdir -p bin && bun build src/index.ts --compile --outfile ./bin/solforge",
|
|
24
|
+
"install:binary": "mkdir -p ~/.local/bin && cp ./dist/solforge ~/.local/bin/solforge && chmod +x ~/.local/bin/solforge",
|
|
25
|
+
"build:install": "bun run build:binary && bun run install:binary",
|
|
26
|
+
"postinstall": "node scripts/postinstall.cjs",
|
|
27
|
+
"prepublishOnly": "rm -rf bin/",
|
|
28
|
+
"start": "bun run dist/index.js",
|
|
29
|
+
"test": "bun test",
|
|
30
|
+
"lint": "bunx @biomejs/biome check src/",
|
|
31
|
+
"format": "bunx @biomejs/biome format src/ --write"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@inquirer/prompts": "^7.5.3",
|
|
35
|
+
"@solana/spl-token": "^0.4.1",
|
|
36
|
+
"@solana/web3.js": "^1.87.6",
|
|
37
|
+
"chalk": "^5.3.0",
|
|
38
|
+
"commander": "^11.1.0",
|
|
39
|
+
"cors": "^2.8.5",
|
|
40
|
+
"express": "^4.18.2",
|
|
41
|
+
"inquirer": "^9.2.12",
|
|
42
|
+
"ora": "^8.0.1",
|
|
43
|
+
"ws": "^8.16.0",
|
|
44
|
+
"zod": "^3.22.4"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/bun": "latest",
|
|
48
|
+
"@types/node": "^20.10.6",
|
|
49
|
+
"@types/express": "^4.17.21",
|
|
50
|
+
"@types/cors": "^2.8.17",
|
|
51
|
+
"@types/ws": "^8.5.10",
|
|
52
|
+
"@types/inquirer": "^9.0.7",
|
|
53
|
+
"@biomejs/biome": "^1.4.1"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"typescript": "^5"
|
|
57
|
+
},
|
|
58
|
+
"keywords": [
|
|
59
|
+
"solana",
|
|
60
|
+
"localnet",
|
|
61
|
+
"blockchain",
|
|
62
|
+
"development",
|
|
63
|
+
"tooling"
|
|
64
|
+
],
|
|
65
|
+
"repository": {
|
|
66
|
+
"type": "git",
|
|
67
|
+
"url": "https://github.com/nitishxyz/solforge.git"
|
|
68
|
+
},
|
|
69
|
+
"author": "nitishxyz",
|
|
70
|
+
"license": "MIT"
|
|
71
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const https = require("https");
|
|
6
|
+
const { execSync } = require("child_process");
|
|
7
|
+
|
|
8
|
+
const PACKAGE_NAME = "solforge";
|
|
9
|
+
const VERSION = require("../package.json").version;
|
|
10
|
+
|
|
11
|
+
// Platform mapping
|
|
12
|
+
const PLATFORM_MAP = {
|
|
13
|
+
"darwin-x64": "darwin-x64",
|
|
14
|
+
"darwin-arm64": "darwin-arm64",
|
|
15
|
+
"linux-x64": "linux-x64",
|
|
16
|
+
"linux-arm64": "linux-arm64",
|
|
17
|
+
"win32-x64": "win32-x64.exe",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function getPlatform() {
|
|
21
|
+
const platform = process.platform;
|
|
22
|
+
const arch = process.arch;
|
|
23
|
+
const key = `${platform}-${arch}`;
|
|
24
|
+
|
|
25
|
+
if (!PLATFORM_MAP[key]) {
|
|
26
|
+
console.error(`Unsupported platform: ${platform}-${arch}`);
|
|
27
|
+
console.error("Supported platforms:", Object.keys(PLATFORM_MAP).join(", "));
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return PLATFORM_MAP[key];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function downloadBinary(url, destination) {
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
const file = fs.createWriteStream(destination);
|
|
37
|
+
|
|
38
|
+
https
|
|
39
|
+
.get(url, (response) => {
|
|
40
|
+
if (response.statusCode === 200) {
|
|
41
|
+
response.pipe(file);
|
|
42
|
+
file.on("finish", () => {
|
|
43
|
+
file.close();
|
|
44
|
+
fs.chmodSync(destination, 0o755); // Make executable
|
|
45
|
+
resolve();
|
|
46
|
+
});
|
|
47
|
+
} else if (response.statusCode === 302 || response.statusCode === 301) {
|
|
48
|
+
// Handle redirects
|
|
49
|
+
downloadBinary(response.headers.location, destination)
|
|
50
|
+
.then(resolve)
|
|
51
|
+
.catch(reject);
|
|
52
|
+
} else {
|
|
53
|
+
reject(new Error(`Failed to download: ${response.statusCode}`));
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
.on("error", reject);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function install() {
|
|
61
|
+
try {
|
|
62
|
+
const platform = getPlatform();
|
|
63
|
+
const binDir = path.join(__dirname, "..", "bin");
|
|
64
|
+
const binaryName =
|
|
65
|
+
process.platform === "win32" ? "solforge.exe" : "solforge";
|
|
66
|
+
const binaryPath = path.join(binDir, binaryName);
|
|
67
|
+
|
|
68
|
+
// Create bin directory
|
|
69
|
+
if (!fs.existsSync(binDir)) {
|
|
70
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Try to build locally first (if Bun is available)
|
|
74
|
+
try {
|
|
75
|
+
console.log("Attempting to build locally with Bun...");
|
|
76
|
+
execSync(`bun build src/index.ts --compile --outfile ${binaryPath}`, {
|
|
77
|
+
cwd: path.join(__dirname, ".."),
|
|
78
|
+
stdio: "pipe",
|
|
79
|
+
});
|
|
80
|
+
console.log("✅ Built successfully with local Bun");
|
|
81
|
+
return;
|
|
82
|
+
} catch (e) {
|
|
83
|
+
console.log("Local Bun build failed, downloading pre-built binary...");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Download pre-built binary from GitHub releases
|
|
87
|
+
const downloadUrl = `https://github.com/nitishxyz/solforge/releases/download/v${VERSION}/solforge-${platform}`;
|
|
88
|
+
|
|
89
|
+
console.log(`Downloading ${PACKAGE_NAME} binary for ${platform}...`);
|
|
90
|
+
console.log(`URL: ${downloadUrl}`);
|
|
91
|
+
|
|
92
|
+
await downloadBinary(downloadUrl, binaryPath);
|
|
93
|
+
console.log("✅ Binary downloaded and installed successfully");
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.error("❌ Installation failed:", error.message);
|
|
96
|
+
console.error("\nFallback options:");
|
|
97
|
+
console.error("1. Install Bun and run: bun install -g solforge");
|
|
98
|
+
console.error("2. Clone the repo and build manually");
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
install();
|