mirror of
https://github.com/atom/atom.git
synced 2026-02-18 10:31:54 -05:00
add .atomProject files
This commit is contained in:
@@ -5,6 +5,7 @@ const yargs = require('yargs')
|
||||
const {app} = require('electron')
|
||||
const path = require('path')
|
||||
const fs = require('fs-plus')
|
||||
const CSON = require('season')
|
||||
|
||||
module.exports = function parseCommandLine (processArgs) {
|
||||
const options = yargs(processArgs).wrap(yargs.terminalWidth())
|
||||
@@ -52,6 +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', 'atom-project').describe('p', 'Start atom with an atom-project 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')
|
||||
@@ -91,6 +93,7 @@ module.exports = function parseCommandLine (processArgs) {
|
||||
const benchmark = args['benchmark']
|
||||
const benchmarkTest = args['benchmark-test']
|
||||
const test = args['test']
|
||||
const atomProject = args['atom-project']
|
||||
const mainProcess = args['main-process']
|
||||
const timeout = args['timeout']
|
||||
const newWindow = args['new-window']
|
||||
@@ -125,6 +128,8 @@ module.exports = function parseCommandLine (processArgs) {
|
||||
}
|
||||
}
|
||||
|
||||
// Check to see if atom-project flag is set, then add all paths from the .atom-project.
|
||||
|
||||
if (args['resource-path']) {
|
||||
devMode = true
|
||||
devResourcePath = args['resource-path']
|
||||
@@ -134,6 +139,16 @@ module.exports = function parseCommandLine (processArgs) {
|
||||
devMode = true
|
||||
}
|
||||
|
||||
let projectSettings
|
||||
if (atomProject) {
|
||||
const config = readProjectSettingsSync(atomProject, executedFrom)
|
||||
const paths = config.paths
|
||||
projectSettings = config.config
|
||||
if (paths != null) {
|
||||
pathsToOpen = pathsToOpen.concat(paths)
|
||||
}
|
||||
}
|
||||
|
||||
if (devMode) {
|
||||
resourcePath = devResourcePath
|
||||
}
|
||||
@@ -150,8 +165,8 @@ module.exports = function parseCommandLine (processArgs) {
|
||||
|
||||
resourcePath = normalizeDriveLetterName(resourcePath)
|
||||
devResourcePath = normalizeDriveLetterName(devResourcePath)
|
||||
|
||||
return {
|
||||
projectSettings,
|
||||
resourcePath,
|
||||
devResourcePath,
|
||||
pathsToOpen,
|
||||
@@ -177,7 +192,24 @@ module.exports = function parseCommandLine (processArgs) {
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeDriveLetterName (filePath) {
|
||||
const readProjectSettingsSync = (filepath, executedFrom) => {
|
||||
if (!hasAtomProjectFormat(path.basename(filepath))) {
|
||||
throw new Error('File must match format: *.atom-project.{json, cson}')
|
||||
}
|
||||
try {
|
||||
const readPath = path.isAbsolute(filepath) ? filepath : path.join(executedFrom, filepath)
|
||||
return CSON.readFileSync(readPath)
|
||||
} catch (e) {
|
||||
throw new Error('Unable to read supplied config file.')
|
||||
}
|
||||
}
|
||||
|
||||
const hasAtomProjectFormat = (atomProject) => {
|
||||
const projectFileFormat = /.*\.atomProject\.(json|cson)/
|
||||
return projectFileFormat.test(atomProject)
|
||||
}
|
||||
|
||||
const normalizeDriveLetterName = (filePath) => {
|
||||
if (process.platform === 'win32') {
|
||||
return filePath.replace(/^([a-z]):/, ([driveLetter]) => driveLetter.toUpperCase() + ':')
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user