From f9c552cb0ab00de3aae77edebd3616064d3e1bec Mon Sep 17 00:00:00 2001
From: blavenie <benoit.lavenier@e-is.pro>
Date: Thu, 16 Feb 2017 10:00:13 +0100
Subject: [PATCH] - JSHint Fix - build: remove nacl_factory js lib only on
 android and ios builds

---
 hooks/after_prepare/020_remove_code.js              | 13 ++++++++++---
 hooks/after_prepare/021_template_cache.js           |  3 ---
 hooks/after_prepare/022_translate.js                |  3 ---
 hooks/after_prepare/040_useref.js                   |  2 --
 hooks/after_prepare/050_clean_unused_directories.js |  2 +-
 hooks/before_prepare/02_jshint.js                   |  2 +-
 www/index.html                                      | 11 +++++++----
 www/js/config.js                                    |  2 +-
 www/js/services/crypto-services.js                  |  8 ++++++--
 www/plugins/es/js/entities/comment.js               |  2 +-
 www/plugins/es/js/entities/notification.js          |  6 ++++--
 11 files changed, 31 insertions(+), 23 deletions(-)

diff --git a/hooks/after_prepare/020_remove_code.js b/hooks/after_prepare/020_remove_code.js
index 8b518ab85..89eb5b53b 100755
--- a/hooks/after_prepare/020_remove_code.js
+++ b/hooks/after_prepare/020_remove_code.js
@@ -1,7 +1,6 @@
 #!/usr/bin/env node
 "use strict";
 var gulp = require('gulp');
-var gutil = require('gulp-util');
 var path = require("path");
 var removeCode = require('gulp-remove-code');
 var removeHtml = require('gulp-html-remove');
@@ -9,9 +8,7 @@ var es = require('event-stream');
 var ngAnnotate = require('gulp-ng-annotate');
 var htmlmin = require('gulp-htmlmin');
 
-var cmd = process.env.CORDOVA_CMDLINE;
 var rootdir = process.argv[2];
