/**
 * srvoa - soa infrastructure for node js
 *
 * @copyright   Copyright (c) 2015, Alrik Zachert
 * @license     https://gitlab.com/a-z/node-srvoa/blob/master/LICENSE BSD-2-Clause
 */

var fs = require('fs'),
    exec = require('child_process').exec,
    v8Version = process.versions.v8.split('.'),
    // class support was shipped with v8 3.31.58
    requiredVersion = [3, 31, 58],
    packageFile = 'package-es5.js',
    packagePath = fs.realpathSync(__dirname + '/../');

if (v8Version[0] > requiredVersion[0] || (
    v8Version[0] == requiredVersion[0] && (
        v8Version[1] > requiredVersion[1] || (
            v8Version[1] == requiredVersion[1] && (
                v8Version[2] >= requiredVersion[2]
            )
        )
    )
)) {
    console.info('Your node installation supports es6 classes. Linking es6 version of srvoa.');
    packageFile = 'package-es6.js';
} else {
    console.info('Your node installation does not support es6 classes. Linking babel polyfill version of srvoa.');

    fs.stat(packagePath + '/build', function(err) {
        if (err) {
            console.info('There is no build of srvoa. Calling `npm run ' + packagePath + ' build`.');
            exec('npm run ' + packagePath + ' build', function(err, stdout, stderr) {
                console.log('stdout: ' + stdout);
                console.log('stderr: ' + stderr);

                if (err) {
                    console.log('exec error: ' + err);
                }
            });
        }
    });
}

fs.unlink(packagePath + '/package.js', function(err) {
    if (err) {
        throw new Error(err);
    }

    fs.symlink(packagePath + '/' + packageFile, packagePath + '/package.js', function(err) {
        if (err) {
            throw new Error(err);
        }
    });
});

@@ -1254,24 +1254,58 @@
 , stderr) %7B%0A
+                if (stdout) %7B%0A    
             
@@ -1320,19 +1320,22 @@
 ole.
-log
+info
 ('
+%5B
 stdout
+%5D
 : ' 
@@ -1345,16 +1345,68 @@
 tdout);%0A
+                %7D%0A                if (stderr) %7B%0A    
         
@@ -1425,19 +1425,21 @@
 ole.
-log
+err
 ('
+%5B
 stderr
+%5D
 : ' 
@@ -1448,16 +1448,34 @@
 stderr);
+%0A                %7D
 %0A%0A      
@@ -1519,37 +1519,24 @@
     
-console.log('exec error: ' + 
+throw new Error(
 err)

improve info displayed