UNPKG

xrmcli

Version:

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

101 lines 5.09 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 header_1 = __importDefault(require("../utils/header")); const connect_1 = __importStar(require("../utils/connect")); const validation_1 = __importDefault(require("../utils/validation")); const saveToDisk = (webresource, outputPath) => { const { name, content, displayname } = webresource; console.log(`Saving ${displayname}...`); const path = name.substring(0, name.lastIndexOf('/')); (0, fs_1.mkdirSync)(`${outputPath}/${path}`, { recursive: true }); (0, fs_1.writeFileSync)(`${outputPath}/${name}`, content, { encoding: 'base64' }); }; const saveConfig = (config, outputPath) => { console.log('Saving config...'); const configString = JSON.stringify(config, undefined, 2); (0, fs_1.writeFileSync)(`${outputPath}/webresource.config.json`, configString, { encoding: 'utf-8' }); }; commander_1.program.name('xrmcli typescript export'); (0, connect_1.AddAuthCommandOptions)(); commander_1.program .description('Export webresources from the specified solution to the file system and create a deploy config') .requiredOption('--solution <solution>', 'Unique solution name') .requiredOption('--path <path>', 'Output path') .action(async (options) => { var _a; try { if ((0, validation_1.default)(options)) { const auth = await (0, connect_1.default)(options); const { url, solution, path } = options; // get list of webresources const componentQuery = `/api/data/v9.2/solutions?$select=solutionid&$expand=solution_solutioncomponent($select=objectid;$filter=(componenttype eq 61))&$filter=(uniquename eq '${solution}') and (solution_solutioncomponent/any(o1:(o1/componenttype eq 61)))`; const result = await (0, node_fetch_1.default)(`${url}${componentQuery}`, { headers: (0, header_1.default)(auth.accessToken), method: 'GET', }); const jsonResult = await result.json(); if (jsonResult.value.length === 0) { throw new Error(`${solution} contains no webresources`); } const webresourceids = (_a = jsonResult.value[0].solution_solutioncomponent) === null || _a === void 0 ? void 0 : _a.map((value) => value.objectid); // export each webresource to disk const webresourceQuery = `/api/data/v9.2/webresourceset?$select=name,webresourcetype,content,displayname,description&$filter=(Microsoft.Dynamics.CRM.In(PropertyName='webresourceid',PropertyValues=${JSON.stringify(webresourceids)}))`; const wresult = await (0, node_fetch_1.default)(`${url}${webresourceQuery}`, { headers: (0, header_1.default)(auth.accessToken), method: 'GET', }); const jsonWResult = await wresult.json(); jsonWResult.value.forEach((value) => { saveToDisk(value, path); }); // generate deploy config const config = { WebResources: [], }; jsonWResult.value.forEach((value) => { config.WebResources.push({ name: value.name, displayname: value.displayname, description: value.description, path: `${path}/${value.name}`, type: value.webresourcetype, }); }); saveConfig(config, path); } } catch (e) { console.error(`${e.message || 'Error exporting webresources.'}`); } }); commander_1.program.parseAsync(); //# sourceMappingURL=export.js.map