-var argv = require('yargs').argv;
 
 if (rootdir) {
 
@@ -31,11 +28,18 @@ if (rootdir) {
 
     var pluginPath = path.join(wwwPath, 'plugins') + '/es';
 
+    process.stdout.write('Removing unused code for device \n');
+
+    // Compute options {device-<platform>: true}
+    var platformDeviceRemoveOptions = {};
+    platformDeviceRemoveOptions['device-' + platform] = true;
+
     // Removing unused code for device...
     es.concat(
       // Remove unused HTML tags
       gulp.src([wwwPath + '/templates/**/*.html', pluginPath + '/templates/**/*.html'])
         .pipe(removeCode({device: true}))
+        .pipe(removeCode(platformDeviceRemoveOptions)) // = {device-<platform>: true}
         .pipe(removeHtml('.hidden-xs.hidden-sm'))
         .pipe(removeHtml('.hidden-device'))
         .pipe(removeHtml('[remove-if][remove-if="device"]'))
@@ -44,6 +48,7 @@ if (rootdir) {
 
       gulp.src(path.join(wwwPath, 'index.html'))
         .pipe(removeCode({device: true}))
+        .pipe(removeCode(platformDeviceRemoveOptions)) // = {device-<platform>: true}
         .pipe(removeHtml('.hidden-xs.hidden-sm'))
         .pipe(removeHtml('.hidden-device'))
         .pipe(removeHtml('[remove-if][remove-if="device"]'))
@@ -53,11 +58,13 @@ if (rootdir) {
       // Remove unused JS code + add ng annotations
       gulp.src([wwwPath + '/js/**/*.js'])
         .pipe(removeCode({device: true}))
+        .pipe(removeCode(platformDeviceRemoveOptions)) // = {device-<platform>: true}
         .pipe(ngAnnotate({single_quotes: true}))
         .pipe(gulp.dest(wwwPath + '/dist/dist_js/app')),
 
       gulp.src([pluginPath + '/js/**/*.js'])
         .pipe(removeCode({device: true}))
+        .pipe(removeCode(platformDeviceRemoveOptions)) // = {device-<platform>: true}
         .pipe(ngAnnotate({single_quotes: true}))
         .pipe(gulp.dest(wwwPath + '/dist/dist_js/plugins'))
      );
diff --git a/hooks/after_prepare/021_template_cache.js b/hooks/after_prepare/021_template_cache.js
index f7deb1f29..13d7245bb 100755
--- a/hooks/after_prepare/021_template_cache.js
+++ b/hooks/after_prepare/021_template_cache.js
@@ -1,13 +1,10 @@
 #!/usr/bin/env node
 "use strict";
 var gulp = require('gulp');
-var gutil = require('gulp-util');
 var path = require("path");
 var templateCache = require('gulp-angular-templatecache');
 var es = require('event-stream');
-var cmd = process.env.CORDOVA_CMDLINE;
 var rootdir = process.argv[2];
-var argv = require('yargs').argv;
 
 if (rootdir) {
 
diff --git a/hooks/after_prepare/022_translate.js b/hooks/after_prepare/022_translate.js
index 354418e67..ea6a784b5 100755
--- a/hooks/after_prepare/022_translate.js
+++ b/hooks/after_prepare/022_translate.js
@@ -1,12 +1,9 @@
 #!/usr/bin/env node
 "use strict";
 var gulp = require('gulp');
-var gutil = require('gulp-util');
 var path = require("path");
 var es = require('event-stream');
-var cmd = process.env.CORDOVA_CMDLINE;
 var rootdir = process.argv[2];
-var argv = require('yargs').argv;
 var ngTranslate = require('gulp-angular-translate');
 
 if (rootdir) {
diff --git a/hooks/after_prepare/040_useref.js b/hooks/after_prepare/040_useref.js
index dcc2b0464..848d77e70 100755
--- a/hooks/after_prepare/040_useref.js
+++ b/hooks/after_prepare/040_useref.js
@@ -1,7 +1,6 @@
 #!/usr/bin/env node
 "use strict";
 var gulp = require('gulp');
-var gutil = require('gulp-util');
 var path = require("path");
 var es = require('event-stream');
 var useref = require('gulp-useref');
@@ -13,7 +12,6 @@ var revReplace = require('gulp-rev-replace');
 
 var cmd = process.env.CORDOVA_CMDLINE;
 var rootdir = process.argv[2];
-var argv = require('yargs').argv;
 
 var skip = true;
 if (cmd.indexOf("--release") > -1 || cmd.indexOf("--useref") > -1) {
diff --git a/hooks/after_prepare/050_clean_unused_directories.js b/hooks/after_prepare/050_clean_unused_directories.js
index 99bd43fa5..049a7aa90 100755
--- a/hooks/after_prepare/050_clean_unused_directories.js
+++ b/hooks/after_prepare/050_clean_unused_directories.js
@@ -47,7 +47,7 @@ if (rootdir && !skip) {
       '!'+path.join(wwwPath, 'lib'),
       '!'+path.join(wwwPath, 'lib', 'ionic'),
       '!'+path.join(wwwPath, 'lib', 'ionic', 'fonts'),
-      '!'+path.join(wwwPath, 'lib', 'ionic', 'fonts', '*.*')
+      '!'+path.join(wwwPath, 'lib', 'ionic', 'fonts', '**', '*')
     ]);
   }
 }
diff --git a/hooks/before_prepare/02_jshint.js b/hooks/before_prepare/02_jshint.js
index 9316017ff..992a2bfdf 100755
--- a/hooks/before_prepare/02_jshint.js
+++ b/hooks/before_prepare/02_jshint.js
@@ -12,7 +12,7 @@ var foldersToProcess = [
     'js/services',
     'plugins/es/js',
     'plugins/es/js/controllers',
-    //'plugins/es/js/entities',
+    'plugins/es/js/entities',
     'plugins/es/js/services'
 ];
 
diff --git a/www/index.html b/www/index.html
index aad157b31..266b86a43 100644
--- a/www/index.html
+++ b/www/index.html
@@ -44,20 +44,23 @@
   <script src="lib/ionic/js/angular/angular-bind-notifier.min.js"></script>
   <script src="lib/ionic/js/angular/angular-image-crop.js"></script>
   <script src="js/vendor/base58.js" async></script>
-  <!--removeIf(device)-->
+  <!--removeIf(device-android)-->
+  <!--removeIf(device-ios)-->
   <script src="js/vendor/nacl_factory.js" async></script>
   <script src="js/vendor/scrypt-em.js" async></script>
   <script src="js/vendor/base64.js" async></script>
-  <!--endRemoveIf(device)-->
+  <!--endRemoveIf(device-ios)-->
+  <!--endRemoveIf(device-android)-->
   <!--removeIf(no-device)-->
   <script src="js/vendor/sha256.min.js" async></script>
+  <script src="js/vendor/ng-cordova.min.js"></script>
   <!--endRemoveIf(no-device)-->
+  <!-- endbuild -->
 
   <!--removeIf(no-device)-->
-  <script src="js/vendor/ng-cordova.min.js"></script>
   <script src="cordova.js"></script>
   <!--endRemoveIf(no-device)-->
-  <!-- endbuild -->
+
   <!-- build:js dist_js/cesium.js -->
   <!-- services -->
   <script src="dist/dist_js/app/services/settings-services.js"></script>
diff --git a/www/js/config.js b/www/js/config.js
index 640b786a5..f6c8b636e 100644
--- a/www/js/config.js
+++ b/www/js/config.js
@@ -45,7 +45,7 @@ angular.module("cesium.config", [])
 		}
 	},
 	"version": "0.9.31",
-	"build": "2017-02-15T17:48:36.110Z",
+	"build": "2017-02-16T07:14:45.254Z",
 	"newIssueUrl": "https://github.com/duniter/cesium/issues/new?labels=bug"
 })
 
