Skip to content

Commit

Permalink
Merge branch 'develop' into pr-reduce-immediate-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
chiguireitor authored Sep 27, 2018
2 parents e8b1e29 + cb0a5a8 commit fe961b6
Show file tree
Hide file tree
Showing 30 changed files with 160 additions and 155 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ build.orig/
.DS_Store*
._*
node_modules/
src/servers.json
dist/
.tmp
src/vendors/
npm-debug.log
servers.json
src/bitcore.html
src/bitcoinjs.html
counterwallet.conf.json
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Full list of changes are at: http://goo.gl/AICdol
* Added Rock-Paper-Scissors
* Added Zeroconf support (show pending balances for assets)
* Added IP-based blocking for betting, RPS and dividend issuance. We are currently blocking people
with US-based IP addresses from using these features on counterwallet.co itself.
with US-based IP addresses from using these features on counterwallet.io itself.

**Fixes:**
* Fixed issue with asset name validation (length checking was incorrect)
Expand Down
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,31 @@ Development

The easiest way to develop locally is to install Federated Node in Docker environment. If you already have Bitcoin Core addrindex, Counterparty Server and Counterblock, then Counterwallet can be manually installed using either of these approaches:

* Stand-alone Docker environment: refer to docker\start.sh in the Counterwallet source code.
* Stand-alone Docker environment: refer to docker\start.sh in the Counterwallet source code.
* Manually: example based on the Docker template for Counterwallet on Ubuntu 16.04 is provided below.

