@solidxai/core 0.1.6-beta.14 → 0.1.6-beta.15

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.
@@ -10,4 +10,5 @@ export interface SolidBootstrapOptions {
10
10
  permissionsPolicyOverrides?: Partial<PermissionsPolicyConfig>;
11
11
  }
12
12
  export declare function bootstrapSolidApp(appModuleFactory: () => Promise<any>, options?: SolidBootstrapOptions): Promise<void>;
13
+ export declare function bootstrapSolidCli(appModuleFactory: () => Promise<any>): Promise<void>;
13
14
  //# sourceMappingURL=bootstrap.helper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/bootstrap.helper.ts"],"names":[],"mappings":"AASA,OAAO,EAAmE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAG7H,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IAEpC,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,OAAO,CAAC,EAAE,mBAAmB,GAAG,KAAK,CAAC;IAEtC,0BAA0B,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,CAAC;CAC/D;AAcD,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EACpC,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,IAAI,CAAC,CAsGf"}
1
+ {"version":3,"file":"bootstrap.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/bootstrap.helper.ts"],"names":[],"mappings":"AAYA,OAAO,EAAmE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAyB7H,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IAEpC,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,OAAO,CAAC,EAAE,mBAAmB,GAAG,KAAK,CAAC;IAEtC,0BAA0B,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,CAAC;CAC/D;AAcD,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,EACpC,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,IAAI,CAAC,CAgGf;AAgBD,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,GACnC,OAAO,CAAC,IAAI,CAAC,CAwCf"}
@@ -4,23 +4,36 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.bootstrapSolidApp = bootstrapSolidApp;
7
+ exports.bootstrapSolidCli = bootstrapSolidCli;
7
8
  const common_1 = require("@nestjs/common");
8
9
  const core_1 = require("@nestjs/core");
9
10
  const swagger_1 = require("@nestjs/swagger");
10
11
  const helmet_1 = __importDefault(require("helmet"));
11
12
  const qs_1 = __importDefault(require("qs"));
13
+ const fs_1 = require("fs");
14
+ const path_1 = require("path");
12
15
  const nest_winston_1 = require("nest-winston");
16
+ const nest_commander_1 = require("nest-commander");
13
17
  const wrap_response_interceptor_1 = require("../interceptors/wrap-response.interceptor");
14
18
  const cors_helper_1 = require("./cors.helper");
15
19
  const security_helper_1 = require("./security.helper");
16
20
  const environment_helper_1 = require("./environment.helper");
