UNPKG

xrmcli

Version:

A suite of cli tools to support Xrm/D365/Dataverse development

113 lines 6.42 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; }; 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 node_fetch_1 = __importDefault(require("node-fetch")); const fs_1 = require("fs"); const progress_1 = __importDefault(require("progress")); const validation_1 = __importDefault(require("../utils/validation")); const connect_1 = __importStar(require("../utils/connect")); const header_1 = require("../utils/header"); const exportsolution = async (authToken, url, options, output) => { const bar = new progress_1.default('Exporting :bar :elapsed seconds', { total: 50 }); let barReverse = false; const timer = setInterval(() => { bar.tick(barReverse ? -1 : 1); if (bar.curr === bar.total - 1 || bar.curr <= 1) { barReverse = !(bar.curr <= 1); } }, 500); try { const result = await (0, node_fetch_1.default)(`${url}/api/data/v9.2/ExportSolution`, { headers: (0, header_1.initHeader)(authToken.accessToken), method: 'POST', body: JSON.stringify(options), }); if (result) { const json = await result.json(); if (json.error) { console.error(`\n${json.error.message}`); } else { (0, fs_1.mkdirSync)(output.replace(/(?:.(?!\/|\\))+.zip/, ''), { recursive: true, }); (0, fs_1.writeFileSync)(output, json.ExportSolutionFile, { encoding: 'base64' }); console.log('\nSolution exported'); } } } catch (e) { console.error(`\n${e.message || 'Error exporting solution.'}`); } finally { clearInterval(timer); } }; commander_1.program.name('xrmcli solution export').addHelpText('after', ` https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/exportsolution`); (0, connect_1.AddAuthCommandOptions)(); commander_1.program .requiredOption('-s, --solution <solution>', 'The unique name of the solution.') .requiredOption('-o, --output <output>', 'Path to output zip file') .option('-m, --managed', 'Indicates whether the solution should be exported as a managed solution.', false) .option('-v, --targetversion <targetversion>', 'The version that the exported solution will support.') .option('-an, --exportautonumberingsettings', 'Indicates whether auto numbering settings should be included in the solution being exported.', false) .option('-cal, --exportcalendarsettings', 'Indicates whether calendar settings should be included in the solution being exported', false) .option('-cus, --exportcustomizationsettings', 'Indicates whether customization settings should be included in the solution being exported.', false) .option('-eml, --exportemailtrackingsettings', 'Indicates whether email tracking settings should be included in the solution being exported.', false) .option('-gen, --exportgeneralsettings', 'Indicates whether general settings should be included in the solution being exported.', false) .option('-mkt, --exportmarketingsettings', 'Indicates whether marketing settings should be included in the solution being exported.', false) .option('-olk, --exportoutlooksynchronizationsettings', 'Indicates whether outlook synchronization settings should be included in the solution being exported.', false) .option('-rel, --exportrelationshiproles', 'Indicates whether relationship role settings should be included in the solution being exported.', false) .option('-isv, --exportisvconfig', 'Indicates whether ISV.Config settings should be included in the solution being exported.', false) .option('-sal, --exportsales', 'Indicates whether sales settings should be included in the solution being exported.', false) .option('-ext, --exportexternalapplications', '', false) .action(async (options) => { if ((0, validation_1.default)(options)) { const auth = await (0, connect_1.default)(options); await exportsolution(auth, commander_1.program.opts().url, { SolutionName: options.solution, Managed: !!options.managed, ExportAutoNumberingSettings: !!options.exportautonumberingsettings, ExportCalendarSettings: !!options.exportcalendarsettings, ExportCustomizationSettings: !!options.exportcustomizationsettings, ExportEmailTrackingSettings: !!options.exportemailtrackingsettings, ExportExternalApplications: !!options.exportexternalapplications, ExportGeneralSettings: !!options.exportgeneralsettings, ExportIsvConfig: !!options.exportisvconfig, ExportMarketingSettings: !!options.exportmarketingsettings, ExportOutlookSynchronizationSettings: !!options.exportoutlooksynchronizationsettings, ExportRelationshipRoles: !!options.exportrelationshiproles, ExportSales: !!options.exportsales, TargetVersion: options.targetversion, }, options.output); } }); commander_1.program.parseAsync(); //# sourceMappingURL=exportsolution.js.map