Use path.join() instead of fsUtils.join()

This commit is contained in:
Kevin Sawicki
2013-06-12 16:20:40 -07:00
parent 7cf4063d9e
commit 82013b1970
28 changed files with 234 additions and 230 deletions

View File

@@ -1,6 +1,7 @@
TextMateGrammar = require 'text-mate-grammar'
Package = require 'package'
fsUtils = require 'fs-utils'
path = require 'path'
_ = require 'underscore'
$ = require 'jquery'
CSON = require 'season'
@@ -64,7 +65,7 @@ class AtomPackage extends Package
@keymaps = @getKeymapPaths().map (path) -> [path, CSON.readFileSync(path)]
getKeymapPaths: ->
keymapsDirPath = fsUtils.join(@path, 'keymaps')
keymapsDirPath = path.join(@path, 'keymaps')
if @metadata.keymaps
@metadata.keymaps.map (name) -> fsUtils.resolve(keymapsDirPath, name, ['json', 'cson', ''])
else
@@ -74,7 +75,7 @@ class AtomPackage extends Package
@stylesheets = @getStylesheetPaths().map (path) -> [path, loadStylesheet(path)]
getStylesheetPaths: ->
stylesheetDirPath = fsUtils.join(@path, 'stylesheets')
stylesheetDirPath = path.join(@path, 'stylesheets')
if @metadata.stylesheets
@metadata.stylesheets.map (name) -> fsUtils.resolve(stylesheetDirPath, name, ['css', 'less', ''])
else
@@ -82,13 +83,13 @@ class AtomPackage extends Package
loadGrammars: ->
@grammars = []
grammarsDirPath = fsUtils.join(@path, 'grammars')
grammarsDirPath = path.join(@path, 'grammars')
for grammarPath in fsUtils.list(grammarsDirPath, ['.json', '.cson'])
@grammars.push(TextMateGrammar.loadSync(grammarPath))
loadScopedProperties: ->
@scopedProperties = []
scopedPropertiessDirPath = fsUtils.join(@path, 'scoped-properties')
scopedPropertiessDirPath = path.join(@path, 'scoped-properties')
for scopedPropertiesPath in fsUtils.list(scopedPropertiessDirPath, ['.json', '.cson'])
for selector, properties of fsUtils.readObject(scopedPropertiesPath)
@scopedProperties.push([scopedPropertiesPath, selector, properties])
@@ -124,9 +125,9 @@ class AtomPackage extends Package
@resolvedMainModulePath = true
mainModulePath =
if @metadata.main
fsUtils.join(@path, @metadata.main)
path.join(@path, @metadata.main)
else
fsUtils.join(@path, 'index')
path.join(@path, 'index')
@mainModulePath = fsUtils.resolveExtension(mainModulePath, ["", _.keys(require.extensions)...])
registerDeferredDeserializers: ->

View File

@@ -17,12 +17,12 @@ class AtomTheme extends Theme
if path.extname(@path) in ['.css', '.less']
@loadStylesheet(@path)
else
metadataPath = fsUtils.resolveExtension(fsUtils.join(@path, 'package'), ['cson', 'json'])
metadataPath = fsUtils.resolveExtension(path.join(@path, 'package'), ['cson', 'json'])
if fsUtils.isFile(metadataPath)
stylesheetNames = fsUtils.readObject(metadataPath)?.stylesheets
if stylesheetNames
for name in stylesheetNames
filename = fsUtils.resolveExtension(fsUtils.join(@path, name), ['.css', '.less', ''])
filename = fsUtils.resolveExtension(path.join(@path, name), ['.css', '.less', ''])
@loadStylesheet(filename)
else
@loadStylesheet(stylesheetPath) for stylesheetPath in fsUtils.list(@path, ['.css', '.less'])

View File

