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

Adding Turbo build #10

Merged
merged 9 commits into from
Oct 23, 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
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
dist
coverage
.github
.husky
*.config.js
23 changes: 23 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {

Check failure on line 1 in .eslintrc.js

View workflow job for this annotation

GitHub Actions / autofix

'module' is not defined
root: true,
parser: '@typescript-eslint/parser',
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
plugins: ['@typescript-eslint'],
ignorePatterns: ['node_modules', 'dist', '.turbo', '.next', 'build'],
rules: {
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
},
],
'no-console': 'warn',
'prefer-const': 'error',
'no-var': 'error',
},
};
73 changes: 73 additions & 0 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: autofix.ci

on:
pull_request:
push:
branches: [ "main" ]

permissions:
contents: read

jobs:
autofix:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0

- uses: pnpm/action-setup@v2
with:
version: 8

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --no-frozen-lockfile

- name: Cache pnpm modules
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-

- name: Format code with Prettier
id: format
run: |
pnpm exec prettier --write "**/*.{js,jsx,ts,tsx,json,md}"
if [ -n "$(git status --porcelain)" ]; then
echo "FORMAT_HAS_CHANGES=true" >> $GITHUB_ENV
fi
git add .

- name: Run ESLint fix
id: lint
continue-on-error: true
run: |
pnpm exec eslint . --ext .js,.jsx,.ts,.tsx --fix
if [ -n "$(git status --porcelain)" ]; then
echo "LINT_HAS_CHANGES=true" >> $GITHUB_ENV
fi
# Run ESLint again to check remaining issues
pnpm exec eslint . --ext .js,.jsx,.ts,.tsx --max-warnings 0 || echo "LINT_HAS_ERRORS=true" >> $GITHUB_ENV
git add .

- name: Check TypeScript
continue-on-error: true
run: |
pnpm exec tsc --noEmit
if [ $? -ne 0 ]; then
echo "TS_HAS_ERRORS=true" >> $GITHUB_ENV
fi
- uses: autofix-ci/action@dd55f44df8f7cdb7a6bf74c78677eb8acd40cd0a
20 changes: 15 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
*/**.turbo/
*/**/node_modules
*/**/dist
# temp model
*/**/models
# Dependencies
node_modules/
*/**/node_modules/

# Turbo
.turbo/
*/**/.turbo/

# Build outputs
dist/
*/**/dist/

# Models
models/
*/**/models/
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
dist
coverage
.github
package-lock.json
yarn.lock
pnpm-lock.yaml
9 changes: 9 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
singleQuote: true,
trailingComma: 'es5',
printWidth: 80,
tabWidth: 2,
semi: true,
bracketSpacing: true,
endOfLine: 'lf',
};
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Still on progress

