Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
collettemathieu committed Jul 10, 2024
1 parent 6c8247e commit 813c7ca
Show file tree
Hide file tree
Showing 24 changed files with 455 additions and 24 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on:
push:
branches:
- main
pull_request:

permissions:
actions: read
contents: read

jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0


- uses: oven-sh/setup-bun@v1
with:
bun-version: latest


# Connect your workspace on nx.app and uncomment this to enable task distribution.
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested
# - run: bunx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build"


- run: bun install --no-cache
- uses: nrwl/nx-set-shas@v4

# Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud
# - run: bun nx-cloud record -- echo Hello World
- run: bun nx affected -t lint test build
3 changes: 3 additions & 0 deletions .hooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
echo "Checking with commitlint...."
bun run commitlint --edit $1
3 changes: 3 additions & 0 deletions .hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
echo "Formatting code...."
bun run format
5 changes: 3 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"recommendations": [

"nrwl.angular-console",
"esbenp.prettier-vscode"
"esbenp.prettier-vscode",
"oven.bun-vscode",
"biomejs.biome"
]
}
48 changes: 48 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "bun",
"request": "launch",
"name": "Debug Bun",
"program": "${file}",

// The arguments to pass to the program, if any.
"args": [],

// The working directory of the program.
"cwd": "${workspaceFolder}",

// The environment variables to pass to the program.
"env": {},

// If the environment variables should not be inherited from the parent process.
"strictEnv": false,

// If the program should be run in watch mode.
// This is equivalent to passing `--watch` to the `bun` executable.
// You can also set this to "hot" to enable hot reloading using `--hot`.
"watchMode": false,

// If the debugger should stop on the first line of the program.
"stopOnEntry": false,

// If the debugger should be disabled. (for example, breakpoints will not be hit)
"noDebug": false,

// The path to the `bun` executable, defaults to your `PATH` environment variable.
"runtime": "bun",

// The arguments to pass to the `bun` executable, if any.
// Unlike `args`, these are passed to the executable itself, not the program.
"runtimeArgs": [],
},
{
"type": "bun",
"request": "attach",
"name": "Attach to Bun",
// This value can be retrieved by using `bun --inspect`.
"url": "ws://localhost:6499/",
}
]
}
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"bun.runtime": "$HOME/.bun/bin/bun",
"bun.debugTerminal.enabled": true,
"bun.debugTerminal.stopOnEntry": false,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
"quickfix.biome": "explicit",
"source.organizeImports.biome": "explicit"
},
"editor.defaultFormatter": "biomejs.biome"
}
17 changes: 17 additions & 0 deletions apps/bewoak-api/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "../../node_modules/@biomejs/biome/configuration_schema.json",
"extends": ["../../biome.json"],
"linter": {
"rules": {
"nursery": {
"noRestrictedImports": {
"options": {
"paths": {}
},
"level": "error"
}
}
}
},
"overrides": [{}]
}
30 changes: 30 additions & 0 deletions apps/bewoak-api/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "bewoak-api",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/bewoak-api/src",
"projectType": "application",
"tags": ["bewoak-api"],
"targets": {
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"options": {
"buildTarget": "bewoak-api:build"
},
"configurations": {
"development": {
"buildTarget": "bewoak-api:build:development"
},
"production": {
"buildTarget": "bewoak-api:build:production"
}
}
},
"lint": {
"executor": "nx:run-commands",
"options": {
"command": "bun run biome check --write {projectRoot} --config-path={projectRoot}/biome.json"
}
}
}
}
23 changes: 23 additions & 0 deletions apps/bewoak-api/src/app/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Test, type TestingModule } from '@nestjs/testing';
import { beforeAll, describe, expect, test } from 'bun:test';

import { AppController } from './app.controller';
import { AppService } from './app.service';

describe('AppController', () => {
let app: TestingModule;

beforeAll(async () => {
app = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
});

describe('getData', () => {
test('should return "Hello API"', () => {
const appController = app.get<AppController>(AppController);
expect(appController.getData()).toEqual({ message: 'Hello API' });
});
});
});
13 changes: 13 additions & 0 deletions apps/bewoak-api/src/app/app.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Controller, Get, Inject } from '@nestjs/common';

import { AppService } from './app.service';

@Controller()
export class AppController {
constructor(@Inject(AppService) private readonly appService: AppService) {}

@Get()
getData() {
return this.appService.getData();
}
}
11 changes: 11 additions & 0 deletions apps/bewoak-api/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';

import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
imports: [],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
22 changes: 22 additions & 0 deletions apps/bewoak-api/src/app/app.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Test } from '@nestjs/testing';
import { beforeAll, describe, expect, test } from 'bun:test';

import { AppService } from './app.service';

describe('AppService', () => {
let service: AppService;

beforeAll(async () => {
const app = await Test.createTestingModule({
providers: [AppService],
}).compile();

service = app.get<AppService>(AppService);
});

describe('getData', () => {
test('should return "Hello API"', () => {
expect(service.getData()).toEqual({ message: 'Hello API' });
});
});
});
8 changes: 8 additions & 0 deletions apps/bewoak-api/src/app/app.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
getData(): { message: string } {
return { message: 'Hello API' };
}
}
Empty file.
22 changes: 22 additions & 0 deletions apps/bewoak-api/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* This is not a production server yet!
* This is only a minimal backend to get started.
*/

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();
17 changes: 17 additions & 0 deletions apps/bewoak-api/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["node"],
"emitDecoratorMetadata": true,
"target": "es2021",
"strictNullChecks": true,
"noImplicitAny": true,
"strictBindCallApply": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true
},
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
"include": ["src/**/*.ts"]
}
13 changes: 13 additions & 0 deletions apps/bewoak-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/bewoak-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('node:path');

module.exports = {
output: {
path: join(__dirname, '../../dist/apps/bewoak-api'),
},
plugins: [
new NxAppWebpackPlugin({
target: 'node',
compiler: 'swc',
main: './src/main.ts',
tsConfig: './tsconfig.app.json',
assets: ['./src/assets'],
optimization: process.env.BUN_ENV === 'production',
outputHashing:
process.env.BUN_ENV === 'production' ? 'all' : 'none',
}),
],
};
67 changes: 67 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"formatter": {
"attributePosition": "auto",
"enabled": true,
"formatWithErrors": false,
"ignore": [
"dist",
"coverage",
".nx",
".vscode",
"node_modules",
"tmp",
".angular"
],
"indentStyle": "space",
"indentWidth": 4,
"lineEnding": "lf",
"lineWidth": 80
},
"linter": {
"enabled": true,
"ignore": [
"dist",
"coverage",
".nx",
".vscode",
"node_modules",
"tmp",
".angular"
],
"rules": {
"recommended": true,
"suspicious": {
"noConsoleLog": "error"
}
}
},
"organizeImports": {
"enabled": true
},
"javascript": {
"formatter": {
"arrowParentheses": "always",
"attributePosition": "auto",
"bracketSameLine": false,
"bracketSpacing": true,
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"quoteStyle": "single",
"semicolons": "always",
"trailingCommas": "es5"
},
"linter": {
"enabled": true
},
"parser": {
"unsafeParameterDecoratorsEnabled": true
}
},
"json": {
"parser": {
"allowComments": false,
"allowTrailingCommas": true
}
}
}
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { extends: ['@commitlint/config-conventional'] };
Loading

0 comments on commit 813c7ca

Please sign in to comment.