From 819e977ae3185cd4bcaea05bfa51266a44d3adab Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Fri, 21 Oct 2016 12:01:29 -0400 Subject: [PATCH 1/7] feature(externalServices): apply external services configuration via environment variable --no-verify --- README.md | 10 ++++++++++ app-template/apply.js | 11 ++++++++--- .../{package.json => package-template.json} | 3 +-- package.json | 15 ++++++++------- 4 files changed, 27 insertions(+), 12 deletions(-) rename app-template/{package.json => package-template.json} (95%) diff --git a/README.md b/README.md index 2183d7209..2fe2e65da 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,16 @@ npm run final:desktop On success, the Chrome extension will be located at: `browser-extensions/chrome/copay-chrome-extension`. To install it go to `chrome://extensions/` in your browser and ensure you have the 'developer mode' option enabled in the settings. Then click on "Load unpacked chrome extension" and choose the directory mentioned above. +## Configuration + +### Enable External Services + +To enable external services, set the `COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION` environment variable to the location of your configuration before running the `apply` task. + +```sh +export COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION="~/.copay/externalServices.json" +``` + ## About Copay ### General diff --git a/app-template/apply.js b/app-template/apply.js index 191f2b571..106bfc998 100755 --- a/app-template/apply.js +++ b/app-template/apply.js @@ -5,7 +5,7 @@ // var templates = { - 'package.json': '/', + 'package-template.json': '/', 'index.html': 'www/', 'Makefile': 'cordova/', 'ProjectMakefile': 'cordova/', @@ -64,6 +64,8 @@ Object.keys(templates).forEach(function(k) { if(k === 'config-template.xml'){ k = 'config.xml'; + } else if (k === 'package-template.json') { + k = 'package.json'; } if (!fs.existsSync('../' + targetDir)){ @@ -80,8 +82,11 @@ fs.writeFileSync('../appConfig.json', configBlob, 'utf8'); //////////////// var externalServices; try { - console.log('Copying ' + configDir + '/externalServices.json' + ' to root'); - externalServices = fs.readFileSync(configDir + '/externalServices.json', 'utf8'); + if(typeof process.env.COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION !== 'undefined') { + var location = process.env.COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION; + console.log('Copying ' + location + ' to root'); + externalServices = fs.readFileSync(location, 'utf8'); + } } catch(err) { externalServices = '{}'; console.log('External services not configured'); diff --git a/app-template/package.json b/app-template/package-template.json similarity index 95% rename from app-template/package.json rename to app-template/package-template.json index 1a56073d7..6fb7b14f4 100644 --- a/app-template/package.json +++ b/app-template/package-template.json @@ -79,8 +79,7 @@ "shelljs": "^0.3.0" }, "scripts": { - "postinstall": "bower install && npm run postapply", - "postapply": "echo && echo \"To finish, choose a distribution by running 'npm run apply:copay' or 'npm run apply:bitpay'.\" && echo", + "postinstall": "bower install", "start": "npm run build:www && ionic serve --nolivereload --nogulp -s", "start:ios": "npm run build:www && npm run build:ios && npm run open:ios", "start:android": "npm run build:www && npm run build:android && npm run run:android", diff --git a/package.json b/package.json index 9e43644ba..b2434908a 100644 --- a/package.json +++ b/package.json @@ -1,20 +1,21 @@ { + "changes": "changes to this file can be commited with the --no-verify option", "name": "distribution-not-selected", "description": "Choose a distribution by running 'npm run apply:copay' or 'npm run apply:bitpay'.", "primary-package-json": "See the tempate in app-template/package.json", "scripts": { - "postinstall": "npm run apply:copay", + "postinstall": "npm run apply:copay && echo && echo \"Repo configured for standard Copay distribution. To switch to the BitPay distribution, run 'npm run apply:bitpay'.\" && echo", "start": "echo && echo \"Choose a distribution by running 'npm run apply:copay' or 'npm run apply:bitpay'.\" && echo", - "preapply": "npm i fs-extra", - "apply:copay": "npm run preapply && cd app-template && node apply.js copay && cd .. && npm i && npm run postapply", - "apply:bitpay": "npm run preapply && cd app-template && node apply.js bitpay && cd .. && npm i && npm run postapply", + "apply:copay": "cd app-template && node apply.js copay && cd .. && npm i && npm run postapply", + "apply:bitpay": "cd app-template && node apply.js bitpay && cd .. && npm i && npm run postapply", "clean-all": "git clean -dfx" }, + "dependencies": { + "fs-extra": "^0.30.0" + }, "license": "MIT", "repository": { - "url": "git://github.com/bitpay/copay.git", "url": "git://github.com/bitpay/bitpay-wallet.git", "type": "git" - }, - "changes": "changes to this file can be commited with the --no-verify option" + } } From d9d0a4d63361cbbed8b4bdcc5cc5e0979695b81b Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Fri, 21 Oct 2016 12:04:02 -0400 Subject: [PATCH 2/7] feature(package): unstage package via pre-commit hook before apply --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index b2434908a..e635267af 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,15 @@ { - "changes": "changes to this file can be commited with the --no-verify option", "name": "distribution-not-selected", "description": "Choose a distribution by running 'npm run apply:copay' or 'npm run apply:bitpay'.", "primary-package-json": "See the tempate in app-template/package.json", + "pre-commit": "unstage-package", + "changes": "changes to this file can be commited with the --no-verify option", "scripts": { "postinstall": "npm run apply:copay && echo && echo \"Repo configured for standard Copay distribution. To switch to the BitPay distribution, run 'npm run apply:bitpay'.\" && echo", "start": "echo && echo \"Choose a distribution by running 'npm run apply:copay' or 'npm run apply:bitpay'.\" && echo", "apply:copay": "cd app-template && node apply.js copay && cd .. && npm i && npm run postapply", "apply:bitpay": "cd app-template && node apply.js bitpay && cd .. && npm i && npm run postapply", + "unstage-package": "git reset package.json", "clean-all": "git clean -dfx" }, "dependencies": { From 0495a8cf9cb8d3611aa50a427da1bbf2467b057a Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Fri, 21 Oct 2016 12:11:45 -0400 Subject: [PATCH 3/7] fix(package): install properly after clean-all --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e635267af..31c9fb832 100644 --- a/package.json +++ b/package.json @@ -7,13 +7,13 @@ "scripts": { "postinstall": "npm run apply:copay && echo && echo \"Repo configured for standard Copay distribution. To switch to the BitPay distribution, run 'npm run apply:bitpay'.\" && echo", "start": "echo && echo \"Choose a distribution by running 'npm run apply:copay' or 'npm run apply:bitpay'.\" && echo", - "apply:copay": "cd app-template && node apply.js copay && cd .. && npm i && npm run postapply", - "apply:bitpay": "cd app-template && node apply.js bitpay && cd .. && npm i && npm run postapply", + "apply:copay": "npm i fs-extra@0.30 && cd app-template && node apply.js copay && cd .. && npm i", + "apply:bitpay": "npm i fs-extra@0.30 && cd app-template && node apply.js bitpay && cd .. && npm i", "unstage-package": "git reset package.json", "clean-all": "git clean -dfx" }, "dependencies": { - "fs-extra": "^0.30.0" + "pre-commit": "^1.1.3" }, "license": "MIT", "repository": { From 2c34f53de4c79ef45f96d7aa9b0aa8e33bca91f8 Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Fri, 21 Oct 2016 12:30:02 -0400 Subject: [PATCH 4/7] fix(apply): properly replace the ~ char in COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION --- app-template/apply.js | 5 +++++ app-template/package-template.json | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app-template/apply.js b/app-template/apply.js index 106bfc998..9f5a5625a 100755 --- a/app-template/apply.js +++ b/app-template/apply.js @@ -82,8 +82,13 @@ fs.writeFileSync('../appConfig.json', configBlob, 'utf8'); //////////////// var externalServices; try { + console.log('Looking for COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION...'); if(typeof process.env.COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION !== 'undefined') { var location = process.env.COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION; + if(location.charAt(0) === '~') { + location = location.replace(/^\~/, os.homedir()); + } + console.log('Found at: ' + location); console.log('Copying ' + location + ' to root'); externalServices = fs.readFileSync(location, 'utf8'); } diff --git a/app-template/package-template.json b/app-template/package-template.json index 6fb7b14f4..5ff4ab91e 100644 --- a/app-template/package-template.json +++ b/app-template/package-template.json @@ -101,8 +101,8 @@ "run:android": "cordova run android --device", "log:android": "adb logcat | grep chromium", "sign:android": "rm -f platforms/android/build/outputs/apk/android-release-signed-aligned.apk; jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ../copay.keystore -signedjar platforms/android/build/outputs/apk/android-release-signed.apk platforms/android/build/outputs/apk/android-release-unsigned.apk copay_play && ../android-sdk-macosx/build-tools/21.1.1/zipalign -v 4 platforms/android/build/outputs/apk/android-release-signed.apk platforms/android/build/outputs/apk/android-release-signed-aligned.apk", - "apply:copay": "cd app-template && node apply.js copay && cordova prepare", - "apply:bitpay": "cd app-template && node apply.js bitpay && cordova prepare", + "apply:copay": "npm i && cd app-template && node apply.js copay && cordova prepare", + "apply:bitpay": "npm i && cd app-template && node apply.js bitpay && cordova prepare", "test": "./node_modules/.bin/grunt test-coveralls", "clean": "trash platforms && trash plugins && cordova prepare", "unstage-package": "git reset package.json", From da48c12ea9a60f7a55d98e92310f16cc450b6847 Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Fri, 21 Oct 2016 12:44:26 -0400 Subject: [PATCH 5/7] fix(apply): use a better option for getting the user's home dir --- app-template/apply.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app-template/apply.js b/app-template/apply.js index 9f5a5625a..188af9ee3 100755 --- a/app-template/apply.js +++ b/app-template/apply.js @@ -86,7 +86,7 @@ try { if(typeof process.env.COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION !== 'undefined') { var location = process.env.COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION; if(location.charAt(0) === '~') { - location = location.replace(/^\~/, os.homedir()); + location = location.replace(/^\~/, process.env.HOME || process.env.USERPROFILE); } console.log('Found at: ' + location); console.log('Copying ' + location + ' to root'); From fbe24eab7812a8d76485dfeb7d19442b034c576e Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Fri, 21 Oct 2016 13:17:58 -0400 Subject: [PATCH 6/7] fix(apply): add BITPAY_EXTERNAL_SERVICES_CONFIG_LOCATION var to apply task --- README.md | 6 ++++-- app-template/apply.js | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2fe2e65da..1643e2ad4 100644 --- a/README.md +++ b/README.md @@ -137,10 +137,12 @@ On success, the Chrome extension will be located at: `browser-extensions/chrome/ ### Enable External Services -To enable external services, set the `COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION` environment variable to the location of your configuration before running the `apply` task. +To enable external services, set the `COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION` or `BITPAY_EXTERNAL_SERVICES_CONFIG_LOCATION` environment variable to the location of your configuration before running the `apply` task. ```sh -export COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION="~/.copay/externalServices.json" +COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION="~/.copay/externalServices.json" && npm run apply:copay +# or +BITPAY_EXTERNAL_SERVICES_CONFIG_LOCATION="~/.bitpay/externalServices.json" && npm run apply:bitpay ``` ## About Copay diff --git a/app-template/apply.js b/app-template/apply.js index 188af9ee3..7cad2bccd 100755 --- a/app-template/apply.js +++ b/app-template/apply.js @@ -82,9 +82,11 @@ fs.writeFileSync('../appConfig.json', configBlob, 'utf8'); //////////////// var externalServices; try { - console.log('Looking for COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION...'); - if(typeof process.env.COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION !== 'undefined') { - var location = process.env.COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION; + var confName = configDir.toUpperCase(); + externalServicesConf = confName + '_EXTERNAL_SERVICES_CONFIG_LOCATION'; + console.log('Looking for ' + externalServicesConf + '...'); + if(typeof process.env[externalServicesConf] !== 'undefined') { + var location = process.env[externalServicesConf] if(location.charAt(0) === '~') { location = location.replace(/^\~/, process.env.HOME || process.env.USERPROFILE); } From 6e6f6b3da19caa348a09fdd0a91966a91fff3661 Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Sat, 22 Oct 2016 10:56:00 -0400 Subject: [PATCH 7/7] fix(apply): better handling of external services config --- README.md | 4 ++-- app-template/apply.js | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1643e2ad4..ee4d4007f 100644 --- a/README.md +++ b/README.md @@ -140,9 +140,9 @@ On success, the Chrome extension will be located at: `browser-extensions/chrome/ To enable external services, set the `COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION` or `BITPAY_EXTERNAL_SERVICES_CONFIG_LOCATION` environment variable to the location of your configuration before running the `apply` task. ```sh -COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION="~/.copay/externalServices.json" && npm run apply:copay +COPAY_EXTERNAL_SERVICES_CONFIG_LOCATION="~/.copay/externalServices.json" npm run apply:copay # or -BITPAY_EXTERNAL_SERVICES_CONFIG_LOCATION="~/.bitpay/externalServices.json" && npm run apply:bitpay +BITPAY_EXTERNAL_SERVICES_CONFIG_LOCATION="~/.bitpay/externalServices.json" npm run apply:bitpay ``` ## About Copay diff --git a/app-template/apply.js b/app-template/apply.js index 7cad2bccd..2f0015e34 100755 --- a/app-template/apply.js +++ b/app-template/apply.js @@ -83,7 +83,7 @@ fs.writeFileSync('../appConfig.json', configBlob, 'utf8'); var externalServices; try { var confName = configDir.toUpperCase(); - externalServicesConf = confName + '_EXTERNAL_SERVICES_CONFIG_LOCATION'; + var externalServicesConf = confName + '_EXTERNAL_SERVICES_CONFIG_LOCATION'; console.log('Looking for ' + externalServicesConf + '...'); if(typeof process.env[externalServicesConf] !== 'undefined') { var location = process.env[externalServicesConf] @@ -93,8 +93,11 @@ try { console.log('Found at: ' + location); console.log('Copying ' + location + ' to root'); externalServices = fs.readFileSync(location, 'utf8'); + } else { + throw externalServicesConf + ' environment variable not set.'; } } catch(err) { + console.log(err); externalServices = '{}'; console.log('External services not configured'); }