mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
move File module into fs.coffee. rename File.expand to File.absolute
absolute() is the commonjs form of expand()
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
$ = require 'jquery'
|
||||
_ = require 'underscore'
|
||||
|
||||
{Chrome, File, Process, Dir} = require 'osx'
|
||||
{Chrome, Process, Dir} = require 'osx'
|
||||
File = require 'fs'
|
||||
|
||||
ace = require 'ace/ace'
|
||||
canon = require 'pilot/canon'
|
||||
|
||||
30
src/fs.coffee
Normal file
30
src/fs.coffee
Normal file
@@ -0,0 +1,30 @@
|
||||
# commonjs fs module
|
||||
# http://ringojs.org/api/v0.8/fs/
|
||||
|
||||
module.exports =
|
||||
# Make the given path absolute by resolving it against the
|
||||
# current working directory.
|
||||
absolute: (path) ->
|
||||
if /~/.test path
|
||||
OSX.NSString.stringWithString(path).stringByExpandingTildeInPath
|
||||
else if path.indexOf('./') is 0
|
||||
"#{Chrome.appRoot}/#{path}"
|
||||
else
|
||||
path
|
||||
|
||||
# Returns true if the file specified by path exists and is a
|
||||
# regular file.
|
||||
isFile: (path) ->
|
||||
isDir = new jscocoa.outArgument
|
||||
exists = OSX.NSFileManager.defaultManager.
|
||||
fileExistsAtPath_isDirectory path, isDir
|
||||
exists and not isDir.valueOf()
|
||||
|
||||
# Open, read, and close a file, returning the file's contents.
|
||||
read: (path) ->
|
||||
OSX.NSString.stringWithContentsOfFile(@absolute path).toString()
|
||||
|
||||
# Open, write, flush, and close a file, writing the given content.
|
||||
write: (path, content) ->
|
||||
str = OSX.NSString.stringWithString content
|
||||
str.writeToFile_atomically @absolute(path), true
|
||||
@@ -4,6 +4,7 @@ $ = require 'jquery'
|
||||
_ = require 'underscore'
|
||||
jscocoa = require 'jscocoa'
|
||||
Editor = require 'editor'
|
||||
File = require 'fs'
|
||||
|
||||
# Handles the UI chrome
|
||||
Chrome =
|
||||
@@ -87,28 +88,9 @@ Chrome =
|
||||
OSX.NSBundle.mainBundle.resourcePath
|
||||
|
||||
# Handles the file system
|
||||
File =
|
||||
read: (path) ->
|
||||
OSX.NSString.stringWithContentsOfFile(File.expand path).toString()
|
||||
write: (path, contents) ->
|
||||
str = OSX.NSString.stringWithString contents
|
||||
str.writeToFile_atomically File.expand(path), true
|
||||
expand: (path) ->
|
||||
if /~/.test path
|
||||
OSX.NSString.stringWithString(path).stringByExpandingTildeInPath
|
||||
else if path.indexOf('./') is 0
|
||||
"#{Chrome.appRoot}/#{path}"
|
||||
else
|
||||
path
|
||||
isFile: (path) ->
|
||||
isDir = new jscocoa.outArgument
|
||||
exists = OSX.NSFileManager.defaultManager.
|
||||
fileExistsAtPath_isDirectory path, isDir
|
||||
exists and not isDir.valueOf()
|
||||
|
||||
Dir =
|
||||
list: (path, recursive) ->
|
||||
path = File.expand path
|
||||
path = File.absolute path
|
||||
fm = OSX.NSFileManager.defaultManager
|
||||
if recursive
|
||||
paths = fm.subpathsAtPath path
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
$ = require 'jquery'
|
||||
_ = require 'underscore'
|
||||
|
||||
{Chrome, Dir, File} = require 'osx'
|
||||
{Chrome, Dir} = require 'osx'
|
||||
File = require 'fs'
|
||||
|
||||
_.map Dir.list(Chrome.appRoot() + "/plugins"), (plugin) ->
|
||||
require plugin
|
||||
|
||||
Reference in New Issue
Block a user