@ethersphere/swarm-cli
Version:
CLI tool for Bee
80 lines (79 loc) • 3.32 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetBee = void 0;
const cafe_utility_1 = require("cafe-utility");
const child_process_1 = require("child_process");
const fs_1 = require("fs");
const node_fetch_1 = __importDefault(require("node-fetch"));
const root_command_1 = require("../root-command");
const archTable = {
arm64: 'arm64',
x64: 'amd64',
};
const platformTable = {
win32: 'windows',
darwin: 'darwin',
linux: 'linux',
};
class GetBee extends root_command_1.RootCommand {
constructor() {
super(...arguments);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'get-bee'
});
Object.defineProperty(this, "description", {
enumerable: true,
configurable: true,
writable: true,
value: 'Downloads the Bee binary for the current platform'
});
}
async run() {
super.init();
const archString = Reflect.get(archTable, process.arch);
const platformString = Reflect.get(platformTable, process.platform);
const suffixString = process.platform === 'win32' ? '.exe' : '';
if (!archString || !platformString) {
throw Error(`Unsupported system: arch=${process.arch} platform=${process.platform}`);
}
const url = `https://github.com/ethersphere/bee/releases/download/v2.4.0/bee-${platformString}-${archString}${suffixString}`;
this.console.info(`Downloading Bee from ${url}`);
await (0, node_fetch_1.default)(url)
.then(x => x.arrayBuffer())
.then(x => (0, fs_1.writeFileSync)(`bee${suffixString}`, Buffer.from(x)));
this.console.log('Bee downloaded successfully');
if (process.platform !== 'win32') {
this.console.info(`Running chmod +x bee to make it executable`);
(0, child_process_1.execSync)('chmod +x bee');
}
if ((0, fs_1.existsSync)('bee.yaml')) {
this.console.log('bee.yaml already exists, done');
return;
}
this.console.info('');
this.console.info('Ultra-light: Limited download capabilities, no funding required.');
this.console.info('Light: Full functionality; requires xDAI to launch and xBZZ for uploading and retrieving data.');
const type = await this.console.promptList(['ultra-light', 'light'], 'Select the type of configuration to create');
(0, fs_1.writeFileSync)('bee.yaml', `api-addr: 127.0.0.1:1633
blockchain-rpc-endpoint: "https://xdai.fairdatasociety.org"
cors-allowed-origins: ["*"]
data-dir: "${process.cwd()}/data-dir"
full-node: false
mainnet: true
resolver-options: ["https://cloudflare-eth.com"]
storage-incentives-enable: false
swap-enable: ${type === 'light' ? 'true' : 'false'}
password: "${cafe_utility_1.Strings.randomAlphanumeric(20)}"`);
this.console.info('');
this.console.log('All set! Start Bee node by running:');
this.console.info('');
this.console.log('./bee start --config=bee.yaml');
}
}
exports.GetBee = GetBee;