@@ -90,7 +90,7 @@ window.atom =
packagePath = fsUtils.resolve(config.packageDirPaths..., name)
return packagePath if fsUtils.isDirectory(packagePath)
packagePath = fsUtils.join(window.resourcePath, 'node_modules', name)
packagePath = path.join(window.resourcePath, 'node_modules', name)
return packagePath if @isInternalPackage(packagePath)
isInternalPackage: (packagePath) ->
@@ -116,7 +116,7 @@ window.atom =
for packagePath in fsUtils.list(packageDirPath)
packagePaths.push(packagePath) if fsUtils.isDirectory(packagePath)
for packagePath in fsUtils.list(fsUtils.join(window.resourcePath, 'node_modules'))
for packagePath in fsUtils.list(path.join(window.resourcePath, 'node_modules'))
packagePaths.push(packagePath) if @isInternalPackage(packagePath)
_.uniq(packagePaths)
@@ -151,7 +151,7 @@ window.atom =
@loadedThemes.push Theme.load(name)
loadUserStylesheet: ->
userStylesheetPath = fsUtils.resolve(fsUtils.join(config.configDirPath, 'user'), ['css', 'less'])
userStylesheetPath = fsUtils.resolve(path.join(config.configDirPath, 'user'), ['css', 'less'])
if fsUtils.isFile(userStylesheetPath)
userStyleesheetContents = loadStylesheet(userStylesheetPath)
applyStylesheet(userStylesheetPath, userStyleesheetContents, 'userTheme')
@@ -237,7 +237,7 @@ window.atom =
filename = "editor-#{sha1}"
filename ?= 'undefined'
fsUtils.join(config.userStoragePath, filename)
path.join(config.userStoragePath, filename)
setWindowState: (keyPath, value) ->
windowState = @getWindowState()
@@ -273,7 +273,7 @@ window.atom =
process.crash()
requireUserInitScript: ->
userInitScriptPath = fsUtils.join(config.configDirPath, "user.coffee")
userInitScriptPath = path.join(config.configDirPath, "user.coffee")
try
require userInitScriptPath if fsUtils.isFile(userInitScriptPath)
catch error

View File

@@ -3,18 +3,19 @@ _ = require 'underscore'
EventEmitter = require 'event-emitter'
CSON = require 'season'
fs = require 'fs'
path = require 'path'
async = require 'async'
pathWatcher = require 'pathwatcher'
configDirPath = fsUtils.absolute("~/.atom")
bundledPackagesDirPath = fsUtils.join(resourcePath, "src/packages")
nodeModulesDirPath = fsUtils.join(resourcePath, "node_modules")
bundledThemesDirPath = fsUtils.join(resourcePath, "themes")
vendoredPackagesDirPath = fsUtils.join(resourcePath, "vendor/packages")
vendoredThemesDirPath = fsUtils.join(resourcePath, "vendor/themes")
userThemesDirPath = fsUtils.join(configDirPath, "themes")
userPackagesDirPath = fsUtils.join(configDirPath, "packages")
userStoragePath = fsUtils.join(configDirPath, ".storage")
bundledPackagesDirPath = path.join(resourcePath, "src/packages")
nodeModulesDirPath = path.join(resourcePath, "node_modules")
bundledThemesDirPath = path.join(resourcePath, "themes")
vendoredPackagesDirPath = path.join(resourcePath, "vendor/packages")
vendoredThemesDirPath = .join(resourcePath, "vendor/themes")
userThemesDirPath = path.join(configDirPath, "themes")
userPackagesDirPath = path.join(configDirPath, "packages")
userStoragePath = path.join(configDirPath, ".storage")
# Public: Handles all of Atom's configuration details.
#
@@ -28,7 +29,7 @@ class Config
packageDirPaths: [userPackagesDirPath, vendoredPackagesDirPath, bundledPackagesDirPath]
userPackagesDirPath: userPackagesDirPath
userStoragePath: userStoragePath
lessSearchPaths: [fsUtils.join(resourcePath, 'static'), fsUtils.join(resourcePath, 'vendor')]
lessSearchPaths: [path.join(resourcePath, 'static'), path.join(resourcePath, 'vendor')]
defaultSettings: null
settings: null
configFileHasErrors: null
@@ -41,7 +42,7 @@ class Config
editor: _.clone(require('editor').configDefaults)
@settings = {}
@configFilePath = fsUtils.resolve(configDirPath, 'config', ['json', 'cson'])
@configFilePath ?= fsUtils.join(configDirPath, 'config.cson')
@configFilePath ?= path.join(configDirPath, 'config.cson')
initializeConfigDirectory: (done) ->
return if fsUtils.exists(@configDirPath)
@@ -55,14 +56,14 @@ class Config
templateConfigDirPath = fsUtils.resolve(window.resourcePath, 'dot-atom')
onConfigDirFile = (sourcePath) =>
relativePath = sourcePath.substring(templateConfigDirPath.length + 1)
destinationPath = fsUtils.join(@configDirPath, relativePath)
destinationPath = path.join(@configDirPath, relativePath)
queue.push({sourcePath, destinationPath})
fsUtils.traverseTree(templateConfigDirPath, onConfigDirFile, (path) -> true)
configThemeDirPath = fsUtils.join(@configDirPath, 'themes')
configThemeDirPath = path.join(@configDirPath, 'themes')
onThemeDirFile = (sourcePath) ->
relativePath = sourcePath.substring(bundledThemesDirPath.length + 1)
destinationPath = fsUtils.join(configThemeDirPath, relativePath)
destinationPath = path.join(configThemeDirPath, relativePath)
queue.push({sourcePath, destinationPath})
fsUtils.traverseTree(bundledThemesDirPath, onThemeDirFile, (path) -> true)

