require('shelljs/global');

var platform = {
  path: 'sashimi-platform',
  buildPath: 'public'
};
var webapp = {
  path: 'sashimi-webapp',
  buildPath: 'dist'
};
var statusBuild = -1;
var statusStart = -1;


printTitle('Build web application');

cd(`./${webapp.path}`);
exec('yarn');
statusBuild = exec('yarn run build').code;
throwErrorIfFailedToExec(statusBuild, 'build failed')



printTitle('Copy webapp to server folder');

mkdir('-p', webapp.buildPath);
mkdir('-p', `../${platform.path}/${platform.buildPath}`);
rm('-rf', `../${platform.path}/${platform.buildPath}`);
cp('-R', webapp.buildPath, `../${platform.path}`);
mv(`../${platform.path}/${webapp.buildPath}`, `../${platform.path}/${platform.buildPath}`);

ls(`../${platform.path}/${platform.buildPath}`).forEach(function(file) {
  console.log(file);
});

cd(`..`);


printTitle('Run web server')

cd(`./${platform.path}`);
exec('yarn')


function throwErrorIfFailedToExec(statusCode, message) {
  if (statusCode !== 0) {
    printTitle(`Error: ${message}`);
    printMessage(`Script exit(${statusCode})`);    
    exit(1);
  }
}

function printMessage(message) {
  var echoMsg = message || '';
  echo(` [Deploy] > ${echoMsg}`);
}

function printTitle(message) {
  var echoMsg = message || '----------------';
  echo('');
  echo(` [Deploy] ${echoMsg}`);
  echo('');
}
@@ -200,17 +200,114 @@
  = -1;%0A%0A
-%0A
+// Don't need to build web app if NODE_ENV is testing%0Aif (process.env.NODE_ENV !== 'testing') %7B%0A  
 printTit
@@ -332,24 +332,26 @@
 ication');%0A%0A
+  
 cd(%60./$%7Bweba
@@ -354,32 +354,34 @@
 webapp.path%7D%60);%0A
+  
 exec('yarn');%0Ast
@@ -378,16 +378,18 @@
 yarn');%0A
+  
 statusBu
@@ -423,16 +423,18 @@
 ).code;%0A
+  
 throwErr
@@ -480,18 +480,18 @@
 iled')%0A%0A
-%0A%0A
+  
 printTit
@@ -527,16 +527,18 @@
 der');%0A%0A
+  
 mkdir('-
@@ -560,16 +560,18 @@
 dPath);%0A
+  
 mkdir('-
@@ -620,16 +620,18 @@
 ath%7D%60);%0A
+  
 rm('-rf'
@@ -678,16 +678,18 @@
 ath%7D%60);%0A
+  
 cp('-R',
@@ -731,16 +731,18 @@
 ath%7D%60);%0A
+  
 mv(%60../$
@@ -826,16 +826,18 @@
 th%7D%60);%0A%0A
+  
 ls(%60../$
@@ -901,16 +901,18 @@
 file) %7B%0A
+  
   consol
@@ -928,12 +928,17 @@
 e);%0A
+  
 %7D);%0A
+%7D%0A%0A
 %0Acd(

Remove build process for testing environment