Permalink
Browse files

Rewrote main module in JavaScript. Added Travis-CI. Added jsonfile de…

…pendence.
  • Loading branch information...
1 parent 66ed3ea commit 179033d0fa7a5664424a8996a127750931700cc0 @jprichardson committed Sep 10, 2012
Showing with 228 additions and 315 deletions.
  1. +4 −0 .travis.yml
  2. +6 −0 CHANGELOG.md
  3. +72 −20 README.md
  4. +42 −48 lib/copy.js
  5. +11 −0 lib/create.js
  6. +36 −45 lib/index.js
  7. +3 −8 lib/mkdir.js
  8. +0 −24 lib/read.js
  9. +10 −32 lib/remove.js
  10. +44 −29 package.json
  11. +0 −32 src/copy.coffee
  12. +0 −35 src/index.coffee
  13. +0 −4 src/mkdir.coffee
  14. +0 −13 src/read.coffee
  15. +0 −25 src/remove.coffee
View
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+ - 0.6
+ - 0.8
View
@@ -1,3 +1,9 @@
+0.2.0 / 2012-09-10
+------------------
+* Rewrote module into JavaScript. (Must still rewrite tests into JavaScript)
+* Added all methods of [jsonfile][https://github.com/jprichardson/node-jsonfile]
+* Added Travis-CI.
+
0.1.3 / 2012-08-13
------------------
* Added method `readJSONFile`.
View
@@ -1,3 +1,5 @@
+[![build status](https://secure.travis-ci.org/jprichardson/node-fs-extra.png)](http://travis-ci.org/jprichardson/node-fs-extra)
+
Node.js: fs-extra
=================
@@ -12,22 +14,6 @@ I got tired of including `mkdirp` and `rimraf` in most of my projects.
-Installation
-------------
-
- npm install fs-extra
-
-
-
-Usage
------
-
-```javascript
-var fs = require('fs-extra');
-```
-
-
-
Naming
------
@@ -50,20 +36,35 @@ So, if you want to remove a file or a directory regardless of whether it has con
-
Compromise
----------
If you feel that this module should add functionality, please let me know. If you don't like the naming scheme, let me know that as well. I'm willing to work with the community so that we can develop a logical grouping of file system functions that aren't found Node.js.
+Installation
+------------
+
+ npm install fs-extra
+
+
+
+Usage
+-----
+
+```javascript
+var fs = require('fs-extra');
+```
+
+
Methods
-------
**NOTE:** You can still use the native Node.js methods. They are copied over to `fs-extra`.
+
### copy()
Copy a file or directory. The directory can have contents. Like `cp -r`. There isn't a synchronous version implemented yet.
@@ -93,6 +94,7 @@ fs.copy('/tmp/mydir', '/tmp/mynewdir'function(err){
```
+
### remove()
Removes a file or directory. The directory can have contents. Like `rm -rf`.
@@ -117,6 +119,7 @@ fs.removeSync('/home/jprichardson'); //I just deleted my entire HOME directory.
```
+
### mkdir()
Creates a directory. If the parent hierarchy doesn't exist, it's created. Like `mkdir -p`.
@@ -145,7 +148,11 @@ fs.mkdir('/tmp/node/cant/do/this', function(err){
});
```
-### fs.readJSONFile()
+
+
+### Methods from [jsonfile][jsonfile]
+
+### fs.readJSONFile() / fs.readJSONFileSync()
Reads a JSON file and then parses it into an object.
@@ -159,16 +166,61 @@ fs.readJSONFile('./package.json', function(err, packageObj) {
});
```
+
+### fs.writeJSONFile() / fs.writeJSONFileSync()
+
+Writes an object to a JSON file.
+
+Example:
+
+```javascript
+var fs = require('fs-extra');
+fs.writeJSONFile('./package.json', {name: 'fs-extra'}, function(err){
+ console.log(err);
+});
+```
+
+
+
### exists() / existsSync()
-These methods are actually from `path`. But in Node v0.8 they are moved from `path` to `fs`. So you might as well start future proofing your code now.
+These methods are actually from `path`. But in Node v0.8 they are moved from `path` to `fs`. So you can use this module to help make your modules v0.6 and v0.8 compatible.
+
-## License
+TODO
+----
+
+* Remove all CoffeeScript from tests.
+
+
+
+Author
+------
+
+`node-fs-extra` was written by [JP Richardson][aboutjp]. You should follow him on Twitter [@jprichardson][twitter]. Also read his coding blog [Procbits][procbits]. If you write software with others, you should checkout [Gitpilot][gitpilot] to make collaboration with Git simple.
+
+
+
+
+License
+-------
+
Licensed under MIT
Copyright (c) 2011-2012 JP Richardson
[1]: http://nodejs.org/docs/latest/api/fs.html
+
+[jsonfile]: https://github.com/jprichardson/node-jsonfile
+
+
+[aboutjp]: http://about.me/jprichardson
+[twitter]: http://twitter.com/jprichardson
+[procbits]: http://procbits.com
+[gitpilot]: http://gitpilot.com
+
+
+
View
@@ -1,48 +1,42 @@
-// Generated by CoffeeScript 1.3.3
-(function() {
- var BUF_LENGTH, copy, copyFile, copyFileSync, fs, ncp, _buff;
-
- fs = require('fs');
-
- ncp = require('ncp').ncp;
-
- BUF_LENGTH = 64 * 1024;
-
- _buff = new Buffer(BUF_LENGTH);
-
- copyFileSync = function(srcFile, destFile) {
- var bytesRead, fdr, fdw, pos;
- fdr = fs.openSync(srcFile, 'r');
- fdw = fs.openSync(destFile, 'w');
- bytesRead = 1;
- pos = 0;
- while (bytesRead > 0) {
- bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos);
- fs.writeSync(fdw, _buff, 0, bytesRead);
- pos += bytesRead;
- }
- fs.closeSync(fdr);
- return fs.closeSync(fdw);
- };
-
- copyFile = function(srcFile, destFile, cb) {
- var fdr, fdw;
- fdr = fs.createReadStream(srcFile);
- fdw = fs.createWriteStream(destFile);
- fdr.on('end', function() {
- return cb(null);
- });
- return fdr.pipe(fdw);
- };
-
- copy = function(source, dest, callback) {
- return ncp(source, dest, callback);
- };
-
- module.exports.copyFileSync = copyFileSync;
-
- module.exports.copyFile = copyFile;
-
- module.exports.copy = copy;
-
-}).call(this);
+var fs = require('fs')
+ , ncp = require('ncp').ncp;
+
+var BUF_LENGTH = 64 * 1024;
+var _buff = new Buffer(BUF_LENGTH);
+
+copyFileSync = function(srcFile, destFile) {
+ var bytesRead, fdr, fdw, pos;
+ fdr = fs.openSync(srcFile, 'r');
+ fdw = fs.openSync(destFile, 'w');
+ bytesRead = 1;
+ pos = 0;
+ while (bytesRead > 0) {
+ bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos);
+ fs.writeSync(fdw, _buff, 0, bytesRead);
+ pos += bytesRead;
+ }
+ fs.closeSync(fdr);
+ return fs.closeSync(fdw);
+};
+
+copyFile = function(srcFile, destFile, cb) {
+ var fdr, fdw;
+ fdr = fs.createReadStream(srcFile);
+ fdw = fs.createWriteStream(destFile);
+ fdr.on('end', function() {
+ return cb(null);
+ });
+ return fdr.pipe(fdw);
+};
+
+function copy(source, dest, callback) {
+ if (callback)
+ ncp(source, dest, callback);
+ else
+ ncp(source, dest, function(){});
+};
+
+
+module.exports.copyFileSync = copyFileSync;
+module.exports.copyFile = copyFile;
+module.exports.copy = copy;
View
@@ -0,0 +1,11 @@
+var fs = require('fs');
+
+function touch(path, callback) {
+ fs.writeFile(path, '', callback);
+}
+
+function touchSync(path) {
+
+}
+
+module.exports.touch = touch;
View
@@ -1,54 +1,45 @@
-// Generated by CoffeeScript 1.3.3
-(function() {
- var copy, fs, fse, key, mkdir, path, read, remove, val;
-
- fs = require('fs');
-
- path = require('path');
-
- fse = {};
-
- for (key in fs) {
- val = fs[key];
- if (typeof val === 'function') {
- fse[key] = val;
+var fs = require('fs')
+ , path = require('path')
+ , jsonFile = require('jsonfile')
+ , fse = {};
+
+for (var funcName in fs) {
+ var func = fs[funcName];
+ if (fs.hasOwnProperty(funcName)) {
+ if (typeof func == 'function')
+ fse[funcName] = func;
}
- }
-
- fs = fse;
-
- copy = require('./copy');
-
- fs.copy = copy.copy;
-
- remove = require('./remove');
-
- fs.remove = remove.remove;
-
- fs.removeSync = remove.removeSync;
-
- fs["delete"] = fs.remove;
-
- fs.deleteSync = fs.removeSync;
-
- mkdir = require('./mkdir');
+}
- fs.mkdir = mkdir.mkdir;
+fs = fse;
- fs.mkdirSync = mkdir.mkdirSync;
+fs.copy = require('./copy').copy;
- if (!(fs.exists != null)) {
- fs.exists = path.exists;
- }
+var remove = require('./remove');
+fs.remove = remove.remove;
+fs.removeSync = remove.removeSync;
+fs['delete'] = fs.remove
+fs.deleteSync = fs.removeSync
- if (!(fs.existsSync != null)) {
- fs.existsSync = path.existsSync;
- }
+var mkdir = require('./mkdir')
+fs.mkdir = mkdir.mkdir
+fs.mkdirSync = mkdir.mkdirSync
- read = require('./read');
+fs.readJsonFile = jsonFile.readFile;
+fs.readJSONFile = jsonFile.readFile;
+fs.readJsonFileSync = jsonFile.readFileSync;
+fs.readJSONFileSync = jsonFile.readFileSync;
- fs.readJSONFile = read.readJSONFile;
+fs.writeJsonFile = jsonFile.writeFile;
+fs.writeJSONFile = jsonFile.writeFile;
+fs.writeJsonFileSync = jsonFile.writeFileSync;
+fs.writeJSONFileSync = jsonFile.writeFileSync;
- module.exports = fs;
+//make compatible for Node v0.8
+if (typeof fs.exists == 'undefined')
+ fs.exists = path.exists
+if (typeof fs.existsSync == 'undefined')
+ fs.existsSync = path.existsSync
-}).call(this);
+module.exports = fs
+module.exports.jsonfile = jsonFile; //so users of fs-extra can modify jsonFile.spaces;
View
@@ -1,11 +1,6 @@
-// Generated by CoffeeScript 1.3.3
-(function() {
- var mkdirp;
+var mkdirp = require('mkdirp');
- mkdirp = require('mkdirp');
+module.exports.mkdir = mkdirp;
+module.exports.mkdirSync = mkdirp.sync;
- module.exports.mkdir = mkdirp;
- module.exports.mkdirSync = mkdirp.sync;
-
-}).call(this);
Oops, something went wrong.

0 comments on commit 179033d

Please sign in to comment.