UNPKG

@constructor-io/constructorio-connect-cli

Version:

CLI tool to enable users to interface with the Constructor Connect Ecosystem

84 lines (83 loc) 4.08 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const errors_1 = require("@oclif/core/errors"); const kleur_1 = __importDefault(require("kleur")); const config_1 = require("../customer/config"); const get_connect_token_1 = require("../customer/get-connect-token"); const template_source_code_1 = require("../customer/template-source-code"); const ux_action_1 = require("../helpers/ux-action"); const deploy_request_1 = require("../http/deploy-request"); const render_tip_1 = require("../rendering/render-tip"); const refresh_connections_1 = require("./refresh-connections"); const child_process_1 = require("child_process"); class Deploy extends refresh_connections_1.RefreshConnectionsCommand { static args = { env: core_1.Args.string({ options: ["development", "qa", "production", "demo"], description: "The target Constructor environment to deploy to.", required: true, }), }; static flags = { force: core_1.Flags.boolean({ char: "f", description: "Skip tests before deploying", }), }; static description = "Deploys all templates defined on the `connectrc.js` file to the specified environment, after running tests ('--force' to skip). \n\nThe script will use the `CONNECT_AUTH_TOKEN` environment variable to authenticate with Constructor."; static examples = [ "$ <%= config.bin %> deploy development", "$ <%= config.bin %> deploy qa", "$ <%= config.bin %> deploy production", "$ <%= config.bin %> deploy production --force", ]; async runCommand() { const { flags, args } = await this.parse(Deploy); if (!flags.force) { try { (0, child_process_1.execSync)("npm run test", { stdio: "inherit", cwd: process.cwd(), }); this.log(`\n`); } catch (_) { this.log(`\n${kleur_1.default.red("❌ Tests failed!")}\n`); throw new errors_1.CLIError(`Tests failed. Fix the tests or use --force to deploy anyway.`); } } const config = await (0, ux_action_1.uxAction)("📡 Reading your config", async () => { return await (0, config_1.getRepositoryConfigFile)(); })(); const environment = await (0, ux_action_1.uxAction)("✨ Validating your environment", async () => { const env = config.environments.find(({ environment }) => environment === args.env); if (!env) { throw new errors_1.CLIError(`💥 Could not find an environment named ${kleur_1.default.bold(args.env)} in your ${kleur_1.default.bold("connectrc.js")} file.`); } return env; })(); // Load the connect token to ensure we can authenticate with Constructor. // We do this here because the terminal output gets weird when there is a prompt during a ux action. await (0, get_connect_token_1.getConnectToken)(); const templates = await (0, template_source_code_1.getTemplatesSourceCode)(environment.templates); const helpers = await (0, template_source_code_1.getHelpersSourceCode)(config.helpers); await (0, ux_action_1.uxAction)("🚀 Deploying your templates", async () => { await (0, deploy_request_1.performDeploy)({ environment: args.env, templates, helpers, config, }); })(); this.log(`\n${kleur_1.default.bold("🎉 Deploy completed!")}\n`); (0, render_tip_1.renderTip)(["Future catalog ingestions will use the new templates."]); (0, render_tip_1.renderTip)([ "Check the Constructor dashboard to see your latest ingestion results.", ]); } } exports.default = Deploy;