@newt-app/templates 0.9.0 → 0.12.0

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.
Files changed (2) hide show
  1. package/dist/index.js +80 -31
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1046,37 +1046,50 @@ var tsconfig_build_default = {
1046
1046
  var app_module_default = {
1047
1047
  filename: "apps/api/src/app.module.ts",
1048
1048
  template: `import { Module } from '@nestjs/common';
1049
+ import { AppService } from './app.service';
1049
1050
  import { TodosModule } from './todos/todos.module';
1050
1051
 
1051
1052
  @Module({
1052
1053
  imports: [TodosModule],
1054
+ providers: [AppService],
1053
1055
  })
1054
1056
  export class AppModule {}`
1055
1057
  };
1056
1058
 
1057
- // src/api/templates/main.ts
1058
- var main_default = {
1059
- filename: "apps/api/src/main.ts",
1060
- template: `import dotenv from 'dotenv';
1061
- import { resolve } from 'path';
1059
+ // src/api/templates/app-service.ts
1060
+ var app_service_default = {
1061
+ filename: "apps/api/src/app.service.ts",
1062
+ template: `import { Injectable } from '@nestjs/common';
1062
1063
 
1063
- // Load root .env first, then local .env (local takes precedence)
1064
- dotenv.config({ path: resolve(process.cwd(), '../../.env') });
1065
- dotenv.config({ path: resolve(process.cwd(), '.env') });
1064
+ @Injectable()
1065
+ export class AppService {
1066
+ getHello(): string {
1067
+ return 'Hello from Nest';
1068
+ }
1069
+ }`
1070
+ };
1066
1071
 
1067
- import { NestFactory } from '@nestjs/core';
1068
- import { AppModule } from './app.module';
1072
+ // src/api/templates/app-service-spec.ts
1073
+ var app_service_spec_default = {
1074
+ filename: "apps/api/src/app.service.spec.ts",
1075
+ template: `import { Test, TestingModule } from '@nestjs/testing';
1076
+ import { AppService } from './app.service';
1069
1077
 
1070
- async function bootstrap() {
1071
- const app = await NestFactory.create(AppModule, { bodyParser: false });
1072
- app.setGlobalPrefix('api');
1073
- app.enableCors({
1074
- origin: process.env.CORS_ORIGIN ?? 'http://localhost:3000',
1075
- credentials: true,
1078
+ describe('AppService', () => {
1079
+ let service: AppService;
1080
+
1081
+ beforeEach(async () => {
1082
+ const module: TestingModule = await Test.createTestingModule({
1083
+ providers: [AppService],
1084
+ }).compile();
1085
+
1086
+ service = module.get<AppService>(AppService);
1076
1087
  });
1077
- await app.listen(process.env.PORT ?? 3001);
1078
- }
1079
- void bootstrap();`
1088
+
1089
+ it('should be defined', () => {
1090
+ expect(service).toBeDefined();
1091
+ });
1092
+ });`
1080
1093
  };
1081
1094
 
1082
1095
  // src/api/templates/todos-module.ts
@@ -1182,7 +1195,8 @@ var api = {
1182
1195
  tsconfig_default2,
1183
1196
  tsconfig_build_default,
1184
1197
  app_module_default,
1185
- main_default,
1198
+ app_service_default,
1199
+ app_service_spec_default,
1186
1200
  todos_module_default,
1187
1201
  todos_service_default,
1188
1202
  todos_service_spec_default,
@@ -9140,6 +9154,7 @@ var api_tsconfig_default = {
9140
9154
  var api_index_default = {
9141
9155
  filename: "apps/api/src/index.ts",
9142
9156
  template: `export { AppModule } from './app.module';
9157
+ export { AppService } from './app.service';
9143
9158
  export { TodosService } from './todos/todos.service';
9144
9159
  export type { Todo } from './todos/todos.service';`
9145
9160
  };
@@ -9154,7 +9169,7 @@ import type { INestApplicationContext } from '@nestjs/common';
9154
9169
 
9155
9170
  let context: INestApplicationContext | null = null;
9156
9171
 
9157
- export async function getNestApp(): Promise<INestApplicationContext> {
9172
+ export async function getContext(): Promise<INestApplicationContext> {
9158
9173
  if (!context) {
9159
9174
  context = await NestFactory.createApplicationContext(AppModule, {
9160
9175
  logger: false,
@@ -9168,18 +9183,18 @@ export async function getNestApp(): Promise<INestApplicationContext> {
9168
9183
  var web_todos_route_default = {
9169
9184
  filename: "apps/web/app/api/todos/route.ts",
9170
9185
  template: `import { NextResponse } from 'next/server';
9171
- import { getNestApp } from '@/lib/nest';
9186
+ import { getContext } from '@/lib/nest';
9172
9187
  import { TodosService } from '@<%= projectName %>/api';
9173
9188
 
9174
9189
  export async function GET() {
9175
- const app = await getNestApp();
9190
+ const app = await getContext();
9176
9191
  const todos = app.get(TodosService);
9177
9192
  return NextResponse.json(todos.findAll());
9178
9193
  }
9179
9194
 
9180
9195
  export async function POST(req: Request) {
9181
9196
  const { title } = await req.json();
9182
- const app = await getNestApp();
9197
+ const app = await getContext();
9183
9198
  const todos = app.get(TodosService);
9184
9199
  return NextResponse.json(todos.create(title), { status: 201 });
9185
9200
  }`
@@ -9189,12 +9204,12 @@ export async function POST(req: Request) {
9189
9204
  var web_todos_id_route_default = {
9190
9205
  filename: "apps/web/app/api/todos/[id]/route.ts",
9191
9206
  template: `import { NextResponse } from 'next/server';
9192
- import { getNestApp } from '@/lib/nest';
9207
+ import { getContext } from '@/lib/nest';
9193
9208
  import { TodosService } from '@<%= projectName %>/api';
9194
9209
 
9195
9210
  export async function DELETE(_req: Request, { params }: { params: Promise<{ id: string }> }) {
9196
9211
  const { id } = await params;
9197
- const app = await getNestApp();
9212
+ const app = await getContext();
9198
9213
  const todos = app.get(TodosService);
9199
9214
  todos.remove(Number(id));
9200
9215
  return new NextResponse(null, { status: 204 });
@@ -9205,12 +9220,12 @@ export async function DELETE(_req: Request, { params }: { params: Promise<{ id:
9205
9220
  var web_todos_toggle_route_default = {
9206
9221
  filename: "apps/web/app/api/todos/[id]/toggle/route.ts",
9207
9222
  template: `import { NextResponse } from 'next/server';
9208
- import { getNestApp } from '@/lib/nest';
9223
+ import { getContext } from '@/lib/nest';
9209
9224
  import { TodosService } from '@<%= projectName %>/api';
9210
9225
 
9211
9226
  export async function PATCH(_req: Request, { params }: { params: Promise<{ id: string }> }) {
9212
9227
  const { id } = await params;
9213
- const app = await getNestApp();
9228
+ const app = await getContext();
9214
9229
  const todos = app.get(TodosService);
9215
9230
  return NextResponse.json(todos.toggle(Number(id)));
9216
9231
  }`
@@ -9320,9 +9335,13 @@ var web_tsconfig_default = {
9320
9335
  var web_hello_route_default = {
9321
9336
  filename: "apps/web/app/api/hello/route.ts",
9322
9337
  template: `import { NextResponse } from 'next/server';
9338
+ import { getContext } from '@/lib/nest';
9339
+ import { AppService } from '@<%= projectName %>/api';
9323
9340
 
9324
9341
  export async function GET() {
9325
- return NextResponse.json({ message: 'Hello from Nest' });
9342
+ const ctx = await getContext();
9343
+ const appService = ctx.get(AppService);
9344
+ return NextResponse.json({ message: appService.getHello() });
9326
9345
  }`
9327
9346
  };
9328
9347
 
@@ -9353,9 +9372,12 @@ import {
9353
9372
  Session,
9354
9373
  UserSession,
9355
9374
  } from '@thallesp/nestjs-better-auth';
9375
+ import { AppService } from './app.service';
9356
9376
 
9357
9377
  @Controller()
9358
9378
  export class AppController {
9379
+ constructor(private readonly appService: AppService) {}
9380
+
9359
9381
  @AllowAnonymous()
9360
9382
  @Get('hello')
9361
9383
  getHello(@Session() session: UserSession | null) {
@@ -9363,7 +9385,7 @@ export class AppController {
9363
9385
  return { message: \`Hello \${session.user.name}\` };
9364
9386
  }
9365
9387
 
9366
- return { message: 'Hello from Nest' };
9388
+ return { message: this.appService.getHello() };
9367
9389
  }
9368
9390
  }`
9369
9391
  };
@@ -9399,16 +9421,42 @@ import { APP_GUARD } from '@nestjs/core';
9399
9421
  import { AuthGuard, AuthModule } from '@thallesp/nestjs-better-auth';
9400
9422
  import { auth } from '@<%= projectName %>/auth';
9401
9423
  import { AppController } from './app.controller';
9424
+ import { AppService } from './app.service';
9402
9425
  import { TodosModule } from './todos/todos.module';
9403
9426
 
9404
9427
  @Module({
9405
9428
  imports: [AuthModule.forRoot({ auth }), TodosModule],
9406
9429
  controllers: [AppController],
9407
- providers: [{ provide: APP_GUARD, useClass: AuthGuard }],
9430
+ providers: [AppService, { provide: APP_GUARD, useClass: AuthGuard }],
9408
9431
  })
9409
9432
  export class AppModule {}`
9410
9433
  };
9411
9434
 
9435
+ // src/api/templates/main.ts
9436
+ var main_default = {
9437
+ filename: "apps/api/src/main.ts",
9438
+ template: `import dotenv from 'dotenv';
9439
+ import { resolve } from 'path';
9440
+
9441
+ // Load root .env first, then local .env (local takes precedence)
9442
+ dotenv.config({ path: resolve(process.cwd(), '../../.env') });
9443
+ dotenv.config({ path: resolve(process.cwd(), '.env') });
9444
+
9445
+ import { NestFactory } from '@nestjs/core';
9446
+ import { AppModule } from './app.module';
9447
+
9448
+ async function bootstrap() {
9449
+ const app = await NestFactory.create(AppModule, { bodyParser: false });
9450
+ app.setGlobalPrefix('api');
9451
+ app.enableCors({
9452
+ origin: process.env.CORS_ORIGIN ?? 'http://localhost:3000',
9453
+ credentials: true,
9454
+ });
9455
+ await app.listen(process.env.PORT ?? 3001);
9456
+ }
9457
+ void bootstrap();`
9458
+ };
9459
+
9412
9460
  // src/api-controllers/templates/todos-controller.ts
9413
9461
  var todos_controller_default = {
9414
9462
  filename: "apps/api/src/todos/todos.controller.ts",
@@ -9469,6 +9517,7 @@ var apiControllers = {
9469
9517
  app_controller_default,
9470
9518
  app_controller_spec_default,
9471
9519
  app_module_default2,
9520
+ main_default,
9472
9521
  todos_controller_default,
9473
9522
  todos_module_default2
9474
9523
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newt-app/templates",
3
- "version": "0.9.0",
3
+ "version": "0.12.0",
4
4
  "private": false,
5
5
  "description": "Templates for newt-app",
6
6
  "type": "module",