Generate Templates
The generate feature allows you to quickly scaffold a basic pricing structure template that you can customize for your needs.
Overview
Creating a pricing structure from scratch can be time-consuming. The generate feature lets you quickly create a template pricing file with common structures like tiers, intervals, and metadata. This is perfect for getting started with Prices as Code or for quickly setting up a new pricing model.
Using the CLI
The simplest way to generate a pricing template is using the CLI:
npx prices-as-code generate pricing.yml
This will create a YAML file with a default pricing structure containing three tiers (basic, pro, enterprise) with monthly and yearly pricing options.
Customizing Your Template
You can customize your generated template with several options:
--tiers
: Define your product tiers (comma-separated)--intervals
: Set billing intervals (comma-separated)--currency
: Set the currency (ISO code)--format
: Output format (yaml, json, or ts)--no-metadata
: Don't include metadata in the template--no-features
: Don't include feature lists in the template
Examples
# Generate with custom tiers
npx prices-as-code generate --tiers=free,basic,pro pricing.yml
# Generate with custom currency and format
npx prices-as-code generate --currency=eur --format=ts pricing.ts
# Generate with only monthly billing
npx prices-as-code generate --intervals=month pricing.yml
# Generate without metadata
npx prices-as-code generate --no-metadata pricing.yml
Programmatic Usage
You can also generate templates programmatically:
import { generate } from 'prices-as-code';
async function generatePricing() {
const result = await generate({
configPath: './pricing.yml',
format: 'yaml',
productTiers: ['free', 'basic', 'pro'],
intervals: ['month', 'year'],
currency: 'usd',
includeMetadata: true,
includeFeatures: true
});
console.log(`Generated template with ${result.products.length} products and ${result.prices.length} prices`);
}
generatePricing();
Generated Structure
The generated template includes:
- Products for each tier with appropriate names and descriptions
- Prices for each tier and interval combination
- Metadata with display information
- Feature lists that get more advanced with higher tiers
- Pricing that follows standard SaaS patterns (monthly & yearly options with discounts)
Here's an example of a generated template structure:
products:
- provider: stripe
name: Basic Plan
description: Basic features for individuals
features:
- Core feature 1
- Core feature 2
highlight: false
metadata:
displayOrder: 1
key: basic
key: basic
# More products...
prices:
- provider: stripe
name: Basic Monthly
nickname: Basic Monthly
unitAmount: 999
currency: usd
type: recurring
recurring:
interval: month
intervalCount: 1
active: true
productKey: basic
metadata:
displayName: Basic Monthly
popular: false
# More prices...
Customizing After Generation
After generating your template, you should:
- Update product names, descriptions, and features to match your actual offerings
- Adjust pricing to reflect your business model
- Add any additional metadata relevant to your application
- Modify or add tiers as needed
The generate feature provides a solid starting point, but you'll want to customize it to fit your specific needs.
Next Steps
After generating and customizing your pricing template, you can: