|
1 | 1 | /* eslint-disable no-console */ |
| 2 | +import {Command} from 'commander' |
2 | 3 | import {watch} from 'fs' |
3 | 4 | import {extname} from 'path' |
4 | 5 | import {compileContract} from './compile' |
5 | | -import {deployContract} from '../contract/deploy' |
6 | | -import {getChainStatus, startLocalChain, stopLocalChain} from '../chain/local' |
| 6 | +import {deployContract} from './contract/deploy' |
| 7 | +import {getChainStatus, startLocalChain, stopLocalChain} from './chain/local' |
7 | 8 |
|
8 | 9 | interface DevOptions { |
9 | 10 | account?: string |
@@ -154,3 +155,30 @@ process.on('SIGINT', async () => { |
154 | 155 | process.on('SIGTERM', async () => { |
155 | 156 | await stopDevMode() |
156 | 157 | }) |
| 158 | + |
| 159 | +/** |
| 160 | + * Create the dev command |
| 161 | + */ |
| 162 | +export function createDevCommand(): Command { |
| 163 | + const dev = new Command('dev') |
| 164 | + dev.description( |
| 165 | + 'Start local chain and watch for changes (auto-compile and auto-deploy on file changes)' |
| 166 | + ) |
| 167 | + .option('-a, --account <name>', 'Contract account name (default: derived from filename)') |
| 168 | + .option('-p, --port <port>', 'Port for local blockchain', '8888') |
| 169 | + .option('-c, --clean', 'Start with a clean blockchain state') |
| 170 | + .action(async (options) => { |
| 171 | + try { |
| 172 | + await startDevMode({ |
| 173 | + account: options.account, |
| 174 | + port: parseInt(options.port), |
| 175 | + clean: options.clean, |
| 176 | + }) |
| 177 | + } catch (error: any) { |
| 178 | + console.error(`Error: ${error.message}`) |
| 179 | + process.exit(1) |
| 180 | + } |
| 181 | + }) |
| 182 | + |
| 183 | + return dev |
| 184 | +} |
0 commit comments