Generator Ai
Generator Ai
3 changes: 3 additions & 0 deletions backend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PORT=8080
JWT_SECRET="JACKSONCHENNAHEULALLEN"
SALT_ROUNDS=123
2 changes: 1 addition & 1 deletion backend/.env.development
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
PORT=3000
PORT=8080
JWT_SECRET="JACKSONCHENNAHEULALLEN"
SALT_ROUNDS=123
8 changes: 8 additions & 0 deletions backend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'../.eslintrc.js',
],
root: true,
env: {
Expand All @@ -21,5 +22,12 @@ module.exports = {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'prefer-const': [
'error',
{
destructuring: 'all',
ignoreReadBeforeAssign: true,
},
],
},
};
6 changes: 0 additions & 6 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ lerna-debug.log*
!.vscode/launch.json
!.vscode/extensions.json

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# temp directory
.temp
Expand Down
14 changes: 9 additions & 5 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "codefox",
"name": "codefox-backend",
"version": "0.0.1",
"description": "",
"author": "",
Expand All @@ -9,12 +9,14 @@
"scripts": {
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"lint": "ts-prune \"{src,apps,libs,test}/**/*.ts\" && eslint \"{src,apps,libs,test}/**/*.ts\" --fix ",
"start": "nest start --watch",
"start:dev": "nest start --watch",
"dev": "pnpm start:dev",
"dev:backend": "pnpm start:dev",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test": "jest --passWithNoTests",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
Expand Down Expand Up @@ -44,6 +46,7 @@
"typeorm": "^0.3.20"
},
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
Expand All @@ -53,7 +56,7 @@
"@types/supertest": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"eslint": "^9.0.0",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.5.0",
Expand All @@ -64,7 +67,8 @@
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"ts-prune": "^0.10.3",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
}
}
}
2 changes: 1 addition & 1 deletion backend/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@
await this.jwtService.verifyAsync(params.token);
return this.jwtCacheService.isTokenStored(params.token);
} catch (error) {
console.log(error);

Check warning on line 80 in backend/src/auth/auth.service.ts

View workflow job for this annotation

GitHub Actions / autofix

Unexpected console statement
return false;
}
}
async logout(token: string): Promise<Boolean> {
async logout(token: string): Promise<boolean> {
Logger.log('logout token', token);
try {
await this.jwtService.verifyAsync(token);
} catch (error) {

Check warning on line 88 in backend/src/auth/auth.service.ts

View workflow job for this annotation

GitHub Actions / autofix

'error' is defined but never used
return false;
}

Expand Down
19 changes: 10 additions & 9 deletions backend/src/chat/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-namespace */
export interface ChatCompletionChunk {
/**
* A unique identifier for the chat completion. Each chunk has the same ID.
Expand Down Expand Up @@ -25,13 +26,13 @@ export interface ChatCompletionChunk {
/**
* The object type, which is always `chat.completion.chunk`.
*/
object: "chat.completion.chunk";
object: 'chat.completion.chunk';

/**
* The service tier used for processing the request. This field is only included if
* the `service_tier` parameter is specified in the request.
*/
service_tier?: "scale" | "default" | null;
service_tier?: 'scale' | 'default' | null;

/**
* This fingerprint represents the backend configuration that the model runs with.
Expand All @@ -57,11 +58,11 @@ export namespace ChatCompletionChunk {
* function.
*/
finish_reason:
| "stop"
| "length"
| "tool_calls"
| "content_filter"
| "function_call"
| 'stop'
| 'length'
| 'tool_calls'
| 'content_filter'
| 'function_call'
| null;

/**
Expand Down Expand Up @@ -94,7 +95,7 @@ export namespace ChatCompletionChunk {
/**
* The role of the author of this message.
*/
role?: "system" | "user" | "assistant" | "tool";
role?: 'system' | 'user' | 'assistant' | 'tool';

tool_calls?: Array<Delta.ToolCall>;
}
Expand Down Expand Up @@ -132,7 +133,7 @@ export namespace ChatCompletionChunk {
/**
* The type of the tool. Currently, only `function` is supported.
*/
type?: "function";
type?: 'function';
}

export namespace ToolCall {
Expand Down
13 changes: 9 additions & 4 deletions backend/src/decorator/get-auth-token.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { createParamDecorator, ExecutionContext, UnauthorizedException } from '@nestjs/common';
import {
createParamDecorator,
ExecutionContext,
UnauthorizedException,
} from '@nestjs/common';
import { GqlExecutionContext } from '@nestjs/graphql';
import { JwtService } from '@nestjs/jwt';

Expand All @@ -15,15 +19,16 @@ export const GetAuthToken = createParamDecorator(
},
);


export const GetUserIdFromToken = createParamDecorator(
(data: unknown, context: ExecutionContext) => {
const ctx = GqlExecutionContext.create(context);
const request = ctx.getContext().req;
const authHeader = request.headers.authorization;

if (!authHeader || !authHeader.startsWith('Bearer ')) {
throw new UnauthorizedException('Authorization token is missing or invalid');
throw new UnauthorizedException(
'Authorization token is missing or invalid',
);
}

const token = authHeader.split(' ')[1];
Expand All @@ -36,4 +41,4 @@ export const GetUserIdFromToken = createParamDecorator(

return decodedToken.userId;
},
);
);
1 change: 1 addition & 0 deletions backend/src/guard/project.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@nestjs/common';
import { GqlExecutionContext } from '@nestjs/graphql';
import { JwtService } from '@nestjs/jwt';

import { ProjectService } from '../project/project.service';

@Injectable()
Expand Down
4 changes: 1 addition & 3 deletions backend/src/project/project.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ export class Project extends SystemBaseModel {
@OneToMany(
() => ProjectPackages,
(projectPackage) => projectPackage.project,
{
cascade: true,
},
{ cascade: true },
)
projectPackages: ProjectPackages[];
}
Loading
Loading