Skip to content

Commit

Permalink
Merge pull request #3428 from LiteFarmOrg/LF-4395-setup-typescript-on…
Browse files Browse the repository at this point in the history
…-backend

Lf 4395 setup typescript on backend
  • Loading branch information
antsgar authored Feb 3, 2025
2 parents a3b7c6d + 9313379 commit 7a2bd7e
Show file tree
Hide file tree
Showing 36 changed files with 5,543 additions and 8,108 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/automated_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
api_unit_tests:
name: API Unit Tests
runs-on: ubuntu-20.04
container: node:18.16.1
container: node:20.17
services:
postgres:
image: postgres:13
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/lint_translation_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
run-linters-in-webapp:
name: Run linters in webapp
runs-on: ubuntu-latest
container: node:20.17
defaults:
run:
working-directory: packages/webapp/
Expand Down Expand Up @@ -44,7 +45,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20.17

- name: Install dependencies for Node.js server
run: npm install
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/webapp_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
webapp_unit_tests:
name: Webapp Unit Tests
runs-on: ubuntu-latest
container: node:20.17
defaults:
run:
working-directory: packages/webapp
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.16.1
v20.17.0
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ If you’re a farmer and would like to join LiteFarm you can sign up today at ap
LiteFarm is comprised of three applications which all reside in this monorepo.

- `packages/webapp` is the client-facing application
- `packages/api` is the back-end API server with entry point `src/server.js`
- `packages/api` is the back-end API server with entry point `src/server.ts`
- `packages/api/src/jobs` is the "jobs scheduler" for certification exports, with entry point `index.js`

## Preliminaries
Expand Down Expand Up @@ -103,7 +103,7 @@ In a Terminal window:

## api

In a terminal, navigate to the `packages/api` folder. Run `npm run nodemon` to launch the backend application. Nodemon will automatically restart the application when changes are made to the backend code.
In a terminal, navigate to the `packages/api` folder. Run `npm run dev` to launch the backend application in development mode. The server will automatically restart when changes are made to the backend code.

## webapp

Expand Down Expand Up @@ -261,7 +261,7 @@ _Note: Please make sure to run the commands in the following order:_
- `npm run ngrok` or `npm run ngrok:api` or `npm run ngrok:webapp`
- `npm run ngrok:setup` (in a new terminal)
- `pnpm dev` (in a new terminal from the `packages/webapp` folder)
- `npm run nodemon` (in a new terminal from the `packages/api` folder)
- `npm run dev` (in a new terminal from the `packages/api` folder)

# Docker

Expand Down
2 changes: 1 addition & 1 deletion beta-export-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ git stash
git pull origin integration
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
nvm use 18.16.1
nvm use 20.17
node -v
cd packages/api
npm install
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ services:
- export

export:
image: litefarm/node-awscli:0.0.2
image: litefarm/node-awscli:latest
restart: unless-stopped
volumes:
- ./packages/api:/packages/api
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"engines": {
"node": ">=20.6"
},
"devDependencies": {
"husky": "^7.0.4",
"lerna": "^5.0.0",
Expand Down
2 changes: 0 additions & 2 deletions packages/api/.eslintignore

This file was deleted.

29 changes: 0 additions & 29 deletions packages/api/.eslintrc.cjs

This file was deleted.

3 changes: 2 additions & 1 deletion packages/api/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
src/jobs/locales/*/crop.json
src/jobs/locales/*/*_old.json
/exports/temp
**/logs
**/logs
dist
64 changes: 21 additions & 43 deletions packages/api/.knex/knexfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>.
*/
// import path from 'path';
// import { fileURLToPath } from 'url';

const dotenv = require('dotenv');
const path = require('path');
import dotenv from 'dotenv';
dotenv.config({ path: '../.env' });

dotenv.config({ path: path.resolve(__dirname, '../.env') });
const migrations = {
directory: '../db/migration',
};

const root = path.resolve(__dirname, '../');
const seeds = {
directory: '../db/seeds',
};

module.exports = {
export default {
development: {
client: 'postgresql',
connection: {
Expand All @@ -32,12 +34,8 @@ module.exports = {
password: process.env.DEV_DATABASE_PASSWORD,
port: process.env.DEV_DATABASE_PORT || 5432,
},
migrations: {
directory: root + '/db/migration',
},
seeds: {
directory: root + '/db/seeds',
},
migrations,
seeds,
},

ci: {
Expand All @@ -48,12 +46,8 @@ module.exports = {
user: 'postgres',
password: 'postgres',
},
migrations: {
directory: root + '/db/migration',
},
seeds: {
directory: root + '/db/seeds',
},
migrations,
seeds,
},

integration: {
Expand All @@ -66,24 +60,16 @@ module.exports = {
password: process.env.DEV_DATABASE_PASSWORD,
ssl: { rejectUnauthorized: false },
},
migrations: {
directory: root + '/db/migration',
},
seeds: {
directory: root + '/db/seeds',
},
migrations,
seeds,
},

production: {
client: 'postgresql',
debug: true,
connection: process.env.DATABASE_URL,
migrations: {
directory: root + '/db/migration',
},
seeds: {
directory: root + '/db/seeds',
},
migrations,
seeds,
ssl: {
rejectUnauthorized: false,
},
Expand All @@ -98,12 +84,8 @@ module.exports = {
port: process.env.TEST_DATABASE_PORT || 5432,
},
pool: { min: 0, max: 100 },
migrations: {
directory: root + '/db/migration',
},
seeds: {
directory: root + '/db/seeds',
},
migrations,
seeds,
},
pipeline: {
client: 'postgresql',
Expand All @@ -115,11 +97,7 @@ module.exports = {
password: 'pipeline',
},
pool: { min: 0, max: 100 },
migrations: {
directory: root + '/db/migration',
},
seeds: {
directory: root + '/db/seeds',
},
migrations,
seeds,
},
};
4 changes: 2 additions & 2 deletions packages/api/.knex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"version": "1.0.0",
"description": "",
"main": "knexfile.js",
"type": "commonjs",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
}
1 change: 1 addition & 0 deletions packages/api/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
2 changes: 1 addition & 1 deletion packages/api/.nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.16.1
20.17.0
16 changes: 0 additions & 16 deletions packages/api/babel.config.cjs

This file was deleted.

31 changes: 31 additions & 0 deletions packages/api/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// @ts-check

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import json from 'eslint-plugin-json';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{
files: ['**/*.json'],
...json.configs['recommended'],
extends: [eslint.configs.recommended, ...tseslint.configs.recommended],
},
{
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
},
},
);
5 changes: 5 additions & 0 deletions packages/api/lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
'*.{ts}': [() => 'tsc'],
'*.{md,yml,json,js,ts}': 'prettier --write',
'*.{js,ts}': 'eslint --quiet --fix',
};
Loading

0 comments on commit 7a2bd7e

Please sign in to comment.