<commit_before><commit_msg>Install package via api.<commit_after>'use strict';

const fs = require('fs');
const path = require('path');
const rekitCore = require('rekit-core');
const spawn = require('child_process').spawn;

function installPackage(io, name, type, version) {
  const prjRoot = rekitCore.utils.getProjectRoot();
  return new Promise((resolve) => {
    const isCra = fs.existsSync(path.join(prjRoot, 'scripts/build.js'));

    const args = [];
    if (isCra) args.push(`${prjRoot}/scripts/build.js`, '--colors');
    else args.push(`${prjRoot}/tools/build.js`);
    const child = spawn('node',
      args,
      {
        stdio: 'pipe',
        cwd: prjRoot
      }
    );
    child.stdout.pipe(process.stdout);
    const handleOutput = (data) => {
      // collect the data
      const text = data.toString('utf8').replace(/ /g, '&nbsp;').split('\n');

      const arr = [];
      text.forEach(t => arr.push(t));
      io.emit('output', {
        type: 'build',
        output: arr,
      });
    };
    child.stdout.on('data', handleOutput);
    child.stderr.on('data', handleOutput);

    child.on('close', () => {
      io.emit('build-finished', {});
      resolve();
    });
  });
}

module.exports = installPackage;
{'fraction_non_alphanumeric': 0.18866396761133603, 'fraction_numerical': 0.0008097165991902834, 'mean_word_length': 2.9238095238095236, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4935682', 'n_tokens_mistral': 399, 'n_tokens_neox': 394, 'n_words': 78}