Example #1
0
  var intervalId = setInterval(function(){
    if (runningInstances >= maxInstances) return;
    runningInstances += 1;
    clearInterval(intervalId);

    // If we are running in watch mode, and we have previously compiled
    // the current file, then let the user know that elm-make is running
    // and can be slow
    if (alreadyCompiledFiles.indexOf(input) > -1){
      console.log('Started compiling Elm..');
    }

    var compilation = elmCompiler.compileToString(input, options)
      .then(function(v) { runningInstances -= 1; return { kind: 'success', result: v }; })
      .catch(function(v) { runningInstances -= 1; return { kind: 'error', error: v }; });

    promises.push(compilation);

    Promise.all(promises)
      .then(function(results) {
        var output = results[results.length - 1]; // compilation output is always last

        if (output.kind == 'success') {
          alreadyCompiledFiles.push(input);
          callback(null, output.result);
        } else {
          output.error.message = 'Compiler process exited with error ' + output.error.message;
          callback(output.error);
        }
      }).catch(function(err){
        callback(err);
      });

  }, 200);
Example #2
0
module.exports = function() {
  this.cacheable && this.cacheable();

  var callback = this.async();

  if (!callback) {
    throw 'elm-webpack-loader currently only supports async mode.';
  }

  var input = getInput.call(this);
  var options = getOptions.call(this);

  var dependencies = Promise.resolve()
    .then(function() {
      if (!options.cache || cachedDependencies.length === 0) {
        return elmCompiler.findAllDependencies(input).then(addDependencies.bind(this));
      }
    }.bind(this));

  var compilation = elmCompiler.compileToString(input, options);

  Promise.all([dependencies, compilation])
    .then(function(results) {
      var output = results[1]; // compilation output
      if (options.appendExport) {
        var outputWithExport = [output, 'module.exports = Elm;'].join('\n');
        callback(null, outputWithExport);
      } else {
        callback(null, output);
      }
    })
    .catch(function(err) {
      callback('Compiler process exited with error ' + err);
    });
}
Example #3
0
async function compileElm(elmFile) {
  console.log('Compiling %s', elmFile)

  let dirname = await findElmDirectory(elmFile)
  try {
    let data = await compiler.compileToString(
      [elmFile], {yes: true, cwd: dirname})
    return data.toString()
  } catch (err) {
    let text = err.toString().replace(/`/g, '\\`')
    return 'console.error(`' + text + '`)'
  }
}
Example #4
0
var compile = function (filename) {
  return compiler.compileToString([filename], {yes: true, cwd: fixturesDir})
    .then(function (data) {
      return data.toString();
    });
}
var compile = function (filename) {
  return compiler.compileToString([filename], {yes: true, cwd: fixturesDir})
    .then(function (data) {
      return [data.toString(), 'module.exports = Elm;'].join('\n');
    });
}