aura-ai
Version:
AI-powered marketing strategist CLI tool for developers
174 lines (148 loc) ⢠4.97 kB
JavaScript
import fs from 'fs/promises'
import { existsSync } from 'fs'
import path from 'path'
export async function initCommand(options) {
const { answers, file, force, json, quiet, interactive } = options
try {
// Check if already initialized
if (existsSync('aura.md') && !force) {
const error = 'Product already analyzed. Use --force to overwrite.'
if (json) {
console.log(JSON.stringify({ status: 'error', error }))
process.exit(1)
} else {
console.error(`ā ${error}`)
process.exit(1)
}
}
let productAnswers = []
// Get answers from different sources
if (answers) {
// Parse answers from command line
productAnswers = answers.split('|').map(a => a.trim())
if (productAnswers.length !== 3) {
throw new Error('Must provide exactly 3 answers separated by |')
}
} else if (file) {
// Read answers from file
const content = await fs.readFile(file, 'utf-8')
productAnswers = content.split('\n').filter(line => line.trim()).slice(0, 3)
if (productAnswers.length !== 3) {
throw new Error('File must contain exactly 3 lines of answers')
}
} else if (!interactive) {
// For non-interactive mode, answers are required
throw new Error('Answers required in non-interactive mode. Use --answers or --file')
} else {
// Interactive mode - launch the full Ink app
if (!quiet) {
console.log('Launching interactive product analysis...')
}
// Dynamic import to avoid loading Ink when not needed
const { runInitInteractive } = await import('./interactive.jsx')
await runInitInteractive()
if (json) {
console.log(JSON.stringify({
status: 'success',
message: 'Product analysis completed',
file: 'aura.md'
}))
}
return
}
// Process answers and generate analysis
const [description, audience, value] = productAnswers
if (!quiet && !json) {
console.log('š Analyzing your product...')
}
// Generate marketing analysis using AI
const analysis = await generateAnalysis(description, audience, value)
// Save to aura.md
await fs.writeFile('aura.md', analysis)
// Output result
if (json) {
// For agents: print full analysis
console.log('\n' + '='.repeat(60))
console.log('šÆ PRODUCT MARKETING ANALYSIS')
console.log('='.repeat(60))
console.log('\nš Product:', description)
console.log('š„ Audience:', audience)
console.log('š” Value:', value)
console.log('\n' + '-'.repeat(60))
console.log('\nš Generated Marketing Strategy:\n')
console.log(analysis)
console.log('\n' + '='.repeat(60))
console.log('ā
Analysis saved to aura.md')
console.log('='.repeat(60))
} else if (!quiet) {
console.log('ā
Product analysis completed!')
console.log('š Marketing strategy saved to: aura.md')
console.log('\nYour product profile:')
console.log(` ⢠Product: ${description}`)
console.log(` ⢠Audience: ${audience}`)
console.log(` ⢠Value: ${value}`)
}
} catch (error) {
if (json) {
console.log(JSON.stringify({
status: 'error',
error: error.message
}))
process.exit(1)
} else {
console.error(`ā Error: ${error.message}`)
process.exit(1)
}
}
}
async function generateAnalysis(description, audience, value) {
// Import AI service
const { openai } = await import('@ai-sdk/openai')
const { generateText } = await import('ai')
const prompt = `Create a comprehensive marketing strategy for:
Product: ${description}
Target Audience: ${audience}
Value Proposition: ${value}
Generate a detailed marketing analysis including:
1. Product positioning
2. Target market analysis
3. Marketing channels
4. Growth strategies
5. Key messaging
6. Competitive advantages
Format as markdown with clear sections.`
try {
const result = await generateText({
model: openai('gpt-4o-mini'),
prompt,
temperature: 0.7,
maxTokens: 1000,
})
return `# Product Marketing Analysis
## Product Overview
**Product:** ${description}
**Target Audience:** ${audience}
**Value Proposition:** ${value}
---
${result.text}`
} catch (error) {
// Fallback if AI fails
return `# Product Marketing Analysis
## Product Overview
**Product:** ${description}
**Target Audience:** ${audience}
**Value Proposition:** ${value}
## Marketing Strategy
This analysis will be enhanced with AI insights when API is configured.
### Target Market
Your target audience is: ${audience}
### Value Proposition
Key benefit: ${value}
### Next Steps
1. Define your unique selling points
2. Research competitor positioning
3. Identify primary marketing channels
4. Create messaging framework
5. Develop content strategy`
}
}