mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-20 22:49:18 +00:00
Merge branch 'master' into port-colision
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
<html lang='en'>
|
<html lang='en'>
|
||||||
<head>
|
<head>
|
||||||
<meta charset='utf-8' />
|
<meta charset='utf-8' />
|
||||||
|
<base href="/">
|
||||||
<link rel='icon' href='/favicon.ico' />
|
<link rel='icon' href='/favicon.ico' />
|
||||||
<meta name='viewport' content='width=device-width, initial-scale=1' />
|
<meta name='viewport' content='width=device-width, initial-scale=1' />
|
||||||
<meta name='theme-color' content='#101010' />
|
<meta name='theme-color' content='#101010' />
|
||||||
|
|||||||
@@ -87,9 +87,9 @@
|
|||||||
"sass": "^1.57.1",
|
"sass": "^1.57.1",
|
||||||
"typescript": "catalog:",
|
"typescript": "catalog:",
|
||||||
"vite": "^5.2.11",
|
"vite": "^5.2.11",
|
||||||
"vite-plugin-compression2": "^0.12.0",
|
"vite-plugin-compression2": "^1.3.3",
|
||||||
"vite-plugin-svgr": "^4.2.0",
|
"vite-plugin-svgr": "^4.2.0",
|
||||||
"vite-tsconfig-paths": "^4.3.1",
|
"vite-tsconfig-paths": "^4.3.1",
|
||||||
"vitest": "^1.6.0"
|
"vitest": "catalog:"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,9 @@ export default function ProjectData() {
|
|||||||
uploadInputRef.current?.click();
|
uploadInputRef.current?.click();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteLogo = () => {
|
const handleDeleteLogo = (e: React.MouseEvent<HTMLButtonElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
setValue('projectLogo', null, {
|
setValue('projectLogo', null, {
|
||||||
shouldDirty: true,
|
shouldDirty: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { sentryVitePlugin } from '@sentry/vite-plugin';
|
|||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import { fileURLToPath, URL } from 'node:url';
|
import { fileURLToPath, URL } from 'node:url';
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import { splitVendorChunkPlugin } from 'vite';
|
|
||||||
import { compression } from 'vite-plugin-compression2';
|
import { compression } from 'vite-plugin-compression2';
|
||||||
import svgrPlugin from 'vite-plugin-svgr';
|
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({
|
export default defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
react(),
|
react(),
|
||||||
splitVendorChunkPlugin(),
|
|
||||||
svgrPlugin(),
|
svgrPlugin(),
|
||||||
!isDev &&
|
!isDev &&
|
||||||
sentryVitePlugin({
|
sentryVitePlugin({
|
||||||
@@ -33,7 +31,10 @@ export default defineConfig({
|
|||||||
excludeReplayWorker: true,
|
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: {
|
server: {
|
||||||
port: 3000,
|
port: 3000,
|
||||||
@@ -46,6 +47,16 @@ export default defineConfig({
|
|||||||
build: {
|
build: {
|
||||||
outDir: './build',
|
outDir: './build',
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
|
rollupOptions: {
|
||||||
|
output: {
|
||||||
|
manualChunks(id) {
|
||||||
|
// Split vendor code
|
||||||
|
if (id.includes('node_modules')) {
|
||||||
|
return 'vendor';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
|
|||||||
@@ -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',
|
||||||
|
});
|
||||||
@@ -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',
|
||||||
|
});
|
||||||
@@ -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',
|
||||||
|
});
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
export const esbuildCommon = {
|
||||||
|
logLevel: 'error',
|
||||||
|
platform: 'node',
|
||||||
|
target: ['node20'],
|
||||||
|
format: 'cjs',
|
||||||
|
bundle: true,
|
||||||
|
minify: true,
|
||||||
|
legalComments: 'external',
|
||||||
|
dropLabels: ['DEV'],
|
||||||
|
};
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"ext": "js,json,ts"
|
|
||||||
}
|
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
"@types/ws": "^8.5.10",
|
"@types/ws": "^8.5.10",
|
||||||
"@typescript-eslint/eslint-plugin": "catalog:",
|
"@typescript-eslint/eslint-plugin": "catalog:",
|
||||||
"@typescript-eslint/parser": "catalog:",
|
"@typescript-eslint/parser": "catalog:",
|
||||||
"esbuild": "^0.19.10",
|
"esbuild": "^0.24.0",
|
||||||
"eslint": "catalog:",
|
"eslint": "catalog:",
|
||||||
"eslint-plugin-prettier": "catalog:",
|
"eslint-plugin-prettier": "catalog:",
|
||||||
"ontime-types": "workspace:*",
|
"ontime-types": "workspace:*",
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
"ts-essentials": "^9.4.1",
|
"ts-essentials": "^9.4.1",
|
||||||
"tsx": "^4.16.2",
|
"tsx": "^4.16.2",
|
||||||
"typescript": "catalog:",
|
"typescript": "catalog:",
|
||||||
"vitest": "^1.6.0"
|
"vitest": "catalog:"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"addversion": "node -p \"'export const ONTIME_VERSION = ' + JSON.stringify(require('../../package.json').version) + ';'\" > src/ONTIME_VERSION.js",
|
"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": "cross-env NODE_ENV=development tsx watch ./src/index.ts",
|
||||||
"dev:inspect": "cross-env NODE_ENV=development tsx watch --inspect ./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",
|
"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": "node esbuild.electron.js",
|
||||||
"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:electron": "node esbuild.electron.js",
|
||||||
"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:local": "node esbuild.dev.js",
|
||||||
"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:docker": "node esbuild.docker.js",
|
||||||
"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:localdocker": "cross-env NODE_ENV=local node esbuild.docker.js",
|
||||||
"build:debug": "esbuild src/app.ts --platform=node --format=cjs --bundle --legal-comments=external --outfile=dist/index.cjs",
|
|
||||||
"lint": "eslint . --quiet",
|
"lint": "eslint . --quiet",
|
||||||
"test": "cross-env IS_TEST=true vitest",
|
"test": "cross-env IS_TEST=true vitest",
|
||||||
"test:pipeline": "cross-env IS_TEST=true vitest run",
|
"test:pipeline": "cross-env IS_TEST=true vitest run",
|
||||||
|
|||||||
+21
-6
@@ -6,11 +6,11 @@ import expressStaticGzip from 'express-static-gzip';
|
|||||||
import http, { Server } from 'http';
|
import http, { Server } from 'http';
|
||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
import serverTiming from 'server-timing';
|
import serverTiming from 'server-timing';
|
||||||
|
import { extname, resolve } from 'path';
|
||||||
|
|
||||||
// import utils
|
// import utils
|
||||||
import { resolve } from 'path';
|
|
||||||
import { publicDir, srcDir } from './setup/index.js';
|
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 { ONTIME_VERSION } from './ONTIME_VERSION.js';
|
||||||
import { consoleSuccess, consoleHighlight, consoleError } from './utils/console.js';
|
import { consoleSuccess, consoleHighlight, consoleError } from './utils/console.js';
|
||||||
|
|
||||||
@@ -53,9 +53,12 @@ if (!canLog) {
|
|||||||
console.log(`Ontime public directory at ${publicDir.root} `);
|
console.log(`Ontime public directory at ${publicDir.root} `);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// calls an update to the client router prefix
|
||||||
|
updateRouterPrefix();
|
||||||
|
|
||||||
// Create express APP
|
// Create express APP
|
||||||
const app = express();
|
const app = express();
|
||||||
if (process.env.NODE_ENV === 'development') {
|
if (!isProduction) {
|
||||||
// log server timings to requests
|
// log server timings to requests
|
||||||
app.use(serverTiming());
|
app.use(serverTiming());
|
||||||
}
|
}
|
||||||
@@ -89,10 +92,22 @@ app.use(
|
|||||||
expressStaticGzip(srcDir.clientDir, {
|
expressStaticGzip(srcDir.clientDir, {
|
||||||
enableBrotli: true,
|
enableBrotli: true,
|
||||||
orderPreference: ['br'],
|
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
|
// 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
|
// meaning that the client does not need to revalidate the contents with the server
|
||||||
serveStatic: { etag: false, lastModified: false, immutable: true, maxAge: '1y' },
|
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');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
* This file contains a list of constants that may need to be resolved at runtime
|
* 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
|
// resolve running environment
|
||||||
const env = process.env.NODE_ENV || 'production';
|
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 environment = isTest ? 'test' : env;
|
||||||
export const isDocker = env === 'docker';
|
export const isDocker = env === 'docker';
|
||||||
export const isProduction = isDocker || (env === 'production' && !isTest);
|
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 */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
"ontime-types": "workspace:*",
|
"ontime-types": "workspace:*",
|
||||||
"prettier": "catalog:",
|
"prettier": "catalog:",
|
||||||
"typescript": "catalog:",
|
"typescript": "catalog:",
|
||||||
"vitest": "^1.6.0"
|
"vitest": "catalog:"
|
||||||
},
|
},
|
||||||
"sideEffects": false
|
"sideEffects": false
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+370
-539
File diff suppressed because it is too large
Load Diff
+2
-1
@@ -10,4 +10,5 @@ catalog:
|
|||||||
prettier: 3.3.1
|
prettier: 3.3.1
|
||||||
eslint: 8.56.0
|
eslint: 8.56.0
|
||||||
eslint-config-prettier: 9.1.0
|
eslint-config-prettier: 9.1.0
|
||||||
eslint-plugin-prettier: 5.1.3
|
eslint-plugin-prettier: 5.1.3
|
||||||
|
vitest: 2.1.6
|
||||||
|
|||||||
@@ -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',
|
||||||
|
]);
|
||||||
Reference in New Issue
Block a user