diff --git a/packages/server/package.json b/packages/server/package.json
index ad0988476..af237350a 100644
--- a/packages/server/package.json
+++ b/packages/server/package.json
@@ -27,7 +27,7 @@
"cli:tenants:migrate:rollback": "ts-node -r tsconfig-paths/register src/cli.ts tenants:migrate:rollback",
"cli:tenants:migrate:make": "ts-node -r tsconfig-paths/register src/cli.ts tenants:migrate:make",
"cli:tenants:list": "ts-node -r tsconfig-paths/register src/cli.ts tenants:list",
- "openapi:export": "ts-node -r tsconfig-paths/register scripts/export-openapi.ts",
+ "openapi:export": "ts-node -r tsconfig-paths/register src/cli.ts openapi:export",
"cli:system:seed:latest": "ts-node -r tsconfig-paths/register src/cli.ts system:seed:latest",
"cli:tenants:seed:latest": "ts-node -r tsconfig-paths/register src/cli.ts tenants:seed:latest"
},
diff --git a/packages/server/scripts/export-openapi.ts b/packages/server/scripts/export-openapi.ts
deleted file mode 100644
index 196cf60b7..000000000
--- a/packages/server/scripts/export-openapi.ts
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * Exports the OpenAPI document from the NestJS app to shared/sdk-ts/openapi.json.
- * Run from packages/server: pnpm run openapi:export
- */
-///
-import { NestFactory } from '@nestjs/core';
-import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
-import { ClsMiddleware } from 'nestjs-cls';
-import * as path from 'path';
-import * as fs from 'fs';
-import '@/utils/moment-mysql';
-import { AppModule } from '@/modules/App/App.module';
-import { NestExpressApplication } from '@nestjs/platform-express';
-
-async function exportOpenApi() {
- global.__public_dirname = path.join(__dirname, '..', 'public');
- global.__static_dirname = path.join(__dirname, '..', 'static');
- global.__views_dirname = path.join(global.__static_dirname, '/views');
- global.__images_dirname = path.join(global.__static_dirname, '/images');
-
- const app = await NestFactory.create(AppModule, {
- rawBody: true,
- });
- app.set('query parser', 'extended');
- app.setGlobalPrefix('/api');
- app.use(new ClsMiddleware({}).use);
-
- const config = new DocumentBuilder()
- .setTitle('Bigcapital')
- .setDescription('Financial accounting software')
- .setVersion('1.0')
- .build();
-
- const document = SwaggerModule.createDocument(app, config);
- await app.close();
-
- const outputPath = path.resolve(__dirname, '../../../shared/sdk-ts/openapi.json');
- fs.mkdirSync(path.dirname(outputPath), { recursive: true });
- fs.writeFileSync(outputPath, JSON.stringify(document, null, 2), 'utf-8');
- console.log(`OpenAPI spec written to ${outputPath}`);
-}
-
-exportOpenApi().catch((err) => {
- console.error(err);
- process.exit(1);
-});
diff --git a/packages/server/src/cli.ts b/packages/server/src/cli.ts
index 7d96b896b..08d913c86 100644
--- a/packages/server/src/cli.ts
+++ b/packages/server/src/cli.ts
@@ -1,3 +1,4 @@
+///
import { CommandFactory } from 'nest-commander';
import { CLIModule } from './modules/CLI/CLI.module';
diff --git a/packages/server/src/modules/App/App.module.ts b/packages/server/src/modules/App/App.module.ts
index ef50f0efa..38852d9ec 100644
--- a/packages/server/src/modules/App/App.module.ts
+++ b/packages/server/src/modules/App/App.module.ts
@@ -123,7 +123,7 @@ import { AppThrottleModule } from './AppThrottle.module';
useFactory: () => ({
fallbackLanguage: 'en',
loaderOptions: {
- path: join(__dirname, '/../../i18n/'),
+ path: join(__dirname, '../../i18n/'),
watch: true,
},
}),
diff --git a/packages/server/src/modules/CLI/CLI.module.ts b/packages/server/src/modules/CLI/CLI.module.ts
index d62b9f13a..df491b23e 100644
--- a/packages/server/src/modules/CLI/CLI.module.ts
+++ b/packages/server/src/modules/CLI/CLI.module.ts
@@ -11,6 +11,7 @@ import { TenantsMigrateMakeCommand } from './commands/TenantsMigrateMake.command
import { TenantsListCommand } from './commands/TenantsList.command';
import { SystemSeedLatestCommand } from './commands/SystemSeedLatest.command';
import { TenantsSeedLatestCommand } from './commands/TenantsSeedLatest.command';
+import { OpenApiExportCommand } from './commands/OpenApiExport.command';
@Module({
imports: [
@@ -30,6 +31,7 @@ import { TenantsSeedLatestCommand } from './commands/TenantsSeedLatest.command';
TenantsListCommand,
SystemSeedLatestCommand,
TenantsSeedLatestCommand,
+ OpenApiExportCommand,
],
})
export class CLIModule { }
diff --git a/packages/server/src/modules/CLI/commands/OpenApiExport.command.ts b/packages/server/src/modules/CLI/commands/OpenApiExport.command.ts
new file mode 100644
index 000000000..981d417e5
--- /dev/null
+++ b/packages/server/src/modules/CLI/commands/OpenApiExport.command.ts
@@ -0,0 +1,44 @@
+import { Command, CommandRunner } from 'nest-commander';
+import { NestFactory } from '@nestjs/core';
+import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
+import { ClsMiddleware } from 'nestjs-cls';
+import * as path from 'path';
+import * as fs from 'fs';
+import '@/utils/moment-mysql';
+import { AppModule } from '@/modules/App/App.module';
+import { NestExpressApplication } from '@nestjs/platform-express';
+
+@Command({
+ name: 'openapi:export',
+ description: 'Export the OpenAPI document from the NestJS app to shared/sdk-ts/openapi.json',
+})
+export class OpenApiExportCommand extends CommandRunner {
+ async run(): Promise {
+ const serverRoot = process.cwd();
+ global.__public_dirname = path.join(serverRoot, 'public');
+ global.__static_dirname = path.join(serverRoot, 'static');
+ global.__views_dirname = path.join(global.__static_dirname, '/views');
+ global.__images_dirname = path.join(global.__static_dirname, '/images');
+
+ const app = await NestFactory.create(AppModule, {
+ rawBody: true,
+ });
+ app.set('query parser', 'extended');
+ app.setGlobalPrefix('/api');
+ app.use(new ClsMiddleware({}).use);
+
+ const config = new DocumentBuilder()
+ .setTitle('Bigcapital')
+ .setDescription('Financial accounting software')
+ .setVersion('1.0')
+ .build();
+
+ const document = SwaggerModule.createDocument(app, config);
+ await app.close();
+
+ const outputPath = path.resolve(process.cwd(), '../../shared/sdk-ts/openapi.json');
+ fs.mkdirSync(path.dirname(outputPath), { recursive: true });
+ fs.writeFileSync(outputPath, JSON.stringify(document, null, 2), 'utf-8');
+ console.log(`OpenAPI spec written to ${outputPath}`);
+ }
+}