UNPKG

@tywalk/pcf-helper

Version:

Command line helper for building and publishing PCF controls to Dataverse.

52 lines (51 loc) 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleResults = exports.setupExecutionContext = exports.resolveSpawnCommand = void 0; const color_logger_1 = require("@tywalk/color-logger"); const performanceUtil_1 = require("./performanceUtil"); const resolveSpawnCommand = (command, args) => { if (command !== 'npm') { return { command, args }; } const npmExecPath = process.env.npm_execpath; if (npmExecPath) { return { command: process.execPath, args: [npmExecPath, ...args] }; } return { command: process.platform === 'win32' ? 'npm.cmd' : 'npm', args }; }; exports.resolveSpawnCommand = resolveSpawnCommand; const setupExecutionContext = (options) => { const logger = new color_logger_1.Logger('log'); if (options.verbose) { logger.setDebug(true); logger.setLevel('debug'); } else { logger.setLevel('info'); } return { logger, tick: performance.now() }; }; exports.setupExecutionContext = setupExecutionContext; // Helper function to execute tasks and handle results const handleResults = (taskName, logger, tick, result) => { if (taskName !== 'session') { if (result === 0) { logger.log(`[PCF Helper] ${taskName} completed successfully!`); } else { logger.log(`[PCF Helper] ${taskName} completed with errors.`); } const tock = performance.now(); logger.log((0, performanceUtil_1.formatMsToSec)(`[PCF Helper] ${(0, performanceUtil_1.formatTime)(new Date())} ${taskName} finished in %is.`, tock - tick)); } if (taskName !== 'session' || result === 1) { process.exit(result); } }; exports.handleResults = handleResults;