Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
'use strict';
 
const path = require('path');
const { spawn } = require('child_process');
const treeKill = require('tree-kill');
 
async function installOrtPackages(testCaseName, PRESERVE, PACKAGES_TO_INSTALL) {
  if (!PRESERVE) {
    const wd = path.join(__dirname, 'testcases', testCaseName);
    if (PACKAGES_TO_INSTALL.length === 0) {
      await runShellCmd('npm ci', { wd });
    } else {
      await runShellCmd(`npm install ${PACKAGES_TO_INSTALL.map((i) => `"${i}"`).join(' ')}`, { wd });
    }
  }
}
 
async function runShellCmd(cmd, { wd = __dirname, event = null, ready = null, ignoreExitCode = false }) {
  console.log('===============================================================');
  console.log(' Running command in shell:');
  console.log(' > ' + cmd);
  console.log('===============================================================');
 
  return new Promise((resolve, reject) => {
    const childProcess = spawn(cmd, { shell: true, stdio: ['ignore', 'pipe', 'inherit'], cwd: wd });
    childProcess.on('close', function (code, signal) {
      if (code === 0 || ignoreExitCode) {
        resolve();
      } else {
        reject(`Process exits with code ${code}`);
      }
    });
    childProcess.stdout.on('data', (data) => {
      process.stdout.write(data);
 
      if (ready && event && data.toString().includes(ready)) {
        event.emit('serverReady');
      }
    });
    if (event) {
      event.on('kill', () => {
        childProcess.stdout.destroy();
        treeKill(childProcess.pid);
        console.log('killing process...');
      });
    }
  });
}
 
module.exports = {
  runShellCmd,
  installOrtPackages,
};