mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-02-15 04:44:08 +00:00
* Refactor protocol change handler * Refactor protocol stream creation * Refactor Peer constructor * Refactor peer CLIs to a separate cli folder * Move peer node setup to a separate file * Add a getter method for primary relay node mutiaddr * Close new relay peer connection if limit already reached
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
//
|
|
// Copyright 2022 Vulcanize, Inc.
|
|
//
|
|
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import { hideBin } from 'yargs/helpers';
|
|
import yargs from 'yargs';
|
|
|
|
import { createPeerId } from '../peer.js';
|
|
|
|
interface Arguments {
|
|
file: string;
|
|
}
|
|
|
|
async function main (): Promise<void> {
|
|
const obj = await createPeerId();
|
|
|
|
const argv: Arguments = _getArgv();
|
|
if (argv.file) {
|
|
const exportFilePath = path.resolve(argv.file);
|
|
const exportFileDir = path.dirname(exportFilePath);
|
|
|
|
if (!fs.existsSync(exportFileDir)) {
|
|
fs.mkdirSync(exportFileDir, { recursive: true });
|
|
}
|
|
|
|
fs.writeFileSync(exportFilePath, JSON.stringify(obj, null, 2));
|
|
console.log(`Peer id ${obj.id.toString()} exported to file ${exportFilePath}`);
|
|
} else {
|
|
console.log(obj);
|
|
}
|
|
}
|
|
|
|
function _getArgv (): any {
|
|
return yargs(hideBin(process.argv)).parserConfiguration({
|
|
'parse-numbers': false
|
|
}).options({
|
|
file: {
|
|
type: 'string',
|
|
alias: 'f',
|
|
describe: 'Peer Id export file path (json)'
|
|
}
|
|
}).argv;
|
|
}
|
|
|
|
main().catch(err => {
|
|
console.log(err);
|
|
});
|