Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more apps and libs #5

Merged
merged 7 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,17 @@ jobs:
THDK_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [[ "${{ steps.git.outputs.branch-name }}" == "main" ]]; then
npx nx release --skip-publish --verbose
npx nx release \
--skip-publish \
--verbose
else
npx nx release version --preid ${{ steps.git.outputs.commit-sha-short }} --no-git-commit --no-git-tag --verbose
npx nx release version \
--preid ${{ steps.git.outputs.commit-sha-short }} \
--no-git-commit \
--no-git-tag \
--verbose
fi

- name: Push version bumps, tags and changelogs
if: ${{ steps.git.outputs.branch-name == 'main' }}
run: |
git push
git push --tags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish
run: |
npx nx release publish --yes --verbose
Expand Down
7 changes: 0 additions & 7 deletions apps/books-api/src/books/books.module.ts

This file was deleted.

26 changes: 5 additions & 21 deletions apps/books-api/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
/**
* This is not a production server yet!
* This is only a minimal backend to get started.
*/
import { bootstrap } from '@nx-demo/nest-bootstrap';
import { AppModule } from '@nx-demo/books-api-lib';

import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';

import { AppModule } from './app/app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
const globalPrefix = 'api';
app.setGlobalPrefix(globalPrefix);
const port = process.env.PORT || 3000;
await app.listen(port);
Logger.log(
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`
);
}

bootstrap();
bootstrap(AppModule, {
globalPrefix: 'api',
});
3 changes: 0 additions & 3 deletions apps/books-api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
Expand Down
7 changes: 7 additions & 0 deletions apps/books-app/remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@ export default {
// assetsBuildDirectory: "public/build",
// serverBuildPath: "build/index.js",
// publicPath: "/build/",
future: {
v3_fetcherPersist: true,
v3_lazyRouteDiscovery: true,
v3_relativeSplatPath: true,
v3_singleFetch: true,
v3_throwAbortReason: true,
},
watchPaths: () => createWatchPaths(__dirname),
};
18 changes: 18 additions & 0 deletions apps/hello-api/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
43 changes: 43 additions & 0 deletions apps/hello-api/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "hello-api",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/hello-api/src",
"projectType": "application",
"tags": [],
"targets": {
"build": {
"executor": "nx:run-commands",
"options": {
"command": "webpack-cli build",
"args": ["node-env=production"]
},
"configurations": {
"development": {
"args": ["node-env=development"]
}
}
},
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"dependsOn": ["build"],
"options": {
"buildTarget": "hello-api:build",
"runBuildTargetDependencies": false
},
"configurations": {
"development": {
"buildTarget": "hello-api:build:development"
},
"production": {
"buildTarget": "hello-api:build:production"
}
}
},
"test": {
"options": {
"passWithNoTests": true
}
}
}
}
Empty file.
3 changes: 3 additions & 0 deletions apps/hello-api/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { bootstrap } from '@nx-demo/nest-bootstrap';
import { AppModule } from '@nx-demo/hello-api-lib';
bootstrap(AppModule);
11 changes: 11 additions & 0 deletions apps/hello-api/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": ["node"],
"emitDecoratorMetadata": true,
"target": "es2021"
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
}
13 changes: 13 additions & 0 deletions apps/hello-api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.app.json"
}
],
"compilerOptions": {
"esModuleInterop": true
}
}
20 changes: 20 additions & 0 deletions apps/hello-api/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin');
const { join } = require('path');

module.exports = {
output: {
path: join(__dirname, '../../dist/apps/hello-api'),
},
plugins: [
new NxAppWebpackPlugin({
target: 'node',
compiler: 'tsc',
main: './src/main.ts',
tsConfig: './tsconfig.app.json',
assets: ['./src/assets'],
optimization: false,
outputHashing: 'none',
generatePackageJson: true,
}),
],
};
1 change: 0 additions & 1 deletion apps/remix-app/.env.local

This file was deleted.

1 change: 1 addition & 0 deletions libs/books-api-contracts/src/lib/books/get-books.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const getBooksSchema = z.array(
z.object({
title: z.string(),
id: z.number(),
summary: z.string(),
})
);
1 change: 1 addition & 0 deletions libs/books-api-contracts/src/lib/books/get-books.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('getBooksSchema', () => {
{
id: 1,
title: 'The Great Gatsby',
summary: 'A book by F. Scott Fitzgerald',
},
];

Expand Down
18 changes: 18 additions & 0 deletions libs/books-api-lib/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions libs/books-api-lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# books-api-lib

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test books-api-lib` to execute the unit tests via [Jest](https://jestjs.io).
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/* eslint-disable */
export default {
displayName: 'books-api',
displayName: 'books-api-lib',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/books-api',
coverageDirectory: '../../coverage/libs/books-api-lib',
};
9 changes: 9 additions & 0 deletions libs/books-api-lib/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "books-api-lib",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/books-api-lib/src",
"projectType": "library",
"tags": [],
"// targets": "to see all targets run: nx show project books-api-lib --web",
"targets": {}
}
4 changes: 4 additions & 0 deletions libs/books-api-lib/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './lib/app/app.module';
export * from './lib/app/app.service';
export * from './lib/pipes/zod-validation-pipe';
export * from './lib/validation/zod-response-validation-interceptor';
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { BooksModule } from '../books/books.module';
import { BootstrapModule } from '@nx-demo/nest-bootstrap';

@Module({
imports: [BooksModule],
imports: [BooksModule, BootstrapModule.forRoot()],
controllers: [AppController],
providers: [AppService],
})
Expand Down
8 changes: 8 additions & 0 deletions libs/books-api-lib/src/lib/books-api-lib.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';

@Module({
controllers: [],
providers: [],
exports: [],
})
export class BooksApiLibModule {}
16 changes: 16 additions & 0 deletions libs/books-api-lib/src/lib/books/books.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Controller, Get, Logger, UseInterceptors } from '@nestjs/common';
import { ZodResponseValidationInterceptor } from '../validation/zod-response-validation-interceptor';
import { getBooksSchema } from '@thdk/books-api-contracts/schemas';
import { BooksService } from './books.service';

