feat: vite dev mode

This commit is contained in:
Eli Bosley
2024-11-05 10:20:47 -05:00
parent 9f0ab7fa38
commit 7177171b75
8 changed files with 1028 additions and 772 deletions

1751
api/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -22,14 +22,7 @@
"test": "DOTENV_CONFIG_PATH=./.env.test NODE_ENV=test vitest run --pool=forks",
"coverage": "DOTENV_CONFIG_PATH=./.env.test NODE_ENV=test vitest run --coverage",
"release": "standard-version",
"install:unraid": "./scripts/install-in-unraid.sh",
"boot:unraid": "tsx -r dotenv/config src/index.ts",
"tsx:unraid": "tsx -r dotenv/config src/cli.ts",
"start:plugin": "INTROSPECTION=true LOG_MOTHERSHIP_MESSAGES=true LOG_TYPE=pretty LOG_LEVEL=trace unraid-api start --debug",
"start:plugin-verbose": "LOG_CONTEXT=true LOG_MOTHERSHIP_MESSAGES=true LOG_TYPE=pretty LOG_LEVEL=trace unraid-api start --debug",
"run:tsx": "LOG_MOTHERSHIP_MESSAGES=true LOG_TYPE=pretty LOG_LEVEL=trace DOTENV_CONFIG_PATH=./.env.development tsx -r dotenv/config src/cli.ts",
"watch:tsx": "LOG_MOTHERSHIP_MESSAGES=true LOG_TYPE=pretty LOG_LEVEL=trace DOTENV_CONFIG_PATH=./.env.development tsx watch -r dotenv/config src/cli.ts",
"start:dev": "LOG_MOTHERSHIP_MESSAGES=true LOG_TYPE=pretty NODE_ENV=development LOG_LEVEL=trace DOTENV_CONFIG_PATH=./.env.development node -r dotenv/config dist/main.js",
"start:dev": "vite",
"restart:dev": "npm run run:tsx -- restart --debug",
"stop:dev": "npm run run:tsx -- stop --debug",
"start:report": "npm run run:tsx -- report --debug",
@@ -83,7 +76,7 @@
"docker-event-emitter": "^0.3.0",
"dockerode": "^3.3.5",
"dotenv": "^16.4.5",
"execa": "^9.4.1",
"execa": "^9.5.1",
"exit-hook": "^4.0.0",
"express": "^4.19.2",
"filenamify": "^6.0.0",
@@ -143,6 +136,7 @@
"@graphql-typed-document-node/core": "^3.2.0",
"@nestjs/testing": "^10.3.8",
"@originjs/vite-plugin-commonjs": "^1.0.3",
"@rollup/plugin-node-resolve": "^15.3.0",
"@types/async-exit-hook": "^2.0.2",
"@types/btoa": "^1.2.5",
"@types/bytes": "^3.1.4",
@@ -176,6 +170,7 @@
"standard-version": "^9.5.0",
"typescript": "^5.4.5",
"typescript-eslint": "^8.10.0",
"vite": "^5.4.10",
"vite-plugin-node": "^4.0.0",
"vite-plugin-static-copy": "^2.0.0",
"vite-tsconfig-paths": "^4.3.2",

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env node
import '@app/dotenv';
import { main } from '@app/cli/index';
import { internalLogger } from '@app/core/log';

View File

@@ -2,18 +2,16 @@ import { parse } from 'ts-command-line-args';
import { cliLogger } from '@app/core/log';
import { type Flags, mainOptions, options, args } from '@app/cli/options';
import { setEnv } from '@app/cli/set-env';
import { env } from '@app/dotenv';
import { getters } from '@app/store';
import { execSync } from 'child_process';
import { PM2_PATH } from '@app/consts';
import * as ENVIRONMENT from '@app/environment';
const command = mainOptions.command as unknown as string;
export const main = async (...argv: string[]) => {
cliLogger.debug(env, 'Loading env file');
// Set envs
cliLogger.debug({ paths: getters.paths() }, 'Starting CLI');
cliLogger.debug({ paths: getters.paths(), environment: ENVIRONMENT }, 'Starting CLI');
setEnv('PORT', process.env.PORT ?? mainOptions.port ?? '9000');

View File

@@ -1,10 +1,11 @@
import { logger } from '@app/core/log';
import { config } from 'dotenv';
export const env =
const env =
process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test'
? config({ debug: true, path: `./.env.${process.env.NODE_ENV}`, encoding: 'utf-8' })
: config({
path: '/usr/local/unraid-api/.env',
encoding: 'utf-8',
});
export default env;

View File

@@ -2,7 +2,6 @@ import { join } from 'path';
import { loadFilesSync } from '@graphql-tools/load-files';
import { mergeTypeDefs } from '@graphql-tools/merge';
console.log('Loading type definitions from ' + join(import.meta.dirname, './types'));
const files = loadFilesSync(join(import.meta.dirname, './types'), {
extensions: ['graphql'],
});

View File

@@ -1,5 +1,6 @@
import 'reflect-metadata';
import 'global-agent/bootstrap.js';
import '@app/dotenv';
import http from 'http';
import https from 'https';
import CacheableLookup from 'cacheable-lookup';

View File

@@ -3,20 +3,42 @@ import tsconfigPaths from 'vite-tsconfig-paths';
import nodeExternals from 'rollup-plugin-node-externals';
import { viteCommonjs } from '@originjs/vite-plugin-commonjs';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import nodeResolve from '@rollup/plugin-node-resolve';
import { VitePluginNode } from 'vite-plugin-node';
export default defineConfig(() => {
return {
plugins: [
tsconfigPaths(),
nodeExternals(),
nodeResolve(),
viteCommonjs(),
viteStaticCopy({
targets: [{ src: 'src/graphql/schema/types', dest: '' }],
}),
...VitePluginNode({
adapter: ({ app, req, res }) => {
// Example adapter code to run src/index.ts with VitePluginNode
app(req, res);
},
appPath: 'src/index.ts',
initAppOnBoot: true,
})
],
define: {
'process.env': 'process.env',
},
optimizeDeps: {
exclude: [
'cpu-features',
'ssh2',
'pty.js',
'term.js',
'class-transformer/storage',
'unicorn-magic'
]
},
build: {
sourcemap: true,
outDir: 'dist',