@fecommunity/reactpress 2.0.0-beta-4-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +122 -0
- package/LICENSE +21 -0
- package/README.md +195 -0
- package/client/bin/reactpress-client.js +190 -0
- package/package.json +92 -0
- package/scripts/reactpress-cli.js +90 -0
- package/scripts/reactpress-deploy.sh +47 -0
- package/scripts/reactpress-dev.js +39 -0
- package/scripts/reactpress-publish.js +945 -0
- package/scripts/reactpress.js +90 -0
- package/server/bin/reactpress-server.js +203 -0
|
@@ -0,0 +1,90 @@
|
|
|
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,0 +1,203 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ReactPress Server CLI Entry Point
|
|
5
|
+
* This script allows starting the ReactPress server via npx
|
|
6
|
+
* Supports both regular and PM2 startup modes
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const { spawn, spawnSync } = require('child_process');
|
|
12
|
+
|
|
13
|
+
// Capture the original working directory where npx was executed
|
|
14
|
+
// BUT prioritize the REACTPRESS_ORIGINAL_CWD environment variable if it exists
|
|
15
|
+
// This ensures consistency when running via pnpm dev from root directory
|
|
16
|
+
const originalCwd = process.env.REACTPRESS_ORIGINAL_CWD || process.cwd();
|
|
17
|
+
|
|
18
|
+
// Get command line arguments
|
|
19
|
+
const args = process.argv.slice(2);
|
|
20
|
+
const usePM2 = args.includes('--pm2');
|
|
21
|
+
const showHelp = args.includes('--help') || args.includes('-h');
|
|
22
|
+
|
|
23
|
+
// Show help if requested
|
|
24
|
+
if (showHelp) {
|
|
25
|
+
console.log(`
|
|
26
|
+
ReactPress Server - NestJS-based backend API for ReactPress CMS
|
|
27
|
+
|
|
28
|
+
Usage:
|
|
29
|
+
npx @fecommunity/reactpress-server [options]
|
|
30
|
+
|
|
31
|
+
Options:
|
|
32
|
+
--pm2 Start server with PM2 process manager
|
|
33
|
+
--help, -h Show this help message
|
|
34
|
+
|
|
35
|
+
Examples:
|
|
36
|
+
npx @fecommunity/reactpress-server # Start server normally
|
|
37
|
+
npx @fecommunity/reactpress-server --pm2 # Start server with PM2
|
|
38
|
+
npx @fecommunity/reactpress-server --help # Show this help message
|
|
39
|
+
`);
|
|
40
|
+
process.exit(0);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Get the directory where this script is located
|
|
44
|
+
const binDir = __dirname;
|
|
45
|
+
const serverDir = path.join(binDir, '..');
|
|
46
|
+
const distPath = path.join(serverDir, 'dist', 'main.js');
|
|
47
|
+
const ecosystemPath = path.join(serverDir, 'ecosystem.config.js');
|
|
48
|
+
|
|
49
|
+
// Function to check if PM2 is installed
|
|
50
|
+
function isPM2Installed() {
|
|
51
|
+
try {
|
|
52
|
+
require.resolve('pm2');
|
|
53
|
+
return true;
|
|
54
|
+
} catch (e) {
|
|
55
|
+
// Check if PM2 is installed globally
|
|
56
|
+
try {
|
|
57
|
+
spawnSync('pm2', ['--version'], { stdio: 'ignore' });
|
|
58
|
+
return true;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Function to install PM2
|
|
66
|
+
function installPM2() {
|
|
67
|
+
console.log('[ReactPress Server] Installing PM2...');
|
|
68
|
+
const installResult = spawnSync('npm', ['install', 'pm2', '--no-save'], {
|
|
69
|
+
stdio: 'inherit',
|
|
70
|
+
cwd: serverDir
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
if (installResult.status !== 0) {
|
|
74
|
+
console.error('[ReactPress Server] Failed to install PM2');
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Function to start with PM2
|
|
82
|
+
function startWithPM2() {
|
|
83
|
+
// Check if PM2 is installed
|
|
84
|
+
if (!isPM2Installed()) {
|
|
85
|
+
// Try to install PM2
|
|
86
|
+
if (!installPM2()) {
|
|
87
|
+
console.error('[ReactPress Server] Cannot start with PM2');
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Check if the server is built
|
|
93
|
+
if (!fs.existsSync(distPath)) {
|
|
94
|
+
console.log('[ReactPress Server] Server not built yet. Building...');
|
|
95
|
+
|
|
96
|
+
// Try to build the server
|
|
97
|
+
const buildResult = spawnSync('npm', ['run', 'build'], {
|
|
98
|
+
stdio: 'inherit',
|
|
99
|
+
cwd: serverDir
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
if (buildResult.status !== 0) {
|
|
103
|
+
console.error('[ReactPress Server] Failed to build server');
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
console.log('[ReactPress Server] Starting with PM2...');
|
|
109
|
+
|
|
110
|
+
// Use ecosystem.config.js if it exists, otherwise use direct command
|
|
111
|
+
let pm2Command = 'pm2';
|
|
112
|
+
try {
|
|
113
|
+
// Try to resolve PM2 path
|
|
114
|
+
pm2Command = path.join(serverDir, 'node_modules', '.bin', 'pm2');
|
|
115
|
+
if (!fs.existsSync(pm2Command)) {
|
|
116
|
+
pm2Command = 'pm2';
|
|
117
|
+
}
|
|
118
|
+
} catch (e) {
|
|
119
|
+
pm2Command = 'pm2';
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Check if ecosystem.config.js exists
|
|
123
|
+
if (fs.existsSync(ecosystemPath)) {
|
|
124
|
+
const pm2 = spawn(pm2Command, ['start', ecosystemPath], {
|
|
125
|
+
stdio: 'inherit',
|
|
126
|
+
cwd: serverDir
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
pm2.on('close', (code) => {
|
|
130
|
+
console.log(`[ReactPress Server] PM2 process exited with code ${code}`);
|
|
131
|
+
process.exit(code);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
pm2.on('error', (error) => {
|
|
135
|
+
console.error('[ReactPress Server] Failed to start with PM2:', error);
|
|
136
|
+
process.exit(1);
|
|
137
|
+
});
|
|
138
|
+
} else {
|
|
139
|
+
// Fallback to direct start
|
|
140
|
+
const pm2 = spawn(pm2Command, ['start', distPath, '--name', 'reactpress-server'], {
|
|
141
|
+
stdio: 'inherit',
|
|
142
|
+
cwd: serverDir
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
pm2.on('close', (code) => {
|
|
146
|
+
console.log(`[ReactPress Server] PM2 process exited with code ${code}`);
|
|
147
|
+
process.exit(code);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
pm2.on('error', (error) => {
|
|
151
|
+
console.error('[ReactPress Server] Failed to start with PM2:', error);
|
|
152
|
+
process.exit(1);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Function to start with regular Node.js
|
|
158
|
+
function startWithNode() {
|
|
159
|
+
// Check if the server is built
|
|
160
|
+
if (!fs.existsSync(distPath)) {
|
|
161
|
+
console.log('[ReactPress Server] Server not built yet. Building...');
|
|
162
|
+
|
|
163
|
+
// Try to build the server
|
|
164
|
+
const buildResult = spawnSync('npm', ['run', 'build'], {
|
|
165
|
+
stdio: 'inherit',
|
|
166
|
+
cwd: serverDir
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
if (buildResult.status !== 0) {
|
|
170
|
+
console.error('[ReactPress Server] Failed to build server');
|
|
171
|
+
process.exit(1);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ONLY set the environment variable if it's not already set
|
|
176
|
+
// This preserves the value set by set-env.js when running pnpm dev from root
|
|
177
|
+
if (!process.env.REACTPRESS_ORIGINAL_CWD) {
|
|
178
|
+
process.env.REACTPRESS_ORIGINAL_CWD = originalCwd;
|
|
179
|
+
} else {
|
|
180
|
+
console.log(`[ReactPress Server] Using existing REACTPRESS_ORIGINAL_CWD: ${process.env.REACTPRESS_ORIGINAL_CWD}`);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Change to the server directory
|
|
184
|
+
process.chdir(serverDir);
|
|
185
|
+
|
|
186
|
+
// Set environment variables
|
|
187
|
+
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
|
|
188
|
+
|
|
189
|
+
// Import and run the server
|
|
190
|
+
try {
|
|
191
|
+
require(distPath);
|
|
192
|
+
} catch (error) {
|
|
193
|
+
console.error('[ReactPress Server] Failed to start server:', error);
|
|
194
|
+
process.exit(1);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Main execution
|
|
199
|
+
if (usePM2) {
|
|
200
|
+
startWithPM2();
|
|
201
|
+
} else {
|
|
202
|
+
startWithNode();
|
|
203
|
+
}
|