### Manual installation in local environment (Ubuntu 16.04 x64):
1. Download required release or branch (optionally check Pull Requests, if any).
2. Enter the archive directory: `cd $PATH2SOURCE`
3. Install NodeJS and create a symlink if needed: `sudo apt-get install nodejs ; sudo ln -s /usr/bin/nodejs /usr/bin/node`
4. Prepare: `npm install -g --save-dev bower grunt-cli`
5. Download dependencies in the src subdirectory: `cd src; bower --allow-root --config.interactive=false update`
6. Prepublish `cd $PATH2SOURCE; mkdir build ; npm update`
7. Build: Copy counterwallet.conf.json.example to counterwallet.conf.json. Use text editor to add `"http://wallet.counterwallet.io"` in between the square brackets in `servers` in counterwallet.conf.json. Then build: `grunt build --dontcheckdeps --dontminify && cp counterwallet.conf.json build/`. The application will be stored in the build subdirectory.
8. Serve: Open a seperate terminal, install serve (`sudo npm install -g serve`) and in the build subdirectory start Counterwallet service: `cd build/; serve`.
9. Use: Visit `http://localhost:3000` (or you can specify a different port for `serve` if you like)
### Manual installation in local environment (Ubuntu 16.04):
1. Clone repostiroty and `cd` into result folder
2. NodeJS 9.x + NPM installation (if you don't have it):
```
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
sudo apt-get install -y nodejs
```
5. Dowload dependencies in the root folder: `npm install`
6. Build: `npm run build`. The application will be stored in the `./build` subdirectory.
4. Configure: Copy `counterwallet.conf.json.example` to .`/build/counterwallet.conf.json`.
- Notice the `servers` parameter in JSON file. It's responsible for API endpoint(s). By default it's `https://wallet.counterwallet.io`
6. Run: `npm run serve`
7. Use: Visit `http://localhost:3000`

#### Notes:

* the `--dontcheckdeps` speeds up the process and avoids having to do `grunt freeze` everytime you make a change to a dependency during development
* the `--dontminify` makes your debugging life a bit easier
* the `cp` is neccesary because grunt keeps clearing the `build` folder
* If you want to test your local version on another device (or let another person test something) use https://ngrok.com to setup a tunnel to your local environment
* If you want to use HTTPS, refer to additional steps required in the Counterwallet Docker start script

### Note concerning `npm install`
`npm install` triggers a `prepublish` which is configured to do `grunt build`
`npm install` triggers a `prepublish` which is configured to do `grunt build`
and will bork if you haven't done a `grunt freeze` after making changes to dependencies.
You can use `npm update` to circumvent this during development.

Expand Down
9 changes: 8 additions & 1 deletion counterwallet.conf.json.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"servers": [],
"AVAILABLE_LANGUAGES": ["en", "zh_cn", "zh_tw", "ru", "cs", "da"],
"restrictedAreas": {
"pages/betting.html": ["US"],
"pages/openbets.html": ["US"],
"pages/matchedbets.html": ["US"],
"dividend": ["US"],
"pages/simplebuy.html": ["US"]
},
"AVAILABLE_LANGUAGES": ["en", "zh-cn", "zh-tw", "ru", "cs", "da"],
"DEFAULT_LANGUAGE": "en"
}
86 changes: 43 additions & 43 deletions grunt-tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ module.exports = function(grunt) {

var generateHash = function(path) {
var content = path;
grunt.log.writeln('generating hash: '+path);
if (grunt.file.exists(path)) {
grunt.log.writeln('generating hash: '+path);
if (grunt.file.exists(path)) {
if (path.split('.').pop()=='js') {
content = grunt.file.read(path);
var ast = Uglify.parser.parse(content); // parse code and get the initial AST
Expand All @@ -40,39 +40,39 @@ module.exports = function(grunt) {

var generateHashes = function(fileList, config) {
var hashes = {};
fileList.forEach(function (fileObj) {
fileList.forEach(function (fileObj) {
var files = grunt.file.expand({nonull: true}, fileObj.src);
files.forEach(function (filename) {
grunt.log.writeln('filename: '+filename);
var file = new File(filename);
file.blocks.forEach(function(block) {
if (block.type=='js') {
for (var b in block.src) {
var path = config.srcDir+block.src[b];
var path = config.srcDir+block.src[b];
if (path.indexOf(config.depsDir)==0) {
var hash = generateHash(path);
hashes[path] = hash;
}
}
}
}
}
});
});
});
return hashes;
}

var generate_timeago_i18n = function(config) {
grunt.log.writeln('Generate jQuery-TimeAgo localizations');

var languages = config.get('transifex').languages.sort();
var options = config.get('build').options;
var srcDir = options.srcDir;
var depsDir = options.srcDir + options.depsDir;

timeago_i18n_file = "// This file is automatically generated by grunt build\n"
+ "// from locale files found in src/vendors/jquery-timeago/locales/\n"
+ "function switchTimeagoLocale(locale)\n{\nswitch(locale)\n{\n";

for (var l in languages)
{
// correct language code mismatch here
Expand All @@ -90,9 +90,9 @@ module.exports = function(grunt) {
default:
timeago_lang=languages[l];
}

timeagoTranslation = depsDir + 'jquery-timeago/locales/jquery.timeago.' + timeago_lang + '.js';

if(grunt.file.exists(timeagoTranslation))
{
timeago_i18n_file += "case '"+languages[l].toLowerCase()+"':\n";
Expand All @@ -103,7 +103,7 @@ module.exports = function(grunt) {
timeago_i18n_file += "default:\n";
timeago_i18n_file += grunt.file.read(depsDir + 'jquery-timeago/locales/jquery.timeago.en.js').toString();
timeago_i18n_file += "}\n};\n";
grunt.file.write(srcDir + 'js/jquery-timeago.i18n.js', timeago_i18n_file);
grunt.file.write(srcDir + 'js/jquery-timeago.i18n.js', timeago_i18n_file);
};

// generate number between 0 and max from arbitratry string
Expand All @@ -118,7 +118,7 @@ module.exports = function(grunt) {
// generate url relative to destfile or cdn url if cdn config is present
var generateFinalUrl = function(url, destfile, config) {
var dir = url.split('/').shift();

if (config.cdn && config.cdn.hosts && config.cdn.hosts[dir]) {

var hosts = config.cdn.hosts[dir];
Expand All @@ -129,7 +129,7 @@ module.exports = function(grunt) {

var from = Path.dirname('/'+destfile);
var to = '/'+url;
url = Path.relative(from, to);
url = Path.relative(from, to);

}
return url;
Expand Down Expand Up @@ -159,14 +159,14 @@ module.exports = function(grunt) {
if (urlPathParts.length>1) {
anchor = urlPathParts.pop();
}
urlPath = urlPathParts.shift();
urlPath = urlPathParts.shift();

grunt.log.writeln("Source path: "+urlPath);
grunt.log.writeln("Source path: "+urlPath);

var ext = urlPath.split(".").pop();
// TODO: 12 chars seems enough, but check collisions for cleanliness
var newFilename = generateHash(urlPath).substr(0,12)+"."+ext;

grunt.log.writeln("newFilename: "+newFilename);

newUrl = config.assetsHome+newFilename;
Expand All @@ -178,7 +178,7 @@ module.exports = function(grunt) {
}

newUrl = generateFinalUrl(newUrl, destfile, config);

grunt.log.writeln("New url: "+newUrl);

var newUrlPath = Path.resolve(config.assetsDir+newFilename);
Expand All @@ -202,7 +202,7 @@ module.exports = function(grunt) {
}

var replaceHtmlUrl = function(content, srcfiledir, destfile, config) {
return content.replace(/(src|href)=['"]([^"']+)["']/gi, function(match, location) {
return content.replace(/(src|href)=['"]([^"']+)["']/gi, function(match, location) {
var urlParts = match.replace(/\s/g, '').replace(/"|'/g, '').split("=");
var attr = urlParts.shift();
var url = urlParts.join("=");
Expand All @@ -211,13 +211,13 @@ module.exports = function(grunt) {
// IMPORTANT: we consider all html files are in root dir (eg. /index.html).
// html files in subfolders must be loaded with js from html file in root folder
url = processUrl(url, srcfiledir, destfile, config);
}
}
return attr+'="'+url+'"';
});
}

var replaceJsUrl = function(content, srcfiledir, destfile, config) {
return content.replace(/loadScript\(['"]([^"']+)["']/gi, function(match, location) {
return content.replace(/loadScript\(['"]([^"']+)["']/gi, function(match, location) {
var urlParts = match.replace(/\s/g, '').replace(/"|'/g, '').split("(");
var attr = urlParts.shift();
var url = urlParts.join("(");
Expand Down Expand Up @@ -302,15 +302,15 @@ module.exports = function(grunt) {

var minifyApp = function(fileList, config) {

fileList.forEach(function (fileObj) {
fileList.forEach(function (fileObj) {
var files = grunt.file.expand({nonull: true}, fileObj.src);
files.forEach(function (filename) {

grunt.log.writeln('parse file: '+filename);

var file = new File(filename);
var root = Path.resolve(Path.dirname(filename));
var htmlcontent = grunt.file.read(filename);
var htmlcontent = grunt.file.read(filename);

// blocks parsing
file.blocks.forEach(function(block) {
Expand All @@ -323,13 +323,13 @@ module.exports = function(grunt) {
// html parsing
grunt.log.writeln('Dest path: '+fileObj.dest);
htmlcontent = processContent(htmlcontent, "", {type: 'html'}, config)
grunt.file.write(fileObj.dest, htmlcontent);
grunt.file.write(fileObj.dest, htmlcontent);

});
});
}

grunt.registerMultiTask('checkdependencies', 'Check dependencies checksums', function() {
grunt.registerMultiTask('checkdependencies', 'Check dependencies checksums', function() {
var config = this.options(defaultOptions);
config.depsDir = config.srcDir+config.depsDir;
var currenthashes = generateHashes(this.files, config);
Expand All @@ -345,7 +345,7 @@ module.exports = function(grunt) {
} else {
grunt.log.writeln("cheksum ok: "+filename);
}
}
}
});

grunt.registerMultiTask('freezedependencies', 'Generate dependencies checksums', function() {
Expand All @@ -356,30 +356,30 @@ module.exports = function(grunt) {
var hashes = generateHashes(this.files, config);
var hashesjs = JSON.stringify(hashes, null, 4);
grunt.file.write(config.srcDir+config.depsHashesFile, hashesjs);

});

grunt.registerTask('clean', 'Clean build diretcory', function() {
var config = this.options(defaultOptions);
grunt.log.writeln("Clean build diretcory: "+config.buildDir);
cleanDirectory(config.buildDir);

grunt.log.writeln("Clean build/assets diretcory: "+config.buildDir);
cleanDirectory(config.buildDir + '/' + config.assetsHome);
});

grunt.registerMultiTask('minify', 'Put all css medias in assets folders, replace assets urls and merge <script> and <link> tags', function() {
var config = this.options(defaultOptions);
config.assetsDir = config.buildDir+config.assetsHome;

minifyApp(this.files, config);
minifyApp(this.files, config);
});

// this task populate others tasks config and run them
grunt.registerMultiTask('build', 'Build app', function() {

var config = this.options(defaultOptions);
var config = this.options(defaultOptions);
var homePath = (process.env['HOME'] + '/') || (process.env['USERPROFILE'] + '/') || './';

if (this.target=='process') {
if (this.target=='process') {

if (config.checkDeps && config.depsDir) {
grunt.config.set('checkdependencies', {
Expand All @@ -395,20 +395,20 @@ module.exports = function(grunt) {
options: config
});
grunt.task.run('clean');

generate_timeago_i18n(grunt.config);

grunt.config.set('minify', {
options: config,
main: {
files: this.files
}
});
});
grunt.task.run('minify');

}

if (this.target=='copy') {
if (this.target=='copy') {

grunt.config.set('copy', {
main: {
Expand All @@ -419,10 +419,10 @@ module.exports = function(grunt) {

if (grunt.file.exists(homePath + '.transifex'))
grunt.task.run('transifex');

}
});

});

// populate freezedependencies config with build config and run freezedependencies
grunt.registerTask('freeze', 'Generate dependencies checksums', function() {
Expand Down Expand Up @@ -458,7 +458,7 @@ module.exports = function(grunt) {
project_slug: 'counterwallet',
credential: credential // In the same format
});

var languageDone = function(lang) {
grunt.log.writeln(lang + ' done');
languages_done.push(lang)
Expand All @@ -474,7 +474,7 @@ module.exports = function(grunt) {
throw new Error("Error during translation.json download: " + err.message);
} else {
grunt.file.write(buildDir + 'locales/' + lang.toLowerCase() + '/translation.json', data);

languageDone(lang);
}
});
Expand Down
Loading

0 comments on commit fe961b6

Please sign in to comment.