UNPKG

@forzalabs/remora

Version:

A powerful CLI tool for seamless data translation.

119 lines (118 loc) 5.75 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const commander_1 = require("commander"); const dotenv_1 = __importDefault(require("dotenv")); const compile_1 = require("./actions/compile"); const debug_1 = require("./actions/debug"); const deploy_1 = require("./actions/deploy"); const init_1 = require("./actions/init"); const run_1 = require("./actions/run"); const discover_1 = require("./actions/discover"); const create_producer_1 = require("./actions/create_producer"); const create_consumer_1 = require("./actions/create_consumer"); const Constants_1 = __importDefault(require("./Constants")); const LicenceManager_1 = __importDefault(require("./licencing/LicenceManager")); const Runtime_1 = __importDefault(require("./helper/Runtime")); const automap_1 = require("./actions/automap"); const sample_1 = require("./actions/sample"); const mock_1 = require("./actions/mock"); const ProcessENVManager_1 = __importDefault(require("./engines/ProcessENVManager")); dotenv_1.default.configDotenv(); const program = new commander_1.Command(); // Validate the remora licence const remoraLicenceKey = ProcessENVManager_1.default.getEnvVariable('REMORA_LICENCE_KEY'); const check = LicenceManager_1.default.validate(remoraLicenceKey); if (!check.valid) { console.error(`Invalid Remora licence key, the product is not active: remember to set "REMORA_LICENCE_KEY" environment variable.`); process.exit(1); } // Runtime check on heap size to warn user of insufficent runtime resources const { heapSizeMB } = Runtime_1.default.getHeap(); if (heapSizeMB < Constants_1.default.defaults.MIN_RUNTIME_HEAP_MB) console.warn(`Remora is running with ${heapSizeMB}MB of runtime heap, which is below the bare minimum of ${Constants_1.default.defaults.MIN_RUNTIME_HEAP_MB}MB (Recommended: ${Constants_1.default.defaults.RECOMMENDED_RUNTIME_HEAP_MB}MB).`); else if (heapSizeMB < Constants_1.default.defaults.RECOMMENDED_RUNTIME_HEAP_MB) console.warn(`Remora is running with ${heapSizeMB} MB of runtime heap, which is below the recommended of ${Constants_1.default.defaults.RECOMMENDED_RUNTIME_HEAP_MB} MB.`); // Initialize all commands program .version(Constants_1.default.cliVersion + '', '-v, --version', 'Display the version of the CLI') .description('CLI tool for setting up and managing Data-Remora'); program .command('version') .description('Display the version of the CLI') .action(() => { const packageJson = require('../package.json'); console.log(`Data-Remora CLI version: ${packageJson.version}`); }); program .command('init') .description('Initialize the application and set up configuration') .action(init_1.init); program .command('compile') .description('Compile the config and check for errors') .action(compile_1.compile); program .command('debug') .description('Check the connection with sources and producers') .action(debug_1.debug); program .command('deploy') .description('Deploy the application to the specified environment') .option('-e, --env <environment>', 'Target environment (staging, production)', 'staging') .option('--skip-tests', 'Skip running tests before deployment') .option('--build-only', 'Build without deploying') .action(deploy_1.deploy); program .command('run [name]') .description('Execute consumers. Optionally specify a single consumer name or use --project to run all consumers in a project.') .option('-p, --project <name>', 'Run all consumers belonging to the specified project') .action((name, options) => (0, run_1.run)(name, options)); program .command('discover') .description('Discover the data shape of a producer and automatically create the resource for it.') .argument('<producer>', 'The producer to discover') .action(discover_1.discover); program .command('create-producer <name>') .description('Create a new producer configuration with default settings') .action(create_producer_1.create_producer); program .command('automap') .description('Automatically map a producer to consumers using specified schemas.') .argument('<producer>', 'The producer to analyze') .argument('<schemas...>', 'One or more schema names to map against') .action(automap_1.automap); program .command('create-consumer <name>') .description('Create a new consumer configuration with default settings') .option('-p, --producer <name>', 'Producer to create a one-to-one mapping from') .action((name, options) => (0, create_consumer_1.create_consumer)(name, options.producer)); program .command('sample <name>') .description('Sample data from a producer or consumer and display it in a formatted table') .option('-s, --size <number>', 'Number of sample rows to display (default: 10)', '10') .action((name, options) => { const sampleSize = parseInt(options.size, 10); if (isNaN(sampleSize) || sampleSize <= 0) { console.error('Sample size must be a positive number'); process.exit(1); } (0, sample_1.sample)(name, sampleSize); }); program .command('mock <producer>') .description('Generate mock data for a producer based on its dimensions') .argument('<records>', 'Number of mock records to generate') .action((producer, records) => { const recordCount = parseInt(records, 10); if (isNaN(recordCount) || recordCount <= 0) { console.error('Record count must be a positive number'); process.exit(1); } (0, mock_1.mock)(producer, recordCount); }); program.parse(process.argv);