Skip to content

Commit

Permalink
#25 eslint approved
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanShabanov committed Jun 28, 2017
1 parent 0aed9b2 commit 87a2a8a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ globals:
cordova: true
extends:
- airbnb-base
rules:
no-console: 0
no-useless-escape: 0
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"bitcore-lib": "^0.13.14",
"bitcore-mnemonic": "~1.0.0",
"byteballcore": "git+https://github.com/byteball/byteballcore.git#testnet",
"chokidar": "^1.7.0",
"jszip": "^3.1.3",
"lodash": "^4.6.1",
"preconditions": "^1.0.8",
Expand Down
66 changes: 31 additions & 35 deletions src/js/live-reload.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
if(window.location.href.indexOf('chrome') > -1){
var chokidar = require('chokidar');
var watcher = chokidar.watch('.', {ignored: /[\/\\]\./});
var reloading = false;

function triggerReload(){

console.warn('Reloading app...');

if(location){
location.reload();
}

const chokidar = require('chokidar');

function triggerReload() {
console.warn('Reloading app...');

if (location) {
location.reload();
}
}

if (window.location.href.indexOf('chrome') > -1) {
const watcher = chokidar.watch('.', {
ignored: /[\/\\]\./,
});
let reloading = false;

watcher.on('all', (event, path) => {
if (event === 'change' && path && (path.indexOf('public/') > -1 || path.indexOf('src/') > -1)) {
if (path.indexOf('.css') > -1 || path.indexOf('.scss') > -1) {
const styles = document.querySelectorAll('link[rel=stylesheet]');

styles.forEach((style) => {
const restyled = `${style.getAttribute('href')}?v=${Math.floor((Math.random() * 10000) + 1)}`;
style.setAttribute('href', restyled);
});
} else if (!reloading) {
reloading = true;
setInterval(triggerReload, 100);
}
}

watcher.on('all', function(event, path) {
if (event == "change" && path && (path.indexOf('public/') > -1 || path.indexOf('src/') > -1)){

if(path.indexOf('.css') > -1 || path.indexOf('.scss') > -1){
var styles = document.querySelectorAll('link[rel=stylesheet]');

for (var i = 0; i < styles.length; i++) {
// reload styles
var restyled = styles[i].getAttribute('href') + '?v='+Math.random(0,10000);
styles[i].setAttribute('href', restyled);
}
}else{
if(!reloading){
reloading = true;
setInterval(triggerReload, 100);
}
}
}

});
}
});
}
14 changes: 6 additions & 8 deletions util/version.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
#!/usr/bin/env node
'use strict';

const fs = require('fs');
const shell = require('shelljs');

const getCommitHash = function () {
// exec git command to get the hash of the current commit
// git rev-parse HEAD
const getCommitHash = () => {
// exec git command to get the hash of the current commit
// git rev-parse HEAD

const hash = shell.exec('git rev-parse HEAD', {
silent: true,
}).output.trim().substr(0, 7);
if (hash === 'fatal: ') { return 'n/a'; }
return hash;

return (hash === 'fatal: ' ? 'n/a' : hash);
};

const commitHash = getCommitHash();
const json = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
console.log(`v${json.version} #${commitHash}`);

let content = `window.version="${json.version}";`;
content = `${content}\nwindow.commitHash="${commitHash}";`;
const content = `window.version="${json.version}";\nwindow.commitHash="${commitHash}";`;
fs.writeFileSync('./src/js/version.js', content);

0 comments on commit 87a2a8a

Please sign in to comment.