/* jshint node: true */

// var RSVP = require('rsvp');
var path = require('path');
var fs = require('fs');

// For details on each option run `ember help release`
module.exports = {
  // local: true,
  // remote: 'some_remote',
  // annotation: "Release %@",
  // message: "Bumped version to %@",
  // manifest: [ 'package.json', 'bower.json', 'someconfig.json' ],
  // strategy: 'date',
  // format: 'YYYY-MM-DD',
  // timezone: 'America/Los_Angeles',
  //
  // beforeCommit: function(project, versions) {
  //   return new RSVP.Promise(function(resolve, reject) {
  //     // Do custom things here...
  //   });
  // }

  // TODO: rewrite using promises and async fs.
  beforeCommit: function(project, versions) {
    let updateVersion = (fileWithVersionPath) => {
      let filePath = path.join(project.root, fileWithVersionPath);
      if (fs.existsSync(filePath)) {
        let contents = fs.readFileSync(filePath, {
          encoding: 'utf8'
        });

        // Version string without 'v' tag prefix.
        let newVersion = versions.next.replace(/^v/, '');

        // Replace version number in line "var version = 'x.x.x';".
        contents = contents.replace(/(version = ')(.+)(';)/, '$1' + newVersion + '$3');

        fs.writeFileSync(filePath, contents, {
          encoding: 'utf8'
        });
      } else {
        throw new Error('File not found: ' + filePath);
      }
    };

    updateVersion('vendor/ember-flexberry-data/register-version.js');
    updateVersion('addon/version.js');
  }
};

@@ -18,16 +18,31 @@
 rue */%0A%0A
+%22use strict%22;%0A%0A
 // var R
@@ -121,641 +121,50 @@
 );%0A%0A
-// For details on each option run %60ember help release%60%0Amodule.exports = %7B%0A  // local: true,%0A  // remote: 'some_remote',%0A  // annotation: %22Release %25@%22,%0A  // message: %22Bumped version to %25@%22,%0A  // manifest: %5B 'package.json', 'bower.json', 'someconfig.json' %5D,%0A  // strategy: 'date',%0A  // format: 'YYYY-MM-DD',%0A  // timezone: 'America/Los_Angeles',%0A  //%0A  // beforeCommit: function(project, versions) %7B%0A  //   return new RSVP.Promise(function(resolve, reject) %7B%0A  //     // Do custom things here...%0A  //   %7D);%0A  // %7D%0A%0A  // TODO: rewrite using promises and async fs.%0A  beforeCommit: function(project, versions) %7B%0A    let updateVersion = (
+function updateVersion(project, versions, 
 file
@@ -184,17 +184,10 @@
 th) 
-=%3E %7B%0A    
+%7B%0A
   le
@@ -245,20 +245,16 @@
 nPath);%0A
-    
   if (fs
@@ -278,28 +278,24 @@
 ath)) %7B%0A    
- 
-   
 let contents
@@ -323,36 +323,32 @@
 lePath, %7B%0A      
-    
 encoding: 'utf8'
@@ -356,20 +356,12 @@
     
-   
- 
 %7D);%0A
-%0A   
     
@@ -403,20 +403,16 @@
 prefix.%0A
-    
     let 
@@ -462,20 +462,16 @@
 );%0A%0A    
- 
-   
 // Repla
@@ -522,20 +522,16 @@
 x.x';%22.%0A
-    
     cont
@@ -611,20 +611,16 @@
 );%0A%0A    
-   
- 
 fs.write
@@ -656,20 +656,16 @@
 %7B%0A      
-    
 encoding
@@ -677,28 +677,20 @@
 f8'%0A    
-    %7D);%0A    
+%7D);%0A
   %7D else
@@ -692,20 +692,16 @@
  else %7B%0A
-    
     thro
@@ -750,40 +750,658 @@
 ;%0A  
-    %7D%0A 
+%7D%0A%7D%0A%0A// For details on each option run %60ember help release%60%0Amodule.exports = %7B%0A  // local: true,%0A  // remote: 'some_remote',%0A  // annotation: %22Release %25@%22,%0A  // message: %22Bumped version to %25@%22,%0A  // manifest: %5B 'package.json', 'bower.json', 'someconfig.json' %5D,%0A  // strategy: 'date',%0A  // format: 'YYYY-MM-DD',%0A  // timezone: 'America/Los_Angeles',%0A  //%0A  // beforeCommit: function(project, versions) %7B%0A  //   return new RSVP.Promise(function(resolve, reject) %7B%0A  //     // Do custom things here...%0A  //
    %7D
+)
 ;%0A
-%0A    updateVersion(
+  // %7D%0A%0A  // TODO: rewrite using promises and async fs.%0A  beforeCommit: function(project, versions) %7B%0A    updateVersion(project, versions, 
 'ven
@@ -1466,16 +1466,35 @@
 Version(
+project, versions, 
 'addon/v

Fix `release.js`