1+ #!/usr/bin/env node
2+
3+ /**
4+ * ReactPress CLI - Main entry point for all ReactPress commands
5+ * This script allows users to run reactpress commands after installing the package globally
6+ */
7+
8+ const { Command } = require ( 'commander' ) ;
9+ const { spawn } = require ( 'child_process' ) ;
10+ const path = require ( 'path' ) ;
11+ const chalk = require ( 'chalk' ) ;
12+
13+ // Create the CLI program
14+ const program = new Command ( ) ;
15+
16+ // Get the directory where this script is located
17+ const binDir = __dirname ;
18+ const rootDir = path . join ( binDir , '..' ) ;
19+
20+ // Server command
21+ program
22+ . command ( 'server' )
23+ . description ( 'Manage the ReactPress server' )
24+ . option ( 'install' , 'Launch the installation wizard' )
25+ . option ( 'start' , 'Start the ReactPress server' )
26+ . option ( '--pm2' , 'Start server with PM2 process manager' )
27+ . action ( ( options ) => {
28+ const serverScript = path . join ( rootDir , 'scripts' , 'reactpress-server.js' ) ;
29+
30+ let args = [ ] ;
31+ if ( options . install ) {
32+ args . push ( 'install' ) ;
33+ } else if ( options . start ) {
34+ args . push ( 'start' ) ;
35+ }
36+
37+ if ( options . pm2 ) {
38+ args . push ( '--pm2' ) ;
39+ }
40+
41+ const serverProcess = spawn ( 'node' , [ serverScript , ...args ] , {
42+ stdio : 'inherit'
43+ } ) ;
44+
45+ serverProcess . on ( 'error' , ( error ) => {
46+ console . error ( chalk . red ( '[ReactPress CLI] Failed to start server:' ) , error ) ;
47+ process . exit ( 1 ) ;
48+ } ) ;
49+ } ) ;
50+
51+ // Client command
52+ program
53+ . command ( 'client' )
54+ . description ( 'Manage the ReactPress client' )
55+ . option ( '--pm2' , 'Start client with PM2 process manager' )
56+ . action ( ( options ) => {
57+ const clientScript = path . join ( rootDir , 'client' , 'bin' , 'reactpress-client.js' ) ;
58+
59+ let args = [ ] ;
60+ if ( options . pm2 ) {
61+ args . push ( '--pm2' ) ;
62+ }
63+
64+ const clientProcess = spawn ( 'node' , [ clientScript , ...args ] , {
65+ stdio : 'inherit'
66+ } ) ;
67+
68+ clientProcess . on ( 'error' , ( error ) => {
69+ console . error ( chalk . red ( '[ReactPress CLI] Failed to start client:' ) , error ) ;
70+ process . exit ( 1 ) ;
71+ } ) ;
72+ } ) ;
73+
74+ // Set the version from package.json
75+ const packageJson = require ( path . join ( rootDir , 'package.json' ) ) ;
76+ program . version ( packageJson . version ) ;
77+
78+ // Configure help text
79+ program . on ( '--help' , ( ) => {
80+ console . log ( '' ) ;
81+ console . log ( 'For more information, visit: https://github.com/fecommunity/reactpress' ) ;
82+ } ) ;
83+
84+ // Parse the command line arguments
85+ program . parse ( process . argv ) ;
86+
87+ // If no command is provided, show help
88+ if ( ! process . argv . slice ( 2 ) . length ) {
89+ program . outputHelp ( ) ;
90+ }
0 commit comments