Simplify dev resource path detection

This commit is contained in:
David Wilson
2018-08-21 11:57:18 -07:00
parent 09b45911bc
commit ba12a1e2fc
4 changed files with 28 additions and 38 deletions

View File

@@ -1,31 +0,0 @@
'use strict'
const path = require('path')
const fs = require('fs-plus')
const CSON = require('season')
const electron = require('electron')
module.exports = function () {
const appResourcePath = path.dirname(path.dirname(__dirname))
const defaultRepositoryPath = path.join(electron.app.getPath('home'), 'github', 'atom')
if (process.env.ATOM_DEV_RESOURCE_PATH) {
return process.env.ATOM_DEV_RESOURCE_PATH
} else if (isAtomRepoPath(process.cwd())) {
return process.cwd()
} else if (fs.statSyncNoException(defaultRepositoryPath)) {
return defaultRepositoryPath
}
return appResourcePath
}
function isAtomRepoPath (repoPath) {
let packageJsonPath = path.join(repoPath, 'package.json')
if (fs.statSyncNoException(packageJsonPath)) {
let packageJson = CSON.readFileSync(packageJsonPath)
return packageJson.name === 'atom'
}
return false
}

View File

@@ -5,8 +5,10 @@ if (typeof snapshotResult !== 'undefined') {
const startTime = Date.now()
const path = require('path')
const fs = require('fs-plus')
const CSON = require('season')
const yargs = require('yargs')
const getDevResourcePath = require('./get-dev-resource-path')
const electron = require('electron')
const args =
yargs(process.argv)
@@ -14,14 +16,34 @@ const args =
.alias('t', 'test')
.argv
function isAtomRepoPath (repoPath) {
let packageJsonPath = path.join(repoPath, 'package.json')
if (fs.statSyncNoException(packageJsonPath)) {
let packageJson = CSON.readFileSync(packageJsonPath)
return packageJson.name === 'atom'
}
return false
}
let resourcePath
if (args.resourcePath) {
resourcePath = args.resourcePath
} else {
const stableResourcePath = path.dirname(path.dirname(__dirname))
const defaultRepositoryPath = path.join(electron.app.getPath('home'), 'github', 'atom')
if (args.dev || args.test || args.benchmark || args.benchmarkTest) {
resourcePath = getDevResourcePath() || stableResourcePath
if (process.env.ATOM_DEV_RESOURCE_PATH) {
resourcePath = process.env.ATOM_DEV_RESOURCE_PATH
} else if (isAtomRepoPath(process.cwd())) {
resourcePath = process.cwd()
} else if (fs.statSyncNoException(defaultRepositoryPath)) {
resourcePath = defaultRepositoryPath
} else {
resourcePath = stableResourcePath
}
} else {
resourcePath = stableResourcePath
}

View File

@@ -5,9 +5,8 @@ const yargs = require('yargs')
const {app} = require('electron')
const path = require('path')
const fs = require('fs-plus')
const getDevResourcePath = require('./get-dev-resource-path')
module.exports = function parseCommandLine (processArgs) {
module.exports = function parseCommandLine (processArgs, initialResourcePath) {
const options = yargs(processArgs).wrap(yargs.terminalWidth())
const version = app.getVersion()
options.usage(
@@ -120,7 +119,7 @@ module.exports = function parseCommandLine (processArgs) {
let pathsToOpen = []
let urlsToOpen = []
let devMode = args['dev']
let devResourcePath = getDevResourcePath()
let devResourcePath = initialResourcePath
let resourcePath = null
for (const path of args._) {

View File

@@ -9,7 +9,7 @@ const fs = require('fs')
const CSON = require('season')
const Config = require('../config')
module.exports = function start (resourcePath, startTime) {
module.exports = function start (initialResourcePath, startTime) {
global.shellStartTime = startTime
process.on('uncaughtException', function (error = {}) {
@@ -37,7 +37,7 @@ module.exports = function start (resourcePath, startTime) {
app.commandLine.appendSwitch('enable-experimental-web-platform-features')
const args = parseCommandLine(process.argv.slice(1))
const args = parseCommandLine(process.argv.slice(1), initialResourcePath)
atomPaths.setAtomHome(app.getPath('home'))
atomPaths.setUserData(app)
setupCompileCache()