Merge pull request #1062 from atom/ks-extract-fs-utils
Extract fs-utils into a module
Esse commit está contido em:
@@ -3,7 +3,6 @@ require '../spec/spec-helper'
|
||||
path = require 'path'
|
||||
{$, _, Point, fs} = require 'atom'
|
||||
Project = require '../src/project'
|
||||
fsUtils = require '../src/fs-utils'
|
||||
TokenizedBuffer = require '../src/tokenized-buffer'
|
||||
|
||||
defaultCount = 100
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
{Document, Point, Range, Site} = require 'telepath'
|
||||
_ = require 'underscore-plus'
|
||||
|
||||
module.exports =
|
||||
_: _
|
||||
_: require 'underscore-plus'
|
||||
BufferedNodeProcess: require '../src/buffered-node-process'
|
||||
BufferedProcess: require '../src/buffered-process'
|
||||
Directory: require '../src/directory'
|
||||
Document: Document
|
||||
File: require '../src/file'
|
||||
fs: require '../src/fs-utils'
|
||||
fs: require 'fs-plus'
|
||||
Git: require '../src/git'
|
||||
Point: Point
|
||||
Range: Range
|
||||
|
||||
+1
-2
@@ -18,6 +18,7 @@
|
||||
"coffeestack": "0.6.0",
|
||||
"emissary": "0.9.0",
|
||||
"first-mate": "0.5.0",
|
||||
"fs-plus": "0.6.0",
|
||||
"fuzzaldrin": "0.1.0",
|
||||
"git-utils": "0.28.0",
|
||||
"guid": "0.0.10",
|
||||
@@ -29,9 +30,7 @@
|
||||
"optimist": "0.4.0",
|
||||
"pathwatcher": "0.9.0",
|
||||
"pegjs": "0.7.0",
|
||||
"plist": "git://github.com/nathansobo/node-plist.git",
|
||||
"q": "0.9.7",
|
||||
"rimraf": "2.1.4",
|
||||
"scandal": "0.6.2",
|
||||
"season": "0.14.0",
|
||||
"semver": "1.1.4",
|
||||
|
||||
@@ -12,10 +12,10 @@ describe "install(commandPath, callback)", ->
|
||||
spyOn(installer, 'findInstallDirectory').andCallFake (callback) ->
|
||||
callback(directory)
|
||||
|
||||
fs.remove(directory) if fs.exists(directory)
|
||||
fs.removeSync(directory) if fs.existsSync(directory)
|
||||
|
||||
it "symlinks the command and makes it executable", ->
|
||||
fs.writeSync(commandPath, 'test')
|
||||
fs.writeFileSync(commandPath, 'test')
|
||||
expect(fs.isFileSync(commandPath)).toBeTruthy()
|
||||
expect(fs.isExecutableSync(commandPath)).toBeFalsy()
|
||||
expect(fs.isFileSync(destinationPath)).toBeFalsy()
|
||||
|
||||
+17
-17
@@ -177,10 +177,10 @@ describe "Config", ->
|
||||
describe ".initializeConfigDirectory()", ->
|
||||
beforeEach ->
|
||||
config.configDirPath = dotAtomPath
|
||||
expect(fs.exists(config.configDirPath)).toBeFalsy()
|
||||
expect(fs.existsSync(config.configDirPath)).toBeFalsy()
|
||||
|
||||
afterEach ->
|
||||
fs.remove(dotAtomPath) if fs.exists(dotAtomPath)
|
||||
fs.removeSync(dotAtomPath) if fs.existsSync(dotAtomPath)
|
||||
|
||||
describe "when the configDirPath doesn't exist", ->
|
||||
it "copies the contents of dot-atom to ~/.atom", ->
|
||||
@@ -192,23 +192,23 @@ describe "Config", ->
|
||||
waitsFor -> initializationDone
|
||||
|
||||
runs ->
|
||||
expect(fs.exists(config.configDirPath)).toBeTruthy()
|
||||
expect(fs.exists(path.join(config.configDirPath, 'packages'))).toBeTruthy()
|
||||
expect(fs.exists(path.join(config.configDirPath, 'snippets'))).toBeTruthy()
|
||||
expect(fs.existsSync(config.configDirPath)).toBeTruthy()
|
||||
expect(fs.existsSync(path.join(config.configDirPath, 'packages'))).toBeTruthy()
|
||||
expect(fs.existsSync(path.join(config.configDirPath, 'snippets'))).toBeTruthy()
|
||||
expect(fs.isFileSync(path.join(config.configDirPath, 'config.cson'))).toBeTruthy()
|
||||
|
||||
describe ".loadUserConfig()", ->
|
||||
beforeEach ->
|
||||
config.configDirPath = dotAtomPath
|
||||
config.configFilePath = path.join(config.configDirPath, "config.cson")
|
||||
expect(fs.exists(config.configDirPath)).toBeFalsy()
|
||||
expect(fs.existsSync(config.configDirPath)).toBeFalsy()
|
||||
|
||||
afterEach ->
|
||||
fs.remove(dotAtomPath) if fs.exists(dotAtomPath)
|
||||
fs.removeSync(dotAtomPath) if fs.existsSync(dotAtomPath)
|
||||
|
||||
describe "when the config file contains valid cson", ->
|
||||
beforeEach ->
|
||||
fs.writeSync(config.configFilePath, "foo: bar: 'baz'")
|
||||
fs.writeFileSync(config.configFilePath, "foo: bar: 'baz'")
|
||||
config.loadUserConfig()
|
||||
|
||||
it "updates the config data based on the file contents", ->
|
||||
@@ -217,7 +217,7 @@ describe "Config", ->
|
||||
describe "when the config file contains invalid cson", ->
|
||||
beforeEach ->
|
||||
spyOn(console, 'error')
|
||||
fs.writeSync(config.configFilePath, "{{{{{")
|
||||
fs.writeFileSync(config.configFilePath, "{{{{{")
|
||||
|
||||
it "logs an error to the console and does not overwrite the config file on a subsequent save", ->
|
||||
config.loadUserConfig()
|
||||
@@ -227,9 +227,9 @@ describe "Config", ->
|
||||
|
||||
describe "when the config file does not exist", ->
|
||||
it "creates it with an empty object", ->
|
||||
fs.makeTree(config.configDirPath)
|
||||
fs.makeTreeSync(config.configDirPath)
|
||||
config.loadUserConfig()
|
||||
expect(fs.exists(config.configFilePath)).toBe true
|
||||
expect(fs.existsSync(config.configFilePath)).toBe true
|
||||
expect(CSON.readFileSync(config.configFilePath)).toEqual {}
|
||||
|
||||
describe ".observeUserConfig()", ->
|
||||
@@ -238,8 +238,8 @@ describe "Config", ->
|
||||
beforeEach ->
|
||||
config.configDirPath = dotAtomPath
|
||||
config.configFilePath = path.join(config.configDirPath, "config.cson")
|
||||
expect(fs.exists(config.configDirPath)).toBeFalsy()
|
||||
fs.writeSync(config.configFilePath, "foo: bar: 'baz'")
|
||||
expect(fs.existsSync(config.configDirPath)).toBeFalsy()
|
||||
fs.writeFileSync(config.configFilePath, "foo: bar: 'baz'")
|
||||
config.loadUserConfig()
|
||||
config.observeUserConfig()
|
||||
updatedHandler = jasmine.createSpy("updatedHandler")
|
||||
@@ -247,11 +247,11 @@ describe "Config", ->
|
||||
|
||||
afterEach ->
|
||||
config.unobserveUserConfig()
|
||||
fs.remove(dotAtomPath) if fs.exists(dotAtomPath)
|
||||
fs.removeSync(dotAtomPath) if fs.existsSync(dotAtomPath)
|
||||
|
||||
describe "when the config file changes to contain valid cson", ->
|
||||
it "updates the config data", ->
|
||||
fs.writeSync(config.configFilePath, "foo: { bar: 'quux', baz: 'bar'}")
|
||||
fs.writeFileSync(config.configFilePath, "foo: { bar: 'quux', baz: 'bar'}")
|
||||
waitsFor 'update event', -> updatedHandler.callCount > 0
|
||||
runs ->
|
||||
expect(config.get('foo.bar')).toBe 'quux'
|
||||
@@ -260,7 +260,7 @@ describe "Config", ->
|
||||
describe "when the config file changes to contain invalid cson", ->
|
||||
beforeEach ->
|
||||
spyOn(console, 'error')
|
||||
fs.writeSync(config.configFilePath, "}}}")
|
||||
fs.writeFileSync(config.configFilePath, "}}}")
|
||||
waitsFor "error to be logged", -> console.error.callCount > 0
|
||||
|
||||
it "logs a warning and does not update config data", ->
|
||||
@@ -271,7 +271,7 @@ describe "Config", ->
|
||||
|
||||
describe "when the config file subsequently changes again to contain valid cson", ->
|
||||
beforeEach ->
|
||||
fs.writeSync(config.configFilePath, "foo: bar: 'baz'")
|
||||
fs.writeFileSync(config.configFilePath, "foo: bar: 'baz'")
|
||||
waitsFor 'update event', -> updatedHandler.callCount > 0
|
||||
|
||||
it "updates the config data and resumes saving", ->
|
||||
|
||||
@@ -16,10 +16,10 @@ describe "Directory", ->
|
||||
|
||||
beforeEach ->
|
||||
temporaryFilePath = path.join(__dirname, 'fixtures', 'temporary')
|
||||
fs.remove(temporaryFilePath) if fs.exists(temporaryFilePath)
|
||||
fs.removeSync(temporaryFilePath) if fs.existsSync(temporaryFilePath)
|
||||
|
||||
afterEach ->
|
||||
fs.remove(temporaryFilePath) if fs.exists(temporaryFilePath)
|
||||
fs.removeSync(temporaryFilePath) if fs.existsSync(temporaryFilePath)
|
||||
|
||||
it "triggers 'contents-changed' event handlers", ->
|
||||
changeHandler = null
|
||||
@@ -27,13 +27,13 @@ describe "Directory", ->
|
||||
runs ->
|
||||
changeHandler = jasmine.createSpy('changeHandler')
|
||||
directory.on 'contents-changed', changeHandler
|
||||
fs.writeSync(temporaryFilePath, '')
|
||||
fs.writeFileSync(temporaryFilePath, '')
|
||||
|
||||
waitsFor "first change", -> changeHandler.callCount > 0
|
||||
|
||||
runs ->
|
||||
changeHandler.reset()
|
||||
fs.remove(temporaryFilePath)
|
||||
fs.removeSync(temporaryFilePath)
|
||||
|
||||
waitsFor "second change", -> changeHandler.callCount > 0
|
||||
|
||||
@@ -42,10 +42,10 @@ describe "Directory", ->
|
||||
|
||||
beforeEach ->
|
||||
temporaryFilePath = path.join(directory.path, 'temporary')
|
||||
fs.remove(temporaryFilePath) if fs.exists(temporaryFilePath)
|
||||
fs.removeSync(temporaryFilePath) if fs.existsSync(temporaryFilePath)
|
||||
|
||||
afterEach ->
|
||||
fs.remove(temporaryFilePath) if fs.exists(temporaryFilePath)
|
||||
fs.removeSync(temporaryFilePath) if fs.existsSync(temporaryFilePath)
|
||||
|
||||
it "no longer triggers events", ->
|
||||
changeHandler = null
|
||||
@@ -53,7 +53,7 @@ describe "Directory", ->
|
||||
runs ->
|
||||
changeHandler = jasmine.createSpy('changeHandler')
|
||||
directory.on 'contents-changed', changeHandler
|
||||
fs.writeSync(temporaryFilePath, '')
|
||||
fs.writeFileSync(temporaryFilePath, '')
|
||||
|
||||
waitsFor "change event", -> changeHandler.callCount > 0
|
||||
|
||||
@@ -62,7 +62,7 @@ describe "Directory", ->
|
||||
directory.off()
|
||||
waits 20
|
||||
|
||||
runs -> fs.remove(temporaryFilePath)
|
||||
runs -> fs.removeSync(temporaryFilePath)
|
||||
waits 20
|
||||
runs -> expect(changeHandler.callCount).toBe 0
|
||||
|
||||
|
||||
+14
-14
@@ -88,7 +88,7 @@ describe "Editor", ->
|
||||
describe "when the activeEditSession's file is modified on disk", ->
|
||||
it "triggers an alert", ->
|
||||
filePath = path.join(temp.dir, 'atom-changed-file.txt')
|
||||
fs.writeSync(filePath, "")
|
||||
fs.writeFileSync(filePath, "")
|
||||
editSession = project.openSync(filePath)
|
||||
editor.edit(editSession)
|
||||
editor.insertText("now the buffer is modified")
|
||||
@@ -98,7 +98,7 @@ describe "Editor", ->
|
||||
|
||||
spyOn(atom, "confirm")
|
||||
|
||||
fs.writeSync(filePath, "a file change")
|
||||
fs.writeFileSync(filePath, "a file change")
|
||||
|
||||
waitsFor "file to trigger contents-changed event", ->
|
||||
fileChangeHandler.callCount > 0
|
||||
@@ -153,7 +153,7 @@ describe "Editor", ->
|
||||
|
||||
it "triggers alert if edit session's buffer goes into conflict with changes on disk", ->
|
||||
filePath = path.join(temp.dir, 'atom-changed-file.txt')
|
||||
fs.writeSync(filePath, "")
|
||||
fs.writeFileSync(filePath, "")
|
||||
tempEditSession = project.openSync(filePath)
|
||||
editor.edit(tempEditSession)
|
||||
tempEditSession.insertText("a buffer change")
|
||||
@@ -162,7 +162,7 @@ describe "Editor", ->
|
||||
|
||||
contentsConflictedHandler = jasmine.createSpy("contentsConflictedHandler")
|
||||
tempEditSession.on 'contents-conflicted', contentsConflictedHandler
|
||||
fs.writeSync(filePath, "a file change")
|
||||
fs.writeFileSync(filePath, "a file change")
|
||||
waitsFor ->
|
||||
contentsConflictedHandler.callCount > 0
|
||||
|
||||
@@ -249,10 +249,10 @@ describe "Editor", ->
|
||||
|
||||
beforeEach ->
|
||||
filePath = path.join(temp.dir, 'something.txt')
|
||||
fs.writeSync(filePath, filePath)
|
||||
fs.writeFileSync(filePath, filePath)
|
||||
|
||||
afterEach ->
|
||||
fs.remove(filePath) if fs.exists(filePath)
|
||||
fs.removeSync(filePath) if fs.existsSync(filePath)
|
||||
|
||||
it "emits event when buffer's path is changed", ->
|
||||
eventHandler = jasmine.createSpy('eventHandler')
|
||||
@@ -2179,11 +2179,11 @@ describe "Editor", ->
|
||||
|
||||
beforeEach ->
|
||||
filePath = project.resolve('git/working-dir/file.txt')
|
||||
originalPathText = fs.read(filePath)
|
||||
originalPathText = fs.readFileSync(filePath, 'utf8')
|
||||
editor.edit(project.openSync(filePath))
|
||||
|
||||
afterEach ->
|
||||
fs.writeSync(filePath, originalPathText)
|
||||
fs.writeFileSync(filePath, originalPathText)
|
||||
|
||||
it "restores the contents of the editor to the HEAD revision", ->
|
||||
editor.setText('')
|
||||
@@ -2307,10 +2307,10 @@ describe "Editor", ->
|
||||
beforeEach ->
|
||||
tmpdir = fs.absolute(temp.dir)
|
||||
filePath = path.join(tmpdir, "grammar-change.txt")
|
||||
fs.writeSync(filePath, "var i;")
|
||||
fs.writeFileSync(filePath, "var i;")
|
||||
|
||||
afterEach ->
|
||||
fs.remove(filePath) if fs.exists(filePath)
|
||||
fs.removeSync(filePath) if fs.existsSync(filePath)
|
||||
|
||||
it "updates all the rendered lines when the grammar changes", ->
|
||||
editor.edit(project.openSync(filePath))
|
||||
@@ -2654,16 +2654,16 @@ describe "Editor", ->
|
||||
it "saves the state of the rendered lines, the display buffer, and the buffer to a file of the user's choosing", ->
|
||||
saveDialogCallback = null
|
||||
spyOn(atom, 'showSaveDialog').andCallFake (callback) -> saveDialogCallback = callback
|
||||
spyOn(fs, 'writeSync')
|
||||
spyOn(fs, 'writeFileSync')
|
||||
|
||||
editor.trigger 'editor:save-debug-snapshot'
|
||||
|
||||
statePath = path.join(temp.dir, 'state')
|
||||
expect(atom.showSaveDialog).toHaveBeenCalled()
|
||||
saveDialogCallback(statePath)
|
||||
expect(fs.writeSync).toHaveBeenCalled()
|
||||
expect(fs.writeSync.argsForCall[0][0]).toBe statePath
|
||||
expect(typeof fs.writeSync.argsForCall[0][1]).toBe 'string'
|
||||
expect(fs.writeFileSync).toHaveBeenCalled()
|
||||
expect(fs.writeFileSync.argsForCall[0][0]).toBe statePath
|
||||
expect(typeof fs.writeFileSync.argsForCall[0][1]).toBe 'string'
|
||||
|
||||
describe "when the escape key is pressed on the editor", ->
|
||||
it "clears multiple selections if there are any, and otherwise allows other bindings to be handled", ->
|
||||
|
||||
+15
-15
@@ -6,19 +6,19 @@ describe 'File', ->
|
||||
|
||||
beforeEach ->
|
||||
filePath = path.join(__dirname, 'fixtures', 'atom-file-test.txt') # Don't put in /tmp because /tmp symlinks to /private/tmp and screws up the rename test
|
||||
fs.remove(filePath) if fs.exists(filePath)
|
||||
fs.writeSync(filePath, "this is old!")
|
||||
fs.removeSync(filePath) if fs.existsSync(filePath)
|
||||
fs.writeFileSync(filePath, "this is old!")
|
||||
file = new File(filePath)
|
||||
|
||||
afterEach ->
|
||||
file.off()
|
||||
fs.remove(filePath) if fs.exists(filePath)
|
||||
fs.removeSync(filePath) if fs.existsSync(filePath)
|
||||
|
||||
describe "when the file has not been read", ->
|
||||
describe "when the contents of the file change", ->
|
||||
it "triggers 'contents-changed' event handlers", ->
|
||||
file.on 'contents-changed', changeHandler = jasmine.createSpy('changeHandler')
|
||||
fs.writeSync(file.getPath(), "this is new!")
|
||||
fs.writeFileSync(file.getPath(), "this is new!")
|
||||
|
||||
waitsFor "change event", ->
|
||||
changeHandler.callCount > 0
|
||||
@@ -32,14 +32,14 @@ describe 'File', ->
|
||||
changeHandler = null
|
||||
changeHandler = jasmine.createSpy('changeHandler')
|
||||
file.on 'contents-changed', changeHandler
|
||||
fs.writeSync(file.getPath(), "this is new!")
|
||||
fs.writeFileSync(file.getPath(), "this is new!")
|
||||
|
||||
waitsFor "change event", ->
|
||||
changeHandler.callCount > 0
|
||||
|
||||
runs ->
|
||||
changeHandler.reset()
|
||||
fs.writeSync(file.getPath(), "this is newer!")
|
||||
fs.writeFileSync(file.getPath(), "this is newer!")
|
||||
|
||||
waitsFor "second change event", ->
|
||||
changeHandler.callCount > 0
|
||||
@@ -49,7 +49,7 @@ describe 'File', ->
|
||||
removeHandler = null
|
||||
removeHandler = jasmine.createSpy('removeHandler')
|
||||
file.on 'removed', removeHandler
|
||||
fs.remove(file.getPath())
|
||||
fs.removeSync(file.getPath())
|
||||
|
||||
waitsFor "remove event", ->
|
||||
removeHandler.callCount > 0
|
||||
@@ -61,8 +61,8 @@ describe 'File', ->
|
||||
newPath = path.join(path.dirname(filePath), "atom-file-was-moved-test.txt")
|
||||
|
||||
afterEach ->
|
||||
if fs.exists(newPath)
|
||||
fs.remove(newPath)
|
||||
if fs.existsSync(newPath)
|
||||
fs.removeSync(newPath)
|
||||
waitsFor "remove event", (done) -> file.on 'removed', done
|
||||
|
||||
it "it updates its path", ->
|
||||
@@ -71,7 +71,7 @@ describe 'File', ->
|
||||
moveHandler = jasmine.createSpy('moveHandler')
|
||||
file.on 'moved', moveHandler
|
||||
|
||||
fs.move(filePath, newPath)
|
||||
fs.moveSync(filePath, newPath)
|
||||
|
||||
waitsFor "move event", ->
|
||||
moveHandler.callCount > 0
|
||||
@@ -88,14 +88,14 @@ describe 'File', ->
|
||||
changeHandler = jasmine.createSpy('changeHandler')
|
||||
file.on 'contents-changed', changeHandler
|
||||
|
||||
fs.move(filePath, newPath)
|
||||
fs.moveSync(filePath, newPath)
|
||||
|
||||
waitsFor "move event", ->
|
||||
moveHandler.callCount > 0
|
||||
|
||||
runs ->
|
||||
expect(changeHandler).not.toHaveBeenCalled()
|
||||
fs.writeSync(file.getPath(), "this is new!")
|
||||
fs.writeFileSync(file.getPath(), "this is new!")
|
||||
|
||||
waitsFor "change event", ->
|
||||
changeHandler.callCount > 0
|
||||
@@ -112,12 +112,12 @@ describe 'File', ->
|
||||
|
||||
expect(changeHandler).not.toHaveBeenCalled()
|
||||
|
||||
fs.remove(filePath)
|
||||
fs.removeSync(filePath)
|
||||
|
||||
expect(changeHandler).not.toHaveBeenCalled()
|
||||
waits 20
|
||||
runs ->
|
||||
fs.writeSync(filePath, "HE HAS RISEN!")
|
||||
fs.writeFileSync(filePath, "HE HAS RISEN!")
|
||||
expect(changeHandler).not.toHaveBeenCalled()
|
||||
|
||||
waitsFor "resurrection change event", ->
|
||||
@@ -125,7 +125,7 @@ describe 'File', ->
|
||||
|
||||
runs ->
|
||||
expect(removeHandler).not.toHaveBeenCalled()
|
||||
fs.writeSync(filePath, "Hallelujah!")
|
||||
fs.writeFileSync(filePath, "Hallelujah!")
|
||||
changeHandler.reset()
|
||||
|
||||
waitsFor "post-resurrection change event", ->
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
{fs} = require 'atom'
|
||||
path = require 'path'
|
||||
temp = require 'temp'
|
||||
|
||||
describe "fs", ->
|
||||
fixturesDir = path.join(__dirname, 'fixtures')
|
||||
|
||||
describe ".read(path)", ->
|
||||
it "return contents of file", ->
|
||||
expect(fs.read(require.resolve("./fixtures/sample.txt"))).toBe "Some text.\n"
|
||||
|
||||
it "does not through an exception when the path is a binary file", ->
|
||||
expect(-> fs.read(require.resolve("./fixtures/binary-file.png"))).not.toThrow()
|
||||
|
||||
describe ".isFileSync(path)", ->
|
||||
it "returns true with a file path", ->
|
||||
expect(fs.isFileSync(path.join(fixturesDir, 'sample.js'))).toBe true
|
||||
|
||||
it "returns false with a directory path", ->
|
||||
expect(fs.isFileSync(fixturesDir)).toBe false
|
||||
|
||||
it "returns false with a non-existent path", ->
|
||||
expect(fs.isFileSync(path.join(fixturesDir, 'non-existent'))).toBe false
|
||||
expect(fs.isFileSync(null)).toBe false
|
||||
|
||||
describe ".exists(path)", ->
|
||||
it "returns true when path exsits", ->
|
||||
expect(fs.exists(fixturesDir)).toBe true
|
||||
|
||||
it "returns false when path doesn't exsit", ->
|
||||
expect(fs.exists(path.join(fixturesDir, "-nope-does-not-exist"))).toBe false
|
||||
expect(fs.exists("")).toBe false
|
||||
expect(fs.exists(null)).toBe false
|
||||
|
||||
describe ".makeTree(path)", ->
|
||||
aPath = path.join(temp.dir, 'a')
|
||||
|
||||
beforeEach ->
|
||||
fs.remove(aPath) if fs.exists(aPath)
|
||||
|
||||
it "creates all directories in path including any missing parent directories", ->
|
||||
abcPath = path.join(aPath, 'b', 'c')
|
||||
fs.makeTree(abcPath)
|
||||
expect(fs.exists(abcPath)).toBeTruthy()
|
||||
|
||||
describe ".traverseTreeSync(path, onFile, onDirectory)", ->
|
||||
it "calls fn for every path in the tree at the given path", ->
|
||||
paths = []
|
||||
onPath = (childPath) ->
|
||||
paths.push(childPath)
|
||||
true
|
||||
fs.traverseTreeSync fixturesDir, onPath, onPath
|
||||
expect(paths).toEqual fs.listTreeSync(fixturesDir)
|
||||
|
||||
it "does not recurse into a directory if it is pruned", ->
|
||||
paths = []
|
||||
onPath = (childPath) ->
|
||||
if childPath.match(/\/dir$/)
|
||||
false
|
||||
else
|
||||
paths.push(childPath)
|
||||
true
|
||||
fs.traverseTreeSync fixturesDir, onPath, onPath
|
||||
|
||||
expect(paths.length).toBeGreaterThan 0
|
||||
for filePath in paths
|
||||
expect(filePath).not.toMatch /\/dir\//
|
||||
|
||||
it "returns entries if path is a symlink", ->
|
||||
symlinkPath = path.join(fixturesDir, 'symlink-to-dir')
|
||||
symlinkPaths = []
|
||||
onSymlinkPath = (path) -> symlinkPaths.push(path.substring(symlinkPath.length + 1))
|
||||
|
||||
regularPath = path.join(fixturesDir, 'dir')
|
||||
paths = []
|
||||
onPath = (path) -> paths.push(path.substring(regularPath.length + 1))
|
||||
|
||||
fs.traverseTreeSync(symlinkPath, onSymlinkPath, onSymlinkPath)
|
||||
fs.traverseTreeSync(regularPath, onPath, onPath)
|
||||
|
||||
expect(symlinkPaths).toEqual(paths)
|
||||
|
||||
it "ignores missing symlinks", ->
|
||||
directory = temp.mkdirSync('symlink-in-here')
|
||||
paths = []
|
||||
onPath = (childPath) -> paths.push(childPath)
|
||||
fs.symlinkSync(path.join(directory, 'source'), path.join(directory, 'destination'))
|
||||
fs.traverseTreeSync(directory, onPath)
|
||||
expect(paths.length).toBe 0
|
||||
|
||||
describe ".md5ForPath(path)", ->
|
||||
it "returns the MD5 hash of the file at the given path", ->
|
||||
expect(fs.md5ForPath(require.resolve('./fixtures/sample.js'))).toBe 'dd38087d0d7e3e4802a6d3f9b9745f2b'
|
||||
|
||||
describe ".list(path, extensions)", ->
|
||||
it "returns the absolute paths of entries within the given directory", ->
|
||||
paths = fs.listSync(project.getPath())
|
||||
expect(paths).toContain project.resolve('css.css')
|
||||
expect(paths).toContain project.resolve('coffee.coffee')
|
||||
expect(paths).toContain project.resolve('two-hundred.txt')
|
||||
|
||||
it "returns an empty array for paths that aren't directories or don't exist", ->
|
||||
expect(fs.listSync(project.resolve('sample.js'))).toEqual []
|
||||
expect(fs.listSync('/non/existent/directory')).toEqual []
|
||||
|
||||
it "can filter the paths by an optional array of file extensions", ->
|
||||
paths = fs.listSync(project.getPath(), ['.css', 'coffee'])
|
||||
expect(paths).toContain project.resolve('css.css')
|
||||
expect(paths).toContain project.resolve('coffee.coffee')
|
||||
expect(listedPath).toMatch /(css|coffee)$/ for listedPath in paths
|
||||
|
||||
describe ".list(path, [extensions,] callback)", ->
|
||||
paths = null
|
||||
|
||||
it "calls the callback with the absolute paths of entries within the given directory", ->
|
||||
waitsFor (done) ->
|
||||
fs.list project.getPath(), (err, result) ->
|
||||
paths = result
|
||||
done()
|
||||
runs ->
|
||||
expect(paths).toContain project.resolve('css.css')
|
||||
expect(paths).toContain project.resolve('coffee.coffee')
|
||||
expect(paths).toContain project.resolve('two-hundred.txt')
|
||||
|
||||
it "can filter the paths by an optional array of file extensions", ->
|
||||
waitsFor (done) ->
|
||||
fs.list project.getPath(), ['css', '.coffee'], (err, result) ->
|
||||
paths = result
|
||||
done()
|
||||
runs ->
|
||||
expect(paths).toContain project.resolve('css.css')
|
||||
expect(paths).toContain project.resolve('coffee.coffee')
|
||||
expect(listedPath).toMatch /(css|coffee)$/ for listedPath in paths
|
||||
|
||||
describe ".absolute(relativePath)", ->
|
||||
it "converts a leading ~ segment to the HOME directory", ->
|
||||
homeDir = atom.getHomeDirPath()
|
||||
expect(fs.absolute('~')).toBe fs.realpathSync(homeDir)
|
||||
expect(fs.absolute(path.join('~', 'does', 'not', 'exist'))).toBe path.join(homeDir, 'does', 'not', 'exist')
|
||||
expect(fs.absolute('~test')).toBe '~test'
|
||||
+34
-34
@@ -9,7 +9,7 @@ describe "Git", ->
|
||||
|
||||
beforeEach ->
|
||||
gitPath = path.join(temp.dir, '.git')
|
||||
fs.remove(gitPath) if fs.isDirectorySync(gitPath)
|
||||
fs.removeSync(gitPath) if fs.isDirectorySync(gitPath)
|
||||
|
||||
afterEach ->
|
||||
repo.destroy() if repo?.repo?
|
||||
@@ -47,22 +47,22 @@ describe "Git", ->
|
||||
repo = new Git(path.join(__dirname, 'fixtures', 'git', 'working-dir'))
|
||||
filePath = require.resolve('./fixtures/git/working-dir/file.txt')
|
||||
newPath = path.join(__dirname, 'fixtures', 'git', 'working-dir', 'new-path.txt')
|
||||
originalPathText = fs.read(filePath)
|
||||
originalPathText = fs.readFileSync(filePath, 'utf8')
|
||||
|
||||
afterEach ->
|
||||
fs.writeSync(filePath, originalPathText)
|
||||
fs.remove(newPath) if fs.exists(newPath)
|
||||
fs.writeFileSync(filePath, originalPathText)
|
||||
fs.removeSync(newPath) if fs.existsSync(newPath)
|
||||
|
||||
describe "when the path is unstaged", ->
|
||||
it "returns false if the path has not been modified", ->
|
||||
expect(repo.isPathModified(filePath)).toBeFalsy()
|
||||
|
||||
it "returns true if the path is modified", ->
|
||||
fs.writeSync(filePath, "change")
|
||||
fs.writeFileSync(filePath, "change")
|
||||
expect(repo.isPathModified(filePath)).toBeTruthy()
|
||||
|
||||
it "returns true if the path is deleted", ->
|
||||
fs.remove(filePath)
|
||||
fs.removeSync(filePath)
|
||||
expect(repo.isPathModified(filePath)).toBeTruthy()
|
||||
|
||||
it "returns false if the path is new", ->
|
||||
@@ -75,10 +75,10 @@ describe "Git", ->
|
||||
repo = new Git(path.join(__dirname, 'fixtures', 'git', 'working-dir'))
|
||||
filePath = require.resolve('./fixtures/git/working-dir/file.txt')
|
||||
newPath = path.join(__dirname, 'fixtures', 'git', 'working-dir', 'new-path.txt')
|
||||
fs.writeSync(newPath, "i'm new here")
|
||||
fs.writeFileSync(newPath, "i'm new here")
|
||||
|
||||
afterEach ->
|
||||
fs.remove(newPath) if fs.exists(newPath)
|
||||
fs.removeSync(newPath) if fs.existsSync(newPath)
|
||||
|
||||
describe "when the path is unstaged", ->
|
||||
it "returns true if the path is new", ->
|
||||
@@ -93,35 +93,35 @@ describe "Git", ->
|
||||
beforeEach ->
|
||||
repo = new Git(path.join(__dirname, 'fixtures', 'git', 'working-dir'))
|
||||
path1 = require.resolve('./fixtures/git/working-dir/file.txt')
|
||||
originalPath1Text = fs.read(path1)
|
||||
originalPath1Text = fs.readFileSync(path1, 'utf8')
|
||||
path2 = require.resolve('./fixtures/git/working-dir/other.txt')
|
||||
originalPath2Text = fs.read(path2)
|
||||
originalPath2Text = fs.readFileSync(path2, 'utf8')
|
||||
|
||||
afterEach ->
|
||||
fs.writeSync(path1, originalPath1Text)
|
||||
fs.writeSync(path2, originalPath2Text)
|
||||
fs.writeFileSync(path1, originalPath1Text)
|
||||
fs.writeFileSync(path2, originalPath2Text)
|
||||
|
||||
it "no longer reports a path as modified after checkout", ->
|
||||
expect(repo.isPathModified(path1)).toBeFalsy()
|
||||
fs.writeSync(path1, '')
|
||||
fs.writeFileSync(path1, '')
|
||||
expect(repo.isPathModified(path1)).toBeTruthy()
|
||||
expect(repo.checkoutHead(path1)).toBeTruthy()
|
||||
expect(repo.isPathModified(path1)).toBeFalsy()
|
||||
|
||||
it "restores the contents of the path to the original text", ->
|
||||
fs.writeSync(path1, '')
|
||||
fs.writeFileSync(path1, '')
|
||||
expect(repo.checkoutHead(path1)).toBeTruthy()
|
||||
expect(fs.read(path1)).toBe(originalPath1Text)
|
||||
expect(fs.readFileSync(path1, 'utf8')).toBe(originalPath1Text)
|
||||
|
||||
it "only restores the path specified", ->
|
||||
fs.writeSync(path2, 'path 2 is edited')
|
||||
fs.writeFileSync(path2, 'path 2 is edited')
|
||||
expect(repo.isPathModified(path2)).toBeTruthy()
|
||||
expect(repo.checkoutHead(path1)).toBeTruthy()
|
||||
expect(fs.read(path2)).toBe('path 2 is edited')
|
||||
expect(fs.readFileSync(path2, 'utf8')).toBe('path 2 is edited')
|
||||
expect(repo.isPathModified(path2)).toBeTruthy()
|
||||
|
||||
it "fires a status-changed event if the checkout completes successfully", ->
|
||||
fs.writeSync(path1, '')
|
||||
fs.writeFileSync(path1, '')
|
||||
repo.getPathStatus(path1)
|
||||
statusHandler = jasmine.createSpy('statusHandler')
|
||||
repo.on 'status-changed', statusHandler
|
||||
@@ -144,14 +144,14 @@ describe "Git", ->
|
||||
beforeEach ->
|
||||
repo = new Git(path.join(__dirname, 'fixtures', 'git', 'working-dir'))
|
||||
filePath = require.resolve('./fixtures/git/working-dir/file.txt')
|
||||
originalPathText = fs.read(filePath)
|
||||
originalPathText = fs.readFileSync(filePath, 'utf8')
|
||||
|
||||
afterEach ->
|
||||
fs.writeSync(filePath, originalPathText)
|
||||
fs.writeFileSync(filePath, originalPathText)
|
||||
|
||||
it "returns the number of lines added and deleted", ->
|
||||
expect(repo.getDiffStats(filePath)).toEqual {added: 0, deleted: 0}
|
||||
fs.writeSync(filePath, "#{originalPathText} edited line")
|
||||
fs.writeFileSync(filePath, "#{originalPathText} edited line")
|
||||
expect(repo.getDiffStats(filePath)).toEqual {added: 1, deleted: 1}
|
||||
|
||||
describe ".getPathStatus(path)", ->
|
||||
@@ -160,20 +160,20 @@ describe "Git", ->
|
||||
beforeEach ->
|
||||
repo = new Git(path.join(__dirname, 'fixtures', 'git', 'working-dir'))
|
||||
filePath = require.resolve('./fixtures/git/working-dir/file.txt')
|
||||
originalPathText = fs.read(filePath)
|
||||
originalPathText = fs.readFileSync(filePath, 'utf8')
|
||||
|
||||
afterEach ->
|
||||
fs.writeSync(filePath, originalPathText)
|
||||
fs.writeFileSync(filePath, originalPathText)
|
||||
|
||||
it "trigger a status-changed event when the new status differs from the last cached one", ->
|
||||
statusHandler = jasmine.createSpy("statusHandler")
|
||||
repo.on 'status-changed', statusHandler
|
||||
fs.writeSync(filePath, '')
|
||||
fs.writeFileSync(filePath, '')
|
||||
status = repo.getPathStatus(filePath)
|
||||
expect(statusHandler.callCount).toBe 1
|
||||
expect(statusHandler.argsForCall[0][0..1]).toEqual [filePath, status]
|
||||
|
||||
fs.writeSync(filePath, 'abc')
|
||||
fs.writeFileSync(filePath, 'abc')
|
||||
status = repo.getPathStatus(filePath)
|
||||
expect(statusHandler.callCount).toBe 1
|
||||
|
||||
@@ -183,17 +183,17 @@ describe "Git", ->
|
||||
beforeEach ->
|
||||
repo = new Git(path.join(__dirname, 'fixtures', 'git', 'working-dir'))
|
||||
modifiedPath = project.resolve('git/working-dir/file.txt')
|
||||
originalModifiedPathText = fs.read(modifiedPath)
|
||||
originalModifiedPathText = fs.readFileSync(modifiedPath, 'utf8')
|
||||
newPath = project.resolve('git/working-dir/untracked.txt')
|
||||
cleanPath = project.resolve('git/working-dir/other.txt')
|
||||
fs.writeSync(newPath, '')
|
||||
fs.writeFileSync(newPath, '')
|
||||
|
||||
afterEach ->
|
||||
fs.writeSync(modifiedPath, originalModifiedPathText)
|
||||
fs.remove(newPath) if fs.exists(newPath)
|
||||
fs.writeFileSync(modifiedPath, originalModifiedPathText)
|
||||
fs.removeSync(newPath) if fs.existsSync(newPath)
|
||||
|
||||
it "returns status information for all new and modified files", ->
|
||||
fs.writeSync(modifiedPath, 'making this path modified')
|
||||
fs.writeFileSync(modifiedPath, 'making this path modified')
|
||||
statusHandler = jasmine.createSpy('statusHandler')
|
||||
repo.on 'statuses-changed', statusHandler
|
||||
repo.refreshStatus()
|
||||
@@ -215,7 +215,7 @@ describe "Git", ->
|
||||
originalContent = editSession.getText()
|
||||
|
||||
afterEach ->
|
||||
fs.writeSync(editSession.getPath(), originalContent)
|
||||
fs.writeFileSync(editSession.getPath(), originalContent)
|
||||
|
||||
it "emits a status-changed event when a buffer is saved", ->
|
||||
editSession.insertNewline()
|
||||
@@ -227,7 +227,7 @@ describe "Git", ->
|
||||
expect(statusHandler).toHaveBeenCalledWith editSession.getPath(), 256
|
||||
|
||||
it "emits a status-changed event when a buffer is reloaded", ->
|
||||
fs.writeSync(editSession.getPath(), 'changed')
|
||||
fs.writeFileSync(editSession.getPath(), 'changed')
|
||||
|
||||
statusHandler = jasmine.createSpy('statusHandler')
|
||||
project.getRepo().on 'status-changed', statusHandler
|
||||
@@ -238,7 +238,7 @@ describe "Git", ->
|
||||
expect(statusHandler.callCount).toBe 1
|
||||
|
||||
it "emits a status-changed event when a buffer's path changes", ->
|
||||
fs.writeSync(editSession.getPath(), 'changed')
|
||||
fs.writeFileSync(editSession.getPath(), 'changed')
|
||||
|
||||
statusHandler = jasmine.createSpy('statusHandler')
|
||||
project.getRepo().on 'status-changed', statusHandler
|
||||
@@ -252,7 +252,7 @@ describe "Git", ->
|
||||
[originalContent, buffer, project2] = []
|
||||
|
||||
afterEach ->
|
||||
fs.writeSync(buffer.getPath(), originalContent)
|
||||
fs.writeFileSync(buffer.getPath(), originalContent)
|
||||
project2?.destroy()
|
||||
|
||||
it "subscribes to all the serialized buffers in the project", ->
|
||||
|
||||
@@ -365,10 +365,10 @@ describe "Project", ->
|
||||
runs ->
|
||||
fs.rename(path.join(projectPath, 'git.git'), path.join(projectPath, '.git'))
|
||||
ignoredPath = path.join(projectPath, 'ignored.txt')
|
||||
fs.writeSync(ignoredPath, 'this match should not be included')
|
||||
fs.writeFileSync(ignoredPath, 'this match should not be included')
|
||||
|
||||
afterEach ->
|
||||
fs.remove(projectPath) if fs.exists(projectPath)
|
||||
fs.removeSync(projectPath) if fs.existsSync(projectPath)
|
||||
|
||||
it "excludes ignored files", ->
|
||||
project.setPath(projectPath)
|
||||
@@ -402,7 +402,7 @@ describe "Project", ->
|
||||
it "includes files and folders that begin with a '.'", ->
|
||||
projectPath = temp.mkdirSync()
|
||||
filePath = path.join(projectPath, '.text')
|
||||
fs.writeSync(filePath, 'match this')
|
||||
fs.writeFileSync(filePath, 'match this')
|
||||
project.setPath(projectPath)
|
||||
paths = []
|
||||
matches = []
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
path = require 'path'
|
||||
fsUtils = require '../src/fs-utils'
|
||||
fs = require 'fs-plus'
|
||||
|
||||
{_} = require 'atom'
|
||||
|
||||
@@ -15,8 +15,8 @@ module.exports =
|
||||
# Returns nothing.
|
||||
generateEvilFiles: ->
|
||||
evilFilesPath = path.join(__dirname, 'fixtures', 'evil-files')
|
||||
fsUtils.remove(evilFilesPath) if fsUtils.exists(evilFilesPath)
|
||||
fsUtils.mkdirSync(evilFilesPath)
|
||||
fs.removeSync(evilFilesPath) if fs.existsSync(evilFilesPath)
|
||||
fs.mkdirSync(evilFilesPath)
|
||||
|
||||
if (@isWindows())
|
||||
filenames = [
|
||||
@@ -34,5 +34,4 @@ module.exports =
|
||||
]
|
||||
|
||||
for filename in filenames
|
||||
fd = fsUtils.writeFileSync(path.join(evilFilesPath, filename), 'evil file!', flag: 'w')
|
||||
|
||||
fd = fs.writeFileSync(path.join(evilFilesPath, filename), 'evil file!', flag: 'w')
|
||||
|
||||
@@ -165,7 +165,7 @@ addCustomMatchers = (spec) ->
|
||||
toExistOnDisk: (expected) ->
|
||||
notText = this.isNot and " not" or ""
|
||||
@message = -> return "Expected path '" + @actual + "'" + notText + " to exist."
|
||||
fs.exists(@actual)
|
||||
fs.existsSync(@actual)
|
||||
|
||||
window.keyIdentifierForKey = (key) ->
|
||||
if key.length > 1 # named key
|
||||
|
||||
@@ -47,7 +47,7 @@ describe "the `syntax` global", ->
|
||||
|
||||
it "doesn't read the file when the file contents are specified", ->
|
||||
filePath = require.resolve("./fixtures/shebang")
|
||||
filePathContents = fs.read(filePath)
|
||||
filePathContents = fs.readFileSync(filePath, 'utf8')
|
||||
spyOn(fs, 'read').andCallThrough()
|
||||
expect(syntax.selectGrammar(filePath, filePathContents).name).toBe "Ruby"
|
||||
expect(fs.read).not.toHaveBeenCalled()
|
||||
|
||||
@@ -9,7 +9,7 @@ describe 'TextBuffer', ->
|
||||
|
||||
beforeEach ->
|
||||
filePath = require.resolve('./fixtures/sample.js')
|
||||
fileContents = fs.read(filePath)
|
||||
fileContents = fs.readFileSync(filePath, 'utf8')
|
||||
buffer = project.bufferForPathSync(filePath)
|
||||
|
||||
afterEach ->
|
||||
@@ -25,18 +25,18 @@ describe 'TextBuffer', ->
|
||||
it "loads the contents of that file", ->
|
||||
filePath = require.resolve './fixtures/sample.txt'
|
||||
buffer = project.bufferForPathSync(filePath)
|
||||
expect(buffer.getText()).toBe fs.read(filePath)
|
||||
expect(buffer.getText()).toBe fs.readFileSync(filePath, 'utf8')
|
||||
|
||||
it "does not allow the initial state of the buffer to be undone", ->
|
||||
filePath = require.resolve './fixtures/sample.txt'
|
||||
buffer = project.bufferForPathSync(filePath)
|
||||
buffer.undo()
|
||||
expect(buffer.getText()).toBe fs.read(filePath)
|
||||
expect(buffer.getText()).toBe fs.readFileSync(filePath, 'utf8')
|
||||
|
||||
describe "when no file exists for the path", ->
|
||||
it "is modified and is initially empty", ->
|
||||
filePath = "does-not-exist.txt"
|
||||
expect(fs.exists(filePath)).toBeFalsy()
|
||||
expect(fs.existsSync(filePath)).toBeFalsy()
|
||||
buffer = project.bufferForPathSync(filePath)
|
||||
expect(buffer.isModified()).toBeTruthy()
|
||||
expect(buffer.getText()).toBe ''
|
||||
@@ -52,15 +52,15 @@ describe 'TextBuffer', ->
|
||||
beforeEach ->
|
||||
filePath = path.join(__dirname, "fixtures", "atom-manipulate-me")
|
||||
newPath = "#{filePath}-i-moved"
|
||||
fs.writeSync(filePath, "")
|
||||
fs.writeFileSync(filePath, "")
|
||||
bufferToChange = project.bufferForPathSync(filePath)
|
||||
eventHandler = jasmine.createSpy('eventHandler')
|
||||
bufferToChange.on 'path-changed', eventHandler
|
||||
|
||||
afterEach ->
|
||||
bufferToChange.destroy()
|
||||
fs.remove(filePath) if fs.exists(filePath)
|
||||
fs.remove(newPath) if fs.exists(newPath)
|
||||
fs.removeSync(filePath) if fs.existsSync(filePath)
|
||||
fs.removeSync(newPath) if fs.existsSync(newPath)
|
||||
|
||||
it "triggers a `path-changed` event when path is changed", ->
|
||||
bufferToChange.saveAs(newPath)
|
||||
@@ -69,8 +69,8 @@ describe 'TextBuffer', ->
|
||||
it "triggers a `path-changed` event when the file is moved", ->
|
||||
jasmine.unspy(window, "setTimeout")
|
||||
|
||||
fs.remove(newPath) if fs.exists(newPath)
|
||||
fs.move(filePath, newPath)
|
||||
fs.removeSync(newPath) if fs.existsSync(newPath)
|
||||
fs.moveSync(filePath, newPath)
|
||||
|
||||
waitsFor "buffer path change", ->
|
||||
eventHandler.callCount > 0
|
||||
@@ -84,7 +84,7 @@ describe 'TextBuffer', ->
|
||||
beforeEach ->
|
||||
buffer.release()
|
||||
filePath = temp.openSync('atom').path
|
||||
fs.writeSync(filePath, "first")
|
||||
fs.writeFileSync(filePath, "first")
|
||||
buffer = project.bufferForPathSync(filePath).retain()
|
||||
|
||||
afterEach ->
|
||||
@@ -105,7 +105,7 @@ describe 'TextBuffer', ->
|
||||
it "changes the memory contents of the buffer to match the new disk contents and triggers a 'changed' event", ->
|
||||
changeHandler = jasmine.createSpy('changeHandler')
|
||||
buffer.on 'changed', changeHandler
|
||||
fs.writeSync(filePath, "second")
|
||||
fs.writeFileSync(filePath, "second")
|
||||
|
||||
expect(changeHandler.callCount).toBe 0
|
||||
waitsFor "file to trigger change event", ->
|
||||
@@ -125,7 +125,7 @@ describe 'TextBuffer', ->
|
||||
buffer.file.on 'contents-changed', fileChangeHandler
|
||||
|
||||
buffer.insert([0, 0], "a change")
|
||||
fs.writeSync(filePath, "second")
|
||||
fs.writeFileSync(filePath, "second")
|
||||
|
||||
expect(fileChangeHandler.callCount).toBe 0
|
||||
waitsFor "file to trigger 'contents-changed' event", ->
|
||||
@@ -140,7 +140,7 @@ describe 'TextBuffer', ->
|
||||
buffer.insert([0, 0], "a second change")
|
||||
|
||||
handler = jasmine.createSpy('fileChange')
|
||||
fs.writeSync(filePath, "a disk change")
|
||||
fs.writeFileSync(filePath, "a disk change")
|
||||
buffer.on 'contents-conflicted', handler
|
||||
|
||||
expect(handler.callCount).toBe 0
|
||||
@@ -155,7 +155,7 @@ describe 'TextBuffer', ->
|
||||
|
||||
beforeEach ->
|
||||
filePath = path.join(temp.dir, 'atom-file-to-delete.txt')
|
||||
fs.writeSync(filePath, 'delete me')
|
||||
fs.writeFileSync(filePath, 'delete me')
|
||||
bufferToDelete = project.bufferForPathSync(filePath)
|
||||
filePath = bufferToDelete.getPath() # symlinks may have been converted
|
||||
|
||||
@@ -164,7 +164,7 @@ describe 'TextBuffer', ->
|
||||
|
||||
removeHandler = jasmine.createSpy('removeHandler')
|
||||
bufferToDelete.file.on 'removed', removeHandler
|
||||
fs.remove(filePath)
|
||||
fs.removeSync(filePath)
|
||||
waitsFor "file to be removed", ->
|
||||
removeHandler.callCount > 0
|
||||
|
||||
@@ -177,10 +177,10 @@ describe 'TextBuffer', ->
|
||||
|
||||
it "resumes watching of the file when it is re-saved", ->
|
||||
bufferToDelete.save()
|
||||
expect(fs.exists(bufferToDelete.getPath())).toBeTruthy()
|
||||
expect(fs.existsSync(bufferToDelete.getPath())).toBeTruthy()
|
||||
expect(bufferToDelete.isInConflict()).toBeFalsy()
|
||||
|
||||
fs.writeSync(filePath, 'moo')
|
||||
fs.writeFileSync(filePath, 'moo')
|
||||
|
||||
changeHandler = jasmine.createSpy('changeHandler')
|
||||
bufferToDelete.on 'changed', changeHandler
|
||||
@@ -213,19 +213,19 @@ describe 'TextBuffer', ->
|
||||
it "reports the modified status changing to true after the underlying file is deleted", ->
|
||||
buffer.release()
|
||||
filePath = path.join(temp.dir, 'atom-tmp-file')
|
||||
fs.writeSync(filePath, 'delete me')
|
||||
fs.writeFileSync(filePath, 'delete me')
|
||||
buffer = project.bufferForPathSync(filePath)
|
||||
modifiedHandler = jasmine.createSpy("modifiedHandler")
|
||||
buffer.on 'modified-status-changed', modifiedHandler
|
||||
|
||||
fs.remove(filePath)
|
||||
fs.removeSync(filePath)
|
||||
|
||||
waitsFor "modified status to change", -> modifiedHandler.callCount
|
||||
runs -> expect(buffer.isModified()).toBe true
|
||||
|
||||
it "reports the modified status changing to false after a modified buffer is saved", ->
|
||||
filePath = path.join(temp.dir, 'atom-tmp-file')
|
||||
fs.writeSync(filePath, '')
|
||||
fs.writeFileSync(filePath, '')
|
||||
buffer.release()
|
||||
buffer = project.bufferForPathSync(filePath)
|
||||
modifiedHandler = jasmine.createSpy("modifiedHandler")
|
||||
@@ -249,7 +249,7 @@ describe 'TextBuffer', ->
|
||||
|
||||
it "reports the modified status changing to false after a modified buffer is reloaded", ->
|
||||
filePath = path.join(temp.dir, 'atom-tmp-file')
|
||||
fs.writeSync(filePath, '')
|
||||
fs.writeFileSync(filePath, '')
|
||||
buffer.release()
|
||||
buffer = project.bufferForPathSync(filePath)
|
||||
modifiedHandler = jasmine.createSpy("modifiedHandler")
|
||||
@@ -272,8 +272,8 @@ describe 'TextBuffer', ->
|
||||
|
||||
it "reports the modified status changing to false after a buffer to a non-existent file is saved", ->
|
||||
filePath = path.join(temp.dir, 'atom-tmp-file')
|
||||
fs.remove(filePath) if fs.exists(filePath)
|
||||
expect(fs.exists(filePath)).toBeFalsy()
|
||||
fs.removeSync(filePath) if fs.existsSync(filePath)
|
||||
expect(fs.existsSync(filePath)).toBeFalsy()
|
||||
buffer.release()
|
||||
buffer = project.bufferForPathSync(filePath)
|
||||
modifiedHandler = jasmine.createSpy("modifiedHandler")
|
||||
@@ -285,7 +285,7 @@ describe 'TextBuffer', ->
|
||||
modifiedHandler.reset()
|
||||
|
||||
buffer.save()
|
||||
expect(fs.exists(filePath)).toBeTruthy()
|
||||
expect(fs.existsSync(filePath)).toBeTruthy()
|
||||
|
||||
expect(modifiedHandler).toHaveBeenCalledWith(false)
|
||||
expect(buffer.isModified()).toBe false
|
||||
@@ -465,16 +465,16 @@ describe 'TextBuffer', ->
|
||||
|
||||
beforeEach ->
|
||||
filePath = path.join(temp.dir, 'temp.txt')
|
||||
fs.writeSync(filePath, "")
|
||||
fs.writeFileSync(filePath, "")
|
||||
saveBuffer = project.bufferForPathSync(filePath)
|
||||
saveBuffer.setText("blah")
|
||||
|
||||
it "saves the contents of the buffer to the path", ->
|
||||
saveBuffer.setText 'Buffer contents!'
|
||||
saveBuffer.save()
|
||||
expect(fs.read(filePath)).toEqual 'Buffer contents!'
|
||||
expect(fs.readFileSync(filePath, 'utf8')).toEqual 'Buffer contents!'
|
||||
|
||||
it "fires will-be-saved and saved events around the call to fs.writeSync", ->
|
||||
it "fires will-be-saved and saved events around the call to fs.writeFileSync", ->
|
||||
events = []
|
||||
beforeSave1 = -> events.push('beforeSave1')
|
||||
beforeSave2 = -> events.push('beforeSave2')
|
||||
@@ -483,12 +483,12 @@ describe 'TextBuffer', ->
|
||||
|
||||
saveBuffer.on 'will-be-saved', beforeSave1
|
||||
saveBuffer.on 'will-be-saved', beforeSave2
|
||||
spyOn(fs, 'writeSync').andCallFake -> events.push 'fs.writeSync'
|
||||
spyOn(fs, 'writeFileSync').andCallFake -> events.push 'fs.writeFileSync'
|
||||
saveBuffer.on 'saved', afterSave1
|
||||
saveBuffer.on 'saved', afterSave2
|
||||
|
||||
saveBuffer.save()
|
||||
expect(events).toEqual ['beforeSave1', 'beforeSave2', 'fs.writeSync', 'afterSave1', 'afterSave2']
|
||||
expect(events).toEqual ['beforeSave1', 'beforeSave2', 'fs.writeFileSync', 'afterSave1', 'afterSave2']
|
||||
|
||||
it "fires will-reload and reloaded events when reloaded", ->
|
||||
events = []
|
||||
@@ -522,7 +522,7 @@ describe 'TextBuffer', ->
|
||||
|
||||
it "saves the contents of the buffer to the path", ->
|
||||
filePath = path.join(temp.dir, 'temp.txt')
|
||||
fs.remove filePath if fs.exists(filePath)
|
||||
fs.removeSync filePath if fs.existsSync(filePath)
|
||||
|
||||
saveAsBuffer = project.bufferForPathSync(null).retain()
|
||||
eventHandler = jasmine.createSpy('eventHandler')
|
||||
@@ -530,14 +530,14 @@ describe 'TextBuffer', ->
|
||||
|
||||
saveAsBuffer.setText 'Buffer contents!'
|
||||
saveAsBuffer.saveAs(filePath)
|
||||
expect(fs.read(filePath)).toEqual 'Buffer contents!'
|
||||
expect(fs.readFileSync(filePath, 'utf8')).toEqual 'Buffer contents!'
|
||||
|
||||
expect(eventHandler).toHaveBeenCalledWith(saveAsBuffer)
|
||||
|
||||
it "stops listening to events on previous path and begins listening to events on new path", ->
|
||||
originalPath = path.join(temp.dir, 'original.txt')
|
||||
newPath = path.join(temp.dir, 'new.txt')
|
||||
fs.writeSync(originalPath, "")
|
||||
fs.writeFileSync(originalPath, "")
|
||||
|
||||
saveAsBuffer = project.bufferForPathSync(originalPath).retain()
|
||||
changeHandler = jasmine.createSpy('changeHandler')
|
||||
@@ -545,11 +545,11 @@ describe 'TextBuffer', ->
|
||||
saveAsBuffer.saveAs(newPath)
|
||||
expect(changeHandler).not.toHaveBeenCalled()
|
||||
|
||||
fs.writeSync(originalPath, "should not trigger buffer event")
|
||||
fs.writeFileSync(originalPath, "should not trigger buffer event")
|
||||
waits 20
|
||||
runs ->
|
||||
expect(changeHandler).not.toHaveBeenCalled()
|
||||
fs.writeSync(newPath, "should trigger buffer event")
|
||||
fs.writeFileSync(newPath, "should trigger buffer event")
|
||||
|
||||
waitsFor ->
|
||||
changeHandler.callCount > 0
|
||||
@@ -560,22 +560,22 @@ describe 'TextBuffer', ->
|
||||
beforeEach ->
|
||||
filePath = path.join(__dirname, "fixtures", "atom-manipulate-me")
|
||||
newPath = "#{filePath}-i-moved"
|
||||
fs.writeSync(filePath, "")
|
||||
fs.writeFileSync(filePath, "")
|
||||
bufferToChange = project.bufferForPathSync(filePath)
|
||||
eventHandler = jasmine.createSpy('eventHandler')
|
||||
bufferToChange.on 'path-changed', eventHandler
|
||||
|
||||
afterEach ->
|
||||
bufferToChange.destroy()
|
||||
fs.remove(filePath) if fs.exists(filePath)
|
||||
fs.remove(newPath) if fs.exists(newPath)
|
||||
fs.removeSync(filePath) if fs.existsSync(filePath)
|
||||
fs.removeSync(newPath) if fs.existsSync(newPath)
|
||||
|
||||
it "updates when the text buffer's file is moved", ->
|
||||
expect(bufferToChange.getRelativePath()).toBe('atom-manipulate-me')
|
||||
|
||||
jasmine.unspy(window, "setTimeout")
|
||||
eventHandler.reset()
|
||||
fs.move(filePath, newPath)
|
||||
fs.moveSync(filePath, newPath)
|
||||
|
||||
waitsFor "buffer path change", ->
|
||||
eventHandler.callCount > 0
|
||||
@@ -954,13 +954,13 @@ describe 'TextBuffer', ->
|
||||
buffer.release()
|
||||
|
||||
filePath = temp.openSync('atom').path
|
||||
fs.writeSync(filePath, "words")
|
||||
fs.writeFileSync(filePath, "words")
|
||||
{buffer} = project.openSync(filePath)
|
||||
buffer.setText("BUFFER CHANGE")
|
||||
|
||||
state = buffer.serialize()
|
||||
expect(state.getObject('text')).toBe 'BUFFER CHANGE'
|
||||
fs.writeSync(filePath, "DISK CHANGE")
|
||||
fs.writeFileSync(filePath, "DISK CHANGE")
|
||||
|
||||
buffer2 = deserialize(state, {project})
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ describe "ThemeManager", ->
|
||||
|
||||
element = $('head style[id*="css.css"]')
|
||||
expect(element.attr('id')).toBe cssPath
|
||||
expect(element.text()).toBe fs.read(cssPath)
|
||||
expect(element.text()).toBe fs.readFileSync(cssPath, 'utf8')
|
||||
|
||||
# doesn't append twice
|
||||
themeManager.requireStylesheet(cssPath)
|
||||
|
||||
+14
-14
@@ -1,6 +1,6 @@
|
||||
TextMateGrammar = require './text-mate-grammar'
|
||||
Package = require './package'
|
||||
fsUtils = require './fs-utils'
|
||||
fs = require 'fs-plus'
|
||||
path = require 'path'
|
||||
_ = require 'underscore-plus'
|
||||
{$} = require './space-pen-extensions'
|
||||
@@ -118,16 +118,16 @@ class AtomPackage extends Package
|
||||
getKeymapPaths: ->
|
||||
keymapsDirPath = path.join(@path, 'keymaps')
|
||||
if @metadata.keymaps
|
||||
@metadata.keymaps.map (name) -> fsUtils.resolve(keymapsDirPath, name, ['json', 'cson', ''])
|
||||
@metadata.keymaps.map (name) -> fs.resolve(keymapsDirPath, name, ['json', 'cson', ''])
|
||||
else
|
||||
fsUtils.listSync(keymapsDirPath, ['cson', 'json'])
|
||||
fs.listSync(keymapsDirPath, ['cson', 'json'])
|
||||
|
||||
getMenuPaths: ->
|
||||
menusDirPath = path.join(@path, 'menus')
|
||||
if @metadata.menus
|
||||
@metadata.menus.map (name) -> fsUtils.resolve(menusDirPath, name, ['json', 'cson', ''])
|
||||
@metadata.menus.map (name) -> fs.resolve(menusDirPath, name, ['json', 'cson', ''])
|
||||
else
|
||||
fsUtils.listSync(menusDirPath, ['cson', 'json'])
|
||||
fs.listSync(menusDirPath, ['cson', 'json'])
|
||||
|
||||
loadStylesheets: ->
|
||||
@stylesheets = @getStylesheetPaths().map (stylesheetPath) ->
|
||||
@@ -140,25 +140,25 @@ class AtomPackage extends Package
|
||||
stylesheetDirPath = @getStylesheetsPath()
|
||||
|
||||
if @metadata.stylesheetMain
|
||||
[fsUtils.resolve(@path, @metadata.stylesheetMain)]
|
||||
[fs.resolve(@path, @metadata.stylesheetMain)]
|
||||
else if @metadata.stylesheets
|
||||
@metadata.stylesheets.map (name) -> fsUtils.resolve(stylesheetDirPath, name, ['css', 'less', ''])
|
||||
else if indexStylesheet = fsUtils.resolve(@path, 'index', ['css', 'less'])
|
||||
@metadata.stylesheets.map (name) -> fs.resolve(stylesheetDirPath, name, ['css', 'less', ''])
|
||||
else if indexStylesheet = fs.resolve(@path, 'index', ['css', 'less'])
|
||||
[indexStylesheet]
|
||||
else
|
||||
fsUtils.listSync(stylesheetDirPath, ['css', 'less'])
|
||||
fs.listSync(stylesheetDirPath, ['css', 'less'])
|
||||
|
||||
loadGrammars: ->
|
||||
@grammars = []
|
||||
grammarsDirPath = path.join(@path, 'grammars')
|
||||
for grammarPath in fsUtils.listSync(grammarsDirPath, ['.json', '.cson'])
|
||||
for grammarPath in fs.listSync(grammarsDirPath, ['.json', '.cson'])
|
||||
@grammars.push(TextMateGrammar.loadSync(grammarPath))
|
||||
|
||||
loadScopedProperties: ->
|
||||
@scopedProperties = []
|
||||
scopedPropertiessDirPath = path.join(@path, 'scoped-properties')
|
||||
for scopedPropertiesPath in fsUtils.listSync(scopedPropertiessDirPath, ['.json', '.cson'])
|
||||
for selector, properties of fsUtils.readObjectSync(scopedPropertiesPath)
|
||||
for scopedPropertiesPath in fs.listSync(scopedPropertiessDirPath, ['.json', '.cson'])
|
||||
for selector, properties of fs.readObjectSync(scopedPropertiesPath)
|
||||
@scopedProperties.push([scopedPropertiesPath, selector, properties])
|
||||
|
||||
serialize: ->
|
||||
@@ -198,7 +198,7 @@ class AtomPackage extends Package
|
||||
requireMainModule: ->
|
||||
return @mainModule if @mainModule?
|
||||
mainModulePath = @getMainModulePath()
|
||||
@mainModule = require(mainModulePath) if fsUtils.isFileSync(mainModulePath)
|
||||
@mainModule = require(mainModulePath) if fs.isFileSync(mainModulePath)
|
||||
|
||||
getMainModulePath: ->
|
||||
return @mainModulePath if @resolvedMainModulePath
|
||||
@@ -208,7 +208,7 @@ class AtomPackage extends Package
|
||||
path.join(@path, @metadata.main)
|
||||
else
|
||||
path.join(@path, 'index')
|
||||
@mainModulePath = fsUtils.resolveExtension(mainModulePath, ["", _.keys(require.extensions)...])
|
||||
@mainModulePath = fs.resolveExtension(mainModulePath, ["", _.keys(require.extensions)...])
|
||||
|
||||
registerDeferredDeserializers: ->
|
||||
for deserializerName in @metadata.deferredDeserializers ? []
|
||||
|
||||
+15
-5
@@ -4,7 +4,17 @@ Emitter::one = (args...) -> @once(args...)
|
||||
Emitter::trigger = (args...) -> @emit(args...)
|
||||
Emitter::subscriptionCount = (args...) -> @getSubscriptionCount(args...)
|
||||
|
||||
fsUtils = require './fs-utils'
|
||||
#TODO remove once all packages have been updated
|
||||
fs = require 'fs-plus'
|
||||
fs.exists = fs.existsSync
|
||||
fs.makeTree = fs.makeTreeSync
|
||||
fs.move = fs.moveSync
|
||||
fs.read = (filePath) -> fs.readFileSync(filePath, 'utf8')
|
||||
fs.remove = fs.removeSync
|
||||
fs.write = fs.writeFile
|
||||
fs.writeSync = fs.writeFileSync
|
||||
|
||||
fs = require 'fs-plus'
|
||||
{$} = require './space-pen-extensions'
|
||||
_ = require 'underscore-plus'
|
||||
Package = require './package'
|
||||
@@ -243,7 +253,7 @@ class Atom
|
||||
|
||||
# Public: Get the directory path to Atom's configuration area.
|
||||
getConfigDirPath: ->
|
||||
@configDirPath ?= fsUtils.absolute('~/.atom')
|
||||
@configDirPath ?= fs.absolute('~/.atom')
|
||||
|
||||
getWindowStatePath: ->
|
||||
switch @windowMode
|
||||
@@ -267,9 +277,9 @@ class Atom
|
||||
|
||||
loadWindowState: ->
|
||||
if windowStatePath = @getWindowStatePath()
|
||||
if fsUtils.exists(windowStatePath)
|
||||
if fs.existsSync(windowStatePath)
|
||||
try
|
||||
documentStateJson = fsUtils.read(windowStatePath)
|
||||
documentStateJson = fs.readFileSync(windowStatePath, 'utf8')
|
||||
catch error
|
||||
console.warn "Error reading window state: #{windowStatePath}", error.stack, error
|
||||
else
|
||||
@@ -316,7 +326,7 @@ class Atom
|
||||
requireUserInitScript: ->
|
||||
userInitScriptPath = path.join(@config.configDirPath, "user.coffee")
|
||||
try
|
||||
require userInitScriptPath if fsUtils.isFileSync(userInitScriptPath)
|
||||
require userInitScriptPath if fs.isFileSync(userInitScriptPath)
|
||||
catch error
|
||||
console.error "Failed to load `#{userInitScriptPath}`", error.stack, error
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
{$} = require './space-pen-extensions'
|
||||
_ = require 'underscore-plus'
|
||||
fsUtils = require './fs-utils'
|
||||
|
||||
fs = require 'fs-plus'
|
||||
{specificity} = require 'clear-cut'
|
||||
PEG = require 'pegjs'
|
||||
|
||||
@@ -18,7 +17,8 @@ class BindingSet
|
||||
name: null
|
||||
|
||||
constructor: (selector, commandsByKeystrokes, @index, @name) ->
|
||||
BindingSet.parser ?= PEG.buildParser(fsUtils.read(require.resolve './keystroke-pattern.pegjs'))
|
||||
keystrokePattern = fs.readFileSync(require.resolve('./keystroke-pattern.pegjs'), 'utf8')
|
||||
BindingSet.parser ?= PEG.buildParser(keystrokePattern)
|
||||
@specificity = specificity(selector)
|
||||
@selector = selector.replace(/!important/g, '')
|
||||
@commandsByKeystrokes = @normalizeCommandsByKeystrokes(commandsByKeystrokes)
|
||||
|
||||
@@ -291,9 +291,9 @@ class AtomApplication
|
||||
openUrl: ({urlToOpen, devMode}) ->
|
||||
unless @packages?
|
||||
PackageManager = require '../package-manager'
|
||||
fsUtils = require '../fs-utils'
|
||||
fs = require 'fs-plus'
|
||||
@packages = new PackageManager
|
||||
configDirPath: fsUtils.absolute('~/.atom')
|
||||
configDirPath: fs.absolute('~/.atom')
|
||||
devMode: devMode
|
||||
resourcePath: @resourcePath
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
path = require 'path'
|
||||
fs = require 'fs'
|
||||
_ = require 'underscore-plus'
|
||||
async = require 'async'
|
||||
fs = require 'fs-plus'
|
||||
mkdirp = require 'mkdirp'
|
||||
fsUtils = require './fs-utils'
|
||||
|
||||
symlinkCommand = (sourcePath, destinationPath, callback) ->
|
||||
mkdirp path.dirname(destinationPath), (error) ->
|
||||
@@ -26,7 +25,7 @@ unlinkCommand = (destinationPath, callback) ->
|
||||
module.exports =
|
||||
findInstallDirectory: (callback) ->
|
||||
directories = ['/opt/boxen', '/opt/github', '/usr/local']
|
||||
async.detect(directories, fsUtils.isDirectory, callback)
|
||||
async.detect(directories, fs.isDirectory, callback)
|
||||
|
||||
install: (commandPath, commandName, callback) ->
|
||||
if not commandName? or _.isFunction(commandName)
|
||||
|
||||
+9
-10
@@ -1,8 +1,7 @@
|
||||
fsUtils = require './fs-utils'
|
||||
_ = require 'underscore-plus'
|
||||
fs = require 'fs-plus'
|
||||
{Emitter} = require 'emissary'
|
||||
CSON = require 'season'
|
||||
fs = require 'fs'
|
||||
path = require 'path'
|
||||
async = require 'async'
|
||||
pathWatcher = require 'pathwatcher'
|
||||
@@ -52,25 +51,25 @@ class Config
|
||||
core: _.clone(require('./root-view').configDefaults)
|
||||
editor: _.clone(require('./editor').configDefaults)
|
||||
@settings = {}
|
||||
@configFilePath = fsUtils.resolve(@configDirPath, 'config', ['json', 'cson'])
|
||||
@configFilePath = fs.resolve(@configDirPath, 'config', ['json', 'cson'])
|
||||
@configFilePath ?= path.join(@configDirPath, 'config.cson')
|
||||
|
||||
# Private:
|
||||
initializeConfigDirectory: (done) ->
|
||||
return if fsUtils.exists(@configDirPath)
|
||||
return if fs.existsSync(@configDirPath)
|
||||
|
||||
fsUtils.makeTree(@configDirPath)
|
||||
fs.makeTreeSync(@configDirPath)
|
||||
|
||||
queue = async.queue ({sourcePath, destinationPath}, callback) =>
|
||||
fsUtils.copy(sourcePath, destinationPath, callback)
|
||||
fs.copy(sourcePath, destinationPath, callback)
|
||||
queue.drain = done
|
||||
|
||||
templateConfigDirPath = fsUtils.resolve(@resourcePath, 'dot-atom')
|
||||
templateConfigDirPath = fs.resolve(@resourcePath, 'dot-atom')
|
||||
onConfigDirFile = (sourcePath) =>
|
||||
relativePath = sourcePath.substring(templateConfigDirPath.length + 1)
|
||||
destinationPath = path.join(@configDirPath, relativePath)
|
||||
queue.push({sourcePath, destinationPath})
|
||||
fsUtils.traverseTree(templateConfigDirPath, onConfigDirFile, (path) -> true)
|
||||
fs.traverseTree(templateConfigDirPath, onConfigDirFile, (path) -> true)
|
||||
|
||||
# Private:
|
||||
load: ->
|
||||
@@ -80,8 +79,8 @@ class Config
|
||||
|
||||
# Private:
|
||||
loadUserConfig: ->
|
||||
if !fsUtils.exists(@configFilePath)
|
||||
fsUtils.makeTree(path.dirname(@configFilePath))
|
||||
unless fs.existsSync(@configFilePath)
|
||||
fs.makeTreeSync(path.dirname(@configFilePath))
|
||||
CSON.writeFileSync(@configFilePath, {})
|
||||
|
||||
try
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
path = require 'path'
|
||||
fsUtils = require './fs-utils'
|
||||
fs = require 'fs-plus'
|
||||
pathWatcher = require 'pathwatcher'
|
||||
File = require './file'
|
||||
{Emitter} = require 'emissary'
|
||||
@@ -44,7 +44,7 @@ class Directory
|
||||
getRealPath: ->
|
||||
unless @realPath?
|
||||
try
|
||||
@realPath = fsUtils.realpathSync(@path)
|
||||
@realPath = fs.realpathSync(@path)
|
||||
catch e
|
||||
@realPath = @path
|
||||
@realPath
|
||||
@@ -84,11 +84,11 @@ class Directory
|
||||
getEntries: ->
|
||||
directories = []
|
||||
files = []
|
||||
for entryPath in fsUtils.listSync(@path)
|
||||
for entryPath in fs.listSync(@path)
|
||||
try
|
||||
stat = fsUtils.lstatSync(entryPath)
|
||||
stat = fs.lstatSync(entryPath)
|
||||
symlink = stat.isSymbolicLink()
|
||||
stat = fsUtils.statSync(entryPath) if symlink
|
||||
stat = fs.statSync(entryPath) if symlink
|
||||
catch e
|
||||
continue
|
||||
if stat.isDirectory()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
_ = require 'underscore-plus'
|
||||
fsUtils = require './fs-utils'
|
||||
path = require 'path'
|
||||
telepath = require 'telepath'
|
||||
guid = require 'guid'
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ Gutter = require './gutter'
|
||||
EditSession = require './edit-session'
|
||||
CursorView = require './cursor-view'
|
||||
SelectionView = require './selection-view'
|
||||
fsUtils = require './fs-utils'
|
||||
fs = require 'fs-plus'
|
||||
_ = require 'underscore-plus'
|
||||
|
||||
MeasureRange = document.createRange()
|
||||
@@ -1824,7 +1824,7 @@ class Editor extends View
|
||||
|
||||
saveDebugSnapshot: ->
|
||||
atom.showSaveDialog (path) =>
|
||||
fsUtils.writeSync(path, @getDebugSnapshot()) if path
|
||||
fs.writeFileSync(path, @getDebugSnapshot()) if path
|
||||
|
||||
getDebugSnapshot: ->
|
||||
[
|
||||
|
||||
+7
-7
@@ -4,7 +4,7 @@ pathWatcher = require 'pathwatcher'
|
||||
Q = require 'q'
|
||||
{Emitter} = require 'emissary'
|
||||
_ = require 'underscore-plus'
|
||||
fsUtils = require './fs-utils'
|
||||
fs = require 'fs-plus'
|
||||
|
||||
# Public: Represents an individual file.
|
||||
#
|
||||
@@ -24,7 +24,7 @@ class File
|
||||
# * symlink:
|
||||
# A Boolean indicating if the path is a symlink (default: false)
|
||||
constructor: (@path, @symlink=false) ->
|
||||
throw new Error("#{@path} is a directory") if fsUtils.isDirectorySync(@path)
|
||||
throw new Error("#{@path} is a directory") if fs.isDirectorySync(@path)
|
||||
|
||||
@handleEventSubscriptions()
|
||||
|
||||
@@ -57,7 +57,7 @@ class File
|
||||
write: (text) ->
|
||||
previouslyExisted = @exists()
|
||||
@cachedContents = text
|
||||
fsUtils.writeSync(@getPath(), text)
|
||||
fs.writeFileSync(@getPath(), text)
|
||||
@subscribeToNativeChangeEvents() if not previouslyExisted and @subscriptionCount() > 0
|
||||
|
||||
# Private: Deprecated
|
||||
@@ -65,7 +65,7 @@ class File
|
||||
if not @exists()
|
||||
@cachedContents = null
|
||||
else if not @cachedContents? or flushCache
|
||||
@cachedContents = fsUtils.read(@getPath())
|
||||
@cachedContents = fs.readFileSync(@getPath(), 'utf8')
|
||||
else
|
||||
@cachedContents
|
||||
|
||||
@@ -83,14 +83,14 @@ class File
|
||||
if not @exists()
|
||||
promise = Q(null)
|
||||
else if not @cachedContents? or flushCache
|
||||
if fsUtils.statSyncNoException(@getPath()).size >= 1048576 # 1MB
|
||||
if fs.getSizeSync(@getPath()) >= 1048576 # 1MB
|
||||
throw new Error("Atom can only handle files < 1MB, for now.")
|
||||
|
||||
deferred = Q.defer()
|
||||
promise = deferred.promise
|
||||
content = []
|
||||
bytesRead = 0
|
||||
readStream = fsUtils.createReadStream @getPath(), encoding: 'utf8'
|
||||
readStream = fs.createReadStream @getPath(), encoding: 'utf8'
|
||||
readStream.on 'data', (chunk) ->
|
||||
content.push(chunk)
|
||||
bytesRead += chunk.length
|
||||
@@ -110,7 +110,7 @@ class File
|
||||
|
||||
# Public: Returns whether the file exists.
|
||||
exists: ->
|
||||
fsUtils.exists(@getPath())
|
||||
fs.existsSync(@getPath())
|
||||
|
||||
setDigest: (contents) ->
|
||||
@digest = crypto.createHash('sha1').update(contents ? '').digest('hex')
|
||||
|
||||
@@ -1,431 +0,0 @@
|
||||
_ = require 'underscore-plus'
|
||||
fs = require 'fs'
|
||||
mkdirp = require 'mkdirp'
|
||||
Module = require 'module'
|
||||
async = require 'async'
|
||||
rimraf = require 'rimraf'
|
||||
path = require 'path'
|
||||
|
||||
# Public: Useful extensions to node's built-in fs module
|
||||
#
|
||||
# Important, this extends Node's builtin in ['fs' module][fs], which means that you
|
||||
# can do anything that you can do with Node's 'fs' module plus a few extra
|
||||
# functions that we've found to be helpful.
|
||||
#
|
||||
# [fs]: http://nodejs.org/api/fs.html
|
||||
fsExtensions =
|
||||
# Public: Make the given path absolute by resolving it against the current
|
||||
# working directory.
|
||||
#
|
||||
# * relativePath:
|
||||
# The String containing the relative path. If the path is prefixed with
|
||||
# '~', it will be expanded to the current user's home directory.
|
||||
#
|
||||
# Returns the absolute path or the relative path if it's unable to determine
|
||||
# it's realpath.
|
||||
absolute: (relativePath) ->
|
||||
return null unless relativePath?
|
||||
|
||||
homeDir = process.env[if process.platform is 'win32' then 'USERPROFILE' else 'HOME']
|
||||
|
||||
if relativePath is '~'
|
||||
relativePath = homeDir
|
||||
else if relativePath.indexOf('~/') is 0
|
||||
relativePath = "#{homeDir}#{relativePath.substring(1)}"
|
||||
|
||||
try
|
||||
fs.realpathSync(relativePath)
|
||||
catch e
|
||||
relativePath
|
||||
|
||||
# Public: Is the given path absolute?
|
||||
#
|
||||
# * pathToCheck:
|
||||
# The relative or absolute path to check.
|
||||
#
|
||||
# Returns true if the path is absolute, false otherwise.
|
||||
isAbsolute: (pathToCheck='') ->
|
||||
if process.platform is 'win32'
|
||||
pathToCheck[1] is ':' # C:\ style
|
||||
else
|
||||
pathToCheck[0] is '/' # /usr style
|
||||
|
||||
# Public: Returns true if a file or folder at the specified path exists.
|
||||
exists: (pathToCheck) ->
|
||||
# TODO: rename to existsSync
|
||||
pathToCheck? and fs.statSyncNoException(pathToCheck) isnt false
|
||||
|
||||
# Public: Returns true if the given path exists and is a directory.
|
||||
isDirectorySync: (directoryPath) ->
|
||||
return false unless directoryPath?.length > 0
|
||||
if stat = fs.statSyncNoException(directoryPath)
|
||||
stat.isDirectory()
|
||||
else
|
||||
false
|
||||
|
||||
# Public: Asynchronously checks that the given path exists and is a directory.
|
||||
isDirectory: (directoryPath, done) ->
|
||||
return done(false) unless directoryPath?.length > 0
|
||||
fs.exists directoryPath, (exists) ->
|
||||
if exists
|
||||
fs.stat directoryPath, (error, stat) ->
|
||||
if error?
|
||||
done(false)
|
||||
else
|
||||
done(stat.isDirectory())
|
||||
else
|
||||
done(false)
|
||||
|
||||
# Public: Returns true if the specified path exists and is a file.
|
||||
isFileSync: (filePath) ->
|
||||
return false unless filePath?.length > 0
|
||||
if stat = fs.statSyncNoException(filePath)
|
||||
stat.isFile()
|
||||
else
|
||||
false
|
||||
|
||||
# Public: Returns true if the specified path is executable.
|
||||
isExecutableSync: (pathToCheck) ->
|
||||
return false unless pathToCheck?.length > 0
|
||||
if stat = fs.statSyncNoException(pathToCheck)
|
||||
(stat.mode & 0o777 & 1) isnt 0
|
||||
else
|
||||
false
|
||||
|
||||
# Public: Returns an Array with the paths of the files and directories
|
||||
# contained within the directory path. It is not recursive.
|
||||
#
|
||||
# * rootPath:
|
||||
# The absolute path to the directory to list.
|
||||
# * extensions:
|
||||
# An array of extensions to filter the results by. If none are given, none
|
||||
# are filtered (optional).
|
||||
listSync: (rootPath, extensions) ->
|
||||
return [] unless @isDirectorySync(rootPath)
|
||||
paths = fs.readdirSync(rootPath)
|
||||
paths = @filterExtensions(paths, extensions) if extensions
|
||||
paths = paths.map (childPath) -> path.join(rootPath, childPath)
|
||||
paths
|
||||
|
||||
# Public: Asynchronously lists the files and directories in the given path.
|
||||
# The listing is not recursive.
|
||||
#
|
||||
# * rootPath:
|
||||
# The absolute path to the directory to list.
|
||||
# * extensions:
|
||||
# An array of extensions to filter the results by. If none are given, none
|
||||
# are filtered (optional)
|
||||
# * callback:
|
||||
# The function to call
|
||||
list: (rootPath, rest...) ->
|
||||
extensions = rest.shift() if rest.length > 1
|
||||
done = rest.shift()
|
||||
fs.readdir rootPath, (error, paths) =>
|
||||
if error?
|
||||
done(error)
|
||||
else
|
||||
paths = @filterExtensions(paths, extensions) if extensions
|
||||
paths = paths.map (childPath) -> path.join(rootPath, childPath)
|
||||
done(null, paths)
|
||||
|
||||
# Private: Returns only the paths which end with one of the given extensions.
|
||||
filterExtensions: (paths, extensions) ->
|
||||
extensions = extensions.map (ext) ->
|
||||
if ext is ''
|
||||
ext
|
||||
else
|
||||
'.' + ext.replace(/^\./, '')
|
||||
paths.filter (pathToCheck) -> _.include(extensions, path.extname(pathToCheck))
|
||||
|
||||
# Deprecated: No one currently uses this.
|
||||
listTreeSync: (rootPath) ->
|
||||
paths = []
|
||||
onPath = (childPath) ->
|
||||
paths.push(childPath)
|
||||
true
|
||||
@traverseTreeSync(rootPath, onPath, onPath)
|
||||
paths
|
||||
|
||||
# Public: Moves the file or directory to the target synchronously.
|
||||
move: (source, target) ->
|
||||
# TODO: This should be renamed to moveSync
|
||||
fs.renameSync(source, target)
|
||||
|
||||
# Public: Removes the file or directory at the given path synchronously.
|
||||
remove: (pathToRemove) ->
|
||||
# TODO: This should be renamed to removeSync
|
||||
rimraf.sync(pathToRemove)
|
||||
|
||||
# Public: Open, read, and close a file, returning the file's contents
|
||||
# synchronously.
|
||||
read: (filePath) ->
|
||||
# TODO: This should be renamed to readSync
|
||||
fs.readFileSync(filePath, 'utf8')
|
||||
|
||||
# Public: Open, write, flush, and close a file, writing the given content
|
||||
# synchronously.
|
||||
#
|
||||
# It also creates the necessary parent directories.
|
||||
writeSync: (filePath, content) ->
|
||||
mkdirp.sync(path.dirname(filePath))
|
||||
fs.writeFileSync(filePath, content)
|
||||
|
||||
# Public: Open, write, flush, and close a file, writing the given content
|
||||
# asynchronously.
|
||||
#
|
||||
# It also creates the necessary parent directories.
|
||||
write: (filePath, content, callback) ->
|
||||
mkdirp path.dirname(filePath), (error) ->
|
||||
if error?
|
||||
callback?(error)
|
||||
else
|
||||
fs.writeFile(filePath, content, callback)
|
||||
|
||||
# Public: Copies the given path asynchronously.
|
||||
copy: (sourcePath, destinationPath, done) ->
|
||||
mkdirp path.dirname(destinationPath), (error) ->
|
||||
if error?
|
||||
done?(error)
|
||||
return
|
||||
|
||||
sourceStream = fs.createReadStream(sourcePath)
|
||||
sourceStream.on 'error', (error) ->
|
||||
done?(error)
|
||||
done = null
|
||||
|
||||
destinationStream = fs.createWriteStream(destinationPath)
|
||||
destinationStream.on 'error', (error) ->
|
||||
done?(error)
|
||||
done = null
|
||||
destinationStream.on 'close', ->
|
||||
done?()
|
||||
done = null
|
||||
|
||||
sourceStream.pipe(destinationStream)
|
||||
|
||||
# Public: Create a directory at the specified path including any missing
|
||||
# parent directories synchronously.
|
||||
makeTree: (directoryPath) ->
|
||||
# TODO: rename to makeTreeSync
|
||||
mkdirp.sync(directoryPath) if directoryPath and not @exists(directoryPath)
|
||||
|
||||
# Public: Recursively walk the given path and execute the given functions
|
||||
# synchronously.
|
||||
#
|
||||
# * rootPath:
|
||||
# The String containing the directory to recurse into.
|
||||
# * onFile:
|
||||
# The function to execute on each file, receives a single argument the
|
||||
# absolute path.
|
||||
# * onDirectory:
|
||||
# The function to execute on each directory, receives a single argument the
|
||||
# absolute path (defaults to onFile)
|
||||
traverseTreeSync: (rootPath, onFile, onDirectory=onFile) ->
|
||||
return unless @isDirectorySync(rootPath)
|
||||
|
||||
traverse = (directoryPath, onFile, onDirectory) ->
|
||||
for file in fs.readdirSync(directoryPath)
|
||||
childPath = path.join(directoryPath, file)
|
||||
stats = fs.lstatSync(childPath)
|
||||
if stats.isSymbolicLink()
|
||||
if linkStats = fs.statSyncNoException(childPath)
|
||||
stats = linkStats
|
||||
if stats.isDirectory()
|
||||
traverse(childPath, onFile, onDirectory) if onDirectory(childPath)
|
||||
else if stats.isFile()
|
||||
onFile(childPath)
|
||||
|
||||
traverse(rootPath, onFile, onDirectory)
|
||||
|
||||
# Public: Recursively walk the given path and execute the given functions
|
||||
# asynchronously.
|
||||
#
|
||||
# * rootPath:
|
||||
# The String containing the directory to recurse into.
|
||||
# * onFile:
|
||||
# The function to execute on each file, receives a single argument the
|
||||
# absolute path.
|
||||
# * onDirectory:
|
||||
# The function to execute on each directory, receives a single argument the
|
||||
# absolute path (defaults to onFile)
|
||||
traverseTree: (rootPath, onFile, onDirectory, onDone) ->
|
||||
fs.readdir rootPath, (error, files) ->
|
||||
if error
|
||||
onDone?()
|
||||
else
|
||||
queue = async.queue (childPath, callback) ->
|
||||
fs.stat childPath, (error, stats) ->
|
||||
if error
|
||||
callback(error)
|
||||
else if stats.isFile()
|
||||
onFile(childPath)
|
||||
callback()
|
||||
else if stats.isDirectory()
|
||||
if onDirectory(childPath)
|
||||
fs.readdir childPath, (error, files) ->
|
||||
if error
|
||||
callback(error)
|
||||
else
|
||||
for file in files
|
||||
queue.unshift(path.join(childPath, file))
|
||||
callback()
|
||||
else
|
||||
callback()
|
||||
queue.concurrency = 1
|
||||
queue.drain = onDone
|
||||
queue.push(path.join(rootPath, file)) for file in files
|
||||
|
||||
# Public: Hashes the contents of the given file.
|
||||
#
|
||||
# * pathToDigest:
|
||||
# The String containing the absolute path.
|
||||
#
|
||||
# Returns a String containing the MD5 hexadecimal hash.
|
||||
md5ForPath: (pathToDigest) ->
|
||||
contents = fs.readFileSync(pathToDigest)
|
||||
require('crypto').createHash('md5').update(contents).digest('hex')
|
||||
|
||||
# Public: Finds a relative path among the given array of paths.
|
||||
#
|
||||
# * loadPaths:
|
||||
# An Array of absolute and relative paths to search.
|
||||
# * pathToResolve:
|
||||
# The string containing the path to resolve.
|
||||
# * extensions:
|
||||
# An array of extensions to pass to {resolveExtensions} in which case
|
||||
# pathToResolve should not contain an extension (optional).
|
||||
#
|
||||
# Returns the absolute path of the file to be resolved if it's found and
|
||||
# undefined otherwise.
|
||||
resolve: (args...) ->
|
||||
extensions = args.pop() if _.isArray(_.last(args))
|
||||
pathToResolve = args.pop()
|
||||
loadPaths = args
|
||||
|
||||
if @isAbsolute(pathToResolve)
|
||||
if extensions and resolvedPath = @resolveExtension(pathToResolve, extensions)
|
||||
return resolvedPath
|
||||
else
|
||||
return pathToResolve if @exists(pathToResolve)
|
||||
|
||||
for loadPath in loadPaths
|
||||
candidatePath = path.join(loadPath, pathToResolve)
|
||||
if extensions
|
||||
if resolvedPath = @resolveExtension(candidatePath, extensions)
|
||||
return resolvedPath
|
||||
else
|
||||
return @absolute(candidatePath) if @exists(candidatePath)
|
||||
undefined
|
||||
|
||||
# Deprecated:
|
||||
resolveOnLoadPath: (args...) ->
|
||||
loadPaths = Module.globalPaths.concat(module.paths)
|
||||
@resolve(loadPaths..., args...)
|
||||
|
||||
# Public: Finds the first file in the given path which matches the extension
|
||||
# in the order given.
|
||||
#
|
||||
# * pathToResolve:
|
||||
# The String containing relative or absolute path of the file in question
|
||||
# without the extension or '.'.
|
||||
# * extensions:
|
||||
# The ordered Array of extensions to try.
|
||||
#
|
||||
# Returns the absolute path of the file if it exists with any of the given
|
||||
# extensions, otherwise it's undefined.
|
||||
resolveExtension: (pathToResolve, extensions) ->
|
||||
for extension in extensions
|
||||
if extension == ""
|
||||
return @absolute(pathToResolve) if @exists(pathToResolve)
|
||||
else
|
||||
pathWithExtension = pathToResolve + "." + extension.replace(/^\./, "")
|
||||
return @absolute(pathWithExtension) if @exists(pathWithExtension)
|
||||
undefined
|
||||
|
||||
# Public: Returns true for extensions associated with compressed files.
|
||||
isCompressedExtension: (ext) ->
|
||||
_.indexOf([
|
||||
'.gz'
|
||||
'.jar'
|
||||
'.tar'
|
||||
'.tgz'
|
||||
'.zip'
|
||||
], ext, true) >= 0
|
||||
|
||||
# Public: Returns true for extensions associated with image files.
|
||||
isImageExtension: (ext) ->
|
||||
_.indexOf([
|
||||
'.gif'
|
||||
'.jpeg'
|
||||
'.jpg'
|
||||
'.png'
|
||||
'.tiff'
|
||||
], ext, true) >= 0
|
||||
|
||||
# Public: Returns true for extensions associated with pdf files.
|
||||
isPdfExtension: (ext) ->
|
||||
ext is '.pdf'
|
||||
|
||||
# Public: Returns true for extensions associated with binary files.
|
||||
isBinaryExtension: (ext) ->
|
||||
_.indexOf([
|
||||
'.DS_Store'
|
||||
'.a'
|
||||
'.o'
|
||||
'.so'
|
||||
'.woff'
|
||||
], ext, true) >= 0
|
||||
|
||||
# Public: Returns true for files named similarily to 'README'
|
||||
isReadmePath: (readmePath) ->
|
||||
extension = path.extname(readmePath)
|
||||
base = path.basename(readmePath, extension).toLowerCase()
|
||||
base is 'readme' and (extension is '' or @isMarkdownExtension(extension))
|
||||
|
||||
# Private: Used by isReadmePath.
|
||||
isMarkdownExtension: (ext) ->
|
||||
_.indexOf([
|
||||
'.markdown'
|
||||
'.md'
|
||||
'.mdown'
|
||||
'.mkd'
|
||||
'.mkdown'
|
||||
'.ron'
|
||||
], ext, true) >= 0
|
||||
|
||||
# Public: Reads and returns CSON, JSON or Plist files and returns the
|
||||
# corresponding Object.
|
||||
readObjectSync: (objectPath) ->
|
||||
CSON = require 'season'
|
||||
if CSON.isObjectPath(objectPath)
|
||||
CSON.readFileSync(objectPath)
|
||||
else
|
||||
@readPlistSync(objectPath)
|
||||
|
||||
# Public: Reads and returns CSON, JSON or Plist files and calls the specified
|
||||
# callback with the corresponding Object.
|
||||
readObject: (objectPath, done) ->
|
||||
CSON = require 'season'
|
||||
if CSON.isObjectPath(objectPath)
|
||||
CSON.readFile(objectPath, done)
|
||||
else
|
||||
@readPlist(objectPath, done)
|
||||
|
||||
# Private: Used by readObjectSync.
|
||||
readPlistSync: (plistPath) ->
|
||||
plist = require 'plist'
|
||||
plist.parseStringSync(@read(plistPath))
|
||||
|
||||
# Private: Used by readObject.
|
||||
readPlist: (plistPath, done) ->
|
||||
plist = require 'plist'
|
||||
fs.readFile plistPath, 'utf8', (error, contents) ->
|
||||
if error?
|
||||
done(error)
|
||||
else
|
||||
try
|
||||
done(null, plist.parseStringSync(contents))
|
||||
catch parseError
|
||||
done(parseError)
|
||||
|
||||
module.exports = _.extend({}, fs, fsExtensions)
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
_ = require 'underscore-plus'
|
||||
fsUtils = require './fs-utils'
|
||||
fs = require 'fs-plus'
|
||||
Task = require './task'
|
||||
{Emitter, Subscriber} = require 'emissary'
|
||||
GitUtils = require 'git-utils'
|
||||
@@ -106,7 +106,7 @@ class Git
|
||||
|
||||
# Public: Returns the path of the repository.
|
||||
getPath: ->
|
||||
@path ?= fsUtils.absolute(@getRepo().getPath())
|
||||
@path ?= fs.absolute(@getRepo().getPath())
|
||||
|
||||
# Public: Returns the working directory of the repository.
|
||||
getWorkingDirectory: -> @getRepo().getWorkingDirectory()
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{$} = require './space-pen-extensions'
|
||||
_ = require 'underscore-plus'
|
||||
fsUtils = require './fs-utils'
|
||||
fs = require 'fs-plus'
|
||||
path = require 'path'
|
||||
CSON = require 'season'
|
||||
BindingSet = require './binding-set'
|
||||
@@ -41,7 +41,7 @@ class Keymap
|
||||
@load(userKeymapPath) if userKeymapPath
|
||||
|
||||
loadDirectory: (directoryPath) ->
|
||||
@load(filePath) for filePath in fsUtils.listSync(directoryPath, ['.cson', '.json'])
|
||||
@load(filePath) for filePath in fs.listSync(directoryPath, ['.cson', '.json'])
|
||||
|
||||
load: (path) ->
|
||||
@add(path, CSON.readFileSync(path))
|
||||
|
||||
@@ -3,8 +3,7 @@ path = require 'path'
|
||||
_ = require 'underscore-plus'
|
||||
ipc = require 'ipc'
|
||||
CSON = require 'season'
|
||||
|
||||
fsUtils = require './fs-utils'
|
||||
fs = require 'fs-plus'
|
||||
|
||||
# Public: Provides a registry for menu items that you'd like to appear in the
|
||||
# application menu.
|
||||
@@ -37,7 +36,7 @@ class MenuManager
|
||||
|
||||
# Private
|
||||
loadCoreItems: ->
|
||||
menuPaths = fsUtils.listSync(atom.config.bundledMenusDirPath, ['cson', 'json'])
|
||||
menuPaths = fs.listSync(atom.config.bundledMenusDirPath, ['cson', 'json'])
|
||||
for menuPath in menuPaths
|
||||
data = CSON.readFileSync(menuPath)
|
||||
@add(data.menu)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{Emitter} = require 'emissary'
|
||||
fsUtils = require './fs-utils'
|
||||
fs = require 'fs-plus'
|
||||
_ = require 'underscore-plus'
|
||||
Package = require './package'
|
||||
path = require 'path'
|
||||
@@ -173,10 +173,10 @@ class PackageManager
|
||||
pack for pack in @getLoadedPackages() when pack.getType() in types
|
||||
|
||||
resolvePackagePath: (name) ->
|
||||
return name if fsUtils.isDirectorySync(name)
|
||||
return name if fs.isDirectorySync(name)
|
||||
|
||||
packagePath = fsUtils.resolve(@packageDirPaths..., name)
|
||||
return packagePath if fsUtils.isDirectorySync(packagePath)
|
||||
packagePath = fs.resolve(@packageDirPaths..., name)
|
||||
return packagePath if fs.isDirectorySync(packagePath)
|
||||
|
||||
packagePath = path.join(@resourcePath, 'node_modules', name)
|
||||
return packagePath if @isInternalPackage(packagePath)
|
||||
@@ -192,16 +192,16 @@ class PackageManager
|
||||
packagePaths = []
|
||||
|
||||
for packageDirPath in @packageDirPaths
|
||||
for packagePath in fsUtils.listSync(packageDirPath)
|
||||
packagePaths.push(packagePath) if fsUtils.isDirectorySync(packagePath)
|
||||
for packagePath in fs.listSync(packageDirPath)
|
||||
packagePaths.push(packagePath) if fs.isDirectorySync(packagePath)
|
||||
|
||||
try
|
||||
metadataPath = path.join(@resourcePath, 'package.json')
|
||||
{packageDependencies} = JSON.parse(fsUtils.read(metadataPath)) ? {}
|
||||
{packageDependencies} = JSON.parse(fs.readFileSync(metadataPath)) ? {}
|
||||
packagesPath = path.join(@resourcePath, 'node_modules')
|
||||
for packageName, packageVersion of packageDependencies ? {}
|
||||
packagePath = path.join(packagesPath, packageName)
|
||||
packagePaths.push(packagePath) if fsUtils.isDirectorySync(packagePath)
|
||||
packagePaths.push(packagePath) if fs.isDirectorySync(packagePath)
|
||||
|
||||
_.uniq(packagePaths)
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
fsUtils = require './fs-utils'
|
||||
path = require 'path'
|
||||
url = require 'url'
|
||||
Q = require 'q'
|
||||
|
||||
_ = require 'underscore-plus'
|
||||
fs = require 'fs-plus'
|
||||
Q = require 'q'
|
||||
telepath = require 'telepath'
|
||||
{Range} = telepath
|
||||
|
||||
TextBuffer = require './text-buffer'
|
||||
EditSession = require './edit-session'
|
||||
{Emitter} = require 'emissary'
|
||||
@@ -116,7 +117,7 @@ class Project
|
||||
|
||||
@destroyRepo()
|
||||
if projectPath?
|
||||
directory = if fsUtils.isDirectorySync(projectPath) then projectPath else path.dirname(projectPath)
|
||||
directory = if fs.isDirectorySync(projectPath) then projectPath else path.dirname(projectPath)
|
||||
@rootDirectory = new Directory(directory)
|
||||
if @repo = Git.open(projectPath, project: this)
|
||||
@repo.refreshIndex()
|
||||
@@ -159,8 +160,8 @@ class Project
|
||||
if uri?.match(/[A-Za-z0-9+-.]+:\/\//) # leave path alone if it has a scheme
|
||||
uri
|
||||
else
|
||||
uri = path.join(@getPath(), uri) unless fsUtils.isAbsolute(uri)
|
||||
fsUtils.absolute uri
|
||||
uri = path.join(@getPath(), uri) unless fs.isAbsolute(uri)
|
||||
fs.absolute uri
|
||||
|
||||
# Public: Make the given path relative to the project directory.
|
||||
relativize: (fullPath) ->
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
fs = require 'fs'
|
||||
ipc = require 'ipc'
|
||||
path = require 'path'
|
||||
Q = require 'q'
|
||||
{$, $$, View} = require './space-pen-extensions'
|
||||
fsUtils = require './fs-utils'
|
||||
_ = require 'underscore-plus'
|
||||
fs = require 'fs-plus'
|
||||
telepath = require 'telepath'
|
||||
Editor = require './editor'
|
||||
Pane = require './pane'
|
||||
@@ -180,9 +179,6 @@ class RootView extends View
|
||||
editSession = activePane.itemForUri(project.relativize(filePath)) if activePane and filePath
|
||||
promise = project.open(filePath, {initialLine}) if not editSession
|
||||
|
||||
fileSize = 0
|
||||
fileSize = fs.statSync(filePath).size if fsUtils.exists(filePath)
|
||||
|
||||
Q(editSession ? promise).then (editSession) =>
|
||||
if not activePane
|
||||
activePane = new Pane(editSession)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
_ = require 'underscore-plus'
|
||||
{specificity} = require 'clear-cut'
|
||||
{$, $$} = require './space-pen-extensions'
|
||||
fsUtils = require './fs-utils'
|
||||
{Emitter} = require 'emissary'
|
||||
NullGrammar = require './null-grammar'
|
||||
TextMateScopeSelector = require('first-mate').ScopeSelector
|
||||
|
||||
@@ -6,7 +6,6 @@ Q = require 'q'
|
||||
telepath = require 'telepath'
|
||||
|
||||
_ = require 'underscore-plus'
|
||||
fsUtils = require './fs-utils'
|
||||
File = require './file'
|
||||
|
||||
{Point, Range} = telepath
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
_ = require 'underscore-plus'
|
||||
fsUtils = require './fs-utils'
|
||||
plist = require 'plist'
|
||||
fs = require 'fs-plus'
|
||||
Token = require './token'
|
||||
{OnigRegExp, OnigScanner} = require 'oniguruma'
|
||||
path = require 'path'
|
||||
@@ -16,14 +15,14 @@ class TextMateGrammar
|
||||
Emitter.includeInto(this)
|
||||
|
||||
@load: (grammarPath, done) ->
|
||||
fsUtils.readObject grammarPath, (error, object) ->
|
||||
fs.readObject grammarPath, (error, object) ->
|
||||
if error?
|
||||
done(error)
|
||||
else
|
||||
done(null, new TextMateGrammar(object))
|
||||
|
||||
@loadSync: (grammarPath) ->
|
||||
new TextMateGrammar(fsUtils.readObjectSync(grammarPath))
|
||||
new TextMateGrammar(fs.readObjectSync(grammarPath))
|
||||
|
||||
name: null
|
||||
rawPatterns: null
|
||||
@@ -74,7 +73,7 @@ class TextMateGrammar
|
||||
true
|
||||
|
||||
getScore: (filePath, contents) ->
|
||||
contents = fsUtils.read(filePath) if not contents? and fsUtils.isFileSync(filePath)
|
||||
contents = fs.readFileSync(filePath, 'utf8') if not contents? and fs.isFileSync(filePath)
|
||||
|
||||
if syntax.grammarOverrideForPath(filePath) is @scopeName
|
||||
2 + (filePath?.length ? 0)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Package = require './package'
|
||||
fsUtils = require './fs-utils'
|
||||
path = require 'path'
|
||||
_ = require 'underscore-plus'
|
||||
fs = require 'fs-plus'
|
||||
TextMateGrammar = require './text-mate-grammar'
|
||||
async = require 'async'
|
||||
|
||||
@@ -54,9 +54,9 @@ class TextMatePackage extends Package
|
||||
legalGrammarExtensions: ['plist', 'tmLanguage', 'tmlanguage', 'json', 'cson']
|
||||
|
||||
loadGrammars: (done) ->
|
||||
fsUtils.isDirectory @getSyntaxesPath(), (isDirectory) =>
|
||||
fs.isDirectory @getSyntaxesPath(), (isDirectory) =>
|
||||
if isDirectory
|
||||
fsUtils.list @getSyntaxesPath(), @legalGrammarExtensions, (error, paths) =>
|
||||
fs.list @getSyntaxesPath(), @legalGrammarExtensions, (error, paths) =>
|
||||
if error?
|
||||
console.log("Error loading grammars of TextMate package '#{@path}':", error.stack, error)
|
||||
done()
|
||||
@@ -72,7 +72,7 @@ class TextMatePackage extends Package
|
||||
done()
|
||||
|
||||
loadGrammarsSync: ->
|
||||
for grammarPath in fsUtils.listSync(@getSyntaxesPath(), @legalGrammarExtensions)
|
||||
for grammarPath in fs.listSync(@getSyntaxesPath(), @legalGrammarExtensions)
|
||||
@addGrammar(TextMateGrammar.loadSync(grammarPath))
|
||||
|
||||
addGrammar: (grammar) ->
|
||||
@@ -83,14 +83,14 @@ class TextMatePackage extends Package
|
||||
|
||||
getSyntaxesPath: ->
|
||||
syntaxesPath = path.join(@path, "syntaxes")
|
||||
if fsUtils.isDirectorySync(syntaxesPath)
|
||||
if fs.isDirectorySync(syntaxesPath)
|
||||
syntaxesPath
|
||||
else
|
||||
path.join(@path, "Syntaxes")
|
||||
|
||||
getPreferencesPath: ->
|
||||
preferencesPath = path.join(@path, "preferences")
|
||||
if fsUtils.isDirectorySync(preferencesPath)
|
||||
if fs.isDirectorySync(preferencesPath)
|
||||
preferencesPath
|
||||
else
|
||||
path.join(@path, "Preferences")
|
||||
@@ -101,8 +101,8 @@ class TextMatePackage extends Package
|
||||
selector = syntax.cssSelectorFromScopeSelector(grammar.scopeName)
|
||||
@scopedProperties.push({selector, properties})
|
||||
|
||||
for preferencePath in fsUtils.listSync(@getPreferencesPath())
|
||||
{scope, settings} = fsUtils.readObjectSync(preferencePath)
|
||||
for preferencePath in fs.listSync(@getPreferencesPath())
|
||||
{scope, settings} = fs.readObjectSync(preferencePath)
|
||||
if properties = @propertiesFromTextMateSettings(settings)
|
||||
selector = syntax.cssSelectorFromScopeSelector(scope) if scope?
|
||||
@scopedProperties.push({selector, properties})
|
||||
@@ -134,17 +134,17 @@ class TextMatePackage extends Package
|
||||
@loadTextMatePreferenceObjects(preferenceObjects, done)
|
||||
|
||||
loadTextMatePreferenceObjects: (preferenceObjects, done) ->
|
||||
fsUtils.isDirectory @getPreferencesPath(), (isDirectory) =>
|
||||
fs.isDirectory @getPreferencesPath(), (isDirectory) =>
|
||||
return done() unless isDirectory
|
||||
|
||||
fsUtils.list @getPreferencesPath(), (error, paths) =>
|
||||
fs.list @getPreferencesPath(), (error, paths) =>
|
||||
if error?
|
||||
console.log("Error loading preferences of TextMate package '#{@path}':", error.stack, error)
|
||||
done()
|
||||
return
|
||||
|
||||
loadPreferencesAtPath = (preferencePath, done) ->
|
||||
fsUtils.readObject preferencePath, (error, preferences) =>
|
||||
fs.readObject preferencePath, (error, preferences) =>
|
||||
if error?
|
||||
console.warn("Failed to parse preference at path '#{preferencePath}'", error.stack, error)
|
||||
else
|
||||
|
||||
+13
-11
@@ -1,11 +1,13 @@
|
||||
path = require 'path'
|
||||
{Emitter} = require 'emissary'
|
||||
Package = require './package'
|
||||
AtomPackage = require './atom-package'
|
||||
|
||||
_ = require 'underscore-plus'
|
||||
{Emitter} = require 'emissary'
|
||||
fs = require 'fs-plus'
|
||||
|
||||
Package = require './package'
|
||||
AtomPackage = require './atom-package'
|
||||
{$} = require './space-pen-extensions'
|
||||
fsUtils = require './fs-utils'
|
||||
|
||||
|
||||
# Private: Handles discovering and loading available themes.
|
||||
###
|
||||
@@ -81,12 +83,12 @@ class ThemeManager
|
||||
if themePath = @packageManager.resolvePackagePath(themeName)
|
||||
themePaths.push(path.join(themePath, AtomPackage.stylesheetsDir))
|
||||
|
||||
themePath for themePath in themePaths when fsUtils.isDirectorySync(themePath)
|
||||
themePath for themePath in themePaths when fs.isDirectorySync(themePath)
|
||||
|
||||
# Public:
|
||||
getUserStylesheetPath: ->
|
||||
stylesheetPath = fsUtils.resolve(path.join(atom.config.configDirPath, 'user'), ['css', 'less'])
|
||||
if fsUtils.isFileSync(stylesheetPath)
|
||||
stylesheetPath = fs.resolve(path.join(atom.config.configDirPath, 'user'), ['css', 'less'])
|
||||
if fs.isFileSync(stylesheetPath)
|
||||
stylesheetPath
|
||||
else
|
||||
null
|
||||
@@ -106,7 +108,7 @@ class ThemeManager
|
||||
# Internal-only:
|
||||
reloadBaseStylesheets: ->
|
||||
@requireStylesheet('../static/atom')
|
||||
if nativeStylesheetPath = fsUtils.resolveOnLoadPath(process.platform, ['css', 'less'])
|
||||
if nativeStylesheetPath = fs.resolveOnLoadPath(process.platform, ['css', 'less'])
|
||||
@requireStylesheet(nativeStylesheetPath)
|
||||
|
||||
# Internal-only:
|
||||
@@ -116,9 +118,9 @@ class ThemeManager
|
||||
# Internal-only:
|
||||
resolveStylesheet: (stylesheetPath) ->
|
||||
if path.extname(stylesheetPath).length > 0
|
||||
fsUtils.resolveOnLoadPath(stylesheetPath)
|
||||
fs.resolveOnLoadPath(stylesheetPath)
|
||||
else
|
||||
fsUtils.resolveOnLoadPath(stylesheetPath, ['css', 'less'])
|
||||
fs.resolveOnLoadPath(stylesheetPath, ['css', 'less'])
|
||||
|
||||
# Public: resolves and applies the stylesheet specified by the path.
|
||||
#
|
||||
@@ -140,7 +142,7 @@ class ThemeManager
|
||||
if path.extname(stylesheetPath) is '.less'
|
||||
@loadLessStylesheet(stylesheetPath)
|
||||
else
|
||||
fsUtils.read(stylesheetPath)
|
||||
fs.readFileSync(stylesheetPath, 'utf8')
|
||||
|
||||
# Internal-only:
|
||||
loadLessStylesheet: (lessStylesheetPath) ->
|
||||
|
||||
@@ -3,7 +3,7 @@ _ = require 'underscore-plus'
|
||||
ipc = require 'ipc'
|
||||
shell = require 'shell'
|
||||
{Subscriber} = require 'emissary'
|
||||
fsUtils = require './fs-utils'
|
||||
fs = require 'fs-plus'
|
||||
|
||||
# Private: Handles low-level events related to the window.
|
||||
module.exports =
|
||||
@@ -28,7 +28,7 @@ class WindowEventHandler
|
||||
@subscribe $(window), 'blur', -> $("body").addClass('is-blurred')
|
||||
|
||||
@subscribe $(window), 'window:open-path', (event, {pathToOpen, initialLine}) ->
|
||||
unless fsUtils.isDirectorySync(pathToOpen)
|
||||
unless fs.isDirectorySync(pathToOpen)
|
||||
atom.rootView?.open(pathToOpen, {initialLine})
|
||||
|
||||
@subscribe $(window), 'beforeunload', =>
|
||||
|
||||
@@ -26,7 +26,7 @@ module.exports = (grunt) ->
|
||||
grunt.log.writeln("Launching #{path.basename(packagePath)} specs.")
|
||||
spawn options, (error, results, code) ->
|
||||
grunt.log.writeln()
|
||||
passed = passed and code is 0
|
||||
passed = passed and not error and code is 0
|
||||
callback()
|
||||
|
||||
modulesDirectory = path.resolve('node_modules')
|
||||
@@ -51,7 +51,7 @@ module.exports = (grunt) ->
|
||||
spawn options, (error, results, code) ->
|
||||
grunt.log.writeln()
|
||||
packageSpecQueue.concurrency = 2
|
||||
callback(null, code is 0)
|
||||
callback(null, not error and code is 0)
|
||||
|
||||
grunt.registerTask 'run-specs', 'Run the specs', ->
|
||||
done = @async()
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário