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

Lf 4395 setup typescript on backend #3428

Open
wants to merge 37 commits into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d89353c
LF-4395 use @swc/jest for tests transformation
navDhammu Sep 10, 2024
1facaec
LF-4395 use node v20 in github actions
navDhammu Sep 10, 2024
9abc14a
LF-4395 create tsconfig and dev script with @swc-node
navDhammu Sep 11, 2024
b0f56e3
LF-4395 convert .knex to esm modules
navDhammu Sep 11, 2024
d28933b
LF-4395 add typescript and setup build scripts with tsc
navDhammu Sep 11, 2024
918b136
LF-4395 update dev and start scripts
navDhammu Sep 11, 2024
d8f5969
LF-4395 remove import.meta from knexfile and update knex version
navDhammu Sep 11, 2024
b0c302f
LF-4395 convert server.js to typescript
navDhammu Sep 11, 2024
114d2a5
LF-4395 update lint-staged with typechecking
navDhammu Sep 11, 2024
b799979
LF-4395 setup typescript-eslint and update eslint version
navDhammu Sep 11, 2024
e76b724
LF-4395 fix linting of json files
navDhammu Sep 11, 2024
d6ed249
LF-4395 require node >= 20.6 in package.json
navDhammu Sep 11, 2024
eec6db0
LF-4395 remove nodemon
navDhammu Sep 11, 2024
5f7a2da
LF-4395 update npm scripts containing nodemon
navDhammu Sep 11, 2024
58530b5
LF-4395 remove babel dependencies
navDhammu Sep 11, 2024
259183c
LF-4395 update .nvmrc to v20
navDhammu Sep 12, 2024
e139d47
LF-4395 modify root tsconfig to noEmit and include tests
navDhammu Sep 12, 2024
fbc570a
LF-4395 add separate tsconfig for src and adjust build script
navDhammu Sep 12, 2024
84f3923
LF-4395 use node v20 in api linting job
navDhammu Sep 12, 2024
690be55
LF-4395 add dotenv setupFile for jest tests
navDhammu Sep 29, 2024
43a0e2d
Merge branch integration into LF-4395-setup-typescript-on-backend
navDhammu Sep 29, 2024
4016d81
LF-4395 install jest types
navDhammu Sep 30, 2024
6abf6f5
Update README.md
navDhammu Oct 8, 2024
68f2b22
LF-4395 set node version 20 with engine-strict for all packages
navDhammu Oct 10, 2024
f0606a9
LF-4395 update node version to lts in beta-export-deploy.sh and prod.…
navDhammu Oct 11, 2024
8267608
LF-4395 replace nodemon in api/prod.Dockerfile
navDhammu Oct 11, 2024
45fc01b
LF-4395 set node version to lts in github actions for lint translatio…
navDhammu Oct 11, 2024
0fb5100
LF-4395 set pnpm version 9 in webapp_unit_tests and lint_translation_…
navDhammu Oct 11, 2024
82f82cb
LF-4395 update pnpm-lock file
navDhammu Oct 11, 2024
5136c4c
LF-4395 update docker image tag to :latest
navDhammu Jan 16, 2025
638b0d3
LF-4395 replace all instances of node:lts with 20.17
navDhammu Jan 16, 2025
83da703
LF-4395 set node version to 20.17 in all packages
navDhammu Jan 16, 2025
ae7f81a
LF-4395 resolve merge conflict in workflows
navDhammu Jan 16, 2025
d777d25
LF-4395 regenerate webapp and api lock files
navDhammu Jan 16, 2025
c6f2326
Merge branch 'integration' into LF-4395-setup-typescript-on-backend
navDhammu Jan 31, 2025
5eb7006
LF-4395 update api linter to node 20.17
navDhammu Jan 31, 2025
9313379
LF-4395 update api lock file
navDhammu Jan 31, 2025
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
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
Loading