|
| 1 | +import { Command, Flags } from '@oclif/core'; |
| 2 | +import {spawn} from 'child_process'; |
| 3 | +import * as path from "path"; |
| 4 | + |
| 5 | + |
| 6 | +export default class Recreate extends Command { |
| 7 | + static override description = "Prunes and ups the network. Default config file path is '\$(pwd)/fablo-config.json' or '\$(pwd)/fablo-config.yaml'" |
| 8 | + static flags = { |
| 9 | + config: Flags.string({ |
| 10 | + char: 'c', |
| 11 | + description: 'Path to fablo config file (JSON or YAML)', |
| 12 | + required: false, |
| 13 | + default: 'fablo-config.json', |
| 14 | + }) |
| 15 | + } |
| 16 | + |
| 17 | + async run(): Promise<void> { |
| 18 | + const { flags } = await this.parse(Recreate) |
| 19 | + |
| 20 | + const shPath = path.resolve(__dirname, '../../../../fablo.sh') |
| 21 | + const args = ['recreate'] |
| 22 | + if (flags.config) args.push(flags.config) |
| 23 | + |
| 24 | + this.log(`Starting network with: ${shPath} ${args.join(' ')}\n`) |
| 25 | + const child = spawn(shPath, args, { |
| 26 | + stdio: ['inherit', 'pipe', 'pipe'], |
| 27 | + shell: process.platform === 'win32' ? 'bash.exe' : true, |
| 28 | + }) |
| 29 | + |
| 30 | + child.stdout?.on('data', (data) => { |
| 31 | + process.stdout.write(data.toString()) |
| 32 | + }) |
| 33 | + child.stderr?.on('data', (data) => { |
| 34 | + process.stderr.write(data.toString()) |
| 35 | + }) |
| 36 | + |
| 37 | + child.on('close', (code) => { |
| 38 | + if (code === 0) { |
| 39 | + this.log('\nNetwork recreate successfully!') |
| 40 | + } else { |
| 41 | + this.error(`\nFablo recreate failed with exit code: ${code}`) |
| 42 | + } |
| 43 | + }) |
| 44 | + |
| 45 | + process.on('SIGINT', () => { |
| 46 | + child.kill('SIGINT') |
| 47 | + process.exit() |
| 48 | + }) |
| 49 | + } |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +} |
0 commit comments