17
- async function bootstrapSolidApp(appModuleFactory, options = {}) {
21
+ function registerGlobalProcessHandlers() {
18
22
  process.on('unhandledRejection', (reason, promise) => {
19
23
  console.error('Unhandled Rejection at:', promise, 'reason:', reason);
20
24
  });
21
25
  process.on('uncaughtException', (err) => {
22
26
  console.error('Uncaught Exception thrown:', err);
23
27
  });
28
+ process.on('warning', (warning) => {
29
+ if (warning.name === 'DeprecationWarning' && (warning.message.includes('client.query()') || warning.message.includes('punycode'))) {
30
+ return;
31
+ }
32
+ console.warn(warning);
33
+ });
34
+ }
35
+ async function bootstrapSolidApp(appModuleFactory, options = {}) {
36
+ registerGlobalProcessHandlers();
24
37
  const { globalPrefix = 'api', swagger = {}, permissionsPolicyOverrides = {} } = options;
25
38
  const appModule = await appModuleFactory();
26
39
  const app = await core_1.NestFactory.create(appModule);
@@ -83,4 +96,37 @@ async function bootstrapSolidApp(appModuleFactory, options = {}) {
83
96
  types.setTypeParser(types.builtins.INT8, (val) => parseInt(val));
84
97
  await app.listen(port);
85
98
  }
99
+ async function bootstrapSolidCli(appModuleFactory) {
100
+ registerGlobalProcessHandlers();
101
+ process.on('exit', (code) => {
102
+ if (code !== 0) {
103
+ console.error(`Exiting with error status code: ${code}`);
104
+ }
105
+ });
106
+ const packageJsonPath = (0, path_1.resolve)(process.cwd(), 'package.json');
107
+ if (!(0, fs_1.existsSync)(packageJsonPath)) {
108
+ console.error('Does not seem to be a valid solid-api project.');
109
+ console.error('Exit reason: missing package.json in the current directory.');
110
+ process.exit(1);
111
+ }
112
+ const showLogs = process.argv.includes('--verbose') || process.argv.includes('-v');
113
+ for (const flag of ['--verbose', '-v']) {
114
+ const idx = process.argv.indexOf(flag);
115
+ if (idx !== -1)
116
+ process.argv.splice(idx, 1);
117
+ }
118
+ const appModule = await appModuleFactory();
119
+ process.env.SOLID_CLI_RUNNING = 'true';
120
+ const app = await nest_commander_1.CommandFactory.createWithoutRunning(appModule, {
121
+ logger: showLogs ? ['debug', 'error', 'fatal', 'log', 'verbose', 'warn'] : false,
122
+ });
123
+ try {
124
+ await nest_commander_1.CommandFactory.runApplication(app);
125
+ }
126
+ catch (e) {
127
+ console.error('CLI exited abruptly due to an error:', e);
128
+ process.exit(1);
129
+ }
130
+ process.exit(0);
131
+ }
86
132
  //# sourceMappingURL=bootstrap.helper.js.map
@@ -1 +1 @@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ggerModule } from '@nestjs/swagger';\nimport { NextFunction, Request, Response } from 'express';\nimport helmet from 'helmet';\nimport qs from 'qs';\nimport { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';\nimport { WrapResponseInterceptor } from '../interceptors/wrap-response.interceptor';\nimport { buildDefaultCorsOptions } from './cors.helper';\nimport { buildDefaultSecurityHeaderOptions, buildPermissionsPolicyHeader, PermissionsPolicyConfig } from './security.helper';\nimport { parseBooleanEnv } from './environment.helper';\n\nexport interface SolidSwaggerOptions {\n title?: string;\n description?: string;\n version?: string;\n}\n\nexport interface SolidBootstrapOptions {\n /** Global API prefix. Defaults to 'api'. Set to '' to disable. */\n globalPrefix?: string;\n /** Swagger configuration. Set to false to disable Swagger entirely. */\n swagger?: SolidSwaggerOptions | false;\n /** Permissions-Policy header overrides (merged with defaults). */\n permissionsPolicyOverrides?: Partial<PermissionsPolicyConfig>;\n}\n\n/**\n * Bootstraps a SolidX NestJS application with sensible defaults:\n * security headers, CORS, Winston logger, ValidationPipe,\n * WrapResponseInterceptor, qs deep query parsing, Swagger, and the\n * pg BIGINT type parser.\n *\n * @example\n * // main.ts\n * bootstrapSolidApp(() => AppModule.forRoot(), {\n * swagger: { title: 'My API', description: 'My API description' },\n * });\n */\nexport async function bootstrapSolidApp(\n appModuleFactory: () => Promise<any>,\n options: SolidBootstrapOptions = {},\n): Promise<void> {\n process.on('unhandledRejection', (reason, promise) => {\n console.error('Unhandled Rejection at:', promise, 'reason:', reason);\n });\n\n process.on('uncaughtException', (err) => {\n console.error('Uncaught Exception thrown:', err);\n });\n\n const { globalPrefix = 'api', swagger = {}, permissionsPolicyOverrides = {} } = options;\n\n const appModule = await appModuleFactory();\n const app = await NestFactory.create(appModule);\n\n const apiEnabled = parseBooleanEnv('API_ENABLED', true);\n\n if (!apiEnabled) {\n await app.init();\n app\n .get(WINSTON_MODULE_NEST_PROVIDER)\n .log('API server disabled via API_ENABLED=false. Skipping HTTP listen.', 'Bootstrap');\n return;\n }\n\n // Health check at root path\n const server = app.getHttpAdapter().getInstance();\n server.get('/', (_req, res) => res.status(200).send('SOLID OK'));\n\n // Security headers\n app.use(helmet(buildDefaultSecurityHeaderOptions()));\n\n // Permissions-Policy header\n app.use((_req: Request, res: Response, next: NextFunction) => {\n res.setHeader('Permissions-Policy', buildPermissionsPolicyHeader(permissionsPolicyOverrides));\n next();\n });\n\n // Winston logger\n app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));\n\n const port = process.env.PORT || 3000;\n\n if (globalPrefix) {\n app.setGlobalPrefix(globalPrefix);\n }\n\n // qs-based deep query parsing (dot notation, nested objects, arrays)\n app.use((req: Request, _res: Response, next: NextFunction) => {\n if (req.query) {\n req.query = qs.parse(req.url.split('?')[1], {\n allowDots: true,\n depth: 10,\n arrayLimit: 100,\n });\n }\n next();\n });\n\n // Global ValidationPipe\n app.useGlobalPipes(\n new ValidationPipe({\n transform: true,\n transformOptions: { enableImplicitConversion: true },\n }),\n );\n\n // Swagger\n if (swagger !== false) {\n const { title = 'Solid Starters', description = 'Solid Starters API', version = '1.0' } = swagger;\n const swaggerConfig = new DocumentBuilder()\n .setTitle(title)\n .setDescription(description)\n .setVersion(version)\n .setExternalDoc('Postman Collection', '/docs-json')\n .addBearerAuth(\n {\n description: 'Please enter token in following format: Bearer <JWT>',\n name: 'Authorization',\n bearerFormat: 'Bearer',\n scheme: 'Bearer',\n type: 'http',\n in: 'Header',\n },\n 'jwt',\n )\n .build();\n const document = SwaggerModule.createDocument(app, swaggerConfig);\n SwaggerModule.setup('/docs', app, document);\n }\n\n // Global interceptor\n app.useGlobalInterceptors(new WrapResponseInterceptor());\n\n // CORS\n app.enableCors(buildDefaultCorsOptions());\n\n // Fix pg returning BIGINT columns as strings\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const types = require('pg').types;\n types.setTypeParser(types.builtins.INT8, (val: string) => parseInt(val));\n\n await app.listen(port);\n}\n"]}
1
+ {"version":3,"file":"bootstrap.helper.js","sourceRoot":"","sources":["../../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AK,CAAC,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,gBAAgB,EAAE,CAAC;IAC3C,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,MAAM,CAAC;IAGvC,MAAM,GAAG,GAAG,MAAM,+BAAc,CAAC,oBAAoB,CAAC,SAAS,EAAE;QAC/D,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK;KACjF,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,MAAM,+BAAc,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IAC3C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,sCAAsC,EAAE,CAAC,CAAC,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC","sourcesContent":["import { ValidationPipe } from '@nestjs/common';\nimport { NestFactory } from '@nestjs/core';\nimport { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';\nimport { NextFunction, Request, Response } from 'express';\nimport helmet from 'helmet';\nimport qs from 'qs';\nimport { existsSync } from 'fs';\nimport { resolve } from 'path';\nimport { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';\nimport { CommandFactory } from 'nest-commander';\nimport { WrapResponseInterceptor } from '../interceptors/wrap-response.interceptor';\nimport { buildDefaultCorsOptions } from './cors.helper';\nimport { buildDefaultSecurityHeaderOptions, buildPermissionsPolicyHeader, PermissionsPolicyConfig } from './security.helper';\nimport { parseBooleanEnv } from './environment.helper';\n\n// ---- Shared process handlers ----\n\nfunction registerGlobalProcessHandlers() {\n process.on('unhandledRejection', (reason, promise) => {\n console.error('Unhandled Rejection at:', promise, 'reason:', reason);\n });\n\n process.on('uncaughtException', (err) => {\n console.error('Uncaught Exception thrown:', err);\n });\n\n // Suppress pg deprecation warning caused by TypeORM's internal query scheduling\n process.on('warning', (warning) => {\n if (warning.name === 'DeprecationWarning' && (warning.message.includes('client.query()') || warning.message.includes('punycode'))) {\n return;\n }\n console.warn(warning);\n });\n}\n\n// ---- HTTP server bootstrap ----\n\nexport interface SolidSwaggerOptions {\n title?: string;\n description?: string;\n version?: string;\n}\n\nexport interface SolidBootstrapOptions {\n /** Global API prefix. Defaults to 'api'. Set to '' to disable. */\n globalPrefix?: string;\n /** Swagger configuration. Set to false to disable Swagger entirely. */\n swagger?: SolidSwaggerOptions | false;\n /** Permissions-Policy header overrides (merged with defaults). */\n permissionsPolicyOverrides?: Partial<PermissionsPolicyConfig>;\n}\n\n/**\n * Bootstraps a SolidX NestJS HTTP application with sensible defaults:\n * security headers, CORS, Winston logger, ValidationPipe,\n * WrapResponseInterceptor, qs deep query parsing, Swagger, and the\n * pg BIGINT type parser.\n *\n * @example\n * // main.ts\n * bootstrapSolidApp(() => AppModule.forRoot(), {\n * swagger: { title: 'My API', description: 'My API description' },\n * });\n */\nexport async function bootstrapSolidApp(\n appModuleFactory: () => Promise<any>,\n options: SolidBootstrapOptions = {},\n): Promise<void> {\n registerGlobalProcessHandlers();\n\n const { globalPrefix = 'api', swagger = {}, permissionsPolicyOverrides = {} } = options;\n\n const appModule = await appModuleFactory();\n const app = await NestFactory.create(appModule);\n\n const apiEnabled = parseBooleanEnv('API_ENABLED', true);\n\n if (!apiEnabled) {\n await app.init();\n app\n .get(WINSTON_MODULE_NEST_PROVIDER)\n .log('API server disabled via API_ENABLED=false. Skipping HTTP listen.', 'Bootstrap');\n return;\n }\n\n // Health check at root path\n const server = app.getHttpAdapter().getInstance();\n server.get('/', (_req, res) => res.status(200).send('SOLID OK'));\n\n // Security headers\n app.use(helmet(buildDefaultSecurityHeaderOptions()));\n\n // Permissions-Policy header\n app.use((_req: Request, res: Response, next: NextFunction) => {\n res.setHeader('Permissions-Policy', buildPermissionsPolicyHeader(permissionsPolicyOverrides));\n next();\n });\n\n // Winston logger\n app.useLogger(app.get(WINSTON_MODULE_NEST_PROVIDER));\n\n const port = process.env.PORT || 3000;\n\n if (globalPrefix) {\n app.setGlobalPrefix(globalPrefix);\n }\n\n // qs-based deep query parsing (dot notation, nested objects, arrays)\n app.use((req: Request, _res: Response, next: NextFunction) => {\n if (req.query) {\n req.query = qs.parse(req.url.split('?')[1], {\n allowDots: true,\n depth: 10,\n arrayLimit: 100,\n });\n }\n next();\n });\n\n // Global ValidationPipe\n app.useGlobalPipes(\n new ValidationPipe({\n transform: true,\n transformOptions: { enableImplicitConversion: true },\n }),\n );\n\n // Swagger\n if (swagger !== false) {\n const { title = 'Solid Starters', description = 'Solid Starters API', version = '1.0' } = swagger;\n const swaggerConfig = new DocumentBuilder()\n .setTitle(title)\n .setDescription(description)\n .setVersion(version)\n .setExternalDoc('Postman Collection', '/docs-json')\n .addBearerAuth(\n {\n description: 'Please enter token in following format: Bearer <JWT>',\n name: 'Authorization',\n bearerFormat: 'Bearer',\n scheme: 'Bearer',\n type: 'http',\n in: 'Header',\n },\n 'jwt',\n )\n .build();\n const document = SwaggerModule.createDocument(app, swaggerConfig);\n SwaggerModule.setup('/docs', app, document);\n }\n\n // Global interceptor\n app.useGlobalInterceptors(new WrapResponseInterceptor());\n\n // CORS\n app.enableCors(buildDefaultCorsOptions());\n\n // Fix pg returning BIGINT columns as strings\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const types = require('pg').types;\n types.setTypeParser(types.builtins.INT8, (val: string) => parseInt(val));\n\n await app.listen(port);\n}\n\n// ---- CLI bootstrap ----\n\n/**\n * Bootstraps a SolidX NestJS CLI application using nest-commander.\n * Handles verbose flag stripping, project root validation, and clean process exit.\n *\n * @example\n * // main-cli.ts\n * #!/usr/bin/env node\n * import { bootstrapSolidCli } from '@solidxai/core';\n * import { AppModule } from './app.module';\n *\n * bootstrapSolidCli(() => AppModule.forRoot());\n */\nexport async function bootstrapSolidCli(\n appModuleFactory: () => Promise<any>,\n): Promise<void> {\n registerGlobalProcessHandlers();\n\n process.on('exit', (code) => {\n if (code !== 0) {\n console.error(`Exiting with error status code: ${code}`);\n }\n });\n\n // Validate that cwd is a valid Solid API project\n const packageJsonPath = resolve(process.cwd(), 'package.json');\n if (!existsSync(packageJsonPath)) {\n console.error('Does not seem to be a valid solid-api project.');\n console.error('Exit reason: missing package.json in the current directory.');\n process.exit(1);\n }\n\n // Strip --verbose / -v before nest-commander processes argv\n const showLogs = process.argv.includes('--verbose') || process.argv.includes('-v');\n for (const flag of ['--verbose', '-v']) {\n const idx = process.argv.indexOf(flag);\n if (idx !== -1) process.argv.splice(idx, 1);\n }\n\n const appModule = await appModuleFactory();\n process.env.SOLID_CLI_RUNNING = 'true';\n\n // @ts-ignore\n const app = await CommandFactory.createWithoutRunning(appModule, {\n logger: showLogs ? ['debug', 'error', 'fatal', 'log', 'verbose', 'warn'] : false,\n });\n\n try {\n await CommandFactory.runApplication(app);\n } catch (e) {\n console.error('CLI exited abruptly due to an error:', e);\n process.exit(1);\n }\n\n process.exit(0);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidxai/core",
3
- "version": "0.1.6-beta.14",
3
+ "version": "0.1.6-beta.15",
4
4
  "description": "This module is a NestJS module containing all the required core providers required by a Solid application",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -4,12 +4,37 @@ import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
4
4
  import { NextFunction, Request, Response } from 'express';
5
5
  import helmet from 'helmet';
6
6
  import qs from 'qs';
7
+ import { existsSync } from 'fs';
8
+ import { resolve } from 'path';
7
9
  import { WINSTON_MODULE_NEST_PROVIDER } from 'nest-winston';
10
+ import { CommandFactory } from 'nest-commander';
8
11
  import { WrapResponseInterceptor } from '../interceptors/wrap-response.interceptor';
9
12
  import { buildDefaultCorsOptions } from './cors.helper';
10
13
  import { buildDefaultSecurityHeaderOptions, buildPermissionsPolicyHeader, PermissionsPolicyConfig } from './security.helper';
11
14
  import { parseBooleanEnv } from './environment.helper';
12
15
 
16
+ // ---- Shared process handlers ----
17
+
18
+ function registerGlobalProcessHandlers() {
19
+ process.on('unhandledRejection', (reason, promise) => {
20
+ console.error('Unhandled Rejection at:', promise, 'reason:', reason);
21
+ });
22
+
23
+ process.on('uncaughtException', (err) => {
24
+ console.error('Uncaught Exception thrown:', err);
25
+ });
26
+
27
+ // Suppress pg deprecation warning caused by TypeORM's internal query scheduling
28
+ process.on('warning', (warning) => {
29
+ if (warning.name === 'DeprecationWarning' && (warning.message.includes('client.query()') || warning.message.includes('punycode'))) {
30
+ return;
31
+ }
32
+ console.warn(warning);
33
+ });
34
+ }
35
+
36
+ // ---- HTTP server bootstrap ----
37
+
13
38
  export interface SolidSwaggerOptions {
14
39
  title?: string;
15
40
  description?: string;
@@ -26,7 +51,7 @@ export interface SolidBootstrapOptions {
26
51
  }
27
52
 
28
53
  /**
29
- * Bootstraps a SolidX NestJS application with sensible defaults:
54
+ * Bootstraps a SolidX NestJS HTTP application with sensible defaults:
30
55
  * security headers, CORS, Winston logger, ValidationPipe,
31
56
  * WrapResponseInterceptor, qs deep query parsing, Swagger, and the
32
57
  * pg BIGINT type parser.
@@ -41,13 +66,7 @@ export async function bootstrapSolidApp(
41
66
  appModuleFactory: () => Promise<any>,
42
67
  options: SolidBootstrapOptions = {},
43
68
  ): Promise<void> {
44
- process.on('unhandledRejection', (reason, promise) => {
45
- console.error('Unhandled Rejection at:', promise, 'reason:', reason);
46
- });
47
-
48
- process.on('uncaughtException', (err) => {
49
- console.error('Uncaught Exception thrown:', err);
50
- });
69
+ registerGlobalProcessHandlers();
51
70
 
52
71
  const { globalPrefix = 'api', swagger = {}, permissionsPolicyOverrides = {} } = options;
53
72
 
@@ -143,3 +162,61 @@ export async function bootstrapSolidApp(
143
162
 
144
163
  await app.listen(port);
145
164
  }
165
+
166
+ // ---- CLI bootstrap ----
167
+
168
+ /**
169
+ * Bootstraps a SolidX NestJS CLI application using nest-commander.
170
+ * Handles verbose flag stripping, project root validation, and clean process exit.
171
+ *
172
+ * @example
173
+ * // main-cli.ts
174
+ * #!/usr/bin/env node
175
+ * import { bootstrapSolidCli } from '@solidxai/core';
176
+ * import { AppModule } from './app.module';
177
+ *
178
+ * bootstrapSolidCli(() => AppModule.forRoot());
179
+ */
180
+ export async function bootstrapSolidCli(
181
+ appModuleFactory: () => Promise<any>,
182
+ ): Promise<void> {
183
+ registerGlobalProcessHandlers();
184
+
185
+ process.on('exit', (code) => {
186
+ if (code !== 0) {
187
+ console.error(`Exiting with error status code: ${code}`);
188
+ }
189
+ });
190
+
191
+ // Validate that cwd is a valid Solid API project
192
+ const packageJsonPath = resolve(process.cwd(), 'package.json');
193
+ if (!existsSync(packageJsonPath)) {
194
+ console.error('Does not seem to be a valid solid-api project.');
195
+ console.error('Exit reason: missing package.json in the current directory.');
196
+ process.exit(1);
197
+ }
198
+
199
+ // Strip --verbose / -v before nest-commander processes argv
200
+ const showLogs = process.argv.includes('--verbose') || process.argv.includes('-v');
201
+ for (const flag of ['--verbose', '-v']) {
202
+ const idx = process.argv.indexOf(flag);
203
+ if (idx !== -1) process.argv.splice(idx, 1);
204
+ }
205
+
206
+ const appModule = await appModuleFactory();
207
+ process.env.SOLID_CLI_RUNNING = 'true';
208
+
209
+ // @ts-ignore
210
+ const app = await CommandFactory.createWithoutRunning(appModule, {
211
+ logger: showLogs ? ['debug', 'error', 'fatal', 'log', 'verbose', 'warn'] : false,
212
+ });
213
+
214
+ try {
215
+ await CommandFactory.runApplication(app);
216
+ } catch (e) {
217
+ console.error('CLI exited abruptly due to an error:', e);
218
+ process.exit(1);
219
+ }
220
+
221
+ process.exit(0);
222
+ }