diff --git a/www/js/services/crypto-services.js b/www/js/services/crypto-services.js
index 8897f093f..d1a32cac7 100644
--- a/www/js/services/crypto-services.js
+++ b/www/js/services/crypto-services.js
@@ -14,7 +14,9 @@ angular.module('cesium.crypto.services', ['ngResource', 'cesium.device.services'
       var that = this;
 
       this.copy = function(source) {
+        console.debug('Copying object:' + (typeof source));
         _.forEach(_.keys(source), function(key) {
+          console.debug('copying key:' + key + ' of type ' + (typeof source[key]));
           that[key] = source[key];
         });
       };
@@ -612,11 +614,13 @@ angular.module('cesium.crypto.services', ['ngResource', 'cesium.device.services'
 
       var serviceImpl;
 
-      // Use cordova implementation, when exists
-      if (Device.enable && window.plugins && !window.plugins.MiniSodium) {
+      // Use Cordova plugin implementation, when exists
+      if (Device.enable && window.plugins && window.plugins.MiniSodium && crypto && crypto.getRandomValues) {
+        console.debug('[crypto] Loading Cordova MiniSodium implementation...');
         serviceImpl = new CordovaServiceFactory();
       }
       else {
+        console.debug('[crypto] Loading FullJS implementation...');
         serviceImpl = new FullJSServiceFactory();
       }
 
diff --git a/www/plugins/es/js/entities/comment.js b/www/plugins/es/js/entities/comment.js
index c42510688..86c240aa9 100644
--- a/www/plugins/es/js/entities/comment.js
+++ b/www/plugins/es/js/entities/comment.js
@@ -116,6 +116,6 @@ function Comment(id, json) {
 
   // Init from json
   if (json && typeof json === "object") {
-    that.copyFromJson(json)
+    that.copyFromJson(json);
   }
 }
diff --git a/www/plugins/es/js/entities/notification.js b/www/plugins/es/js/entities/notification.js
index 1df01c299..c7b553154 100644
--- a/www/plugins/es/js/entities/notification.js
+++ b/www/plugins/es/js/entities/notification.js
@@ -32,6 +32,8 @@ function Notification(json, markAsReadCallback) {
     }
   };
 
+  var pubkeys;
+
   // Membership
   if (json.code.startsWith('MEMBER_')) {
     that.avatarIcon = 'ion-person';
@@ -42,7 +44,7 @@ function Notification(json, markAsReadCallback) {
   else if (json.code.startsWith('TX_')) {
     that.avatarIcon = 'ion-card';
     that.icon = (json.code == 'TX_SENT') ? 'ion-paper-airplane dark' : 'ion-archive balanced';
-    var pubkeys = json.params.length > 0 ? json.params[0] : null;
+    pubkeys = json.params.length > 0 ? json.params[0] : null;
     if (pubkeys && pubkeys.indexOf(',') == -1) {
       that.pubkey = pubkeys;
     }
@@ -62,7 +64,7 @@ function Notification(json, markAsReadCallback) {
   else if (json.code.startsWith('MESSAGE_')) {
     that.avatarIcon = 'ion-email';
     that.icon = 'ion-email dark';
-    var pubkeys = json.params.length > 0 ? json.params[0] : null;
+    pubkeys = json.params.length > 0 ? json.params[0] : null;
     if (pubkeys && pubkeys.indexOf(',') == -1) {
       that.pubkey = pubkeys;
     }
-- 
GitLab