UNPKG

@facets-cloud/facetsctlv3

Version:
84 lines (83 loc) 3.68 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const config_service_1 = require("../../services/config-service"); const FacetsApi = __importStar(require("../../services/facets-api")); const errors_1 = require("@oclif/core/lib/errors"); class Sync extends core_1.Command { static description = 'Sync out-of-sync apps to match their desired state with the deployed state'; static flags = { project: core_1.Flags.string({ char: 'p', description: 'Project name', required: true, }), environment: core_1.Flags.string({ char: 'e', description: 'Environment name', required: true, }), }; static args = { apps: core_1.Args.string({ description: 'List of app names to sync (comma-separated | example: ... sync app1,app2,app3 -p ...)', required: true, }) }; async run() { const { flags, args } = await this.parse(Sync); const { project, environment } = flags; const apps = args.apps ? args?.apps?.split(',')?.map(app => app.trim()) : []; const configFilePath = config_service_1.ConfigService.findConfigFile(); if (!configFilePath) { throw new errors_1.CLIError('Configuration file not found. Please ensure you are logged in.', { exit: 2 }); } const config = config_service_1.ConfigService.readConfig(configFilePath); this.log(`Logged in to: ${config.ControlPlaneURL} with user: ${config.Username}`); core_1.ux.action.start('Starting sync process'); try { const response = await FacetsApi.syncApps(config.ControlPlaneURL, config.Username, config.AccessToken, project, environment, apps); const outOfSyncResources = []; response?.resourceStatuses?.forEach((resource) => { if (resource?.syncStatus === 'OUT_OF_SYNC') { outOfSyncResources.push(resource.resourceName); } }); if (outOfSyncResources?.length) { this.log(`Started sync process for the following resource(s): ${outOfSyncResources.join(', ')}`); } } catch (error) { core_1.ux.action.stop('Failed'); if (error instanceof Error) { throw new errors_1.CLIError(`Error occurred while syncing: ${error.message}`, { exit: 2 }); } } core_1.ux.action.stop(); this.log('You can use wait command to check resource status.'); } } exports.default = Sync;