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:
parent
34042415e9
commit
7e1bee1082
7 changed files with 59 additions and 32 deletions
4
config/default.json
Normal file
4
config/default.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"disableAutoUpdate": false,
|
||||||
|
"openDevTools": false
|
||||||
|
}
|
6
config/development.json
Normal file
6
config/development.json
Normal 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
3
config/production.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"SERVER_URL": "https://textsecure-service-ca.whispersystems.org"
|
||||||
|
}
|
6
config/staging.json
Normal file
6
config/staging.json
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"SERVER_URL": "https://textsecure-service-staging.whispersystems.org",
|
||||||
|
"storageProfile": "staging",
|
||||||
|
"disableAutoUpdate": true,
|
||||||
|
"openDevTools": true
|
||||||
|
}
|
|
@ -9,6 +9,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('background page reloaded');
|
console.log('background page reloaded');
|
||||||
|
console.log('NODE_ENV', window.env.NODE_ENV);
|
||||||
extension.notification.init();
|
extension.notification.init();
|
||||||
|
|
||||||
// Close and reopen existing windows
|
// Close and reopen existing windows
|
||||||
|
@ -38,11 +39,7 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var SERVER_URL = 'https://textsecure-service-staging.whispersystems.org';
|
var SERVER_URL = env.SERVER_URL;
|
||||||
if (window.env && window.env.node_env === 'production') {
|
|
||||||
SERVER_URL = 'https://textsecure-service-ca.whispersystems.org';
|
|
||||||
}
|
|
||||||
|
|
||||||
var SERVER_PORTS = [80, 4433, 8443];
|
var SERVER_PORTS = [80, 4433, 8443];
|
||||||
var messageReceiver;
|
var messageReceiver;
|
||||||
window.getSocketStatus = function() {
|
window.getSocketStatus = function() {
|
||||||
|
|
20
main.js
20
main.js
|
@ -25,14 +25,17 @@ if (shouldQuit) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read package.json
|
|
||||||
const package_json = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf-8'))
|
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
|
// use a separate data directory for development
|
||||||
if (NODE_ENV !== 'production') {
|
if (config.has('storageProfile')) {
|
||||||
app.setPath('userData', path.join(app.getPath('appData'), 'Signal-' + NODE_ENV))
|
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
|
// 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.
|
// be closed automatically when the JavaScript object is garbage collected.
|
||||||
let mainWindow
|
let mainWindow
|
||||||
|
@ -62,13 +65,14 @@ function createWindow () {
|
||||||
protocol: 'file:',
|
protocol: 'file:',
|
||||||
slashes: true,
|
slashes: true,
|
||||||
query: {
|
query: {
|
||||||
node_env: NODE_ENV,
|
|
||||||
locale: locale,
|
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.
|
// Open the DevTools.
|
||||||
mainWindow.webContents.openDevTools()
|
mainWindow.webContents.openDevTools()
|
||||||
}
|
}
|
||||||
|
@ -86,7 +90,7 @@ function createWindow () {
|
||||||
// initialization and is ready to create browser windows.
|
// initialization and is ready to create browser windows.
|
||||||
// Some APIs can only be used after this event occurs.
|
// Some APIs can only be used after this event occurs.
|
||||||
app.on('ready', function() {
|
app.on('ready', function() {
|
||||||
if (NODE_ENV === 'production') {
|
if (!config.get('disableAutoUpdate')) {
|
||||||
autoUpdater.addListener('update-downloaded', function() {
|
autoUpdater.addListener('update-downloaded', function() {
|
||||||
autoUpdater.quitAndInstall()
|
autoUpdater.quitAndInstall()
|
||||||
});
|
});
|
||||||
|
|
45
package.json
45
package.json
|
@ -33,9 +33,14 @@
|
||||||
"test": "grunt test",
|
"test": "grunt test",
|
||||||
"lint": "grunt jshint",
|
"lint": "grunt jshint",
|
||||||
"start": "electron .",
|
"start": "electron .",
|
||||||
"pack": "build --dir --em.NODE_ENV=$NODE_ENV",
|
"dist": "build --em.environment=$NODE_ENV",
|
||||||
"dist": "build --em.NODE_ENV=$NODE_ENV",
|
"pack": "npm run dist -- --dir",
|
||||||
"release": "build -mwl --em.NODE_ENV=$NODE_ENV",
|
"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"
|
"icon-gen": "icon-gen -r -t png -m 'ico,icns' -n 'ico=icon,icns=icon' -i ./build/icons -o ./build"
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
|
@ -66,32 +71,34 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"files": [
|
"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/*/{CHANGELOG.md,README.md,README,readme.md,readme,test,__tests__,tests,powered-test,example,examples,*.d.ts}",
|
||||||
"!**/node_modules/.bin",
|
"!**/node_modules/.bin",
|
||||||
"!**/*.{o,hprof,orig,pyc,pyo,rbc}",
|
"!**/*.{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}",
|
"!**/{.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"
|
|
||||||
],
|
],
|
||||||
"directories": {
|
"directories": {
|
||||||
"output": "pack"
|
"output": "pack"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"config": "^1.25.1",
|
||||||
"electron-updater": "^1.11.2"
|
"electron-updater": "^1.11.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue