fix(striker-ui-api): revise std outputs in accessModule

main
Tsu-ba-me 2 years ago
parent d5ee937a9e
commit 403bdaddbc
  1. 18
      striker-ui-api/src/lib/accessModule.ts

@ -2,6 +2,10 @@ import { spawnSync, SpawnSyncOptions } from 'child_process';
import SERVER_PATHS from './consts/SERVER_PATHS'; import SERVER_PATHS from './consts/SERVER_PATHS';
import { stderr as sherr, stdout as shout } from './shell';
const formatQuery = (query: string) => query.replace(/\s+/g, ' ');
const execAnvilAccessModule = ( const execAnvilAccessModule = (
args: string[], args: string[],
options: SpawnSyncOptions = { options: SpawnSyncOptions = {
@ -30,7 +34,7 @@ const execAnvilAccessModule = (
} catch (stdoutParseError) { } catch (stdoutParseError) {
output = stdout; output = stdout;
console.warn( sherr(
`Failed to parse anvil-access-module output [${output}]; CAUSE: [${stdoutParseError}]`, `Failed to parse anvil-access-module output [${output}]; CAUSE: [${stdoutParseError}]`,
); );
} }
@ -59,7 +63,7 @@ const execModuleSubroutine = (
args.push('--sub-params', JSON.stringify(subParams)); args.push('--sub-params', JSON.stringify(subParams));
} }
console.log( shout(
`...${subModuleName}->${subName} with params: ${JSON.stringify( `...${subModuleName}->${subName} with params: ${JSON.stringify(
subParams, subParams,
null, null,
@ -113,8 +117,7 @@ const dbJobAnvilSyncShared = (
}; };
const dbQuery = (query: string, options?: SpawnSyncOptions) => { const dbQuery = (query: string, options?: SpawnSyncOptions) => {
// For printing SQL query to debug. shout(formatQuery(query));
// process.stdout.write(`${query.replace(/\s+/g, ' ')}\n`);
return execAnvilAccessModule(['--query', query], options); return execAnvilAccessModule(['--query', query], options);
}; };
@ -122,8 +125,11 @@ const dbQuery = (query: string, options?: SpawnSyncOptions) => {
const dbSubRefreshTimestamp = () => const dbSubRefreshTimestamp = () =>
execModuleSubroutine('refresh_timestamp').stdout; execModuleSubroutine('refresh_timestamp').stdout;
const dbWrite = (query: string, options?: SpawnSyncOptions) => const dbWrite = (query: string, options?: SpawnSyncOptions) => {
execAnvilAccessModule(['--query', query, '--mode', 'write'], options); shout(formatQuery(query));
return execAnvilAccessModule(['--query', query, '--mode', 'write'], options);
};
const getAnvilData = ( const getAnvilData = (
dataStruct: AnvilDataStruct, dataStruct: AnvilDataStruct,

Loading…
Cancel
Save