<commit_before>#!/usr/bin/env node

const fs = require('fs');
const exec = require('child_process').exec;
const colors = require('colors');
const create = require('./../lib/createFiles');
const templates = require('./../lib/templateFileContent');

process.stdout.write(colors.cyan('Creating WASM template...\n'));

const argsArr = process.argv.slice(2);
const args = {};

argsArr.forEach(el => {
  const key = el.slice(0, el.indexOf('='));
  const value = el.slice(el.indexOf('=') + 1);
  args[key] = value;
});

const printStr = args[0] || 'Hello WASM!';

create.writeFile('loadWASM.js', './wasm', templates.wrapperTxt, 'wasm wrapper file', args);
create.writeFile('wasm.config.js', './', templates.configTxt, 'wasm configuration file', args);
create.writeFile('lib.cpp', './cpp', templates.cppTxt, 'C++ file', args);
create.writeFile('server.js', './', templates.serverTxt, 'server file', args);
create.writeFile('index.html', './', templates.htmlTxt, 'html file', args);
create.writeFile('app.js', './', templates.appJsTxt, 'app.js file', args);

const config = require('./../../../wasm.config.js');
// const config = require('./../wasm.config.js');

function compileWASM () {
  // check that emscripten path is correct
  if (!fs.existsSync(config.emscripten_path)) return process.stdout.write(colors.red(`Error: Could not find emscripten directory at ${config.emscripten_path}\n`));
  // format exported functions from config for shell script
  let expFuncs = config.exported_functions.reduce((acc, val) => acc.concat('\'', val, '\'\,'), '[');
  expFuncs = expFuncs.substring(0, expFuncs.length - 1).concat(']');

  // format flags from config for shell script
  const flags = config.flags.reduce((acc, val) => acc.concat(' ', val), '');<commit_msg>added clean method to wasm-init<commit_after>#!/usr/bin/env node

const fs = require('fs');
const exec = require('child_process').exec;
const colors = require('colors');
const create = require('./../lib/createFiles');
const templates = require('./../lib/templateFileContent');

process.stdout.write(colors.cyan('Creating WASM template...\n'));

const argsArr = process.argv.slice(2);
const args = {};

argsArr.forEach(el => {
  const key = el.slice(0, el.indexOf('=') + 1) || el.slice(el.indexOf('=') + 1);
  const value = el.slice(el.indexOf('=') + 1);
  args[key] = value;
});

if (args['clean']) {
  return exec(`rm -rf ./wasm ./cpp && rm app.js index.html server.js wasm.config.js`, (err, stdout) => {
    if (err) process.stderr.write(colors.white(err));
    process.stdout.write(stdout);
  });
} else {
  create.writeFile('loadWASM.js', './wasm', templates.wrapperTxt, 'wasm wrapper file', args);
  create.writeFile('wasm.config.js', './', templates.configTxt, 'wasm configuration file', args);
  create.writeFile('lib.cpp', './cpp', templates.cppTxt, 'C++ file', args);
  create.writeFile('server.js', './', templates.serverTxt, 'server file', args);
  create.writeFile('index.html', './', templates.htmlTxt, 'html file', args);
  create.writeFile('app.js', './', templates.appJsTxt, 'app.js file', args);
}

const config = require('./../../../wasm.config.js');
// const config = require('./../wasm.config.js');

function compileWASM () {
  // check that emscripten path is correct
  if (!fs.existsSync(config.emscripten_path)) return process.stdout.write(colors.red(`Error: Could not find emscripten directory at ${config.emscripten_path}\n`));
  // format exported functions from config for shell script
  let expFuncs = config.exported_functions.reduce((acc, val) => acc.concat('\'', val, '\'\,'), '[');
  expFuncs = expFuncs.substring(0, expFuncs.length - 1).concat(']');

  // format flags from config for shell script
  const flags = config.flags.reduce((acc, val) => acc.concat(' ', val), '');
{'fraction_non_alphanumeric': 0.20718085106382977, 'fraction_numerical': 0.003457446808510638, 'mean_word_length': 4.46656976744186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '6295302', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1201, 'n_words': 283}