Teach --dev to detect Atom repo in process.cwd()

This commit is contained in:
David Wilson
2018-08-21 06:40:25 -07:00
parent 2b73c6b28a
commit 94f972e0bf
3 changed files with 35 additions and 8 deletions

View File

@@ -0,0 +1,31 @@
'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

@@ -8,6 +8,7 @@ const electron = require('electron')
const fs = require('fs')
const path = require('path')
const yargs = require('yargs')
const getDevResourcePath = require('./get-dev-resource-path')
const args =
yargs(process.argv)
@@ -24,13 +25,7 @@ if (args.resourcePath) {
const defaultRepositoryPath = path.join(electron.app.getPath('home'), 'github', 'atom')
if (args.dev || args.test || args.benchmark || args.benchmarkTest) {
if (process.env.ATOM_DEV_RESOURCE_PATH) {
resourcePath = process.env.ATOM_DEV_RESOURCE_PATH
} else if (fs.statSyncNoException(defaultRepositoryPath)) {
resourcePath = defaultRepositoryPath
} else {
resourcePath = stableResourcePath
}
resourcePath = getDevResourcePath() || stableResourcePath
} else {
resourcePath = stableResourcePath
}

View File

@@ -5,6 +5,7 @@ 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) {
const options = yargs(processArgs).wrap(yargs.terminalWidth())
@@ -119,7 +120,7 @@ module.exports = function parseCommandLine (processArgs) {
let pathsToOpen = []
let urlsToOpen = []
let devMode = args['dev']
let devResourcePath = process.env.ATOM_DEV_RESOURCE_PATH || path.join(app.getPath('home'), 'github', 'atom')
let devResourcePath = getDevResourcePath
let resourcePath = null
for (const path of args._) {