@tywalk/pcf-helper
Version:
Command line helper for building and publishing PCF controls to Dataverse.
126 lines (125 loc) • 5.49 kB
JavaScript
;
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 commander_1 = require("commander");
const package_json_1 = require("../package.json");
const configUtil_1 = require("../util/configUtil");
const profileInitUtil_1 = require("../util/profileInitUtil");
const program = new commander_1.Command();
program
.name('pcf-helper-profile')
.description('Inspect and manage pcf-helper profiles in pcf-helper.config.json')
.version(package_json_1.version, '-v, --version');
program
.command('list')
.description('List all available profile names')
.action(() => {
var _a;
const { merged, sources } = (0, configUtil_1.loadPcfHelperConfig)();
const names = Object.keys((_a = merged.profiles) !== null && _a !== void 0 ? _a : {});
const isDefault = (n) => (merged.defaultProfile === n ? ' (default)' : '');
if (sources.length === 0) {
console.log('No pcf-helper config files found.');
console.log('Looked at:');
console.log(' - global: ~/.pcf-helper/config.json');
console.log(' - project: ./pcf-helper.config.json');
process.exit(0);
}
console.log('Loaded config from:');
for (const s of sources)
console.log(` - ${s}`);
if (names.length === 0) {
console.log('\nNo profiles defined.');
process.exit(0);
}
console.log('\nProfiles:');
for (const n of names)
console.log(` - ${n}${isDefault(n)}`);
});
program
.command('show <name>')
.description('Print the resolved contents of a profile')
.action((name) => {
var _a, _b;
const { merged } = (0, configUtil_1.loadPcfHelperConfig)();
const profile = (_a = merged.profiles) === null || _a === void 0 ? void 0 : _a[name];
if (!profile) {
const available = Object.keys((_b = merged.profiles) !== null && _b !== void 0 ? _b : {});
console.error(`Profile "${name}" not found. Available: ${available.join(', ') || '(none)'}`);
process.exit(1);
}
console.log(JSON.stringify(profile, null, 2));
});
program
.command('current')
.description('Print the profile that would be used by default')
.action(() => {
const { merged } = (0, configUtil_1.loadPcfHelperConfig)();
if (!merged.defaultProfile) {
console.log('No defaultProfile set.');
return;
}
console.log(merged.defaultProfile);
});
program
.command('paths')
.description('Print the global and project config paths (whether or not they exist)')
.action(() => {
const { merged: _m, projectPath, globalPath, sources } = (0, configUtil_1.loadPcfHelperConfig)();
void _m;
console.log(`global: ${globalPath}`);
console.log(`project: ${projectPath}`);
console.log(`loaded: ${sources.length ? sources.join(', ') : '(none)'}`);
});
program
.command('init <name>')
.description('Create a new profile in pcf-helper.config.json (project or global)')
.option('-e, --environment <env>', 'Dataverse environment name')
.option('--publisher-name <name>', 'publisher display name')
.option('--publisher-prefix <prefix>', 'publisher prefix (2-8 chars)')
.option('-p, --path <path>', 'path to PCF solution folder')
.option('--template <template>', 'control template (field|dataset)')
.option('--framework <framework>', 'rendering framework (none|react)')
.option('--session-url <url>', 'session: remote environment URL')
.option('--session-script <path>', 'session: remote script to intercept')
.option('--session-bundle <path>', 'session: local bundle path')
.option('-g, --global', 'write to ~/.pcf-helper/config.json instead of project-level')
.option('-d, --set-default', 'set this profile as the defaultProfile')
.option('-f, --force', 'overwrite an existing profile of the same name')
.option('--no-interactive', 'skip prompts for missing fields')
.action((name, flags) => __awaiter(void 0, void 0, void 0, function* () {
const options = {
name,
environment: flags.environment,
publisherName: flags.publisherName,
publisherPrefix: flags.publisherPrefix,
path: flags.path,
template: flags.template,
framework: flags.framework,
sessionUrl: flags.sessionUrl,
sessionScript: flags.sessionScript,
sessionBundle: flags.sessionBundle,
global: !!flags.global,
setDefault: !!flags.setDefault,
force: !!flags.force,
nonInteractive: flags.interactive === false,
};
try {
yield (0, profileInitUtil_1.runProfileInit)(options);
}
catch (e) {
const message = e instanceof Error ? e.message : String(e);
console.error(`Error: ${message}`);
process.exit(1);
}
}));
program.parseAsync();