11#!/usr/bin/env node
22
3- const { spawn, execSync } = require ( 'child_process' ) ;
4- const path = require ( 'path' ) ;
5- const fs = require ( 'fs' ) ;
6- const { write, writeError, getLogFilePath } = require ( './utils/logger' ) ;
7- const { getRuntimeConfigPath } = require ( './utils/paths' ) ;
8-
93const args = process . argv . slice ( 2 ) ;
104
115if ( args . length < 1 || args . includes ( '--help' ) ) {
@@ -19,89 +13,3 @@ Streamline your workflows and leverage AI capabilities seamlessly.
1913 process . exit ( 0 ) ;
2014}
2115
22-
23- const command = args [ 0 ] ;
24- const input = args [ 1 ] ;
25-
26- function resolvePython ( ) {
27- // Prefer venv Python if configured
28- try {
29- const rc = JSON . parse ( fs . readFileSync ( getRuntimeConfigPath ( ) , 'utf8' ) ) ;
30- if ( rc && rc . venvPython ) {
31- try { execSync ( `"${ rc . venvPython } " --version` , { stdio : 'ignore' , timeout : 5000 } ) ; return `"${ rc . venvPython } "` ; } catch ( _ ) { }
32- }
33- } catch ( _ ) { }
34- const candidates = [ 'python3' , 'python' , 'py -3' ] ;
35- for ( const c of candidates ) {
36- try { execSync ( `${ c } --version` , { stdio : 'ignore' , timeout : 5000 } ) ; return c ; } catch ( _ ) { }
37- }
38- return null ;
39- }
40-
41- if ( command === 'analyze' ) {
42- const scriptPath = path . resolve ( __dirname , '..' , 'ml-core' , 'start.py' ) ;
43-
44- if ( ! fs . existsSync ( scriptPath ) ) {
45- console . error ( `❌ start.py not found at: ${ scriptPath } ` ) ;
46- console . error ( '➡️ Please reinstall the CLI or contact support.' ) ;
47- process . exit ( 1 ) ;
48- }
49-
50- if ( ! input ) {
51- console . error ( '❌ No input video path provided.' ) ;
52- console . error ( '➡️ Usage: visionix analyze <video-path>' ) ;
53- process . exit ( 1 ) ;
54- }
55- if ( ! fs . existsSync ( input ) ) {
56- console . error ( `❌ Input video not found: ${ input } ` ) ;
57- console . error ( '➡️ Please provide a valid path to a video file.' ) ;
58- process . exit ( 1 ) ;
59- }
60-
61- console . log ( '📦 Launching Python:' , scriptPath ) ;
62- let spinnerInterval ;
63- let spinnerFrames = [ '⠋' , '⠙' , '⠹' , '⠸' , '⠼' , '⠴' , '⠦' , '⠧' , '⠇' , '⠏' ] ;
64- let spinnerIndex = 0 ;
65- function startSpinner ( ) {
66- process . stdout . write ( '⏳ Processing... ' ) ;
67- spinnerInterval = setInterval ( ( ) => {
68- process . stdout . write ( `\r${ spinnerFrames [ spinnerIndex ++ % spinnerFrames . length ] } Processing... ` ) ;
69- } , 120 ) ;
70- }
71- function stopSpinner ( ) {
72- if ( spinnerInterval ) clearInterval ( spinnerInterval ) ;
73- process . stdout . write ( '\r' ) ;
74- }
75-
76- startSpinner ( ) ;
77- const py = resolvePython ( ) ;
78- if ( ! py ) {
79- stopSpinner ( ) ;
80- console . error ( '❌ Python not found.' ) ;
81- console . error ( '➡️ Please install Python 3 and ensure it is in your PATH.' ) ;
82- console . error ( `📝 See logs: ${ getLogFilePath ( ) } ` ) ;
83- process . exit ( 1 ) ;
84- }
85- const pyParts = py . split ( ' ' ) ;
86- const pyCmd = pyParts [ 0 ] ;
87- const pyArgs = pyParts . slice ( 1 ) . concat ( [ '-u' , scriptPath , input ] ) ;
88- const subprocess = spawn ( pyCmd , pyArgs , {
89- stdio : 'inherit'
90- } ) ;
91-
92- subprocess . on ( 'exit' , ( code ) => {
93- stopSpinner ( ) ;
94- if ( code === 0 ) {
95- console . log ( `\n✅ Analysis complete! Process exited with code ${ code } ` ) ;
96- } else {
97- console . error ( `\n❌ Analysis failed. Process exited with code ${ code } ` ) ;
98- console . error ( '➡️ Please check your Python environment and logs for details.' ) ;
99- }
100- process . exit ( code ) ;
101- } ) ;
102- } else if ( command === 'setup-ml' ) {
103- require ( './scripts/setup-ml' ) ; // install venv, pip install, etc.
104- } else {
105- console . log ( `❌ Unknown command: ${ command } ` ) ;
106- console . log ( '➡️ Use --help to see available commands.' ) ;
107- }
0 commit comments