Skip to content

Commit

Permalink
Merge pull request #1 from yashpokar/lib/config
Browse files Browse the repository at this point in the history
added shared library
  • Loading branch information
yashpokar authored Mar 29, 2024
2 parents 1754cdd + 753bb5d commit 924ef47
Show file tree
Hide file tree
Showing 16 changed files with 585 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
API_PORT=
API_URL=

UI_PORT=
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ build/
package-lock.json

.nx/

.env
.env.local
.env.development
.env.test
.env.production
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpm exec lint-staged
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ To install ManasAI, clone the repository and run the following command:
```shell
pnpm install
```

Create a `.env` file in the root directory and add the following environment variables:

```shell
cp .env.example .env
```
1 change: 1 addition & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"author": "Yash Patel <[email protected]>",
"license": "ISC",
"dependencies": {
"core": "workspace:^",
"express": "^4.19.2",
"socket.io": "^4.7.5"
},
Expand Down
7 changes: 5 additions & 2 deletions apps/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import express from 'express'
import { createServer } from 'node:http'

import { API_PORT, API_URL } from 'core'
import logger from 'core/dist/logger'

const app = express()
const server = createServer(app)

server.listen(8000, () => {
console.log('server running at http://localhost:8000')
server.listen(API_PORT, () => {
logger.info(`server running at ${API_URL}`)
})
1 change: 1 addition & 0 deletions apps/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"test": "echo \"Yet to be implemented\""
},
"dependencies": {
"dotenv": "^16.4.5",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
6 changes: 5 additions & 1 deletion apps/ui/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import 'dotenv/config'

// TODO: refer this from the core package
const port = parseInt(process.env.UI_PORT || '3000')

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
server: {
port: 3000
port
}
})
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
"version": "0.0.1",
"description": "The Manas AI",
"scripts": {
"ui:dev": "nx run ui:dev",
"ui:dev": "concurrently \"nx run core:build:watch\" \"nx run ui:dev\"",
"ui:build": "nx run ui:build",
"ui:lint": "nx run ui:lint",
"ui:test": "nx run ui:test",
"api:dev": "nx run api:dev",
"api:dev": "concurrently \"nx run core:build:watch\" \"nx run api:dev\"",
"api:build": "nx run api:build",
"api:lint": "nx run api:lint",
"api:test": "nx run api:test",
"lint": "nx run-many --target=lint --all",
"test": "nx run-many --target=test --all",
"build": "nx run-many --target=build --all"
"build": "nx run-many --target=build --all",
"prepare": "husky"
},
"lint-staged": {
"*.{js,ts,tsx,json,css,scss,md}": [
"prettier --write"
]
},
"keywords": [
"ManasAI",
Expand All @@ -26,6 +32,9 @@
"author": "Yash Patel <[email protected]>",
"license": "ISC",
"devDependencies": {
"concurrently": "^8.2.2",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"nx": "^18.2.1",
"prettier": "3.2.5"
}
Expand Down
23 changes: 23 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "core",
"private": true,
"version": "0.0.1",
"description": "Core utilities for the project",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "rm -rf dist/ && tsc",
"build:watch": "tsc -w"
},
"keywords": [],
"author": "Yash Patel <[email protected]>",
"license": "ISC",
"devDependencies": {
"@types/node": "^20.11.30",
"typescript": "^5.2.2"
},
"dependencies": {
"dotenv": "^16.4.5",
"winston": "^3.13.0"
}
}
6 changes: 6 additions & 0 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'dotenv/config'

export const API_PORT = parseInt(process.env.API_PORT || '8000')
export const API_URL = process.env.API_URL || `http://localhost:${API_PORT}`

export const UI_PORT = parseInt(process.env.UI_PORT || '3000')
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './config'
export * from './logger'
10 changes: 10 additions & 0 deletions packages/core/src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import winston from 'winston'

const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
defaultMeta: { service: 'api' },
transports: [new winston.transports.Console()]
})

export default logger
19 changes: 19 additions & 0 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "CommonJS",
"declaration": true,
"lib": ["ESNext"],
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
Loading

0 comments on commit 924ef47

Please sign in to comment.