From 1401daab0697158d28d65777986062a3faafaf26 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Mon, 8 Apr 2024 14:03:07 +0100 Subject: [PATCH] Update tsconfig.json files with resolveJsonModule option --- Accounts/tsconfig.json | 6 +- AdminDashboard/tsconfig.json | 6 +- App/tsconfig.json | 6 +- Common/tsconfig.json | 6 +- CommonServer/tsconfig.json | 6 +- CommonUI/tsconfig.json | 6 +- Dashboard/tsconfig.json | 6 +- E2E/tsconfig.json | 6 +- InfrastructureAgent/Index.ts | 109 +++++++++++++++++++----------- InfrastructureAgent/Start.ts | 14 ++++ InfrastructureAgent/tsconfig.json | 8 ++- Ingestor/tsconfig.json | 6 +- IsolatedVM/tsconfig.json | 6 +- Llama/tsconfig.json | 6 +- Model/tsconfig.json | 6 +- Nginx/tsconfig.json | 6 +- Probe/tsconfig.json | 6 +- Scripts/tsconfig.json | 6 +- StatusPage/tsconfig.json | 6 +- TestServer/tsconfig.json | 6 +- tsconfig.json | 6 +- 21 files changed, 162 insertions(+), 77 deletions(-) create mode 100644 InfrastructureAgent/Start.ts diff --git a/Accounts/tsconfig.json b/Accounts/tsconfig.json index a972e42c66..c3fca59dd5 100644 --- a/Accounts/tsconfig.json +++ b/Accounts/tsconfig.json @@ -3,7 +3,8 @@ // these options are overrides used only by ts-node // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable "compilerOptions": { - "module": "commonjs" + "module": "commonjs", + "resolveJsonModule": true, } }, "compilerOptions": { @@ -105,6 +106,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "resolveJsonModule": true } } diff --git a/AdminDashboard/tsconfig.json b/AdminDashboard/tsconfig.json index a972e42c66..c3fca59dd5 100644 --- a/AdminDashboard/tsconfig.json +++ b/AdminDashboard/tsconfig.json @@ -3,7 +3,8 @@ // these options are overrides used only by ts-node // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable "compilerOptions": { - "module": "commonjs" + "module": "commonjs", + "resolveJsonModule": true, } }, "compilerOptions": { @@ -105,6 +106,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "resolveJsonModule": true } } diff --git a/App/tsconfig.json b/App/tsconfig.json index fc24bb33b1..547cf100a3 100644 --- a/App/tsconfig.json +++ b/App/tsconfig.json @@ -3,7 +3,8 @@ // these options are overrides used only by ts-node // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable "compilerOptions": { - "module": "commonjs" + "module": "commonjs", + "resolveJsonModule": true, } }, "compilerOptions": { @@ -105,6 +106,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "resolveJsonModule": true } } diff --git a/Common/tsconfig.json b/Common/tsconfig.json index 82aae7b0b8..291db06a03 100644 --- a/Common/tsconfig.json +++ b/Common/tsconfig.json @@ -3,7 +3,8 @@ // these options are overrides used only by ts-node // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable "compilerOptions": { - "module": "commonjs" + "module": "commonjs", + "resolveJsonModule": true, } }, "compilerOptions": { @@ -108,6 +109,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "resolveJsonModule": true } } diff --git a/CommonServer/tsconfig.json b/CommonServer/tsconfig.json index aa3cbb05ad..29b6d9f775 100644 --- a/CommonServer/tsconfig.json +++ b/CommonServer/tsconfig.json @@ -3,7 +3,8 @@ // these options are overrides used only by ts-node // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable "compilerOptions": { - "module": "commonjs" + "module": "commonjs", + "resolveJsonModule": true, } }, "compilerOptions": { @@ -108,6 +109,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "resolveJsonModule": true } } diff --git a/CommonUI/tsconfig.json b/CommonUI/tsconfig.json index c57f3bc37f..a7b7e0d052 100644 --- a/CommonUI/tsconfig.json +++ b/CommonUI/tsconfig.json @@ -3,7 +3,8 @@ // these options are overrides used only by ts-node // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable "compilerOptions": { - "module": "commonjs" + "module": "commonjs", + "resolveJsonModule": true, } }, "compilerOptions": { @@ -109,6 +110,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "resolveJsonModule": true } } diff --git a/Dashboard/tsconfig.json b/Dashboard/tsconfig.json index a972e42c66..c3fca59dd5 100644 --- a/Dashboard/tsconfig.json +++ b/Dashboard/tsconfig.json @@ -3,7 +3,8 @@ // these options are overrides used only by ts-node // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable "compilerOptions": { - "module": "commonjs" + "module": "commonjs", + "resolveJsonModule": true, } }, "compilerOptions": { @@ -105,6 +106,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "resolveJsonModule": true } } diff --git a/E2E/tsconfig.json b/E2E/tsconfig.json index a972e42c66..c3fca59dd5 100644 --- a/E2E/tsconfig.json +++ b/E2E/tsconfig.json @@ -3,7 +3,8 @@ // these options are overrides used only by ts-node // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable "compilerOptions": { - "module": "commonjs" + "module": "commonjs", + "resolveJsonModule": true, } }, "compilerOptions": { @@ -105,6 +106,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "resolveJsonModule": true } } diff --git a/InfrastructureAgent/Index.ts b/InfrastructureAgent/Index.ts index 67afa5d01a..ecce2a93ed 100755 --- a/InfrastructureAgent/Index.ts +++ b/InfrastructureAgent/Index.ts @@ -1,50 +1,83 @@ #!/usr/bin/env tsx import yargs from 'yargs'; -import MonitorInfrastructure from './Jobs/MonitorInfrastructure'; +import { ChildProcess, spawn } from 'node:child_process'; +import Logger from './Utils/Logger'; +import PackageJson from './package.json'; + +export interface ArgumentType { + [x: string]: unknown; + k: string; + u: string | undefined; + _: (string | number)[]; + $0: string; +} + +let daemon: ChildProcess | null = null; const usage: string = - '\nUsage: oneuptime-infrastructure-agent --secret-key '; + '\nUsage: oneuptime-infrastructure-agent start --secret-key .'; -const argv: - | { - [x: string]: unknown; - k: string; - u: string | undefined; - _: (string | number)[]; - $0: string; - } - | Promise<{ - [x: string]: unknown; - k: string; - u: string | undefined; - _: (string | number)[]; - $0: string; - }> = yargs + +yargs + .scriptName('oneuptime-infrastructure-agent') .usage(usage) - .option('k', { - alias: 'secret-key', - describe: - 'Secret Key for this agent. You will find this on OneUptime Dashboard', - type: 'string', - demandOption: true, + .version(PackageJson.version) + .command('start', 'Start the app as a daemon', (y: any) => { + + return y.option('k', { + alias: 'secret-key', + describe: + 'Secret Key for this agent. You will find this on OneUptime Dashboard', + type: 'string', + demandOption: true, + }) + .option('u', { + alias: 'oneuptime-url', + describe: 'OneUptime Host. By default this is https://oneuptime.com', + type: 'string', + demandOption: false, + }); + }, (y: any) => { + + const argv = y.argv as ArgumentType; + + // add secrt key and oneuptime url + + const startArguments: Array = ['Start.ts']; + + if (argv['secret-key']) { + startArguments.push('--secret-key=' + argv['secret-key'].toString()); + } else { + Logger.info('No --secret-key argument found. You can find secret key for this monitor on OneUptime Dashboard'); + process.exit(1); + } + + if (argv['oneuptime-url']) { + startArguments.push('--oneuptime-url=' + argv['oneuptime-url'].toString()); + } else { + startArguments.push('--oneuptime-url=https://oneuptime.com'); + } + + + daemon = spawn('tsx', startArguments, { + detached: true, + stdio: 'ignore' + }); + daemon.unref(); + Logger.info('OneUptime Infrastructure Agent started as daemon'); }) - .option('u', { - alias: 'oneuptime-url', - describe: 'OneUptime Host. By default this is https://oneuptime.com', - type: 'string', - demandOption: false, + .command('stop', 'Stop the daemon', () => { + if (daemon && daemon.pid) { + process.kill(daemon.pid); + Logger.info('OneUptime Infrastructure Agent stopped'); + } else { + Logger.info('OneUptime Infrastructure Agent not running'); + } + }) + .command('$0', 'the default command', () => { }, (_) => { + yargs.showHelp(); }) .help(true).argv; -const secretKey: string | undefined = (argv as any)['secret-key']; -const oneuptimeHost: string = - (argv as any)['oneuptime-url'] || 'https://oneuptime.com'; -if (!secretKey) { - throw new Error( - 'No secret-key argument found. You can find secret key for this monitor on OneUptime Dashboard' - ); -} - -MonitorInfrastructure.initJob(secretKey, oneuptimeHost); diff --git a/InfrastructureAgent/Start.ts b/InfrastructureAgent/Start.ts new file mode 100644 index 0000000000..a8445a8f54 --- /dev/null +++ b/InfrastructureAgent/Start.ts @@ -0,0 +1,14 @@ +import MonitorInfrastructure from "./Jobs/MonitorInfrastructure"; +import { argv } from 'yargs'; + +const secretKey: string | undefined = (argv as any)['secret-key']; +const oneuptimeHost: string = + (argv as any)['oneuptime-url'] || 'https://oneuptime.com'; + +if (!secretKey) { + throw new Error( + 'No secret-key argument found. You can find secret key for this monitor on OneUptime Dashboard' + ); +} + +MonitorInfrastructure.initJob(secretKey, oneuptimeHost); \ No newline at end of file diff --git a/InfrastructureAgent/tsconfig.json b/InfrastructureAgent/tsconfig.json index fc24bb33b1..27e6aa37fc 100644 --- a/InfrastructureAgent/tsconfig.json +++ b/InfrastructureAgent/tsconfig.json @@ -3,12 +3,13 @@ // these options are overrides used only by ts-node // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable "compilerOptions": { - "module": "commonjs" + "module": "commonjs", + "resolveJsonModule": true, } }, "compilerOptions": { /* Visit https://aka.ms/tsconfig.json to read more about this file */ - + /* Projects */ // "incremental": true, /* Enable incremental compilation */ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ @@ -105,6 +106,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "resolveJsonModule": true } } diff --git a/Ingestor/tsconfig.json b/Ingestor/tsconfig.json index d7436306e5..8d973aca93 100644 --- a/Ingestor/tsconfig.json +++ b/Ingestor/tsconfig.json @@ -3,7 +3,8 @@ // these options are overrides used only by ts-node // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable "compilerOptions": { - "module": "commonjs" + "module": "commonjs", + "resolveJsonModule": true, } }, "compilerOptions": { @@ -108,6 +109,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "resolveJsonModule": true } } diff --git a/IsolatedVM/tsconfig.json b/IsolatedVM/tsconfig.json index d7436306e5..8d973aca93 100644 --- a/IsolatedVM/tsconfig.json +++ b/IsolatedVM/tsconfig.json @@ -3,7 +3,8 @@ // these options are overrides used only by ts-node // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable "compilerOptions": { - "module": "commonjs" + "module": "commonjs", + "resolveJsonModule": true, } }, "compilerOptions": { @@ -108,6 +109,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "resolveJsonModule": true } } diff --git a/Llama/tsconfig.json b/Llama/tsconfig.json index 3784fad585..c447249e58 100644 --- a/Llama/tsconfig.json +++ b/Llama/tsconfig.json @@ -3,7 +3,8 @@ // these options are overrides used only by ts-node // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable "compilerOptions": { - "module": "CommonJS" + "module": "commonjs", + "resolveJsonModule": true, } }, "compilerOptions": { @@ -105,6 +106,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "resolveJsonModule": true } } diff --git a/Model/tsconfig.json b/Model/tsconfig.json index aa3cbb05ad..29b6d9f775 100644 --- a/Model/tsconfig.json +++ b/Model/tsconfig.json @@ -3,7 +3,8 @@ // these options are overrides used only by ts-node // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable "compilerOptions": { - "module": "commonjs" + "module": "commonjs", + "resolveJsonModule": true, } }, "compilerOptions": { @@ -108,6 +109,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "resolveJsonModule": true } } diff --git a/Nginx/tsconfig.json b/Nginx/tsconfig.json index 7f30ba7057..880d2265f9 100644 --- a/Nginx/tsconfig.json +++ b/Nginx/tsconfig.json @@ -3,7 +3,8 @@ // these options are overrides used only by ts-node // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable "compilerOptions": { - "module": "commonjs" + "module": "commonjs", + "resolveJsonModule": true, } }, "compilerOptions": { @@ -105,6 +106,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "resolveJsonModule": true } } diff --git a/Probe/tsconfig.json b/Probe/tsconfig.json index 993e6483de..e58dedefad 100644 --- a/Probe/tsconfig.json +++ b/Probe/tsconfig.json @@ -3,7 +3,8 @@ // these options are overrides used only by ts-node // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable "compilerOptions": { - "module": "commonjs" + "module": "commonjs", + "resolveJsonModule": true, } }, "compilerOptions": { @@ -105,7 +106,8 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "resolveJsonModule": true }, "include": ["/**/*.ts"], "exclude": ["node_modules"] diff --git a/Scripts/tsconfig.json b/Scripts/tsconfig.json index 2c422e44da..60f893d38a 100644 --- a/Scripts/tsconfig.json +++ b/Scripts/tsconfig.json @@ -4,7 +4,8 @@ // these options are overrides used only by ts-node // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable "compilerOptions": { - "module": "commonjs" + "module": "commonjs", + "resolveJsonModule": true, } }, "compilerOptions": { @@ -109,6 +110,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "resolveJsonModule": true } } diff --git a/StatusPage/tsconfig.json b/StatusPage/tsconfig.json index a972e42c66..c3fca59dd5 100644 --- a/StatusPage/tsconfig.json +++ b/StatusPage/tsconfig.json @@ -3,7 +3,8 @@ // these options are overrides used only by ts-node // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable "compilerOptions": { - "module": "commonjs" + "module": "commonjs", + "resolveJsonModule": true, } }, "compilerOptions": { @@ -105,6 +106,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "resolveJsonModule": true } } diff --git a/TestServer/tsconfig.json b/TestServer/tsconfig.json index d7436306e5..8d973aca93 100644 --- a/TestServer/tsconfig.json +++ b/TestServer/tsconfig.json @@ -3,7 +3,8 @@ // these options are overrides used only by ts-node // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable "compilerOptions": { - "module": "commonjs" + "module": "commonjs", + "resolveJsonModule": true, } }, "compilerOptions": { @@ -108,6 +109,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "resolveJsonModule": true } } diff --git a/tsconfig.json b/tsconfig.json index 59ad473934..336794b3f6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,8 @@ // these options are overrides used only by ts-node // same as the --compilerOptions flag and the TS_NODE_COMPILER_OPTIONS environment variable "compilerOptions": { - "module": "commonjs" + "module": "commonjs", + "resolveJsonModule": true, } }, "compilerOptions": { @@ -105,6 +106,7 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "resolveJsonModule": true } } \ No newline at end of file