Browse Source

Renamed mkdir to mkdirp/mkdirs.

ci/travis-osximage
JP Richardson 12 years ago
parent
commit
8aa7c13d1b
  1. 8
      README.md
  2. 6
      lib/index.js
  3. 4
      lib/mkdir.js
  4. 12
      test/mkdir.test.js

8
README.md

@ -32,7 +32,7 @@ We have a dilemma though. How do you consistently name methods perform the follo
My perspective: when in doubt, err on the side of simplicity. Consider that for a moment. A directory is just a hierarchical grouping of directories and files. So when you want to copy it or remove it, in most cases you'll want to copy or remove all of its contents. When you want to create a directory, if the directory that it's suppose to be contained in does not exist, then in most cases you'll want to create that too.
So, if you want to remove a file or a directory regardless of whether it has contents, just call `fs.remove(path)` or its alias `fs.delete(path)`. If you want to copy a file or a directory whether it has contents, just call `fs.copy(source, destination)`. If you want to create a directory regardless of whether its parent directories exist, just call `fs.mkdir(path)`. (Note: you can still use the native Node.js `fs.mkdir()` method by requiring `fs` and calling `mkdir` on that object)
So, if you want to remove a file or a directory regardless of whether it has contents, just call `fs.remove(path)` or its alias `fs.delete(path)`. If you want to copy a file or a directory whether it has contents, just call `fs.copy(source, destination)`. If you want to create a directory regardless of whether its parent directories exist, just call `fs.mkdirs(path)` or `fs.mkdirp(path)`.
@ -120,7 +120,7 @@ fs.removeSync('/home/jprichardson'); //I just deleted my entire HOME directory.
### mkdir()
### mkdirs() / mkdirp()
Creates a directory. If the parent hierarchy doesn't exist, it's created. Like `mkdir -p`.
@ -130,7 +130,7 @@ Examples:
var fs = require('fs');
var fse = require('fs-extra');
fse.mkdir('/tmp/some/long/path/that/prob/doesnt/exist', function(err){
fse.mkdirs('/tmp/some/long/path/that/prob/doesnt/exist', function(err){
if (err) {
console.error(err);
}
@ -139,7 +139,7 @@ fse.mkdir('/tmp/some/long/path/that/prob/doesnt/exist', function(err){
}
});
fse.mkdirSync('/tmp/another/path');
fse.mkdirsSync('/tmp/another/path');
//now use Node.js native mkdir()

6
lib/index.js

@ -22,8 +22,10 @@ fs['delete'] = fs.remove
fs.deleteSync = fs.removeSync
var mkdir = require('./mkdir')
fs.mkdir = mkdir.mkdir
fs.mkdirSync = mkdir.mkdirSync
fs.mkdirs = mkdir.mkdirs
fs.mkdirsSync = mkdir.mkdirsSync
fs.mkdirp = mkdir.mkdirs
fs.mkdirpSync = mkdir.mkdirsSync
fs.readJsonFile = jsonFile.readFile;
fs.readJSONFile = jsonFile.readFile;

4
lib/mkdir.js

@ -1,6 +1,6 @@
var mkdirp = require('mkdirp');
module.exports.mkdir = mkdirp;
module.exports.mkdirSync = mkdirp.sync;
module.exports.mkdirs = mkdirp;
module.exports.mkdirsSync = mkdirp.sync;

12
test/mkdir.test.js

@ -4,13 +4,13 @@ var fs = require('../lib')
describe('fs-extra', function() {
describe('+ mkdir()', function() {
describe('+ mkdirs()', function() {
it('should make the directory', function(done) {
var dir = path.join(path.tempdir(), 'tmp-' + Date.now() + Math.random());
F (fs.existsSync(dir));
fs.mkdir(dir, function(err) {
fs.mkdirs(dir, function(err) {
T (err === null);
T (fs.existsSync(dir));
@ -24,7 +24,7 @@ describe('fs-extra', function() {
F (fs.existsSync(dir));
fs.mkdir(newDir, function(err) {
fs.mkdirs(newDir, function(err) {
T (err === null);
T (fs.existsSync(newDir));
@ -33,12 +33,12 @@ describe('fs-extra', function() {
})
})
describe('+ mkdirSync()', function() {
describe('+ mkdirsSync()', function() {
it('should make the directory', function(done) {
var dir = path.join(path.tempdir(), 'tmp-' + Date.now() + Math.random());
F (fs.existsSync(dir));
fs.mkdirSync(dir);
fs.mkdirsSync(dir);
T (fs.existsSync(dir));
done();
@ -49,7 +49,7 @@ describe('fs-extra', function() {
, newDir = path.join(dir, 'dfdf', 'ffff', 'aaa');
F (fs.existsSync(dir));
fs.mkdirSync(dir);
fs.mkdirsSync(dir);
T (fs.existsSync(dir));
done();

Loading…
Cancel
Save