<commit_before>"use strict";

var child_process = require("child_process");
var fs = require("fs");

// for use with child_process.exec/execFile
function execCallback(task) {
  return function (error, stdout, stderr) {
    if (stdout) console.log(stdout.toString());
    if (stderr) console.error(stderr.toString());
    if (error) {
      console.error(error);
      task.fail(error);
    }
    else task.complete();
  }
}

function catFiles(files, out) {
  fs.writeFileSync(out, files.map(f => fs.readFileSync(f, "utf8")).join(""))
}

function cmdIn(task, dir, cmd) {
  console.log(`[${dir}] ${cmd}`)
  child_process.exec(cmd, { cwd: dir }, execCallback(task))
}

function tscIn(task, dir) {
  cmdIn(task, dir, 'node ../node_modules/typescript/bin/tsc')
}

task('default', ['runprj'])

task('clean', function() {
  jake.rmRf("built")
})

task('runprj', ['buildprj', 'sim'], {async:true, parallelLimit: 10}, function() {
  cmdIn(this, "mbitprj", 'node ../built/sim.js')
})

task('buildprj', ['tsm'], {async:true}, function() {
  let f = fs.readdirSync("mbitprj").filter(f => /\.ts$/.test(f)).join(" ")
  cmdIn(this, "mbitprj", 'node ../built/tsm.js ' + f)
})

task('tsm', ['tsmbit'], function () {
  catFiles([ "node_modules/typescript/lib/typescript.js",
             "built/tsmbit.js"], "built/tsm.js")
})

task('tsmbit', {async : true}, function () { tscIn(this, "src") })
task('sim', {async: true}, function () { tscIn(this, "mbitsim") })
<commit_msg>Fix deps in build<commit_after>"use strict";

var child_process = require("child_process");
var fs = require("fs");

// for use with child_process.exec/execFile
function execCallback(task) {
  return function (error, stdout, stderr) {
    if (stdout) console.log(stdout.toString());
    if (stderr) console.error(stderr.toString());
    if (error) {
      console.error(error);
      task.fail(error);
    }
    else task.complete();
  }
}

function expand(dir) {
  if (Array.isArray(dir)) {
    let r = []
    dir.forEach(f => expand(dir).forEach(f => r.push(f)))
    return r
  }
  if (fs.existsSync(dir) && fs.statSync(dir).isDirectory())
    return fs.readdirSync(dir).map(f => dir + "/" + f)
  else return [dir]
}

function catFiles(files, out) {
  fs.writeFileSync(out, files.map(f => fs.readFileSync(f, "utf8")).join(""))
}

function cmdIn(task, dir, cmd) {
  console.log(`[${dir}] ${cmd}`)
  child_process.exec(cmd, { cwd: dir }, execCallback(task))
}

function tscIn(task, dir) {
  cmdIn(task, dir, 'node ../node_modules/typescript/bin/tsc')
}

task('default', ['runprj'])

task('clean', function() {
  jake.rmRf("built")
})

task('runprj', ['built/microbit.js', 'built/sim.js'], {async:true, parallelLimit: 10}, function() {
  cmdIn(this, "mbitprj", 'node ../built/sim.js')
})

file('built/microbit.js', ['built/tsm.js'], {async:true}, function() {
  let f = fs.readdirSync("mbitprj").filter(f => /\.ts$/.test(f)).join(" ")
  cmdIn(this, "mbitprj", 'node ../built/tsm.js ' + f)
})

file('built/tsm.js', ['built/tsmbit.js'], function () {
  catFiles([ "node_modules/typescript/lib/typescript.js",
             "built/tsmbit.js"], "built/tsm.js")
})

file('built/tsmbit.js', expand("src"), {async : true}, function () { tscIn(this, "src") })
file('built/sim.js', expand("mbitsim"), {async: true}, function () { tscIn(this, "mbitsim") })

{'fraction_non_alphanumeric': 0.22023629203271736, 'fraction_numerical': 0.0018176310209027568, 'mean_word_length': 4.23296354992076, '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': '592153', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1234, 'n_words': 232}