From 7ce5b000e448552bb4ba9556c8f38ccfef127162 Mon Sep 17 00:00:00 2001 From: Philip Weiss Date: Thu, 1 Mar 2018 19:35:59 -0800 Subject: [PATCH] address more of max's comments --- src/atom-environment.js | 1 + src/main-process/atom-application.js | 1 - src/main-process/atom-window.js | 20 ++++++-------------- src/main-process/parse-command-line.js | 22 +++++++--------------- 4 files changed, 14 insertions(+), 30 deletions(-) diff --git a/src/atom-environment.js b/src/atom-environment.js index 8897fc0ea..0688b8428 100644 --- a/src/atom-environment.js +++ b/src/atom-environment.js @@ -224,6 +224,7 @@ class AtomEnvironment { this.config.resetUserSettings(userSettings) if (projectSettings != null && projectSettings.config != null) { + console.log(projectSettings) this.project.replace(projectSettings) } diff --git a/src/main-process/atom-application.js b/src/main-process/atom-application.js index 2907e886f..9dcf1b39f 100644 --- a/src/main-process/atom-application.js +++ b/src/main-process/atom-application.js @@ -100,7 +100,6 @@ class AtomApplication extends EventEmitter { this.safeMode = options.safeMode this.socketPath = options.socketPath this.logFile = options.logFile - this.projectSettings = options.projectSettings this.userDataDir = options.userDataDir this._killProcess = options.killProcess || process.kill.bind(process) if (options.test || options.benchmark || options.benchmarkTest) this.socketPath = null diff --git a/src/main-process/atom-window.js b/src/main-process/atom-window.js index aa085d04a..e8e7cb181 100644 --- a/src/main-process/atom-window.js +++ b/src/main-process/atom-window.js @@ -56,11 +56,13 @@ class AtomWindow extends EventEmitter { if (this.shouldHideTitleBar()) options.frame = false this.browserWindow = new BrowserWindow(options) - if (this.atomApplication.projectSettings != null) { - this.projectSettings = this.atomApplication.projectSettings - } + Object.defineProperty(this.browserWindow, 'loadSettingsJSON', { + get: () => JSON.stringify(Object.assign({ + userSettings: this.atomApplication.configFile.get(), + projectSettings: this.projectSettings + }, this.loadSettings)) + }) - this.loadDataOverProcessBoundary() this.handleEvents() this.loadSettings = Object.assign({}, settings) @@ -151,16 +153,6 @@ class AtomWindow extends EventEmitter { return paths.every(p => this.containsPath(p)) } - loadDataOverProcessBoundary () { - Object.defineProperty(this.browserWindow, 'loadSettingsJSON', { - get: () => JSON.stringify(Object.assign({ - userSettings: this.atomApplication.configFile.get(), - projectSettings: this.projectSettings - }, this.loadSettings)), - configurable: true - }) - } - containsPath (pathToCheck) { if (!pathToCheck) return false let stat diff --git a/src/main-process/parse-command-line.js b/src/main-process/parse-command-line.js index 93461e262..45dd8c2ba 100644 --- a/src/main-process/parse-command-line.js +++ b/src/main-process/parse-command-line.js @@ -53,7 +53,7 @@ module.exports = function parseCommandLine (processArgs) { 'When in test mode, waits until the specified time (in minutes) and kills the process (exit code: 130).' ) options.alias('v', 'version').boolean('v').describe('v', 'Print the version information.') - options.alias('p', 'atomproject').describe('p', 'Start atom with an atomproject file.') + options.alias('p', 'project').describe('p', 'Start atom with an atomproject file.') options.alias('w', 'wait').boolean('w').describe('w', 'Wait for window to be closed before returning.') options.alias('a', 'add').boolean('a').describe('add', 'Open path as a new project in last used window.') options.string('socket-path') @@ -93,7 +93,7 @@ module.exports = function parseCommandLine (processArgs) { const benchmark = args['benchmark'] const benchmarkTest = args['benchmark-test'] const test = args['test'] - const atomProject = args['atomproject'] + const atomProject = args['project'] const mainProcess = args['main-process'] const timeout = args['timeout'] const newWindow = args['new-window'] @@ -144,8 +144,9 @@ module.exports = function parseCommandLine (processArgs) { const config = contents.config const originPath = atomProject const paths = contents.paths.map((curPath) => - relativizeToAtomProject(curPath, atomProject, executedFrom) - ) + relativizeToAtomProject(curPath, path.dirname(path.join(executedFrom, atomProject)) + )) + console.log(paths) pathsToOpen.push(path.dirname(atomProject)) projectSettings = { originPath, paths, config } } @@ -194,9 +195,6 @@ module.exports = function parseCommandLine (processArgs) { } const readProjectSettingsSync = (filepath, executedFrom) => { - if (!hasAtomProjectFormat(path.basename(filepath))) { - throw new Error('File must match format: *.atomproject.{json, cson}') - } try { const readPath = path.isAbsolute(filepath) ? filepath : path.join(executedFrom, filepath) const contents = CSON.readFileSync(readPath) @@ -210,14 +208,8 @@ const readProjectSettingsSync = (filepath, executedFrom) => { } } -const hasAtomProjectFormat = (atomProject) => { - const projectFileFormat = /.*\.atomproject\.(json|cson)/ - return projectFileFormat.test(atomProject) -} - -const relativizeToAtomProject = (curPath, atomProject, executedFrom) => { - const projectPath = path.isAbsolute(atomProject) ? atomProject : path.join(executedFrom, atomProject) - return path.join(path.dirname(projectPath), curPath) +const relativizeToAtomProject = (curPath, atomProject) => { + return path.isAbsolute(curPath) ? curPath : path.join(atomProject, curPath) } const normalizeDriveLetterName = (filePath) => {