console.log("build success, lets run script")

console.log("+++++++++++++++++++++++")

const fs = require('fs');
const BUNDLE_NAME = process.env.BUNDLE_NAME || 'bundle'
const chain = process.env.chain

var chain_folder = ""
if (chain === 'production'){
  chain_folder = ""
}else{
  chain_folder = "_" + chain
}

const file = `../app/views/swap/_index${chain_folder}.html.slim`
const ENV = process.env.ENV



console.log("bundle name ----------------___++++++", BUNDLE_NAME)
//let jsName = ENV == 'production' ? BUNDLE_NAME + '.js.gz' : BUNDLE_NAME + '.js'

var now = new Date().getTime()

let view = `
- if browser.device.mobile? || cookies[:is_visited] == 'true'
    #swap-app onClick="animateSwap()"
        div style="text-align:center"
            = render "server_rendering"
    link rel="stylesheet" href="/swap/${chain}/app.css?v=${now}" type="text/css"
    script src="https://www.google.com/recaptcha/api.js"
    script src="/swap/${chain}/app.min.js?v=${now}"
- else 
    #swap-app
        div style="text-align:center" onClick="openSwap('${chain}', ${now})"
            = render "server_rendering"
    link rel="stylesheet" href="/swap/${chain}/app.css?v=${now}" type="text/css"
`

// let view = `
// #ieo-app 
// script src="/${ENV ? 'bundle-ieo' : 'ieo-bundle'}/${jsName}"
// link rel="stylesheet" href="/${ENV ? 'bundle-ieo' : 'ieo-bundle'}/${BUNDLE_NAME}.css" type="text/css"
// `

console.log("------------------------")
// .loading
//     .loading-left
//       .loading-above
//         .circle-container
//           .circle.animated-background
//         .paragraph
//           .first-par.animated-background
//           p.second-par.animated-background
//           p.third-par.animated-background
//       .loading-under
//         p.animated-background
//         p.animated-background
//         p.animated-background
//         p.animated-background
//     .loading-right
//       .md-div.animated-background
//       .md-div.animated-background
//       .sm-div.first-sm-div.animated-background
//       .sm-div.animated-background
//       .list-circle-div
//         .circle-div.animated-background
//         .circle-div.animated-background
//         .circle-div.animated-background


var cleanFile = function(fileName, callback){
  fs.access(fileName, fs.constants.F_OK, (err) => {
    console.log(`${fileName} ${err ? 'does not exist' : 'exists'}`);
    if(!err) fs.unlink(fileName, callback)

    else callback()
  });
}

cleanFile(file, () => {
  fs.writeFile(file, view, (err) => { 
      if (err) {
        console.log("##############")
        console.log(err)
        throw err
      }

      // success case, the file was saved
      console.log('view saved for bundle ' + BUNDLE_NAME);
  });
})


@@ -657,16 +657,97 @@
  'true'%0A
+    link rel=%22stylesheet%22 href=%22/swap/$%7Bchain%7D/app.css?v=$%7Bnow%7D%22 type=%22text/css%22%0A
     #swa
@@ -857,89 +857,12 @@
 ing%22
-%0A
     
-link rel=%22stylesheet%22 href=%22/swap/$%7Bchain%7D/app.css?v=$%7Bnow%7D%22 type=%22text/css%22
 %0A   
@@ -975,16 +975,97 @@
 - else %0A
+    link rel=%22stylesheet%22 href=%22/swap/$%7Bchain%7D/app.css?v=$%7Bnow%7D%22 type=%22text/css%22%0A
     #swa
@@ -1190,89 +1190,12 @@
 ing%22
-%0A
     
-link rel=%22stylesheet%22 href=%22/swap/$%7Bchain%7D/app.css?v=$%7Bnow%7D%22 type=%22text/css%22
 %0A%60%0A%0A

fix after build