Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
LironEr committed May 11, 2024
1 parent 73a1f20 commit d1af258
Show file tree
Hide file tree
Showing 128 changed files with 480 additions and 423 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
node_modules
.nx
dist/
lib/
**/__tests__/**/assets
.vercel
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,3 @@ deploy.env
.nx/cache
.tmp
tmp
lib
7 changes: 0 additions & 7 deletions apps/service/.test.env

This file was deleted.

2 changes: 1 addition & 1 deletion apps/service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN addgroup --system service && adduser --system -G service service
# Needed by @fastify/secure-session
RUN npm i sodium-native@^4.0.0

COPY dist service
COPY dist/apps/service service

RUN chown -R service:service .

Expand Down
7 changes: 5 additions & 2 deletions apps/service/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export default {
import type { Config } from '@jest/types';

export default async (): Promise<Config.InitialOptions> => ({
displayName: 'service',
preset: '../../jest.preset.js',
coverageDirectory: '../../coverage/apps/service',
setupFilesAfterEnv: ['<rootDir>/tests/hooks.ts'],
};
setupFiles: ['<rootDir>/tests/setup.ts'],
});
13 changes: 2 additions & 11 deletions apps/service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
"license": "MIT",
"scripts": {
"serve": "yarn nx serve service",
"start:server:watch": "nodemon --watch \"src/*\" --exec ts-node -r dotenv/config -r tsconfig-paths/register \"src/app.ts\"",
"start:watch": "nodemon --watch \"src/*\" --ignore \"src/consts/schemas.ts\" --ext \".ts\" --exec \"yarn generate-schemas && ts-node -r tsconfig-paths/register src/app.ts\"",
"watch": "tsc -p tsconfig.release.json --watch --preserveWatchOutput --pretty",
"prebuild": "yarn generate-schemas",
"build": "rimraf dist/ && ncc build --external sodium-native src/app.ts",
"build": "yarn nx build service",
"generate-schemas": "node ./scripts/generateSchemas.js",
"prevercel-deploy": "yarn lint && yarn type-check && yarn generate-schemas && yarn build",
"prevercel-deploy": "yarn nx build service -c vercel",
"vercel-deploy": "vercel deploy",
"start:mock-services": "docker-compose -f docker-compose.test.yml up --remove-orphans",
"gen-local-data": "node -r @swc-node/register -r dotenv/config ./scripts/generateLocalData.ts dotenv_config_path=.development.env"
Expand All @@ -29,13 +25,8 @@
"mongodb": "^6.3.0"
},
"devDependencies": {
"@vercel/ncc": "^0.36.1",
"dotenv": "^16.3.1",
"nodemon": "^3.0.1",
"rimraf": "^5.0.1",
"ts-json-schema-generator": "^1.3.0",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.6",
"vercel": "^31.4.0"
}
Expand Down
5 changes: 0 additions & 5 deletions apps/service/scripts/generateLocalData.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// import * as path from 'node:path';
// import * as dotenv from 'dotenv';
// console.log('TCL ~ __dirname:', __dirname);
// dotenv.config({ path: path.join(__dirname, '../.development.env') });

import { ObjectId } from 'mongodb';
import { getDB } from '../src/framework/mongo/client';
import { getProjectsCollection } from '../src/framework/mongo/projects';
Expand Down
26 changes: 26 additions & 0 deletions apps/service/scripts/initDb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { getDB } from '../src/framework/mongo/client';
import { getCommitRecordsCollection } from '../src/framework/mongo/commitRecords';

export async function initDb() {
const db = await getDB();

await db.admin().ping({ maxTimeMS: 5000 });

const commitRecordsCollection = await getCommitRecordsCollection();

// Create indexes
await commitRecordsCollection.createIndex({ projectId: 1, subProject: 1, branch: 1, creationDate: -1 });

// TTL index - remove commit records on PRs after 30 days
await commitRecordsCollection.createIndex(
{ creationDate: 1 },
{ expireAfterSeconds: 30 * 24 * 60 * 60, partialFilterExpression: { prNumber: { $exists: true } } }
);
}

