@tywalk/pcf-helper
Version:
Command line helper for building and publishing PCF controls to Dataverse.
94 lines (93 loc) • 5.41 kB
JavaScript
;
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 () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const task = __importStar(require("../tasks/session-pcf"));
const package_json_1 = require("../package.json");
const commander_1 = require("commander");
const commandUtil_1 = require("../util/commandUtil");
const performanceUtil_1 = require("../util/performanceUtil");
const argumentUtil_1 = require("../util/argumentUtil");
const program = new commander_1.Command();
const parseWatchRetry = (value) => {
const normalized = value.trim().toLowerCase();
if (normalized === 'true') {
return true;
}
if (normalized === 'false') {
return false;
}
throw new Error('watch-retry must be either true or false');
};
program
.name('pcf-helper-session')
.description('Run development session')
.version(package_json_1.version, '-v, --version')
.option('-V, --verbose', 'enable verbose logging')
.option('-u, --url <url>', 'remote environment URL')
.option('-s, --script <script>', 'remote script to intercept')
.option('-t, --stylesheet <stylesheet>', 'remote stylesheet to intercept')
.option('-b, --bundle <path>', 'local bundle path')
.option('-c, --css <path>', 'local CSS path')
.option('-f, --config <path>', 'config file path', 'session.config.json')
.option('-w, --watch', 'start pcf-scripts watch process')
.option('--watch-retry <enabled>', 'automatically retry watch process on failure (true|false)', parseWatchRetry);
(0, argumentUtil_1.addProfileOption)(program).action((options, command) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
const { logger, tick } = (0, commandUtil_1.setupExecutionContext)(options);
logger.log('PCF Helper version', package_json_1.version);
const config = task.loadConfig(options.config, options.profile);
// Priority: CLI args > config (which itself layers profile > unified > legacy)
const startWatch = (_b = (_a = options.watch) !== null && _a !== void 0 ? _a : config.startWatch) !== null && _b !== void 0 ? _b : false;
const watchRetryFlagWasSet = command.getOptionValueSource('watchRetry') === 'cli';
if (watchRetryFlagWasSet && !startWatch) {
logger.error('❌ --watch-retry can only be used when --watch is enabled.');
process.exit(1);
}
const watchRetry = (_d = (_c = options.watchRetry) !== null && _c !== void 0 ? _c : config.watchRetry) !== null && _d !== void 0 ? _d : true;
yield task.runSession((_f = (_e = options.url) !== null && _e !== void 0 ? _e : config.remoteEnvironmentUrl) !== null && _f !== void 0 ? _f : '', (_h = (_g = options.script) !== null && _g !== void 0 ? _g : config.remoteScriptToIntercept) !== null && _h !== void 0 ? _h : '', (_k = (_j = options.stylesheet) !== null && _j !== void 0 ? _j : config.remoteStylesheetToIntercept) !== null && _k !== void 0 ? _k : '', (_m = (_l = options.bundle) !== null && _l !== void 0 ? _l : config.localBundlePath) !== null && _m !== void 0 ? _m : '', (_p = (_o = options.css) !== null && _o !== void 0 ? _o : config.localCssPath) !== null && _p !== void 0 ? _p : '', startWatch, watchRetry);
const tock = performance.now();
logger.log((0, performanceUtil_1.formatMsToSec)('Session started successfully in %is.', tock - tick));
}));
program.parse();