Configure app/build using node config

Add environment-specific configs under `./config` and integrate with the
build system. Also changes package.json `files` from blacklist to
whitelist.

// FREEBIE
This commit is contained in:
lilia 2017-04-10 00:22:38 -07:00 committed by Scott Nonnenberg
parent 34042415e9
commit 7e1bee1082
No known key found for this signature in database
GPG key ID: A4931C09644C654B
7 changed files with 59 additions and 32 deletions

4
config/default.json Normal file
View file

@ -0,0 +1,4 @@
{
"disableAutoUpdate": false,
"openDevTools": false
}

6
config/development.json Normal file
View file

@ -0,0 +1,6 @@
{
"SERVER_URL": "https://textsecure-service-staging.whispersystems.org",
"storageProfile": "development",
"disableAutoUpdate": true,
"openDevTools": true
}

3
config/production.json Normal file
View file

@ -0,0 +1,3 @@
{
"SERVER_URL": "https://textsecure-service-ca.whispersystems.org"
}

6
config/staging.json Normal file
View file

@ -0,0 +1,6 @@
{
"SERVER_URL": "https://textsecure-service-staging.whispersystems.org",
"storageProfile": "staging",
"disableAutoUpdate": true,
"openDevTools": true
}

View file

@ -9,6 +9,7 @@
};
console.log('background page reloaded');
console.log('NODE_ENV', window.env.NODE_ENV);
extension.notification.init();
// Close and reopen existing windows
@ -38,11 +39,7 @@
});
});
var SERVER_URL = 'https://textsecure-service-staging.whispersystems.org';
if (window.env && window.env.node_env === 'production') {
SERVER_URL = 'https://textsecure-service-ca.whispersystems.org';
}
var SERVER_URL = env.SERVER_URL;
var SERVER_PORTS = [80, 4433, 8443];
var messageReceiver;
window.getSocketStatus = function() {

20
main.js
View file

@ -25,14 +25,17 @@ if (shouldQuit) {
return;
}
// Read package.json
const package_json = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf-8'))
const NODE_ENV = process.env.NODE_ENV || package_json.NODE_ENV || 'development';
process.env.NODE_ENV = process.env.NODE_ENV || package_json.environment || 'development';
process.env.NODE_CONFIG_DIR = path.join(__dirname, 'config');
const config = require('config');
// use a separate data directory for development
if (NODE_ENV !== 'production') {
app.setPath('userData', path.join(app.getPath('appData'), 'Signal-' + NODE_ENV))
if (config.has('storageProfile')) {
app.setPath('userData', path.join(app.getPath('appData'),
'Signal-' + config.get('storageProfile')));
}
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
@ -62,13 +65,14 @@ function createWindow () {
protocol: 'file:',
slashes: true,
query: {
node_env: NODE_ENV,
locale: locale,
version: package_json.version
version: package_json.version,
SERVER_URL: config.get('SERVER_URL'),
NODE_ENV: process.env.NODE_ENV
}
}))
if (NODE_ENV === 'development') {
if (config.get('openDevTools')) {
// Open the DevTools.
mainWindow.webContents.openDevTools()
}
@ -86,7 +90,7 @@ function createWindow () {
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', function() {
if (NODE_ENV === 'production') {
if (!config.get('disableAutoUpdate')) {
autoUpdater.addListener('update-downloaded', function() {
autoUpdater.quitAndInstall()
});

View file

@ -33,9 +33,14 @@
"test": "grunt test",
"lint": "grunt jshint",
"start": "electron .",
"pack": "build --dir --em.NODE_ENV=$NODE_ENV",
"dist": "build --em.NODE_ENV=$NODE_ENV",
"release": "build -mwl --em.NODE_ENV=$NODE_ENV",
"dist": "build --em.environment=$NODE_ENV",
"pack": "npm run dist -- --dir",
"pack-staging": "NODE_ENV=staging npm run pack",
"dist-staging": "NODE_ENV=staging npm run dist",
"pack-prod": "NODE_ENV=production npm run pack",
"dist-prod": "NODE_ENV=production npm run dist",
"dist-prod-all": "NODE_ENV=production npm run dist -- -mwl",
"release": "npm run dist-prod-all",
"icon-gen": "icon-gen -r -t png -m 'ico,icns' -n 'ico=icon,icns=icon' -i ./build/icons -o ./build"
},
"build": {
@ -66,32 +71,34 @@
]
},
"files": [
"**/*",
"package.json",
"config/default.json",
"config/${env.NODE_ENV}.json",
"background.html",
"_locales/**",
"protos/*",
"js/**",
"stylesheets/*.css",
"!js/register.js",
"preload.js",
"main.js",
"menu.js",
"audio/**",
"images/**",
"fonts/*",
"node_modules/**",
"!**/node_modules/*/{CHANGELOG.md,README.md,README,readme.md,readme,test,__tests__,tests,powered-test,example,examples,*.d.ts}",
"!**/node_modules/.bin",
"!**/*.{o,hprof,orig,pyc,pyo,rbc}",
"!**/._*",
"!**/{.DS_Store,.git,.hg,.svn,CVS,RCS,SCCS,__pycache__,thumbs.db,.gitignore,.gitattributes,.editorconfig,.flowconfig,.yarn-metadata.json,.idea,appveyor.yml,.travis.yml,circle.yml,npm-debug.log,.nyc_output,yarn.lock,.yarn-integrity}",
"!test",
"!pack",
"!dist",
"!build",
"!components",
"!bower.json",
"!Gruntfile.js",
"!README.md",
"!CONTRIBUTING.md",
"!.sass-cache",
"!.tx",
"!.github",
"!.bowerrc",
"!.jscsrc"
"!**/{.DS_Store,.git,.hg,.svn,CVS,RCS,SCCS,__pycache__,thumbs.db,.gitignore,.gitattributes,.editorconfig,.flowconfig,.yarn-metadata.json,.idea,appveyor.yml,.travis.yml,circle.yml,npm-debug.log,.nyc_output,yarn.lock,.yarn-integrity}"
],
"directories": {
"output": "pack"
}
},
"dependencies": {
"config": "^1.25.1",
"electron-updater": "^1.11.2"
}
}