// If called directly i.e. "node app"
if (require.main === module) {
(async () => {
await initDb();
})();
}
8 changes: 4 additions & 4 deletions apps/service/src/routes/api/__tests__/authRoutes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('auth routes', () => {
name: 'isSessionExists',
value: expect.any(String),
maxAge: DEFAULT_SESSION_AGE_SECONDS,
domain: 'bundlemon.dev',
domain: 'localhost',
path: '/',
expires: expiresAt,
secure: true,
Expand All @@ -44,7 +44,7 @@ describe('auth routes', () => {
name: 'session',
value: expect.any(String),
maxAge: DEFAULT_SESSION_AGE_SECONDS,
domain: 'bundlemon.dev',
domain: 'localhost',
path: '/',
expires: expiresAt,
httpOnly: true,
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('auth routes', () => {
{
name: 'isSessionExists',
value: '',
domain: 'bundlemon.dev',
domain: 'localhost',
path: '/',
expires: new Date(0),
secure: true,
Expand All @@ -112,7 +112,7 @@ describe('auth routes', () => {
name: 'session',
value: '',
maxAge: 0,
domain: 'bundlemon.dev',
domain: 'localhost',
path: '/',
expires: new Date(0),
httpOnly: true,
Expand Down
15 changes: 14 additions & 1 deletion apps/service/tests/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
/* eslint-disable @typescript-eslint/no-var-requires */

// When using import on top of the file mocks wont mock, so use require inside the hooks
import { initDb } from '../scripts/initDb';
// import { getProjectsCollection } from '@/framework/mongo/projects';
// import { getCommitRecordsCollection } from '@/framework/mongo/commitRecords';

beforeAll(async () => {
await initDb();

// console.log('clear DB');

// const commitRecordsCollection = await getCommitRecordsCollection();
// await commitRecordsCollection.deleteMany({});

// const projectsCollection = await getProjectsCollection();
// await projectsCollection.deleteMany({});

// When using import on top of the file mocks wont mock, so use require inside the hooks
const { app } = require('./app');
await app.ready();
});
Expand Down
4 changes: 3 additions & 1 deletion apps/service/tests/setup.js → apps/service/tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
const path = require('path');

require('dotenv').config({
path: path.resolve(__dirname, '../.test.env'),
path: path.resolve(__dirname, '../.development.env'),
});

process.env.MONGO_DB_NAME = 'test';
19 changes: 10 additions & 9 deletions apps/service/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"compilerOptions": {
"module": "ES2022",
"baseUrl": ".",
"paths": {
"@tests/*": ["./tests/*"],
"@/*": ["src/*"]
}
},
"references": [
{
"path": "./tsconfig.app.json"
Expand All @@ -10,11 +16,6 @@
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@tests/*": ["./tests/*"],
"@/*": ["src/*"]
}
}
"files": [],
"include": [],
}
2 changes: 1 addition & 1 deletion apps/service/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"outDir": "../../dist/out-tsc",
"types": ["jest", "node"]
},
"include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
"include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts", "tests/**/*"]
}
11 changes: 7 additions & 4 deletions apps/website/.bundlemonrc.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"verbose": true,
"baseDir": "./build",
"baseDir": "../../dist/apps/website",
"files": [
{
"path": "index.html"
},
{
"path": "main.<hash>.js"
"path": "assets/Main-*-<hash>.js"
},
{
"friendlyName": "JS files",
"path": "**/*.<hash>.js"
"path": "assets/**/*-<hash>.js"
}
],
"groups": [
Expand All @@ -25,5 +25,8 @@
],
"defaultCompression": "none",
"reportOutput": ["github"],
"includeCommitMessage": true
"includeCommitMessage": true,
"pathLabels": {
"hash": "[a-zA-Z0-9\\-_]+"
}
}
5 changes: 4 additions & 1 deletion apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"private": true,
"license": "MIT",
"scripts": {
"serve": "yarn nx serve website"
"build": "yarn --cwd ../../ nx build website --verbose",
"serve": "yarn --cwd ../../ nx serve website --verbose",
"serve:preview": "yarn --cwd ../../ nx preview website --verbose",
"bundlemon": "node -r @swc-node/register ../../packages/bundlemon/bin/bundlemon.ts"
},
"dependencies": {
"@emotion/react": "^11.11.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/website/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"outputPath": "{projectRoot}/dist",
"outputPath": "dist/{projectRoot}",
"generatePackageJson": false
},
"configurations": {
Expand Down
14 changes: 7 additions & 7 deletions apps/website/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import tsconfigPaths from 'vite-tsconfig-paths';
import svgr from 'vite-plugin-svgr';
import basicSsl from '@vitejs/plugin-basic-ssl'

import basicSsl from '@vitejs/plugin-basic-ssl';

export default defineConfig({
root: __dirname,
Expand All @@ -20,15 +19,16 @@ export default defineConfig({
},
plugins: [react(), tsconfigPaths(), svgr(), basicSsl()],
build: {
outDir: 'dist',
outDir: '../../dist/apps/website',
emptyOutDir: true,
reportCompressedSize: true,
commonjsOptions: {
transformMixedEsModules: true,
include: [/node_modules/, /bundlemon\-utils/],
},
rollupOptions: {
output: {
entryFileNames: `assets/Main-[name]-[hash].js`,
},
},
},
optimizeDeps: {
include: ['bundlemon-utils']
}
});
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"private": true,
"license": "MIT",
"scripts": {
"test-packages": "yarn nx run-many --target=test --projects bundlemon-utils,bundlemon-markdown-output,bundlemon --verbose",
"build-packages": "nx run-many --target=build --projects bundlemon-utils,bundlemon-markdown-output,bundlemon",
"build-packages:watch": "nx watch --projects bundlemon-utils,bundlemon-markdown-output,bundlemon -- nx run \\$NX_PROJECT_NAME:build",
"lint-packages": "yarn nx run-many --target=lint --projects bundlemon-utils,bundlemon-markdown-output,bundlemon",
"test-packages": "yarn nx run-many --target=test --projects tag:type:lib --verbose",
"build-packages": "nx run-many --target=build --projects tag:type:lib",
"build-packages:watch": "nx watch --projects tag:type:lib -- nx run \\$NX_PROJECT_NAME:build",
"lint-packages": "yarn nx run-many --target=lint --projects tag:type:lib",
"type-check-packages": "lerna run type-check --stream",
"start:service": "docker-compose -f docker-compose.dev.yml up --build",
"prepare": "husky install"
Expand All @@ -20,8 +20,6 @@
"@nx/react": "^18.3.3",
"@nx/vite": "18.3.3",
"@nx/web": "18.3.3",
"@swc-node/register": "^1.9.1",
"@swc/core": "^1.4.17",
"@types/jest": "^29.5.1",
"@types/jest-when": "^3.5.2",
"@types/node": "18.16.9",
Expand All @@ -43,10 +41,10 @@
"lint-staged": "^15.2.2",
"nx": "18.3.2",
"prettier": "^3.0.2",
"rimraf": "^5.0.5",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
"typescript": "^5.0.4",
"vite": "~5.0.0"
},
"engines": {
"yarn": "^1.10.0"
Expand Down
13 changes: 4 additions & 9 deletions packages/bundlemon-markdown-output/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,16 @@
"directory": "packages/bundlemon-markdown-output"
},
"engines": {
"node": ">=18"
"node": ">=14.16"
},
"main": "lib/index.js",
"main": "lib/index",
"types": "lib/index.d.ts",
"scripts": {
"build": "rimraf lib && tsc -p tsconfig.lib.json"
},
"scripts": {},
"dependencies": {
"bundlemon-utils": "^1.2.1",
"bytes": "^3.1.0"
},
"devDependencies": {
"@types/bytes": "^3.1.0"
},
"files": [
"lib"
]
}
}
Loading

0 comments on commit d1af258

Please sign in to comment.