mirror of
https://github.com/atom/atom.git
synced 2026-02-18 02:21:43 -05:00
Use path.dirname() instead of fsUtils.directory()
This commit is contained in:
@@ -50,7 +50,7 @@ class EditSession
|
||||
|
||||
@buffer.retain()
|
||||
@subscribe @buffer, "path-changed", =>
|
||||
@project.setPath(fsUtils.directory(@getPath())) unless @project.getPath()?
|
||||
@project.setPath(path.dirname(@getPath())) unless @project.getPath()?
|
||||
@trigger "title-changed"
|
||||
@trigger "path-changed"
|
||||
@subscribe @buffer, "contents-conflicted", => @trigger "contents-conflicted"
|
||||
@@ -112,7 +112,7 @@ class EditSession
|
||||
getLongTitle: ->
|
||||
if sessionPath = @getPath()
|
||||
fileName = path.basename(sessionPath)
|
||||
directory = path.basename(fsUtils.directory(sessionPath))
|
||||
directory = path.basename(path.dirname(sessionPath))
|
||||
"#{fileName} - #{directory}"
|
||||
else
|
||||
'untitled'
|
||||
|
||||
@@ -52,12 +52,12 @@ class Project
|
||||
|
||||
# Sets the project path.
|
||||
#
|
||||
# path - A {String} representing the new path
|
||||
setPath: (path) ->
|
||||
# projectPath - A {String} representing the new path
|
||||
setPath: (projectPath) ->
|
||||
@rootDirectory?.off()
|
||||
|
||||
if path?
|
||||
directory = if fsUtils.isDirectory(path) then path else fsUtils.directory(path)
|
||||
if projectPath?
|
||||
directory = if fsUtils.isDirectory(projectPath) then projectPath else path.dirname(projectPath)
|
||||
@rootDirectory = new Directory(directory)
|
||||
else
|
||||
@rootDirectory = null
|
||||
|
||||
@@ -46,7 +46,7 @@ class PackageGeneratorView extends View
|
||||
getPackagePath: ->
|
||||
packagePath = @miniEditor.getText()
|
||||
packageName = _.dasherize(path.basename(packagePath))
|
||||
fsUtils.join(fsUtils.directory(packagePath), packageName)
|
||||
fsUtils.join(path.dirname(packagePath), packageName)
|
||||
|
||||
validPackagePath: ->
|
||||
if fsUtils.exists(@getPackagePath())
|
||||
@@ -70,7 +70,7 @@ class PackageGeneratorView extends View
|
||||
if fsUtils.isDirectory(path)
|
||||
fsUtils.makeTree(sourcePath)
|
||||
if fsUtils.isFile(path)
|
||||
fsUtils.makeTree(fsUtils.directory(sourcePath))
|
||||
fsUtils.makeTree(path.dirname(sourcePath))
|
||||
content = @replacePackageNamePlaceholders(fsUtils.read(path), packageName)
|
||||
fsUtils.write(sourcePath, content)
|
||||
|
||||
|
||||
@@ -42,14 +42,14 @@ describe 'Package Generator', ->
|
||||
|
||||
it "forces the package's name to be lowercase with dashes", ->
|
||||
packageName = "CamelCaseIsForTheBirds"
|
||||
packagePath = fsUtils.join(fsUtils.directory(packagePath), packageName)
|
||||
packagePath = fsUtils.join(path.dirname(packagePath), packageName)
|
||||
rootView.trigger("package-generator:generate")
|
||||
packageGeneratorView = rootView.find(".package-generator").view()
|
||||
packageGeneratorView.miniEditor.setText(packagePath)
|
||||
packageGeneratorView.trigger "core:confirm"
|
||||
|
||||
expect(packagePath).not.toExistOnDisk()
|
||||
expect(fsUtils.join(fsUtils.directory(packagePath), "camel-case-is-for-the-birds")).toExistOnDisk()
|
||||
expect(fsUtils.join(path.dirname(packagePath), "camel-case-is-for-the-birds")).toExistOnDisk()
|
||||
|
||||
it "correctly lays out the package files and closes the package generator view", ->
|
||||
rootView.attachToDom()
|
||||
|
||||
@@ -47,7 +47,7 @@ class TabView extends View
|
||||
if fileNameText?
|
||||
duplicates = @editor.getEditSessions().filter (session) -> fileNameText is session.buffer.getBaseName()
|
||||
if duplicates.length > 1
|
||||
directory = path.basename(fsUtils.directory(@editSession.getPath()))
|
||||
directory = path.basename(path.dirname(@editSession.getPath()))
|
||||
fileNameText = "#{fileNameText} - #{directory}" if directory
|
||||
else
|
||||
fileNameText = 'untitled'
|
||||
|
||||
@@ -235,7 +235,7 @@ class TreeView extends ScrollView
|
||||
dialog.showError("Error: #{newPath} already exists. Try a different path.")
|
||||
return
|
||||
|
||||
directoryPath = fsUtils.directory(newPath)
|
||||
directoryPath = path.dirname(newPath)
|
||||
try
|
||||
fsUtils.makeTree(directoryPath) unless fsUtils.exists(directoryPath)
|
||||
fsUtils.move(oldPath, newPath)
|
||||
@@ -261,7 +261,7 @@ class TreeView extends ScrollView
|
||||
add: ->
|
||||
selectedEntry = @selectedEntry() or @root
|
||||
selectedPath = selectedEntry.getPath()
|
||||
directoryPath = if fsUtils.isFile(selectedPath) then fsUtils.directory(selectedPath) else selectedPath
|
||||
directoryPath = if fsUtils.isFile(selectedPath) then path.dirname(selectedPath) else selectedPath
|
||||
relativeDirectoryPath = project.relativize(directoryPath)
|
||||
relativeDirectoryPath += '/' if relativeDirectoryPath.length > 0
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ mkdirp = require 'mkdirp'
|
||||
fsUtils = require 'fs-utils'
|
||||
|
||||
symlinkCommand = (sourcePath, destinationPath, callback) ->
|
||||
mkdirp fsUtils.directory(destinationPath), (error) ->
|
||||
mkdirp path.dirname(destinationPath), (error) ->
|
||||
if error?
|
||||
callback(error)
|
||||
else
|
||||
|
||||
@@ -23,14 +23,6 @@ module.exports =
|
||||
catch e
|
||||
path
|
||||
|
||||
# Returns the path of a file's containing directory, albeit the
|
||||
# parent directory if the file is a directory. A terminal directory
|
||||
# separator is ignored.
|
||||
directory: (path) ->
|
||||
parentPath = path.replace(new RegExp("/#{Path.basename(_.escapeRegExp(path))}\/?$"), '')
|
||||
return "" if path == parentPath
|
||||
parentPath
|
||||
|
||||
# Returns true if the file specified by path exists
|
||||
exists: (path) ->
|
||||
path? and fs.existsSync(path)
|
||||
|
||||
Reference in New Issue
Block a user