Skip to content

Commit 09ca65b

Browse files
change internal options
1 parent 698274f commit 09ca65b

File tree

5 files changed

+17
-31
lines changed

5 files changed

+17
-31
lines changed

README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,8 @@ Default: `TMPDIR/mysqlmsn/binaries` (replacing TMPDIR with the OS temp directory
250250

251251
Description: The folder to store the MySQL binaries when they are downloaded from the CDN.
252252

253-
- `_DO_NOT_USE_beforeSignalCleanupMessage: string`
253+
- `_DO_NOT_USE_cli: boolean`
254254

255-
Default: undefined
256-
257-
Description: The message to get displayed in the console before the cleanup that happens when the Node.js process is stopped without the ```stop()``` method being called first.
258-
259-
- `_DO_NOT_USE_afterSignalCleanupMessage: string`
260-
261-
Default: undefined
255+
Default: ```false``` if the package is not being executed via the CLI and ```true``` if it is.
262256

263-
Description: The message to get displayed in the console after the cleanup that happens when the Node.js process is stopped without the ```stop()``` method being called first.
257+
Description: If set to ```true```, this enables certain CLI-only functionality. For example, when ran by the CLI, logging a message to the console when a shutdown signal (like CTRL + C) has been received and the MySQL database is shutting down and getting deleted.

src/cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env node
22
import { createDB } from "./index";
33
import { OPTION_TYPE_CHECKS } from "./constants";
4+
import { ServerOptions } from "../types";
45

56
async function main() {
67
const definedOptions = process.argv.filter((option) => option.startsWith('--'))
7-
const options = {
8-
_DO_NOT_USE_beforeSignalCleanupMessage: '\nShutting down the ephemeral MySQL database and cleaning all related files...',
9-
_DO_NOT_USE_afterSignalCleanupMessage: 'Shutdown and cleanup is complete.'
8+
const options: ServerOptions = {
9+
_DO_NOT_USE_cli: true
1010
}
1111
for (const opt of definedOptions) {
1212
const index = process.argv.indexOf(opt)

src/constants.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ export const DEFAULT_OPTIONS_GENERATOR: () => InternalServerOptions = () => ({
2525
//mysqlmsn = MySQL Memory Server Node.js
2626
_DO_NOT_USE_dbPath: normalizePath(`${tmpdir()}/mysqlmsn/dbs/${randomUUID().replace(/-/g, '')}`),
2727
_DO_NOT_USE_binaryDirectoryPath: `${tmpdir()}/mysqlmsn/binaries`,
28-
_DO_NOT_USE_beforeSignalCleanupMessage: '',
29-
_DO_NOT_USE_afterSignalCleanupMessage: ''
28+
_DO_NOT_USE_cli: false
3029
});
3130

3231
export const DEFAULT_OPTIONS_KEYS = Object.freeze(Object.keys(DEFAULT_OPTIONS_GENERATOR()))
@@ -126,14 +125,9 @@ export const OPTION_TYPE_CHECKS: OptionTypeChecks = {
126125
errorMessage: 'Option _DO_NOT_USE_binaryDirectoryPath must be either undefined or a string.',
127126
definedType: 'string'
128127
},
129-
_DO_NOT_USE_beforeSignalCleanupMessage: {
130-
check: (opt: any) => opt === undefined || typeof opt === 'string',
131-
errorMessage: 'Option _DO_NOT_USE_beforeSignalCleanup must be either undefined or a string.',
132-
definedType: 'string'
133-
},
134-
_DO_NOT_USE_afterSignalCleanupMessage: {
135-
check: (opt: any) => opt === undefined || typeof opt === 'string',
136-
errorMessage: 'Option _DO_NOT_USE_afterSignalCleanup must be either undefined or a string.',
137-
definedType: 'string'
128+
_DO_NOT_USE_cli: {
129+
check: (opt: any) => opt === undefined || typeof opt === 'boolean',
130+
errorMessage: 'Option _DO_NOT_USE_cli must be either undefined or a boolean.',
131+
definedType: 'boolean'
138132
}
139133
} as const;

src/libraries/Executor.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ class Executor {
425425
async startMySQL(options: InternalServerOptions, installedMySQLBinary: InstalledMySQLVersion): Promise<MySQLDB> {
426426
this.version = installedMySQLBinary.version
427427
this.removeExitHandler = onExit(() => {
428-
if (options._DO_NOT_USE_beforeSignalCleanupMessage) {
429-
console.log(options._DO_NOT_USE_beforeSignalCleanupMessage)
428+
if (options._DO_NOT_USE_cli) {
429+
console.log('\nShutting down the ephemeral MySQL database and cleaning all related files...')
430430
}
431431

432432
this.DBDestroySignal.abort()
@@ -448,8 +448,8 @@ class Executor {
448448
}
449449
}
450450

451-
if (options._DO_NOT_USE_afterSignalCleanupMessage) {
452-
console.log(options._DO_NOT_USE_afterSignalCleanupMessage)
451+
if (options._DO_NOT_USE_cli) {
452+
console.log('Shutdown and cleanup is complete.')
453453
}
454454
})
455455

types/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ export type ServerOptions = {
2020
_DO_NOT_USE_deleteDBAfterStopped?: boolean | undefined,
2121
_DO_NOT_USE_dbPath?: string | undefined,
2222
_DO_NOT_USE_binaryDirectoryPath?: string | undefined,
23-
_DO_NOT_USE_beforeSignalCleanupMessage?: string | undefined,
24-
_DO_NOT_USE_afterSignalCleanupMessage?: string | undefined
23+
_DO_NOT_USE_cli?: boolean | undefined
2524
}
2625

2726
export type InternalServerOptions = {
@@ -42,8 +41,7 @@ export type InternalServerOptions = {
4241
_DO_NOT_USE_deleteDBAfterStopped: boolean,
4342
_DO_NOT_USE_dbPath: string,
4443
_DO_NOT_USE_binaryDirectoryPath: string,
45-
_DO_NOT_USE_beforeSignalCleanupMessage: string,
46-
_DO_NOT_USE_afterSignalCleanupMessage: string
44+
_DO_NOT_USE_cli: boolean
4745
}
4846

4947
export type ExecutorOptions = {

0 commit comments

Comments
 (0)