main.js
1 if (typeof snapshotResult !== 'undefined') { 2 snapshotResult.setGlobals(global, process, global, {}, console, require); 3 } 4 5 const startTime = Date.now(); 6 const StartupTime = require('../startup-time'); 7 StartupTime.setStartTime(); 8 9 const path = require('path'); 10 const fs = require('fs-plus'); 11 const CSON = require('season'); 12 const yargs = require('yargs'); 13 const electron = require('electron'); 14 15 const args = yargs(process.argv) 16 .alias('d', 'dev') 17 .alias('t', 'test') 18 .alias('r', 'resource-path').argv; 19 20 function isAtomRepoPath(repoPath) { 21 let packageJsonPath = path.join(repoPath, 'package.json'); 22 if (fs.statSyncNoException(packageJsonPath)) { 23 try { 24 let packageJson = CSON.readFileSync(packageJsonPath); 25 return packageJson.name === 'atom'; 26 } catch (e) { 27 return false; 28 } 29 } 30 31 return false; 32 } 33 34 let resourcePath; 35 let devResourcePath; 36 37 if (args.resourcePath) { 38 resourcePath = args.resourcePath; 39 devResourcePath = resourcePath; 40 } else { 41 const stableResourcePath = path.dirname(path.dirname(__dirname)); 42 const defaultRepositoryPath = path.join( 43 electron.app.getPath('home'), 44 'github', 45 'atom' 46 ); 47 48 if (process.env.ATOM_DEV_RESOURCE_PATH) { 49 devResourcePath = process.env.ATOM_DEV_RESOURCE_PATH; 50 } else if (isAtomRepoPath(process.cwd())) { 51 devResourcePath = process.cwd(); 52 } else if (fs.statSyncNoException(defaultRepositoryPath)) { 53 devResourcePath = defaultRepositoryPath; 54 } else { 55 devResourcePath = stableResourcePath; 56 } 57 58 if (args.dev || args.test || args.benchmark || args.benchmarkTest) { 59 resourcePath = devResourcePath; 60 } else { 61 resourcePath = stableResourcePath; 62 } 63 } 64 65 const start = require(path.join(resourcePath, 'src', 'main-process', 'start')); 66 start(resourcePath, devResourcePath, startTime);