UNPKG

@contentstack/cli-cm-seed

Version:

create a Stack from existing content types, entries, assets, etc.

122 lines (121 loc) 5.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const cli_command_1 = require("@contentstack/cli-command"); const cli_utilities_1 = require("@contentstack/cli-utilities"); const seed_1 = require("../../../seed"); class SeedCommand extends cli_command_1.Command { async run() { try { const { flags: seedFlags } = await this.parse(SeedCommand); const managementTokenAlias = seedFlags.alias; if (!(0, cli_utilities_1.isAuthenticated)() && !managementTokenAlias) { this.error('You need to login or provide an alias for the management token. See: auth:login --help', { exit: 2, suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/'], }); } const options = { parent: this, cdaHost: this.cdaHost, cmaHost: this.cmaHost, gitHubPath: seedFlags.repo, orgUid: seedFlags.org, stackUid: seedFlags['stack-api-key'] || seedFlags.stack, stackName: seedFlags['stack-name'], fetchLimit: seedFlags['fetch-limit'], skipStackConfirmation: seedFlags['yes'], isAuthenticated: (0, cli_utilities_1.isAuthenticated)(), alias: managementTokenAlias, master_locale: seedFlags['locale'], }; const listOfTokens = cli_utilities_1.configHandler.get('tokens'); if (managementTokenAlias && listOfTokens[managementTokenAlias]) { options.managementToken = listOfTokens[managementTokenAlias].token; options.stackUid = listOfTokens[managementTokenAlias].apiKey; } const seeder = new seed_1.default(options); const result = await seeder.run(); return result; } catch (error) { let errorObj = error; if (errorObj.message !== undefined) { cli_utilities_1.cliux.loader(); cli_utilities_1.cliux.print(`Error: ${errorObj.message}`, { color: 'red' }); this.exit(1); } this.error(errorObj, { exit: 1, suggestions: errorObj.suggestions }); } } } exports.default = SeedCommand; SeedCommand.description = 'Create a stack from existing content types, entries, assets, etc'; SeedCommand.examples = [ '$ csdx cm:stacks:seed', '$ csdx cm:stacks:seed --repo "account"', '$ csdx cm:stacks:seed --repo "account/repository"', '$ csdx cm:stacks:seed --repo "account/repository" --stack-api-key "stack-api-key" //seed content into specific stack', '$ csdx cm:stacks:seed --repo "account/repository" --org "your-org-uid" --stack-name "stack-name" //create a new stack in given org uid', ]; SeedCommand.usage = 'cm:stacks:seed [--repo <value>] [--org <value>] [-k <value>] [-n <value>] [-y <value>] [-s <value>] [--locale <value>]'; SeedCommand.flags = { repo: cli_utilities_1.flags.string({ char: 'r', description: 'GitHub organization name or GitHub user name/repository name.', multiple: false, required: false, parse: (0, cli_utilities_1.printFlagDeprecation)(['-r'], ['--repo']), }), org: cli_utilities_1.flags.string({ char: 'o', description: 'Provide Organization UID to create a new stack', multiple: false, required: false, exclusive: ['stack'], parse: (0, cli_utilities_1.printFlagDeprecation)(['-o'], ['--org']), }), 'stack-api-key': cli_utilities_1.flags.string({ char: 'k', description: 'Provide stack API key to seed content to', multiple: false, required: false, exclusive: ['org'], }), 'stack-name': cli_utilities_1.flags.string({ char: 'n', description: 'Name of a new stack that needs to be created.', multiple: false, required: false, exclusive: ['stack'], }), 'fetch-limit': cli_utilities_1.flags.string({ char: 'l', description: 'Limit for number of organizations or stacks to be fetched.', multiple: false, required: false, hidden: true, }), yes: cli_utilities_1.flags.string({ char: 'y', required: false, description: '[Optional] Skip the stack confirmation.', }), //To be deprecated stack: cli_utilities_1.flags.string({ char: 's', description: 'Provide the stack UID to seed content.', multiple: false, required: false, exclusive: ['org', 'name'], parse: (0, cli_utilities_1.printFlagDeprecation)(['s', 'stack'], ['-k', 'stack-api-key']), }), alias: cli_utilities_1.flags.string({ char: 'a', description: 'Alias of the management token', }), locale: cli_utilities_1.flags.string({ description: 'Master Locale of the stack', hidden: true, }), }; SeedCommand.aliases = ['cm:seed'];