UNPKG

@goldstack/template-dynamodb-cli

Version:

Utilities for building modules for DynamoDB access.

69 lines 3.21 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.run = void 0; const utils_package_1 = require("@goldstack/utils-package"); const utils_cli_1 = require("@goldstack/utils-cli"); const utils_terraform_1 = require("@goldstack/utils-terraform"); const utils_terraform_aws_1 = require("@goldstack/utils-terraform-aws"); const utils_package_config_1 = require("@goldstack/utils-package-config"); const yargs_1 = __importDefault(require("yargs")); const assert_1 = __importDefault(require("assert")); const dynamoDBTableCli_1 = require("./dynamoDBTableCli"); const run = async ({ args, migrations, }) => { await (0, utils_cli_1.wrapCli)(async () => { const deploymentPositional = (yargs) => { return yargs.positional('deployment', { type: 'string', describe: 'Name of the deployment of the table', demandOption: true, }); }; const argv = await (0, utils_package_1.buildCli)({ yargs: yargs_1.default, deployCommands: (0, utils_package_1.buildDeployCommands)(), infraCommands: (0, utils_terraform_1.infraCommands)(), }) .usage('$0 <table>') .command('table <init|delete|migrate-to> <deployment>', 'Utility commands for DynamoDB table', (yargs) => { yargs .command('init', 'Initialise DynamoDB table and run all applicable migrations', deploymentPositional) .command('delete', 'Deletes DynamoDB table and all its data', deploymentPositional) .command('migrate-to', 'Migrate DynamoDB table', (yargs) => deploymentPositional(yargs).positional('migration-name', { type: 'string', describe: 'The name of the migration that the table should be migrated to.', demandOption: true, })); }) .help() .parse(); const packageConfig = new utils_package_config_1.PackageConfig({ packagePath: './', }); const config = packageConfig.getConfig(); (0, assert_1.default)(config, 'DynamoDB package config could not be loaded.'); const command = argv._[0]; const [, , , ...opArgs] = args; if (command === 'infra') { await (0, dynamoDBTableCli_1.dynamoDBCli)(migrations, ['init', opArgs[1]]); await (0, utils_terraform_aws_1.terraformAwsCli)(opArgs); if (opArgs[0] === 'destroy') { await (0, dynamoDBTableCli_1.dynamoDBCli)(migrations, ['delete', opArgs[1]]); } return; } if (command === 'deploy') { await (0, dynamoDBTableCli_1.dynamoDBCli)(migrations, ['init', opArgs[0]]); return; } if (command === 'table') { await (0, dynamoDBTableCli_1.dynamoDBCli)(migrations, opArgs); return; } throw new Error('Unknown command: ' + command); }); }; exports.run = run; //# sourceMappingURL=templateDynamoDBCli.js.map