@Controller('books')
export class BooksController {
constructor(private readonly booksService: BooksService) {}

@Get()
@UseInterceptors(new ZodResponseValidationInterceptor(getBooksSchema))
async books() {
Logger.log('Getting books');
return this.booksService.getBooks();
}
}
24 changes: 24 additions & 0 deletions libs/books-api-lib/src/lib/books/books.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Module } from '@nestjs/common';
import { BooksController } from './books.controller';
import { summerizeBook } from '@nx-demo/lorem-book-summarizer';
import { PINO_LOGGER_TOKEN } from '@nx-demo/nest-logger';
import { Logger } from 'pino';
import { BOOK_SUMMARIZER_TOKEN } from './tokens';
import { BooksService } from './books.service';

@Module({
controllers: [BooksController],
providers: [
BooksService,
{
provide: BOOK_SUMMARIZER_TOKEN,
useFactory: (logger: Logger) => {
return (data: { title: string; author: string }) => {
return summerizeBook(data, { logger });
};
},
inject: [{ token: PINO_LOGGER_TOKEN, optional: false }],
},
],
})
export class BooksModule {}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { Controller, Get, UseInterceptors } from '@nestjs/common';
import { ZodResponseValidationInterceptor } from '../validation/zod-response-validation-interceptor';
import { getBooksSchema } from '@thdk/books-api-contracts/schemas';
import { Inject } from '@nestjs/common';
import { BOOK_SUMMARIZER_TOKEN } from './tokens';

@Controller('books')
export class BooksController {
@Get()
@UseInterceptors(new ZodResponseValidationInterceptor(getBooksSchema))
async books() {
export type BookSummarizerFunction = (data: {
title: string;
author: string;
}) => string;

export class BooksService {
constructor(
@Inject(BOOK_SUMMARIZER_TOKEN)
private readonly bookSummarizer: BookSummarizerFunction
) {}

getBooks() {
return [
{ id: 1, title: 'The Great Gatsby' },
{ id: 2, title: 'The Catcher in the Rye' },
Expand All @@ -19,6 +25,12 @@ export class BooksController {
{ id: 9, title: 'The Hobbit' },
{ id: 10, title: 'The Chronicles of Narnia' },
{ id: 11, title: 'The Hunger Games' },
];
].map((book) => ({
...book,
summary: this.bookSummarizer({
title: book.title,
author: 'Unknown',
}),
}));
}
}
1 change: 1 addition & 0 deletions libs/books-api-lib/src/lib/books/tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const BOOK_SUMMARIZER_TOKEN = 'BookSummarizer';
Loading
Loading