@fecommunity/reactpress-server 1.0.0-beta.2 → 1.0.0-beta.20

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.
@@ -1,302 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { program } = require('commander');
4
- const { execSync } = require('child_process');
5
- const path = require('path');
6
- const fs = require('fs');
7
- const chalk = require('chalk');
8
- const inquirer = require('inquirer');
9
-
10
- program
11
- .name('@fecommunity/reactpress-server')
12
- .description('ReactPress Server CLI')
13
- .version('1.0.0');
14
-
15
- // Init command - 初始化服务器配置
16
- program
17
- .command('init')
18
- .description('Initialize ReactPress server configuration')
19
- .option('-d, --database <type>', 'Database type (mysql|postgres)', 'mysql')
20
- .option('-p, --port <port>', 'Server port', '3002')
21
- .option('--skip-db-setup', 'Skip database setup')
22
- .action(async (options) => {
23
- console.log(chalk.blue('🚀 Initializing ReactPress Server...\n'));
24
-
25
- const cwd = process.cwd();
26
- const envPath = path.join(cwd, '.env');
27
-
28
- // 检查.env文件是否已存在
29
- if (fs.existsSync(envPath)) {
30
- const { overwrite } = await inquirer.prompt([
31
- {
32
- type: 'confirm',
33
- name: 'overwrite',
34
- message: 'Configuration file (.env) already exists. Overwrite?',
35
- default: false
36
- }
37
- ]);
38
-
39
- if (!overwrite) {
40
- console.log(chalk.yellow('⚠️ Initialization cancelled.'));
41
- process.exit(0);
42
- }
43
- }
44
-
45
- // 收集配置信息
46
- console.log(chalk.cyan('📋 Please provide the following configuration:\n'));
47
-
48
- const config = await inquirer.prompt([
49
- {
50
- type: 'input',
51
- name: 'DB_HOST',
52
- message: 'Database host:',
53
- default: 'localhost'
54
- },
55
- {
56
- type: 'input',
57
- name: 'DB_PORT',
58
- message: 'Database port:',
59
- default: options.database === 'postgres' ? '5432' : '3306'
60
- },
61
- {
62
- type: 'input',
63
- name: 'DB_USERNAME',
64
- message: 'Database username:',
65
- default: 'root'
66
- },
67
- {
68
- type: 'password',
69
- name: 'DB_PASSWORD',
70
- message: 'Database password:',
71
- mask: '*'
72
- },
73
- {
74
- type: 'input',
75
- name: 'DB_DATABASE',
76
- message: 'Database name:',
77
- default: 'reactpress'
78
- },
79
- {
80
- type: 'input',
81
- name: 'SERVER_PORT',
82
- message: 'Server port:',
83
- default: options.port
84
- },
85
- {
86
- type: 'input',
87
- name: 'JWT_SECRET',
88
- message: 'JWT secret (leave empty to generate):',
89
- default: ''
90
- },
91
- {
92
- type: 'input',
93
- name: 'ADMIN_USER',
94
- message: 'Admin username:',
95
- default: 'admin'
96
- },
97
- {
98
- type: 'password',
99
- name: 'ADMIN_PASSWD',
100
- message: 'Admin password:',
101
- default: 'admin',
102
- mask: '*'
103
- }
104
- ]);
105
-
106
- // 如果没有提供JWT密钥则生成一个
107
- if (!config.JWT_SECRET) {
108
- config.JWT_SECRET = require('crypto').randomBytes(32).toString('hex');
109
- console.log(chalk.green('🔐 Generated JWT secret'));
110
- }
111
-
112
- // 创建.env文件
113
- const envContent = `# ReactPress Server Configuration
114
- # Generated on ${new Date().toISOString()}
115
-
116
- # Database Configuration
117
- DB_TYPE=${options.database}
118
- DB_HOST=${config.DB_HOST}
119
- DB_PORT=${config.DB_PORT}
120
- DB_USERNAME=${config.DB_USERNAME}
121
- DB_PASSWORD=${config.DB_PASSWORD}
122
- DB_DATABASE=${config.DB_DATABASE}
123
-
124
- # Server Configuration
125
- SERVER_PORT=${config.SERVER_PORT}
126
- SERVER_API_PREFIX=/api
127
-
128
- # Security
129
- JWT_SECRET=${config.JWT_SECRET}
130
- ADMIN_USER=${config.ADMIN_USER}
131
- ADMIN_PASSWD=${config.ADMIN_PASSWD}
132
-
133
- # Environment
134
- NODE_ENV=development
135
- `;
136
-
137
- fs.writeFileSync(envPath, envContent);
138
- console.log(chalk.green('✅ Configuration saved to .env file'));
139
-
140
- if (!options.skipDbSetup) {
141
- console.log(chalk.yellow('\n🗄️ Setting up database...'));
142
- console.log(chalk.gray(`Please ensure your ${options.database} server is running and create the database:`));
143
- console.log(chalk.cyan(`CREATE DATABASE ${config.DB_DATABASE};`));
144
- console.log(chalk.gray('Then run: npx @reactpress/server start'));
145
- }
146
-
147
- console.log(chalk.green('\n🎉 ReactPress Server initialized successfully!'));
148
- console.log(chalk.cyan('\nNext steps:'));
149
- console.log(chalk.gray('1. Start the server: npx @fecommunity/reactpress-server start'));
150
- console.log(chalk.gray('2. Visit API: http://localhost:' + config.SERVER_PORT + '/api'));
151
- console.log(chalk.gray('3. API docs: http://localhost:' + config.SERVER_PORT + '/api (Swagger UI)'));
152
- });
153
-
154
- // Start command - 启动服务器
155
- program
156
- .command('start')
157
- .description('Start ReactPress server')
158
- .option('-p, --port <port>', 'Server port')
159
- .option('-d, --dev', 'Start in development mode')
160
- .option('--watch', 'Watch for file changes (dev mode)')
161
- .action(async (options) => {
162
- console.log(chalk.blue('🚀 Starting ReactPress Server...\n'));
163
-
164
- const cwd = process.cwd();
165
- const envPath = path.join(cwd, '.env');
166
-
167
- // 检查.env文件是否存在
168
- if (!fs.existsSync(envPath)) {
169
- console.log(chalk.red('❌ Configuration file (.env) not found!'));
170
- console.log(chalk.yellow('Please run: npx @fecommunity/reactpress-server init'));
171
- process.exit(1);
172
- }
173
-
174
- // 检查是否在项目根目录(有server目录)
175
- const serverPath = path.join(cwd, 'server');
176
- const hasServerDir = fs.existsSync(serverPath);
177
-
178
- let serverMainPath;
179
- if (hasServerDir) {
180
- // 在项目根目录,使用相对路径
181
- serverMainPath = path.join(serverPath, 'dist', 'main.js');
182
- const packageDir = serverPath;
183
-
184
- // 检查构建文件是否存在
185
- if (!fs.existsSync(serverMainPath)) {
186
- console.log(chalk.yellow('⚠️ Built server not found, building...'));
187
- try {
188
- execSync('pnpm run build:server', { cwd: cwd, stdio: 'inherit' });
189
- } catch (error) {
190
- console.log(chalk.red('❌ Build failed'));
191
- process.exit(1);
192
- }
193
- }
194
- } else {
195
- // 可能在独立安装的@reactpress/server包中
196
- try {
197
- const serverPackagePath = require.resolve('@fecommunity/reactpress-server/package.json');
198
- const serverPackageDir = path.dirname(serverPackagePath);
199
- serverMainPath = path.join(serverPackageDir, 'dist', 'main.js');
200
- } catch (error) {
201
- console.log(chalk.red('❌ ReactPress server package not found!'));
202
- console.log(chalk.yellow('Please install: npm install @fecommunity/reactpress-server'));
203
- process.exit(1);
204
- }
205
- }
206
-
207
- // 设置环境变量
208
- const env = {
209
- ...process.env,
210
- NODE_ENV: options.dev ? 'development' : 'production'
211
- };
212
-
213
- if (options.port) {
214
- env.SERVER_PORT = options.port;
215
- }
216
-
217
- try {
218
- if (options.dev || options.watch) {
219
- console.log(chalk.yellow('🔄 Starting in development mode...'));
220
- if (hasServerDir) {
221
- execSync('pnpm run dev:server', {
222
- cwd: cwd,
223
- stdio: 'inherit',
224
- env
225
- });
226
- } else {
227
- console.log(chalk.yellow('⚠️ Development mode requires server source code'));
228
- console.log(chalk.cyan('Starting in production mode instead...'));
229
- execSync(`node ${serverMainPath}`, {
230
- cwd: process.cwd(),
231
- stdio: 'inherit',
232
- env
233
- });
234
- }
235
- } else {
236
- console.log(chalk.green('🌟 Starting in production mode...'));
237
- execSync(`node ${serverMainPath}`, {
238
- cwd: process.cwd(),
239
- stdio: 'inherit',
240
- env
241
- });
242
- }
243
- } catch (error) {
244
- console.log(chalk.red('❌ Failed to start server'));
245
- process.exit(1);
246
- }
247
- });
248
-
249
- // Build command - 构建服务器
250
- program
251
- .command('build')
252
- .description('Build ReactPress server')
253
- .action(() => {
254
- console.log(chalk.blue('🔨 Building ReactPress Server...\n'));
255
-
256
- const cwd = process.cwd();
257
- const serverPath = path.join(cwd, 'server');
258
-
259
- if (!fs.existsSync(serverPath)) {
260
- console.log(chalk.red('❌ Server directory not found!'));
261
- console.log(chalk.yellow('This command should be run from the project root directory.'));
262
- process.exit(1);
263
- }
264
-
265
- try {
266
- execSync('pnpm run build:server', {
267
- cwd: cwd,
268
- stdio: 'inherit'
269
- });
270
- console.log(chalk.green('✅ Build completed successfully!'));
271
- } catch (error) {
272
- console.log(chalk.red('❌ Build failed'));
273
- process.exit(1);
274
- }
275
- });
276
-
277
- // Dev command - 开发模式启动
278
- program
279
- .command('dev')
280
- .description('Start server in development mode')
281
- .option('-p, --port <port>', 'Server port')
282
- .action((options) => {
283
- console.log(chalk.blue('🔄 Starting ReactPress Server in development mode...\n'));
284
-
285
- // 调用start命令的dev模式
286
- const args = ['start', '--dev'];
287
- if (options.port) {
288
- args.push('--port', options.port);
289
- }
290
-
291
- // 重新调用当前脚本
292
- const child = require('child_process').spawn('node', [__filename, ...args], {
293
- stdio: 'inherit',
294
- env: process.env
295
- });
296
-
297
- child.on('exit', (code) => {
298
- process.exit(code);
299
- });
300
- });
301
-
302
- program.parse();
@@ -1,10 +0,0 @@
1
- interface BootstrapOptions {
2
- port?: number;
3
- apiPrefix?: string;
4
- enableSwagger?: boolean;
5
- enableCors?: boolean;
6
- staticPath?: string;
7
- openBrowser?: boolean;
8
- }
9
- export declare function bootstrap(options?: BootstrapOptions): Promise<import("@nestjs/common").INestApplication>;
10
- export {};
package/dist/bootstrap.js DELETED
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bootstrap = void 0;
4
- const core_1 = require("@nestjs/core");
5
- const swagger_1 = require("@nestjs/swagger");
6
- const bodyParser = require("body-parser");
7
- const compression = require("compression");
8
- const express = require("express");
9
- const rateLimit = require("express-rate-limit");
10
- const helmet = require("helmet");
11
- const path_1 = require("path");
12
- const app_module_1 = require("./app.module");
13
- const http_exception_filter_1 = require("./filters/http-exception.filter");
14
- const transform_interceptor_1 = require("./interceptors/transform.interceptor");
15
- async function bootstrap(options = {}) {
16
- const app = await core_1.NestFactory.create(app_module_1.AppModule);
17
- const configService = app.get('ConfigService');
18
- const { port = configService.get('SERVER_PORT', 3002), apiPrefix = configService.get('SERVER_API_PREFIX', '/api'), enableSwagger = true, enableCors = true, staticPath = path_1.join(__dirname, '../public'), openBrowser = false } = options;
19
- if (enableCors) {
20
- app.enableCors();
21
- }
22
- app.setGlobalPrefix(apiPrefix);
23
- app.use(rateLimit({
24
- windowMs: 60 * 1000,
25
- max: 10000,
26
- }));
27
- app.use('/public', express.static(staticPath));
28
- app.use(compression());
29
- app.use(helmet());
30
- app.useGlobalInterceptors(new transform_interceptor_1.TransformInterceptor());
31
- app.useGlobalFilters(new http_exception_filter_1.HttpExceptionFilter());
32
- app.use(bodyParser.json({ limit: '10mb' }));
33
- app.use(bodyParser.urlencoded({ limit: '10mb', extended: true }));
34
- if (enableSwagger) {
35
- const swaggerConfig = new swagger_1.DocumentBuilder()
36
- .setTitle('ReactPress Open Api')
37
- .setDescription('ReactPress Open Api Document')
38
- .setVersion('1.0')
39
- .build();
40
- const document = swagger_1.SwaggerModule.createDocument(app, swaggerConfig);
41
- swagger_1.SwaggerModule.setup('api', app, document);
42
- }
43
- await app.listen(port);
44
- if (openBrowser) {
45
- try {
46
- const open = require('open');
47
- await open(`http://localhost:${port}${apiPrefix}`);
48
- }
49
- catch (error) {
50
- console.log(`[ReactPress] Could not open browser. Visit: http://localhost:${port}${apiPrefix}`);
51
- }
52
- }
53
- console.log(`[ReactPress] 服务启动成功 - Port: ${port}`);
54
- return app;
55
- }
56
- exports.bootstrap = bootstrap;
57
- //# sourceMappingURL=bootstrap.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":";;;AAAA,uCAA2C;AAC3C,6CAAiE;AACjE,0CAA0C;AAC1C,2CAA2C;AAC3C,mCAAmC;AACnC,gDAAgD;AAChD,iCAAiC;AACjC,+BAA4B;AAE5B,6CAAyC;AACzC,2EAAsE;AACtE,gFAA4E;AAWrE,KAAK,UAAU,SAAS,CAAC,UAA4B,EAAE;IAC5D,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,MAAM,CAAC,sBAAS,CAAC,CAAC;IAChD,MAAM,aAAa,GAAG,GAAG,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IA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