-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-cli.js
More file actions
118 lines (99 loc) · 3.36 KB
/
test-cli.js
File metadata and controls
118 lines (99 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env node
// Simple test script to demonstrate the interactive prompts functionality
// This simulates what the CLI would do with prompts installed
import { execSync } from "child_process";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
console.log('🧪 Testing interactive prompts functionality...\n');
// Simulate the prompts functionality for testing
const mockPrompts = async (questions) => {
console.log('📝 Interactive mode would ask:');
if (Array.isArray(questions)) {
const results = {};
for (const q of questions) {
console.log(` ${q.message} ${q.initial ? `(default: ${q.initial})` : ''}`);
if (q.name === 'projectId') results.projectId = 'test-project-123';
if (q.name === 'dataset') results.dataset = 'production';
if (q.name === 'apiVersion') results.apiVersion = '2025-08-20';
if (q.name === 'createEnvFile') results.createEnvFile = true;
}
return results;
} else {
console.log(` ${questions.message}`);
return { setupNow: true };
}
};
// Test the interactive flow
async function testInteractiveSetup() {
console.log('🔧 Let\'s configure your Sanity project...');
console.log('📝 You can find these details in your Sanity dashboard: https://sanity.io/manage\n');
const setupChoice = await mockPrompts({
type: 'confirm',
name: 'setupNow',
message: 'Would you like to configure your Sanity project now?',
initial: true
});
if (setupChoice.setupNow) {
const sanityConfig = await mockPrompts([
{
type: 'text',
name: 'projectId',
message: 'Enter your Sanity Project ID:',
},
{
type: 'text',
name: 'dataset',
message: 'Enter your Sanity Dataset name:',
initial: 'production',
},
{
type: 'text',
name: 'apiVersion',
message: 'Enter API version (YYYY-MM-DD):',
initial: new Date().toISOString().split('T')[0],
},
{
type: 'confirm',
name: 'createEnvFile',
message: 'Create .env.local file with these settings?',
initial: true
}
]);
if (sanityConfig.createEnvFile) {
const envContent = `# Sanity Configuration
NEXT_PUBLIC_SANITY_PROJECT_ID=${sanityConfig.projectId}
NEXT_PUBLIC_SANITY_DATASET=${sanityConfig.dataset}
NEXT_PUBLIC_SANITY_API_VERSION=${sanityConfig.apiVersion}
# Optional: Add token for authenticated requests (preview mode, etc.)
# SANITY_API_READ_TOKEN=your_read_token_here
`;
console.log('\n📄 Would create .env.local with contents:');
console.log('---');
console.log(envContent);
console.log('---');
console.log('✅ .env.local file would be created with your Sanity configuration');
}
console.log(`
✅ Successfully would create test-project!
📋 Project Status:
✅ Template files copied
✅ Dependencies configured
✅ Configured Sanity connection
✅ Git repository ready
🚀 Next steps:
cd test-project
You're all set! Just run: npm run dev
🌐 Your app will be available at:
- Frontend: http://localhost:3000
- Sanity Studio: http://localhost:3000/studio
📖 Resources:
- Documentation: README.md
- Sanity Dashboard: https://sanity.io/manage
Happy coding! 🎉
`);
}
}
testInteractiveSetup();