Skip to content

Commit a4d2331

Browse files
authored
Merge pull request #40924 from github/repo-sync
Repo sync
2 parents 8c98f42 + 317073e commit a4d2331

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

src/content-render/scripts/cta-builder.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ program
6464
validateUrl(options)
6565
})
6666

67+
// Add programmatic build command
68+
program
69+
.command('build')
70+
.description('Build a CTA URL programmatically with flags (outputs URL only)')
71+
.requiredOption('--url <url>', 'Base URL for the CTA')
72+
.requiredOption('--product <product>', 'Product reference (copilot, ghec, desktop)')
73+
.requiredOption('--type <type>', 'CTA type (trial, purchase, engagement)')
74+
.requiredOption('--style <style>', 'CTA style (button, text)')
75+
.option('--plan <plan>', 'Plan reference (free, pro, business, enterprise)')
76+
.action((options) => {
77+
buildProgrammaticCTA(options)
78+
})
79+
6780
// Default to interactive mode
6881
program.action(() => {
6982
interactiveBuilder()
@@ -542,3 +555,54 @@ async function validateUrl(options: { url?: string }): Promise<void> {
542555
console.error(chalk.red('❌ An error occurred:'), error)
543556
}
544557
}
558+
559+
// Programmatic build command handler
560+
async function buildProgrammaticCTA(options: {
561+
url: string
562+
product: string
563+
type: string
564+
style: string
565+
plan?: string
566+
}): Promise<void> {
567+
try {
568+
// Validate base URL
569+
let baseUrl: string
570+
try {
571+
baseUrl = new URL(options.url).toString()
572+
} catch (error) {
573+
console.error(
574+
`Invalid base URL: ${options.url} - ${error instanceof Error ? error.message : error}`,
575+
)
576+
process.exit(1)
577+
}
578+
579+
// Build CTA parameters object
580+
const params: CTAParams = {
581+
ref_product: options.product,
582+
ref_type: options.type,
583+
ref_style: options.style,
584+
}
585+
586+
// Add optional parameters
587+
if (options.plan) {
588+
params.ref_plan = options.plan
589+
}
590+
591+
// Validate parameters against schema
592+
const validation = validateCTAParams(params)
593+
if (!validation.isValid) {
594+
// Output validation errors to stderr and exit with error code
595+
validation.errors.forEach((error) => {
596+
console.error(`Validation error: ${error}`)
597+
})
598+
process.exit(1)
599+
}
600+
601+
// Build and output the URL (stdout only)
602+
const ctaUrl = buildCTAUrl(baseUrl, params)
603+
console.log(ctaUrl)
604+
} catch (error) {
605+
console.error(`Build failed: ${error}`)
606+
process.exit(1)
607+
}
608+
}

0 commit comments

Comments
 (0)