-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_building_nodejs.py
More file actions
277 lines (225 loc) Β· 8.92 KB
/
start_building_nodejs.py
File metadata and controls
277 lines (225 loc) Β· 8.92 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/usr/bin/env python3
"""
Start Building the Viral Video Engine with Node.js/TypeScript
Agency Swarm orchestrates Node.js development
"""
import os
import sys
import time
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Set OpenAI API key
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
from viral_video_agency_nodejs import viral_video_agency
def print_header():
print("""
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π¬ VIRAL VIDEO ENGINE - NODE.JS BUILDER π¬ β
β β
β Agency Swarm β Node.js/TypeScript Implementation β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
""")
def automated_build():
"""Run the automated Node.js build process"""
print("\nπ STARTING NODE.JS/TYPESCRIPT BUILD\n")
print("=" * 70)
# Phase 1: Node.js Project Setup
print("\nπ¦ PHASE 1: NODE.JS PROJECT SETUP")
print("-" * 40)
setup_prompt = """
Start building the Viral Video Engine in Node.js/TypeScript.
First, check Task Master for Task 11, then delegate to NodeInfrastructureDev to:
1. Initialize npm project with package.json
2. Install TypeScript and core dependencies:
- typescript, tsx, @types/node
- openai (official SDK)
- fluent-ffmpeg
- axios, dotenv
- winston (logging)
3. Create tsconfig.json with ES module configuration
4. Set up the directory structure:
- src/lib/ (core modules)
- src/api/ (API integrations)
- src/types/ (TypeScript types)
- src/config/ (configuration)
5. Create src/config/index.ts for environment variables
Update Task Master as you complete subtasks.
"""
print("π§ Setting up Node.js project...")
result = viral_video_agency.get_completion(setup_prompt)
print("β
Node.js project initialized")
time.sleep(2)
# Phase 2: Template System in TypeScript
print("\nπ PHASE 2: TEMPLATE SYSTEM (TYPESCRIPT)")
print("-" * 40)
template_prompt = """
Implement Task 12 in TypeScript.
Delegate to NodeTemplateDev to create:
1. src/types/template.ts with TypeScript interfaces:
- ViralTemplate interface
- TemplateSection interface
- TemplateCategory type
2. src/lib/templateManager.ts with TemplateManager class:
- loadTemplates() method
- selectTemplate(topic) method
- getTemplateById(id) method
3. data/templates.json with all 29 template structures
Use TypeScript for full type safety.
Update Task Master status.
"""
print("π Building TypeScript template system...")
result = viral_video_agency.get_completion(template_prompt)
print("β
Template system implemented")
time.sleep(2)
# Phase 3: OpenAI Integration
print("\nβοΈ PHASE 3: OPENAI SCRIPT GENERATION")
print("-" * 40)
openai_prompt = """
Implement Task 13 using OpenAI's Node.js SDK.
Delegate to NodeScriptGenDev to create:
1. src/types/script.ts with VideoScript interface
2. src/lib/scriptGenerator.ts using OpenAI Node.js SDK:
- Initialize OpenAI client with API key
- generateScript(topic, template) method
- batchGenerate(topics) method
- Implement caching with Map or node-cache
3. src/lib/promptBuilder.ts for prompt engineering
Use async/await for all API calls.
Update Task Master.
"""
print("π€ Integrating OpenAI SDK...")
result = viral_video_agency.get_completion(openai_prompt)
print("β
Script generation ready")
time.sleep(2)
# Phase 4: Media APIs
print("\nπ₯ PHASE 4: MEDIA PROCESSING APIS")
print("-" * 40)
media_prompt = """
Implement Tasks 14 and 15 with Node.js APIs.
Delegate to NodeMediaDev to create:
Visual (Task 14):
1. src/api/pexels.ts - Pexels API client
2. src/api/pixabay.ts - Pixabay API client
3. src/lib/clipManager.ts - manages video clips
Audio (Task 15):
1. src/api/elevenlabs.ts - ElevenLabs REST API
2. src/lib/audioManager.ts - audio processing with fluent-ffmpeg
Use axios for HTTP requests, handle errors properly.
Update Task Master for both tasks.
"""
print("πΈ Building media processing...")
result = viral_video_agency.get_completion(media_prompt)
print("β
Media APIs integrated")
time.sleep(2)
# Phase 5: Video Assembly with FFmpeg
print("\n㪠PHASE 5: VIDEO ASSEMBLY (FLUENT-FFMPEG)")
print("-" * 40)
ffmpeg_prompt = """
Implement Task 16 using fluent-ffmpeg.
Delegate to NodeVideoAssemblyDev to create:
1. src/lib/videoAssembler.ts with VideoAssembler class:
- assembleVideo(script, clips, audio) method
- addCaptions() using drawtext filter
- addTransitions() for smooth cuts
- exportVideo() returning Buffer or file path
2. src/lib/captionGenerator.ts for caption timing
3. Handle async video rendering with Promises
Use fluent-ffmpeg's chain API for video processing.
Update Task Master.
"""
print("π¨ Building video assembly engine...")
result = viral_video_agency.get_completion(ffmpeg_prompt)
print("β
Video assembly complete")
time.sleep(2)
# Phase 6: CLI Application
print("\nπ― PHASE 6: CLI APPLICATION")
print("-" * 40)
cli_prompt = """
Implement Task 20 as a Node.js CLI.
Delegate to NodeCLIDev to create:
1. src/cli.ts using commander.js:
- --topic flag for video topic
- --template flag for template ID
- --variants flag for number of variants
- --output flag for output directory
2. src/index.ts with ViralVideoEngine class that:
- Orchestrates all modules
- Shows progress with ora spinner
- Handles errors gracefully
3. Update package.json scripts:
- "generate": "tsx src/cli.ts"
- "build": "tsc"
Make it work with: npm run generate -- --topic "AI tools" --template 1
Update Task Master.
"""
print("π Creating CLI application...")
result = viral_video_agency.get_completion(cli_prompt)
print("β
CLI ready")
time.sleep(2)
# Phase 7: Testing
print("\nπ§ͺ PHASE 7: JEST TESTING")
print("-" * 40)
test_prompt = """
Set up testing with Jest and TypeScript.
Delegate to NodeTestingAgent to:
1. Install jest, ts-jest, @types/jest
2. Configure jest.config.js for TypeScript
3. Create src/__tests__/ directory
4. Write basic tests for:
- templateManager.test.ts
- scriptGenerator.test.ts
- videoAssembler.test.ts
5. Mock external API calls
Run tests with: npm test
Report results.
"""
print("π Setting up tests...")
result = viral_video_agency.get_completion(test_prompt)
print("β
Testing complete")
print("\n" + "=" * 70)
print("π NODE.JS BUILD COMPLETE!")
print("=" * 70)
print("\nTo generate a video:")
print(' npm run generate -- --topic "Your Topic" --template 1 --variants 3')
print("\nTo run in development:")
print(' npm run dev')
print("\nTo build for production:")
print(' npm run build && npm start')
def main():
print_header()
print("\nSelect mode:")
print("1. π Automated Node.js Build")
print("2. π¬ Interactive Mode")
print("3. π Web Interface")
print("4. π Check Status")
choice = input("\nChoice (1-4): ").strip()
if choice == "1":
automated_build()
elif choice == "2":
print("\n㪠Interactive Mode - Give commands to the agency\n")
while True:
command = input("π Command (or 'exit'): ").strip()
if command.lower() in ['exit', 'quit']:
break
result = viral_video_agency.get_completion(command)
print(f"\n{result}\n")
elif choice == "3":
print("\nπ Starting Gradio interface...")
viral_video_agency.demo_gradio(height=900)
elif choice == "4":
result = viral_video_agency.get_completion(
"Check Task Master status and list pending tasks"
)
print(result)
if __name__ == "__main__":
os.chdir("C:\\Users\\Stuart\\Desktop\\Projects\\viralengine")
if not os.getenv("OPENAI_API_KEY"):
print("β OPENAI_API_KEY not found in .env")
sys.exit(1)
try:
main()
except KeyboardInterrupt:
print("\n\nπ Interrupted")
except Exception as e:
print(f"\nβ Error: {e}")