move Dir into fs.coffee and commonjs it

This commit is contained in:
Chris Wanstrath 2011-09-03 23:11:35 -07:00
parent 884686f55f
commit 8b0b0e4ea3
6 changed files with 37 additions and 25 deletions

View File

@ -1,7 +1,8 @@
$ = require 'jquery'
_ = require 'underscore'
{Chrome, Dir, File, Process} = require 'osx'
{Chrome, Process} = require 'osx'
File = require 'fs'
Editor = require 'editor'
bindKey = Editor.bindKey
@ -40,10 +41,10 @@ exports.reload = ->
$('#project li').remove()
files = Dir.list dir
files = File.list dir
listItems = _.map files, (path) ->
filename = path.replace(dir, "").substring 1
type = if Dir.isDir(path) then 'dir' else 'file'
type = if File.isDir(path) then 'dir' else 'file'
"<li class='#{type}' path='#{encodeURIComponent path}'>#{filename}</li>"
$('#project .files').append listItems.join '\n'

View File

@ -1,7 +1,8 @@
$ = require 'jquery'
_ = require 'underscore'
{Chrome, File, Dir, Process} = require 'osx'
{Chrome, Process} = require 'osx'
File = require 'fs'
{bindKey} = require 'editor'

View File

@ -3,7 +3,7 @@
$ = require 'jquery'
_ = require 'underscore'
{Chrome, Process, Dir} = require 'osx'
{Chrome, Process} = require 'osx'
File = require 'fs'
ace = require 'ace/ace'
@ -24,7 +24,7 @@ save = ->
exports.open = open = (path) ->
filename = path
if Dir.isDir filename
if File.isDir filename
Process.cwd filename
Chrome.title _.last filename.split '/'
editor.getSession().setValue ""

View File

@ -12,6 +12,14 @@ module.exports =
else
path
# Returns true if the file specified by path exists and is a
# directory.
isDirectory: (path) ->
isDir = new jscocoa.outArgument
exists = OSX.NSFileManager.defaultManager.
fileExistsAtPath_isDirectory path, isDir
exists and isDir.valueOf()
# Returns true if the file specified by path exists and is a
# regular file.
isFile: (path) ->
@ -20,6 +28,24 @@ module.exports =
fileExistsAtPath_isDirectory path, isDir
exists and not isDir.valueOf()
# Returns an array with all the names of files contained
# in the directory path.
list: (path, recursive) ->
path = File.absolute path
fm = OSX.NSFileManager.defaultManager
if recursive
paths = fm.subpathsAtPath path
else
paths = fm.contentsOfDirectoryAtPath_error path, null
_.map paths, (entry) -> "#{path}/#{entry}"
# Return an array with all directories below (and including)
# the given path, as discovered by depth-first traversal. Entries
# are in lexically sorted order within directories. Symbolic links
# to directories are not traversed into.
listDirectoryTree: (path) ->
@list path, true
# Open, read, and close a file, returning the file's contents.
read: (path) ->
OSX.NSString.stringWithContentsOfFile(@absolute path).toString()

View File

@ -87,22 +87,6 @@ Chrome =
appRoot: ->
OSX.NSBundle.mainBundle.resourcePath
# Handles the file system
Dir =
list: (path, recursive) ->
path = File.absolute path
fm = OSX.NSFileManager.defaultManager
if recursive
paths = fm.subpathsAtPath path
else
paths = fm.contentsOfDirectoryAtPath_error path, null
_.map paths, (entry) -> "#{path}/#{entry}"
isDir: (path) ->
isDir = new jscocoa.outArgument
exists = OSX.NSFileManager.defaultManager.
fileExistsAtPath_isDirectory path, isDir
exists and isDir.valueOf()
Process =
cwd: (path) ->
if path?

View File

@ -1,10 +1,10 @@
$ = require 'jquery'
_ = require 'underscore'
{Chrome, Dir} = require 'osx'
{Chrome} = require 'osx'
File = require 'fs'
_.map Dir.list(Chrome.appRoot() + "/plugins"), (plugin) ->
_.map File.list(Chrome.appRoot() + "/plugins"), (plugin) ->
require plugin
if css = File.read "~/.atomicity/twilight.css"
@ -15,5 +15,5 @@ if css = File.read "~/.atomicity/twilight.css"
style.appendChild rules
head.appendChild style
_.map Dir.list("~/.atomicity/"), (path) ->
_.map File.list("~/.atomicity/"), (path) ->
require path