Merge branch 'master' into port-colision

This commit is contained in:
Alex Christoffer Rasmussen
2024-11-29 21:12:49 +01:00
committed by GitHub
16 changed files with 489 additions and 564 deletions
+1
View File
@@ -2,6 +2,7 @@
<html lang='en'>
<head>
<meta charset='utf-8' />
<base href="/">
<link rel='icon' href='/favicon.ico' />
<meta name='viewport' content='width=device-width, initial-scale=1' />
<meta name='theme-color' content='#101010' />
+2 -2
View File
@@ -87,9 +87,9 @@
"sass": "^1.57.1",
"typescript": "catalog:",
"vite": "^5.2.11",
"vite-plugin-compression2": "^0.12.0",
"vite-plugin-compression2": "^1.3.3",
"vite-plugin-svgr": "^4.2.0",
"vite-tsconfig-paths": "^4.3.1",
"vitest": "^1.6.0"
"vitest": "catalog:"
}
}
@@ -68,7 +68,9 @@ export default function ProjectData() {
uploadInputRef.current?.click();
};
const handleDeleteLogo = () => {
const handleDeleteLogo = (e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault();
e.stopPropagation();
setValue('projectLogo', null, {
shouldDirty: true,
});
+14 -3
View File
@@ -2,7 +2,6 @@ import { sentryVitePlugin } from '@sentry/vite-plugin';
import react from '@vitejs/plugin-react';
import { fileURLToPath, URL } from 'node:url';
import { defineConfig } from 'vite';
import { splitVendorChunkPlugin } from 'vite';
import { compression } from 'vite-plugin-compression2';
import svgrPlugin from 'vite-plugin-svgr';
@@ -14,7 +13,6 @@ const isDev = process.env.NODE_ENV === 'local' || process.env.NODE_ENV === 'deve
export default defineConfig({
plugins: [
react(),
splitVendorChunkPlugin(),
svgrPlugin(),
!isDev &&
sentryVitePlugin({
@@ -33,7 +31,10 @@ export default defineConfig({
excludeReplayWorker: true,
},
}),
compression({ algorithm: 'brotliCompress' }),
compression({
algorithm: 'brotliCompress',
exclude: /\.(html)$/, // Exclude HTML files from compression so we can change the base property at runtime
}),
],
server: {
port: 3000,
@@ -46,6 +47,16 @@ export default defineConfig({
build: {
outDir: './build',
sourcemap: true,
rollupOptions: {
output: {
manualChunks(id) {
// Split vendor code
if (id.includes('node_modules')) {
return 'vendor';
}
},
},
},
},
resolve: {
alias: {
+10
View File
@@ -0,0 +1,10 @@
import * as esbuild from 'esbuild';
import { esbuildCommon } from './esbuildCommon.js';
await esbuild.build({
...esbuildCommon,
entryPoints: ['src/app.ts'],
minify: false,
dropLabels: [],
outfile: 'dist/index.cjs',
});
+8
View File
@@ -0,0 +1,8 @@
import * as esbuild from 'esbuild';
import { esbuildCommon } from './esbuildCommon.js';
await esbuild.build({
...esbuildCommon,
entryPoints: ['src/index.ts'],
outfile: 'dist/docker.cjs',
});
+8
View File
@@ -0,0 +1,8 @@
import * as esbuild from 'esbuild';
import { esbuildCommon } from './esbuildCommon.js';
await esbuild.build({
...esbuildCommon,
entryPoints: ['src/app.ts'],
outfile: 'dist/index.cjs',
});
+10
View File
@@ -0,0 +1,10 @@
export const esbuildCommon = {
logLevel: 'error',
platform: 'node',
target: ['node20'],
format: 'cjs',
bundle: true,
minify: true,
legalComments: 'external',
dropLabels: ['DEV'],
};
-3
View File
@@ -1,3 +0,0 @@
{
"ext": "js,json,ts"
}
+7 -8
View File
@@ -33,7 +33,7 @@
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "catalog:",
"@typescript-eslint/parser": "catalog:",
"esbuild": "^0.19.10",
"esbuild": "^0.24.0",
"eslint": "catalog:",
"eslint-plugin-prettier": "catalog:",
"ontime-types": "workspace:*",
@@ -43,7 +43,7 @@
"ts-essentials": "^9.4.1",
"tsx": "^4.16.2",
"typescript": "catalog:",
"vitest": "^1.6.0"
"vitest": "catalog:"
},
"scripts": {
"addversion": "node -p \"'export const ONTIME_VERSION = ' + JSON.stringify(require('../../package.json').version) + ';'\" > src/ONTIME_VERSION.js",
@@ -51,12 +51,11 @@
"dev": "cross-env NODE_ENV=development tsx watch ./src/index.ts",
"dev:inspect": "cross-env NODE_ENV=development tsx watch --inspect ./src/index.ts",
"dev:test": "cross-env IS_TEST=true tsx ./src/index.ts",
"build": "esbuild src/app.ts --log-level=error --platform=node --format=cjs --bundle --minify --legal-comments=external --drop-labels=DEV --outfile=dist/index.cjs",
"build:electron": "esbuild src/app.ts --log-level=error --platform=node --format=cjs --bundle --minify --legal-comments=external --drop-labels=DEV --outfile=dist/index.cjs",
"build:local": "esbuild src/app.ts --log-level=error --platform=node --format=cjs --bundle --minify --legal-comments=external --drop-labels=DEV --outfile=dist/index.cjs",
"build:docker": "esbuild src/index.ts --log-level=error --platform=node --format=cjs --minify --bundle --legal-comments=external --drop-labels=DEV --outfile=dist/docker.cjs",
"build:localdocker": "cross-env NODE_ENV=local esbuild src/index.ts --log-level=error --platform=node --format=cjs --minify --bundle --legal-comments=external --drop-labels=DEV --outfile=dist/docker.cjs",
"build:debug": "esbuild src/app.ts --platform=node --format=cjs --bundle --legal-comments=external --outfile=dist/index.cjs",
"build": "node esbuild.electron.js",
"build:electron": "node esbuild.electron.js",
"build:local": "node esbuild.dev.js",
"build:docker": "node esbuild.docker.js",
"build:localdocker": "cross-env NODE_ENV=local node esbuild.docker.js",
"lint": "eslint . --quiet",
"test": "cross-env IS_TEST=true vitest",
"test:pipeline": "cross-env IS_TEST=true vitest run",
+21 -6
View File
@@ -6,11 +6,11 @@ import expressStaticGzip from 'express-static-gzip';
import http, { Server } from 'http';
import cors from 'cors';
import serverTiming from 'server-timing';
import { extname, resolve } from 'path';
// import utils
import { resolve } from 'path';
import { publicDir, srcDir } from './setup/index.js';
import { environment, isProduction } from './externals.js';
import { environment, isProduction, updateRouterPrefix } from './externals.js';
import { ONTIME_VERSION } from './ONTIME_VERSION.js';
import { consoleSuccess, consoleHighlight, consoleError } from './utils/console.js';
@@ -53,9 +53,12 @@ if (!canLog) {
console.log(`Ontime public directory at ${publicDir.root} `);
}
// calls an update to the client router prefix
updateRouterPrefix();
// Create express APP
const app = express();
if (process.env.NODE_ENV === 'development') {
if (!isProduction) {
// log server timings to requests
app.use(serverTiming());
}
@@ -89,10 +92,22 @@ app.use(
expressStaticGzip(srcDir.clientDir, {
enableBrotli: true,
orderPreference: ['br'],
// when we build the client all the react subfiles will get a hashed name we can the immutable tag
// when we build the client the file names contain a unique hash for the build
// this allows us to use the immutable tag
// as the contents of a build file will never change without also changing its name
// so the client dose not need to revalidate the file contetnts with the server
serveStatic: { etag: false, lastModified: false, immutable: true, maxAge: '1y' },
// meaning that the client does not need to revalidate the contents with the server
serveStatic: {
etag: false,
lastModified: false,
immutable: true,
maxAge: '1y',
setHeaders: (res, file) => {
// make sure the HTML files are always revalidated
if (extname(file) === '.html') {
res.setHeader('Cache-Control', 'public, max-age=0');
}
},
},
}),
);
+25
View File
@@ -2,6 +2,9 @@
* This file contains a list of constants that may need to be resolved at runtime
*/
import { readFileSync, writeFileSync } from 'node:fs';
import { resolve } from 'node:path';
// =================================================
// resolve running environment
const env = process.env.NODE_ENV || 'production';
@@ -10,3 +13,25 @@ export const isTest = Boolean(process.env.IS_TEST);
export const environment = isTest ? 'test' : env;
export const isDocker = env === 'docker';
export const isProduction = isDocker || (env === 'production' && !isTest);
/**
* Updates the router prefix in the index.html file
* This is only needed in the cloud environment where the client is not at the root segment
* ie: https://cloud.getontime.com/client-hash/timer
*/
export function updateRouterPrefix(prefix: string | undefined = process.env.ROUTER_PREFIX) {
if (!prefix) {
return;
}
const indexFile = resolve('.', 'client', 'index.html');
try {
const data = readFileSync(indexFile, { encoding: 'utf-8', flag: 'r' }).replace(
/<base href="[^"]*">/g,
`<base href="${prefix}>"`,
);
writeFileSync(indexFile, data, { encoding: 'utf-8', flag: 'w' });
} catch (_error) {
/** unhandled */
}
}
+1 -1
View File
@@ -24,7 +24,7 @@
"ontime-types": "workspace:*",
"prettier": "catalog:",
"typescript": "catalog:",
"vitest": "^1.6.0"
"vitest": "catalog:"
},
"sideEffects": false
}
+370 -539
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -10,4 +10,5 @@ catalog:
prettier: 3.3.1
eslint: 8.56.0
eslint-config-prettier: 9.1.0
eslint-plugin-prettier: 5.1.3
eslint-plugin-prettier: 5.1.3
vitest: 2.1.6
+7
View File
@@ -0,0 +1,7 @@
import { defineWorkspace } from 'vitest/config';
export default defineWorkspace([
'./apps/client/vite.config.js',
'./apps/server/vite.config.ts',
'./packages/utils/vite.config.ts',
]);