'use strict';

var utils = require('./utils');

module.exports = function(callback) {
  var spawn = require('child_process').spawn;
  var path = require('path');
  var installation = null;
  var bashBin = process.env.SHELL || 'bash';

  if (!/bash/i.test(bashBin)) {
    bashBin = 'bash';
  }

  try {
    installation = spawn(
      bashBin, [
        path.join(__dirname, 'framework.sh'),
      ]
    );
  } catch (error) {
    console.error(error);
    return;
  }

  installation.stdout.pipe(process.stdout);
  installation.stderr.pipe(process.stderr);

  installation.on('error', function(error) {
    console.error(error);
  });

  let installationPromise = new Promise((resolve) => {
    installation.on('close', function(code) {
      if (code !== 0) {
        console.error('Framework installation failed (exit with code ' + code + ')');
      }

      resolve();
    });
  });

  let directory = this.microservice.autoload._frontend.replace(/(\/_build)$/, '');

  installationPromise.then(() => {
    return utils.installNodeModules(__dirname, false);
  }).then(() => {
    return utils.installNodeModules(directory, false);
  }).then(() => {
    return utils.initializeApplication(directory)
  }).then(callback).catch((error) => {
    console.error(error);
    callback();
  });
};

@@ -44,46 +44,626 @@
 ');%0A
-%0Amodule.exports = function(callback) %7B
+var exec = require('child_process').exec;%0A%0Afunction installGlobalDependencies() %7B%0A  return new Promise((resolve) =%3E %7B%0A    exec('which tsc', (error, stdout, stderr) =%3E %7B%0A      if (stdout) %7B%0A        return resolve();%0A      %7D%0A%0A      if (stderr) %7B%0A        console.error(stderr);%0A        return resolve();%0A      %7D%0A%0A      console.log('Installing typescript');%0A      exec('npm install -g typings typescript', (error) =%3E %7B%0A        if (error) %7B%0A          console.error(error);%0A        %7D%0A%0A        return resolve();%0A      %7D)%0A    %7D);%0A  %7D);%0A%7D%0A%0Amodule.exports = function(callback) %7Breturn installGlobalDependencies().then(callback);
 %0A  v
@@ -1543,24 +1543,37 @@
 $/, '');%0A%0A  
+Promise.all(%5B
 installation
@@ -1579,16 +1579,47 @@
 nPromise
+, installGlobalDependencies()%5D)
 .then(()

Add typescript installing