mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
command line params refactor
This commit is contained in:
parent
1d264ab559
commit
c0c1f9d786
@ -2,7 +2,6 @@ const fs = require('fs');
|
|||||||
|
|
||||||
let fillContent = '';
|
let fillContent = '';
|
||||||
|
|
||||||
// if (!process.argv.includes('--electron')) {
|
|
||||||
if (process.platform == 'win32') {
|
if (process.platform == 'win32') {
|
||||||
fillContent += `content.msnodesqlv8 = () => require('msnodesqlv8');`;
|
fillContent += `content.msnodesqlv8 = () => require('msnodesqlv8');`;
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ module.exports = {
|
|||||||
raw: true,
|
raw: true,
|
||||||
},
|
},
|
||||||
test(req, res) {
|
test(req, res) {
|
||||||
const subprocess = fork(process.argv[1], ['connectProcess', ...process.argv.slice(3)]);
|
const subprocess = fork(process.argv[1], ['--start-process', 'connectProcess', ...process.argv.slice(3)]);
|
||||||
subprocess.on('message', resp => {
|
subprocess.on('message', resp => {
|
||||||
if (handleProcessCommunication(resp, subprocess)) return;
|
if (handleProcessCommunication(resp, subprocess)) return;
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -40,7 +40,11 @@ module.exports = {
|
|||||||
const existing = this.opened.find(x => x.conid == conid && x.database == database);
|
const existing = this.opened.find(x => x.conid == conid && x.database == database);
|
||||||
if (existing) return existing;
|
if (existing) return existing;
|
||||||
const connection = await connections.get({ conid });
|
const connection = await connections.get({ conid });
|
||||||
const subprocess = fork(process.argv[1], ['databaseConnectionProcess', ...process.argv.slice(3)]);
|
const subprocess = fork(process.argv[1], [
|
||||||
|
'--start-process',
|
||||||
|
'databaseConnectionProcess',
|
||||||
|
...process.argv.slice(3),
|
||||||
|
]);
|
||||||
const lastClosed = this.closed[`${conid}/${database}`];
|
const lastClosed = this.closed[`${conid}/${database}`];
|
||||||
const newOpened = {
|
const newOpened = {
|
||||||
conid,
|
conid,
|
||||||
|
@ -30,7 +30,11 @@ module.exports = {
|
|||||||
const existing = this.opened.find(x => x.conid == conid);
|
const existing = this.opened.find(x => x.conid == conid);
|
||||||
if (existing) return existing;
|
if (existing) return existing;
|
||||||
const connection = await connections.get({ conid });
|
const connection = await connections.get({ conid });
|
||||||
const subprocess = fork(process.argv[1], ['serverConnectionProcess', ...process.argv.slice(3)]);
|
const subprocess = fork(process.argv[1], [
|
||||||
|
'--start-process',
|
||||||
|
'serverConnectionProcess',
|
||||||
|
...process.argv.slice(3),
|
||||||
|
]);
|
||||||
const newOpened = {
|
const newOpened = {
|
||||||
conid,
|
conid,
|
||||||
subprocess,
|
subprocess,
|
||||||
|
@ -65,7 +65,7 @@ module.exports = {
|
|||||||
async create({ conid, database }) {
|
async create({ conid, database }) {
|
||||||
const sesid = uuidv1();
|
const sesid = uuidv1();
|
||||||
const connection = await connections.get({ conid });
|
const connection = await connections.get({ conid });
|
||||||
const subprocess = fork(process.argv[1], ['sessionProcess', ...process.argv.slice(3)]);
|
const subprocess = fork(process.argv[1], ['--start-process', 'sessionProcess', ...process.argv.slice(3)]);
|
||||||
const newOpened = {
|
const newOpened = {
|
||||||
conid,
|
conid,
|
||||||
database,
|
database,
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
const shell = require('./shell');
|
const shell = require('./shell');
|
||||||
|
const processArgs = require('./utility/processArgs');
|
||||||
|
|
||||||
const argument = process.argv[2];
|
if (processArgs.startProcess) {
|
||||||
if (argument && argument.endsWith('Process')) {
|
|
||||||
const proc = require('./proc');
|
const proc = require('./proc');
|
||||||
|
const module = proc[processArgs.startProcess];
|
||||||
const module = proc[argument];
|
|
||||||
module.start();
|
module.start();
|
||||||
} else if (!module['parent'] && !process.argv.includes('--checkParent')) {
|
} else if (!module['parent'] && !processArgs.checkParent) {
|
||||||
const main = require('./main');
|
const main = require('./main');
|
||||||
|
|
||||||
main.start(argument);
|
main.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -29,8 +29,9 @@ const scheduler = require('./controllers/scheduler');
|
|||||||
|
|
||||||
const { rundir } = require('./utility/directories');
|
const { rundir } = require('./utility/directories');
|
||||||
const platformInfo = require('./utility/platformInfo');
|
const platformInfo = require('./utility/platformInfo');
|
||||||
|
const processArgs = require('./utility/processArgs');
|
||||||
|
|
||||||
function start(argument = null) {
|
function start() {
|
||||||
// console.log('process.argv', process.argv);
|
// console.log('process.argv', process.argv);
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
@ -91,7 +92,7 @@ function start(argument = null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argument == '--dynport') {
|
if (processArgs.dynport) {
|
||||||
childProcessChecker();
|
childProcessChecker();
|
||||||
|
|
||||||
findFreePort(53911, function (err, port) {
|
findFreePort(53911, function (err, port) {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
const childProcessChecker = require('../utility/childProcessChecker');
|
const childProcessChecker = require('../utility/childProcessChecker');
|
||||||
|
const processArgs = require('../utility/processArgs');
|
||||||
|
|
||||||
async function runScript(func) {
|
async function runScript(func) {
|
||||||
if (process.argv.includes('--checkParent')) {
|
if (processArgs.checkParent) {
|
||||||
childProcessChecker();
|
childProcessChecker();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -29,7 +29,7 @@ class DatastoreProxy {
|
|||||||
|
|
||||||
async ensureSubprocess() {
|
async ensureSubprocess() {
|
||||||
if (!this.subprocess) {
|
if (!this.subprocess) {
|
||||||
this.subprocess = fork(process.argv[1], ['jslDatastoreProcess', ...process.argv.slice(3)]);
|
this.subprocess = fork(process.argv[1], ['--start-process', 'jslDatastoreProcess', ...process.argv.slice(3)]);
|
||||||
|
|
||||||
this.subprocess.on('message', message => {
|
this.subprocess.on('message', message => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const processArgs = require('./processArgs');
|
||||||
|
|
||||||
const p = process;
|
const platform = process.env.OS_OVERRIDE ? process.env.OS_OVERRIDE : process.platform;
|
||||||
const platform = p.env.OS_OVERRIDE ? p.env.OS_OVERRIDE : p.platform;
|
|
||||||
const isWindows = platform === 'win32';
|
const isWindows = platform === 'win32';
|
||||||
const isMac = platform === 'darwin';
|
const isMac = platform === 'darwin';
|
||||||
const isLinux = platform === 'linux';
|
const isLinux = platform === 'linux';
|
||||||
const isDocker = fs.existsSync('/home/dbgate-docker/public');
|
const isDocker = fs.existsSync('/home/dbgate-docker/public');
|
||||||
const isDevMode = p.env.DEVMODE == '1';
|
const isDevMode = process.env.DEVMODE == '1';
|
||||||
const isNpmDist = p.argv[2] == 'startNodeWeb';
|
const isNpmDist = !!global['dbgateApiModulePath'];
|
||||||
|
|
||||||
// function moduleAvailable(name) {
|
// function moduleAvailable(name) {
|
||||||
// try {
|
// try {
|
||||||
@ -20,7 +20,7 @@ const isNpmDist = p.argv[2] == 'startNodeWeb';
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const isElectronBundle = p.argv.indexOf('--is-electron-bundle') >= 0;
|
const isElectronBundle = processArgs.isElectronBundle;
|
||||||
|
|
||||||
const platformInfo = {
|
const platformInfo = {
|
||||||
isWindows,
|
isWindows,
|
||||||
@ -30,13 +30,13 @@ const platformInfo = {
|
|||||||
isElectronBundle,
|
isElectronBundle,
|
||||||
isDevMode,
|
isDevMode,
|
||||||
isNpmDist,
|
isNpmDist,
|
||||||
isSnap: p.env.ELECTRON_SNAP == 'true',
|
isSnap: process.env.ELECTRON_SNAP == 'true',
|
||||||
isPortable: isWindows && p.env.PORTABLE_EXECUTABLE_DIR,
|
isPortable: isWindows && process.env.PORTABLE_EXECUTABLE_DIR,
|
||||||
isAppImage: p.env.DESKTOPINTEGRATION === 'AppImageLauncher',
|
isAppImage: process.env.DESKTOPINTEGRATION === 'AppImageLauncher',
|
||||||
sshAuthSock: p.env.SSH_AUTH_SOCK,
|
sshAuthSock: process.env.SSH_AUTH_SOCK,
|
||||||
environment: process.env.NODE_ENV,
|
environment: process.env.NODE_ENV,
|
||||||
platform,
|
platform,
|
||||||
runningInWebpack: !!p.env.WEBPACK_DEV_SERVER_URL,
|
runningInWebpack: !!process.env.WEBPACK_DEV_SERVER_URL,
|
||||||
defaultKeyFile: path.join(os.homedir(), '.ssh/id_rsa'),
|
defaultKeyFile: path.join(os.homedir(), '.ssh/id_rsa'),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
21
packages/api/src/utility/processArgs.js
Normal file
21
packages/api/src/utility/processArgs.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
function getNamedArg(name) {
|
||||||
|
const argIndex = process.argv.indexOf(name);
|
||||||
|
if (argIndex > 0) {
|
||||||
|
return process.argv[argIndex + 1];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkParent = process.argv.includes('--checkParent');
|
||||||
|
const dynport = process.argv.includes('--dynport');
|
||||||
|
const nativeModules = getNamedArg('--native-modules');
|
||||||
|
const startProcess = getNamedArg('--start-process');
|
||||||
|
const isElectronBundle = process.argv.includes('--is-electron-bundle');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
checkParent,
|
||||||
|
nativeModules,
|
||||||
|
startProcess,
|
||||||
|
dynport,
|
||||||
|
isElectronBundle,
|
||||||
|
};
|
@ -6,4 +6,4 @@ const dbgateApi = require('dbgate-api');
|
|||||||
global.dbgateApiModulePath = require.resolve('dbgate-api');
|
global.dbgateApiModulePath = require.resolve('dbgate-api');
|
||||||
global.dbgateApiPackagedPluginsPath = path.dirname(global.dbgateApiModulePath);
|
global.dbgateApiPackagedPluginsPath = path.dirname(global.dbgateApiModulePath);
|
||||||
|
|
||||||
dbgateApi.getMainModule().start('startNodeWeb');
|
dbgateApi.getMainModule().start();
|
||||||
|
Loading…
Reference in New Issue
Block a user