Skip to content

A plugin marketplace for GitHub Copilot and other AI agents that provides Power Platform development plugins, including reusable skills, agents, and commands for building and deploying solutions.

2.1 KB
Raw Blame
#!/usr/bin/env node
'use strict';

let emitTemplateOutcome = null;
try {
  ({ emitTemplateOutcome } = require('./lib/create-site-template-telemetry'));
} catch {
  // Template telemetry is optional and must never affect the create-site flow.
}

const { formatJsonResult } = require('./lib/template-cli-args');

// Accepted argv shape:
//   --eventName template_used --templateId company-portal --templateKind spa --framework react --audience internal
//   --eventName template_import_success --templateId company-portal --templateKind spa --framework react --audience internal --seedApplied true
//   --eventName template_import_failure --templateId company-portal --templateKind spa --framework react --audience internal --outcome failure --errorClass PacSolutionImport
//   --eventName template_clone_success --templateId company-portal --templateKind spa --framework react --audience internal
//   --eventName template_clone_failure --templateId company-portal --templateKind spa --framework react --audience internal --outcome failure --errorClass PacPagesClone
// Scratch branch sends:
//   --eventName create_site_from_scratch --framework react --audience internal
// Values are fixed catalog/outcome enums. Free-form error text is intentionally
// unsupported because it can contain paths, URLs, stack traces, or user data.
function parseArgs(argv) {
  const args = {};
  for (let i = 0; i < argv.length; i++) {
    const arg = argv[i];
    if (arg.startsWith('--')) args[arg.slice(2)] = argv[++i];
  }
  return args;
}

function run(argv = process.argv.slice(2)) {
  if (!emitTemplateOutcome) return null;
  const args = parseArgs(argv);
  return emitTemplateOutcome(args);
}

function toCliResult(result) {
  // The emitted event can contain tenant-scoped identifiers. Keep it inside the
  // telemetry boundary and expose only whether the best-effort emission ran.
  return { ok: Boolean(result && result.ok === true) };
}

if (require.main === module) {
  if (formatJsonResult) {
    process.stdout.write(formatJsonResult(toCliResult(run())));
  }
}

module.exports = { parseArgs, run, toCliResult };