mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 04:25:31 +08:00
1157fdc450
Summary: This diff removes significant cruft from N1's compilation and build tooling: - Electron-Packager replaces most of the code in build/tasks/* used to copy things, bundle things, download electron, etc. - script/bootstrap has been replaced with a much simpler script that does not use APM, does not download Electron (we just use electron as an NPM dep) and does not manully compile sqlite. It requires NPMv3, but I think that's safe. - babel and eslint are now devDependencies of the main project. The main project also supports optionalDependencies now. - npm test and npm start replace ./N1.sh - APM is still around, and is only put into N1 so it can install plugins at runtime. It should be removed as soon as we notify package maintainers and have them provide zips. - N1 no longer has it's own compile-cache or babel/typescript/coffeescript compilers. It delegates to electron-compile and electron-compilers. Both of these packages had to be forked and modified slightly, but I'm hopeful the modifications will make it back in to the projects and you can still consult their documentation for more info. + In the near future, I think we should stop shipping electron-compilers with N1. This would mean that all plugins would need to be compiled on pre-publish, just like NPM packages, and would complicate the local development story a bit, but would make the app smaller. electron-compile is not supposed to compile at runtime in the prod app, just pull from the compile cache. - I've re-organized Grunt according to Grunt best practices, where each tasks/* file specifies it's own config and imports grunt tasks. - Unfortunately, I was not able to use any open source projects for the deb and rpm builds, because we have things like postinst hooks and start menu items which are not supported by the electron installer-generators. WIP Turn off all LESS compilation, because themes. Doh. Use Grunt for new build process too, just remove tasks More changes Add babel-eslint Remove unused react-devtools WIP Add name Ignore nonexistent Switch to more modern approach to config for grunt Move zipping to mac installer task Restructure publish task so it aggregates first, can log useful info if publishing is disabled Fix build dirs Fix win installer Fix linux installer Fix linux installer Try making linux A few more Updates Upadtes fixes fixes Get rid of non-meaningful variables Resolve assets path Insert nylas.sh Clean up args more Actually use description Fix display name ugh More tweaks Expliclty write /usr/bin/nylas Improve vars Use old nylas.sh Reinstate APM to better scope this diff Test Plan: Test on Mac, Windows, Linux Reviewers: evan, jackie, juan Reviewed By: jackie, juan Differential Revision: https://phab.nylas.com/D3411
101 lines
2.8 KiB
JavaScript
101 lines
2.8 KiB
JavaScript
window.eval = global.eval = function() {
|
|
throw new Error("Sorry, N1 does not support window.eval() for security reasons.");
|
|
}
|
|
|
|
var util = require('util')
|
|
var path = require('path');
|
|
var electron = require('electron');
|
|
var remote = electron.remote;
|
|
|
|
console.inspect = function consoleInspect(val) {
|
|
console.log(util.inspect(val, true, depth=7, colorize=true));
|
|
}
|
|
|
|
function setLoadTime (loadTime) {
|
|
if (global.NylasEnv) {
|
|
global.NylasEnv.loadTime = loadTime;
|
|
if (NylasEnv.inSpecMode()) return;
|
|
console.log('Window load time: ' + global.NylasEnv.getWindowLoadTime() + 'ms')
|
|
}
|
|
}
|
|
|
|
function handleSetupError (error) {
|
|
var currentWindow = remote.getCurrentWindow()
|
|
currentWindow.setSize(800, 600)
|
|
currentWindow.center()
|
|
currentWindow.show()
|
|
currentWindow.openDevTools()
|
|
console.error(error.stack || error)
|
|
}
|
|
|
|
function copyEnvFromMainProcess() {
|
|
var _ = require('underscore');
|
|
var remote = require('electron').remote;
|
|
var newEnv = _.extend({}, process.env, remote.process.env);
|
|
process.env = newEnv;
|
|
}
|
|
|
|
function setupWindow (loadSettings) {
|
|
if (process.platform === 'linux') {
|
|
// This will properly inherit process.env from the main process, which it
|
|
// doesn't do by default on Linux. See:
|
|
// https://github.com/atom/electron/issues/3306
|
|
copyEnvFromMainProcess();
|
|
}
|
|
|
|
var CompileCache = require('../src/compile-cache')
|
|
CompileCache.setHomeDirectory(loadSettings.configDirPath)
|
|
|
|
var ModuleCache = require('../src/module-cache')
|
|
ModuleCache.register(loadSettings)
|
|
ModuleCache.add(loadSettings.resourcePath)
|
|
|
|
// Start the crash reporter before anything else.
|
|
// require('crash-reporter').start({
|
|
// productName: 'N1',
|
|
// companyName: 'Nylas',
|
|
// // By explicitly passing the app version here, we could save the call
|
|
// // of "require('electron').remote.app.getVersion()".
|
|
// extra: {_version: loadSettings.appVersion}
|
|
// })
|
|
|
|
setupVmCompatibility()
|
|
|
|
require(loadSettings.bootstrapScript)
|
|
}
|
|
|
|
function setupVmCompatibility () {
|
|
var vm = require('vm')
|
|
if (!vm.Script.createContext) {
|
|
vm.Script.createContext = vm.createContext
|
|
}
|
|
}
|
|
|
|
|
|
window.onload = function() {
|
|
try {
|
|
var startTime = Date.now();
|
|
|
|
var fs = require('fs');
|
|
var path = require('path');
|
|
|
|
// Skip "?loadSettings=".
|
|
var rawLoadSettings = decodeURIComponent(location.search.substr(14));
|
|
var loadSettings;
|
|
try {
|
|
loadSettings = JSON.parse(rawLoadSettings);
|
|
} catch (error) {
|
|
console.error("Failed to parse load settings: " + rawLoadSettings);
|
|
throw error;
|
|
}
|
|
|
|
// Normalize to make sure drive letter case is consistent on Windows
|
|
process.resourcesPath = path.normalize(process.resourcesPath);
|
|
|
|
setupWindow(loadSettings)
|
|
setLoadTime(Date.now() - startTime)
|
|
}
|
|
catch (error) {
|
|
handleSetupError(error)
|
|
}
|
|
}
|