diff --git a/src/editor.coffee b/src/editor.coffee index d4d21f7af..a064499cc 100644 --- a/src/editor.coffee +++ b/src/editor.coffee @@ -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' diff --git a/src/fs.coffee b/src/fs.coffee new file mode 100644 index 000000000..78e1214e6 --- /dev/null +++ b/src/fs.coffee @@ -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 diff --git a/src/osx.coffee b/src/osx.coffee index 276563412..bc401d22f 100644 --- a/src/osx.coffee +++ b/src/osx.coffee @@ -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 diff --git a/src/plugins.coffee b/src/plugins.coffee index d7ccd5a73..abe2261d0 100644 --- a/src/plugins.coffee +++ b/src/plugins.coffee @@ -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