View File

@@ -39,7 +39,7 @@ class Keymap
@loadDirectory(fsUtils.resolveOnLoadPath('keymaps'))
loadUserKeymaps: ->
@loadDirectory(fsUtils.join(config.configDirPath, 'keymaps'))
@loadDirectory(path.join(config.configDirPath, 'keymaps'))
loadDirectory: (directoryPath) ->
@load(filePath) for filePath in fsUtils.list(directoryPath, ['.cson', '.json'])

View File

@@ -96,11 +96,11 @@ class Project
# Identifies if a path is ignored.
#
# path - The {String} name of the path to check
# repositoryPath - The {String} name of the path to check
#
# Returns a {Boolean}.
ignoreRepositoryPath: (path) ->
config.get("core.hideGitIgnoredFiles") and git?.isPathIgnored(fsUtils.join(@getPath(), path))
ignoreRepositoryPath: (repositoryPath) ->
config.get("core.hideGitIgnoredFiles") and git?.isPathIgnored(path.join(@getPath(), repositoryPath))
# Given a uri, this resolves it relative to the project directory. If the path
# is already absolute or if it is prefixed with a scheme, it is returned unchanged.
@@ -112,7 +112,7 @@ class Project
if uri?.match(/[A-Za-z0-9+-.]+:\/\//) # leave path alone if it has a scheme
uri
else
uri = fsUtils.join(@getPath(), uri) unless uri[0] == '/'
uri = path.join(@getPath(), uri) unless uri[0] == '/'
fsUtils.absolute uri
# Given a path, this makes it relative to the project directory.

View File

@@ -1,5 +1,6 @@
Git = require 'git-utils'
fsUtils = require 'fs-utils'
path = require 'path'
module.exports =
loadStatuses: (path) ->
@@ -8,7 +9,7 @@ module.exports =
workingDirectoryPath = repo.getWorkingDirectory()
statuses = {}
for path, status of repo.getStatus()
statuses[fsUtils.join(workingDirectoryPath, path)] = status
statuses[path.join(workingDirectoryPath, path)] = status
upstream = repo.getAheadBehindCount()
repo.release()
else

View File

@@ -1,5 +1,6 @@
Package = require 'package'
fsUtils = require 'fs-utils'
path = require 'path'
_ = require 'underscore'
TextMateGrammar = require 'text-mate-grammar'
async = require 'async'
@@ -74,18 +75,18 @@ class TextMatePackage extends Package
getGrammars: -> @grammars
getSyntaxesPath: ->
syntaxesPath = fsUtils.join(@path, "syntaxes")
syntaxesPath = path.join(@path, "syntaxes")
if fsUtils.isDirectory(syntaxesPath)
syntaxesPath
else
fsUtils.join(@path, "Syntaxes")
path.join(@path, "Syntaxes")
getPreferencesPath: ->
preferencesPath = fsUtils.join(@path, "preferences")
preferencesPath = path.join(@path, "preferences")
if fsUtils.isDirectory(preferencesPath)
preferencesPath
else
fsUtils.join(@path, "Preferences")
path.join(@path, "Preferences")
loadScopedPropertiesSync: ->
for grammar in @getGrammars()

View File

@@ -89,11 +89,11 @@ window.unloadEditorWindow = ->
window.git = null
window.installAtomCommand = (callback) ->
commandPath = fsUtils.join(window.resourcePath, 'atom.sh')
commandPath = path.join(window.resourcePath, 'atom.sh')
require('command-installer').install(commandPath, callback)
window.installApmCommand = (callback) ->
commandPath = fsUtils.join(window.resourcePath, 'node_modules', '.bin', 'apm')
commandPath = path.join(window.resourcePath, 'node_modules', '.bin', 'apm')
require('command-installer').install(commandPath, callback)
window.unloadConfigWindow = ->

View File

@@ -369,7 +369,7 @@ describe 'FuzzyFinder', ->
ignoreFile = null
beforeEach ->
ignoreFile = fsUtils.join(project.getPath(), '.gitignore')
ignoreFile = path.join(project.getPath(), '.gitignore')
fsUtils.write(ignoreFile, 'sample.js')
config.set("core.excludeVcsIgnoredPaths", true)

View File

@@ -25,7 +25,7 @@ class PackageGeneratorView extends View
@previouslyFocusedElement = $(':focus')
@message.text("Enter package path")
placeholderName = "package-name"
@miniEditor.setText(fsUtils.join(config.userPackagesDirPath, placeholderName))
@miniEditor.setText(path.join(config.userPackagesDirPath, placeholderName))
pathLength = @miniEditor.getText().length
@miniEditor.setSelectedBufferRange([[0, pathLength - placeholderName.length], [0, pathLength]])
@@ -46,7 +46,7 @@ class PackageGeneratorView extends View
getPackagePath: ->
packagePath = @miniEditor.getText()
packageName = _.dasherize(path.basename(packagePath))
fsUtils.join(path.dirname(packagePath), packageName)
path.join(path.dirname(packagePath), packageName)
validPackagePath: ->
if fsUtils.exists(@getPackagePath())
@@ -57,7 +57,7 @@ class PackageGeneratorView extends View
true
createPackageFiles: ->
templatePath = fsUtils.resolveOnLoadPath(fsUtils.join("package-generator", "template"))
templatePath = fsUtils.resolveOnLoadPath(path.join("package-generator", "template"))
packageName = path.basename(@getPackagePath())
for path in fsUtils.listTree(templatePath)
@@ -66,7 +66,7 @@ class PackageGeneratorView extends View
relativePath = relativePath.replace(/\.template$/, '')
relativePath = @replacePackageNamePlaceholders(relativePath, packageName)
sourcePath = fsUtils.join(@getPackagePath(), relativePath)
sourcePath = path.join(@getPackagePath(), relativePath)
if fsUtils.isDirectory(path)
fsUtils.makeTree(sourcePath)
if fsUtils.isFile(path)

View File

@@ -42,14 +42,14 @@ describe 'Package Generator', ->
it "forces the package's name to be lowercase with dashes", ->
packageName = "CamelCaseIsForTheBirds"
packagePath = fsUtils.join(path.dirname(packagePath), packageName)
packagePath = path.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(path.dirname(packagePath), "camel-case-is-for-the-birds")).toExistOnDisk()
expect(path.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()

View File

@@ -1,6 +1,7 @@
AtomPackage = require 'atom-package'
fs = require 'fs'
fsUtils = require 'fs-utils'
path = require 'path'
_ = require 'underscore'
SnippetExpansion = require './snippet-expansion'
Snippet = require './snippet'
@@ -34,13 +35,13 @@ module.exports =
else
@loadAtomSnippets(pack.path, done)
loadAtomSnippets: (path, done) ->
snippetsDirPath = fsUtils.join(path, 'snippets')
loadAtomSnippets: (packagePath, done) ->
snippetsDirPath = path.join(packagePath, 'snippets')
return done() unless fsUtils.isDirectory(snippetsDirPath)
loadSnippetFile = (filename, done) =>
return done() if filename.indexOf('.') is 0
filepath = fsUtils.join(snippetsDirPath, filename)
filepath = path.join(snippetsDirPath, filename)
CSON.readFile filepath, (err, object) =>
if err
console.warn "Error reading snippets file '#{filepath}': #{err.stack}"
@@ -51,14 +52,14 @@ module.exports =
fs.readdir snippetsDirPath, (err, paths) ->
async.eachSeries(paths, loadSnippetFile, done)
loadTextMateSnippets: (path, done) ->
snippetsDirPath = fsUtils.join(path, 'Snippets')
loadTextMateSnippets: (bundlePath, done) ->
snippetsDirPath = path.join(bundlePath, 'Snippets')
return done() unless fsUtils.isDirectory(snippetsDirPath)
loadSnippetFile = (filename, done) =>
return done() if filename.indexOf('.') is 0
filepath = fsUtils.join(snippetsDirPath, filename)
filepath = path.join(snippetsDirPath, filename)
logError = (err) ->
console.warn "Error reading snippets file '#{filepath}': #{err.stack ? err}"

View File

@@ -3,6 +3,7 @@ _ = require 'underscore'
RootView = require 'root-view'
StatusBar = require 'status-bar/lib/status-bar-view'
fsUtils = require 'fs-utils'
path = require 'path'
{$$} = require 'space-pen'
describe "StatusBar", ->
@@ -57,9 +58,9 @@ describe "StatusBar", ->
describe "when the buffer content has changed from the content on disk", ->
it "disables the buffer modified indicator on save", ->
path = "/tmp/atom-whitespace.txt"
fsUtils.write(path, "")
rootView.open(path)
filePath = "/tmp/atom-whitespace.txt"
fsUtils.write(filePath, "")
rootView.open(filePath)
expect(statusBar.bufferModified.text()).toBe ''
editor.insertText("\n")
advanceClock(buffer.stoppedChangingDelay)
@@ -127,32 +128,32 @@ describe "StatusBar", ->
expect(statusBar.branchLabel.text()).toBe ''
describe "git status label", ->
[repo, path, originalPathText, newPath, ignoredPath] = []
[repo, filePath, originalPathText, newPath, ignoredPath] = []
beforeEach ->
path = require.resolve('fixtures/git/working-dir/file.txt')
newPath = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/git/working-dir'), 'new.txt')
filePath = require.resolve('fixtures/git/working-dir/file.txt')
newPath = path.join(fsUtils.resolveOnLoadPath('fixtures/git/working-dir'), 'new.txt')
fsUtils.write(newPath, "I'm new here")
ignoredPath = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/git/working-dir'), 'ignored.txt')
ignoredPath = path.join(fsUtils.resolveOnLoadPath('fixtures/git/working-dir'), 'ignored.txt')
fsUtils.write(ignoredPath, 'ignored.txt')
git.getPathStatus(path)
git.getPathStatus(filePath)
git.getPathStatus(newPath)
originalPathText = fsUtils.read(path)
originalPathText = fsUtils.read(filePath)
rootView.attachToDom()
afterEach ->
fsUtils.write(path, originalPathText)
fsUtils.write(filePath, originalPathText)
fsUtils.remove(newPath) if fsUtils.exists(newPath)
fsUtils.remove(ignoredPath) if fsUtils.exists(ignoredPath)
it "displays the modified icon for a changed file", ->
fsUtils.write(path, "i've changed for the worse")
git.getPathStatus(path)
rootView.open(path)
fsUtils.write(filePath, "i've changed for the worse")
git.getPathStatus(filePath)
rootView.open(filePath)
expect(statusBar.gitStatusIcon).toHaveClass('modified-status-icon')
it "doesn't display the modified icon for an unchanged file", ->
rootView.open(path)
rootView.open(filePath)
expect(statusBar.gitStatusIcon).toHaveText('')
it "displays the new icon for a new file", ->
@@ -164,18 +165,18 @@ describe "StatusBar", ->
expect(statusBar.gitStatusIcon).toHaveClass('ignored-status-icon')
it "updates when a status-changed event occurs", ->
fsUtils.write(path, "i've changed for the worse")
git.getPathStatus(path)
rootView.open(path)
fsUtils.write(filePath, "i've changed for the worse")
git.getPathStatus(filePath)
rootView.open(filePath)
expect(statusBar.gitStatusIcon).toHaveClass('modified-status-icon')
fsUtils.write(path, originalPathText)
git.getPathStatus(path)
fsUtils.write(filePath, originalPathText)
git.getPathStatus(filePath)
expect(statusBar.gitStatusIcon).not.toHaveClass('modified-status-icon')
it "displays the diff stat for modified files", ->
fsUtils.write(path, "i've changed for the worse")
git.getPathStatus(path)
rootView.open(path)
fsUtils.write(filePath, "i've changed for the worse")
git.getPathStatus(filePath)
rootView.open(filePath)
expect(statusBar.gitStatusIcon).toHaveText('+1,-1')
it "displays the diff stat for new files", ->

View File

@@ -596,11 +596,11 @@ describe "TreeView", ->
beforeEach ->
atom.deactivatePackage('tree-view')
rootDirPath = fsUtils.join(fsUtils.absolute("/tmp"), "atom-tests")
rootDirPath = path.join(fsUtils.absolute("/tmp"), "atom-tests")
fsUtils.remove(rootDirPath) if fsUtils.exists(rootDirPath)
dirPath = fsUtils.join(rootDirPath, "test-dir")
filePath = fsUtils.join(dirPath, "test-file.txt")
dirPath = path.join(rootDirPath, "test-dir")
filePath = path.join(dirPath, "test-file.txt")
fsUtils.makeDirectory(rootDirPath)
fsUtils.makeDirectory(dirPath)
fsUtils.write(filePath, "doesn't matter")
@@ -646,7 +646,7 @@ describe "TreeView", ->
describe "when the path without a trailing '/' is changed and confirmed", ->
describe "when no file exists at that location", ->
it "add a file, closes the dialog and selects the file in the tree-view", ->
newPath = fsUtils.join(dirPath, "new-test-file.txt")
newPath = path.join(dirPath, "new-test-file.txt")
addDialog.miniEditor.insertText(path.basename(newPath))
addDialog.trigger 'core:confirm'
expect(fsUtils.exists(newPath)).toBeTruthy()
@@ -662,7 +662,7 @@ describe "TreeView", ->
describe "when a file already exists at that location", ->
it "shows an error message and does not close the dialog", ->
newPath = fsUtils.join(dirPath, "new-test-file.txt")
newPath = path.join(dirPath, "new-test-file.txt")
fsUtils.write(newPath, '')
addDialog.miniEditor.insertText(path.basename(newPath))
addDialog.trigger 'core:confirm'
@@ -676,7 +676,7 @@ describe "TreeView", ->
describe "when no file or directory exists at the given path", ->
it "adds a directory and closes the dialog", ->
treeView.attachToDom()
newPath = fsUtils.join(dirPath, "new/dir")
newPath = path.join(dirPath, "new/dir")
addDialog.miniEditor.insertText("new/dir/")
addDialog.trigger 'core:confirm'
expect(fsUtils.exists(newPath)).toBeTruthy()
@@ -689,7 +689,7 @@ describe "TreeView", ->
it "selects the created directory", ->
treeView.attachToDom()
newPath = fsUtils.join(dirPath, "new2/")
newPath = path.join(dirPath, "new2/")
addDialog.miniEditor.insertText("new2/")
addDialog.trigger 'core:confirm'
expect(fsUtils.exists(newPath)).toBeTruthy()
@@ -702,7 +702,7 @@ describe "TreeView", ->
describe "when a file or directory already exists at the given path", ->
it "shows an error message and does not close the dialog", ->
newPath = fsUtils.join(dirPath, "new-dir")
newPath = path.join(dirPath, "new-dir")
fsUtils.makeDirectory(newPath)
addDialog.miniEditor.insertText("new-dir/")
addDialog.trigger 'core:confirm'
@@ -784,7 +784,7 @@ describe "TreeView", ->
describe "when the path is changed and confirmed", ->
describe "when all the directories along the new path exist", ->
it "moves the file, updates the tree view, and closes the dialog", ->
newPath = fsUtils.join(rootDirPath, 'renamed-test-file.txt')
newPath = path.join(rootDirPath, 'renamed-test-file.txt')
moveDialog.miniEditor.setText(newPath)
moveDialog.trigger 'core:confirm'
@@ -803,7 +803,7 @@ describe "TreeView", ->
describe "when the directories along the new path don't exist", ->
it "creates the target directory before moving the file", ->
newPath = fsUtils.join(rootDirPath, 'new/directory', 'renamed-test-file.txt')
newPath = path.join(rootDirPath, 'new/directory', 'renamed-test-file.txt')
moveDialog.miniEditor.setText(newPath)
moveDialog.trigger 'core:confirm'
@@ -818,8 +818,8 @@ describe "TreeView", ->
describe "when a file or directory already exists at the target path", ->
it "shows an error message and does not close the dialog", ->
runs ->
fsUtils.write(fsUtils.join(rootDirPath, 'target.txt'), '')
newPath = fsUtils.join(rootDirPath, 'target.txt')
fsUtils.write(path.join(rootDirPath, 'target.txt'), '')
newPath = path.join(rootDirPath, 'target.txt')
moveDialog.miniEditor.setText(newPath)
moveDialog.trigger 'core:confirm'
@@ -847,7 +847,7 @@ describe "TreeView", ->
[dotFilePath, dotFileView, moveDialog] = []
beforeEach ->
dotFilePath = fsUtils.join(dirPath, ".dotfile")
dotFilePath = path.join(dirPath, ".dotfile")
fsUtils.write(dotFilePath, "dot")
dirView.collapse()
dirView.expand()
@@ -878,7 +878,7 @@ describe "TreeView", ->
temporaryFilePath = null
beforeEach ->
temporaryFilePath = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/tree-view'), 'temporary')
temporaryFilePath = path.join(fsUtils.resolveOnLoadPath('fixtures/tree-view'), 'temporary')
if fsUtils.exists(temporaryFilePath)
fsUtils.remove(temporaryFilePath)
waits(20)
@@ -910,7 +910,7 @@ describe "TreeView", ->
[ignoreFile] = []
beforeEach ->
ignoreFile = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/tree-view'), '.gitignore')
ignoreFile = path.join(fsUtils.resolveOnLoadPath('fixtures/tree-view'), '.gitignore')
fsUtils.write(ignoreFile, 'tree-view.js')
config.set "core.hideGitIgnoredFiles", false
@@ -933,15 +933,15 @@ describe "TreeView", ->
beforeEach ->
config.set "core.hideGitIgnoredFiles", false
ignoreFile = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/tree-view'), '.gitignore')
ignoreFile = path.join(fsUtils.resolveOnLoadPath('fixtures/tree-view'), '.gitignore')
fsUtils.write(ignoreFile, 'tree-view.js')
git.getPathStatus(ignoreFile)
newFile = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/tree-view/dir2'), 'new2')
newFile = path.join(fsUtils.resolveOnLoadPath('fixtures/tree-view/dir2'), 'new2')
fsUtils.write(newFile, '')
git.getPathStatus(newFile)
modifiedFile = fsUtils.join(fsUtils.resolveOnLoadPath('fixtures/tree-view/dir1'), 'file1')
modifiedFile = path.join(fsUtils.resolveOnLoadPath('fixtures/tree-view/dir1'), 'file1')
originalFileContent = fsUtils.read(modifiedFile)
fsUtils.write modifiedFile, 'ch ch changes'
git.getPathStatus(modifiedFile)

View File

@@ -27,11 +27,6 @@ module.exports =
exists: (path) ->
path? and fs.existsSync(path)
join: (paths...) ->
return paths[0] if paths.length == 1
[first, rest...] = paths
first.replace(/\/?$/, "/") + @join(rest...)
# Returns true if the file specified by path exists and is a
# directory.
isDirectory: (path) ->
@@ -75,7 +70,7 @@ module.exports =
return [] unless @isDirectory(rootPath)
paths = fs.readdirSync(rootPath)
paths = @filterExtensions(paths, extensions) if extensions
paths = paths.map (path) => @join(rootPath, path)
paths = paths.map (path) -> Path.join(rootPath, path)
paths
listAsync: (rootPath, rest...) ->
@@ -84,7 +79,7 @@ module.exports =
fs.readdir rootPath, (err, paths) =>
return done(err) if err
paths = @filterExtensions(paths, extensions) if extensions
paths = paths.map (path) => @join(rootPath, path)
paths = paths.map (path) -> Path.join(rootPath, path)
done(null, paths)
filterExtensions: (paths, extensions) ->
@@ -171,11 +166,11 @@ module.exports =
traverseTreeSync: (rootPath, onFile, onDirectory) ->
return unless @isDirectory(rootPath)
traverse = (rootPath, prefix, onFile, onDirectory) =>
traverse = (rootPath, prefix, onFile, onDirectory) ->
prefix = "#{prefix}/" if prefix
for file in fs.readdirSync(rootPath)
relativePath = "#{prefix}#{file}"
absolutePath = @join(rootPath, file)
absolutePath = Path.join(rootPath, file)
stats = fs.statSync(absolutePath)
if stats.isDirectory()
traverse(absolutePath, relativePath, onFile, onDirectory) if onDirectory(absolutePath)
@@ -185,12 +180,12 @@ module.exports =
traverse(rootPath, '', onFile, onDirectory)
traverseTree: (rootPath, onFile, onDirectory, onDone) ->
fs.readdir rootPath, (error, files) =>
fs.readdir rootPath, (error, files) ->
if error
onDone?()
else
queue = async.queue (path, callback) =>
fs.stat path, (error, stats) =>
queue = async.queue (path, callback) ->
fs.stat path, (error, stats) ->
if error
callback(error)
else if stats.isFile()
@@ -198,18 +193,18 @@ module.exports =
callback()
else if stats.isDirectory()
if onDirectory(path)
fs.readdir path, (error, files) =>
fs.readdir path, (error, files) ->
if error
callback(error)
else
for file in files
queue.unshift(@join(path, file))
queue.unshift(Path.join(path, file))
callback()
else
callback()
queue.concurrency = 1
queue.drain = onDone
queue.push(@join(rootPath, file)) for file in files
queue.push(Path.join(rootPath, file)) for file in files
md5ForPath: (path) ->
contents = fs.readFileSync(path)
@@ -227,7 +222,7 @@ module.exports =
return pathToResolve if @exists(pathToResolve)
for loadPath in loadPaths
candidatePath = @join(loadPath, pathToResolve)
candidatePath = Path.join(loadPath, pathToResolve)
if extensions
if resolvedPath = @resolveExtension(candidatePath, extensions)
return resolvedPath