motion
Version:
motion - moving development forward
96 lines (95 loc) • 19.6 kB
JSON
{
"_args": [
[
"fs-extra@https://registry.npmjs.org/fs-extra/-/fs-extra-0.26.3.tgz",
"/Users/nw/flint/packages/flint"
]
],
"_from": "fs-extra@0.26.3",
"_id": "fs-extra@0.26.3",
"_inCache": true,
"_location": "/fs-extra",
"_phantomChildren": {},
"_requested": {
"name": "fs-extra",
"raw": "fs-extra@https://registry.npmjs.org/fs-extra/-/fs-extra-0.26.3.tgz",
"rawSpec": "https://registry.npmjs.org/fs-extra/-/fs-extra-0.26.3.tgz",
"scope": null,
"spec": "https://registry.npmjs.org/fs-extra/-/fs-extra-0.26.3.tgz",
"type": "remote"
},
"_requiredBy": [
"/"
],
"_resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-0.26.3.tgz",
"_shasum": "ffe16dd7901344e634afc82a7a143562cbf02029",
"_shrinkwrap": null,
"_spec": "fs-extra@https://registry.npmjs.org/fs-extra/-/fs-extra-0.26.3.tgz",
"_where": "/Users/nw/flint/packages/flint",
"author": {
"email": "jprichardson@gmail.com",
"name": "JP Richardson"
},
"bugs": {
"url": "https://github.com/jprichardson/node-fs-extra/issues"
},
"dependencies": {
"graceful-fs": "^4.1.2",
"jsonfile": "^2.1.0",
"klaw": "^1.0.0",
"path-is-absolute": "^1.0.0",
"rimraf": "^2.2.8"
},
"description": "fs-extra contains methods that aren't included in the vanilla Node.js fs package. Such as mkdir -p, cp -r, and rm -rf.",
"devDependencies": {
"coveralls": "^2.11.2",
"istanbul": "^0.3.5",
"minimist": "^1.1.1",
"mocha": "^2.1.0",
"read-dir-files": "^0.1.1",
"secure-random": "^1.1.1",
"semver": "^4.3.6",
"standard": "^5.3.1"
},
"homepage": "https://github.com/jprichardson/node-fs-extra",
"keywords": [
"copy",
"create",
"delete",
"directory",
"extra",
"extra",
"file",
"file system",
"fs",
"json",
"mkdir",
"mkdirp",
"mkdirs",
"move",
"output",
"read",
"recursive",
"remove",
"text",
"touch",
"write"
],
"license": "MIT",
"main": "./lib/index",
"name": "fs-extra",
"optionalDependencies": {},
"readme": "Node.js: fs-extra\n=================\n\n[](http://travis-ci.org/jprichardson/node-fs-extra)\n[](https://ci.appveyor.com/project/jprichardson/node-fs-extra/branch/master)\n[](https://www.npmjs.org/package/fs-extra)\n[](https://coveralls.io/r/jprichardson/node-fs-extra)\n\n\n`fs-extra` adds file system methods that aren't included in the native `fs` module. It is a drop in replacement for `fs`.\n\n\n\nWhy?\n----\n\nI got tired of including `mkdirp`, `rimraf`, and `cp -r` in most of my projects.\n\n\n\n\nInstallation\n------------\n\n npm install --save fs-extra\n\n\n\nUsage\n-----\n\n`fs-extra` is a drop in replacement for native `fs`. All methods in `fs` are unmodified and attached to `fs-extra`.\n\nYou don't ever need to include the original `fs` module again:\n\n```js\nvar fs = require('fs') // this is no longer necessary\n```\n\nyou can now do this:\n\n```js\nvar fs = require('fs-extra')\n```\n\nor if you prefer to make it clear that you're using `fs-extra` and not `fs`, you may want\nto name your `fs` variable `fse` like so:\n\n```js\nvar fse = require('fs-extra')\n```\n\nyou can also keep both, but it's redundant:\n\n```js\nvar fs = require('fs')\nvar fse = require('fs-extra')\n```\n\n\nMethods\n-------\n- [copy](#copy)\n- [copySync](#copySync)\n- [createOutputStream](#createoutputstreamfile-options)\n- [emptyDir](#emptydirdir-callback)\n- [emptyDirSync](#emptydirdir-callback)\n- [ensureFile](#ensurefilefile-callback)\n- [ensureFileSync](#ensurefilefile-callback)\n- [ensureDir](#ensuredirdir-callback)\n- [ensureDirSync](#ensuredirdir-callback)\n- [ensureLink](#ensurelinksrcpath-dstpath-callback)\n- [ensureLinkSync](#ensurelinksrcpath-dstpath-callback)\n- [ensureSymlink](#ensuresymlinksrcpath-dstpath-type-callback)\n- [ensureSymlinkSync](#ensuresymlinksrcpath-dstpath-type-callback)\n- [mkdirs](#mkdirsdir-callback)\n- [mkdirsSync](#mkdirsdir-callback)\n- [move](#movesrc-dest-options-callback)\n- [outputFile](#outputfilefile-data-callback)\n- [outputFileSync](#outputfilefile-data-callback)\n- [outputJson](#outputjsonfile-data-callback)\n- [outputJsonSync](#outputjsonfile-data-callback)\n- [readJson](#readjsonfile-options-callback)\n- [readJsonSync](#readjsonfile-options-callback)\n- [remove](#removedir-callback)\n- [removeSync](#removedir-callback)\n- [walk](#walk)\n- [writeJson](#writejsonfile-object-options-callback)\n- [writeJsonSync](#writejsonfile-object-options-callback)\n\n\n**NOTE:** You can still use the native Node.js methods. They are copied over to `fs-extra`.\n\n\n### copy()\n\n**copy(src, dest, [options], callback)**\n\n\nCopy a file or directory. The directory can have contents. Like `cp -r`.\n\nOptions:\nclobber (boolean): overwrite existing file or directory \npreserveTimestamps (boolean): will set last modification and access times to the ones of the original source files, default is `false`. \nfilter: Function or RegExp to filter copied files. If function, return true to include, false to exclude. If RegExp, same as function, where `filter` is `filter.test`.\n\nExample:\n\n```js\nvar fs = require('fs-extra')\n\nfs.copy('/tmp/myfile', '/tmp/mynewfile', function (err) {\n if (err) return console.error(err)\n console.log(\"success!\")\n}) // copies file\n\nfs.copy('/tmp/mydir', '/tmp/mynewdir', function (err) {\n if (err) return console.error(err)\n console.log('success!')\n}) // copies directory, even if it has subdirectories or files\n```\n\n### copySync()\n\n**copySync(src, dest, [options])**\n\nSynchronously copies a file or directory. The directory can have contents.\n\n\nExample:\n\n```js\nvar fs = require('fs-extra')\n\ntry {\n fs.copySync('/tmp/mydir', '/tmp/mynewdir'\n} catch (err) {\n console.error('Oh no, there was an error: ' + err.message)\n}\n```\n\n\n\n### createOutputStream(file, [options])\n\nExactly like `createWriteStream`, but if the directory does not exist, it's created.\n\nExamples:\n\n```js\nvar fs = require('fs-extra')\n\n// if /tmp/some does not exist, it is created\nvar ws = fs.createOutputStream('/tmp/some/file.txt')\nws.write('hello\\n')\n```\n\nNote on naming: you'll notice that fs-extra has some methods like `fs.outputJson`, `fs.outputFile`, etc that use the\nword `output` to denote that if the containing directory does not exist, it should be created. If you can think of a\nbetter succinct nomenclature for these methods, please open an issue for discussion. Thanks.\n\n\n### emptyDir(dir, [callback])\n\nEnsures that a directory is empty. If the directory does not exist, it is created. The directory itself is not deleted.\n\nAlias: `emptydir()`\n\nSync: `emptyDirSync()`, `emptydirSync()`\n\nExample:\n\n```js\nvar fs = require('fs-extra')\n\n// assume this directory has a lot of files and folders\nfs.emptyDir('/tmp/some/dir', function (err) {\n if (!err) console.log('success!')\n})\n```\n\n\n### ensureFile(file, callback)\n\nEnsures that the file exists. If the file that is requested to be created is in directories that do not exist, these directories are created. If the file already exists, it is **NOT MODIFIED**.\n\nAlias: `createFile()`\n\nSync: `createFileSync()`,`ensureFileSync()`\n\n\nExample:\n\n```js\nvar fs = require('fs-extra')\n\nvar file = '/tmp/this/path/does/not/exist/file.txt'\nfs.ensureFile(file, function (err) {\n console.log(err) // => null\n // file has now been created, including the directory it is to be placed in\n})\n```\n\n\n### ensureDir(dir, callback)\n\nEnsures that the directory exists. If the directory structure does not exist, it is created.\n\nSync: `ensureDirSync()`\n\n\nExample:\n\n```js\nvar fs = require('fs-extra')\n\nvar dir = '/tmp/this/path/does/not/exist'\nfs.ensureDir(dir, function (err) {\n console.log(err) // => null\n // dir has now been created, including the directory it is to be placed in\n})\n```\n\n\n### ensureLink(srcpath, dstpath, callback)\n\nEnsures that the link exists. If the directory structure does not exist, it is created.\n\nSync: `ensureLinkSync()`\n\n\nExample:\n\n```js\nvar fs = require('fs-extra')\n\nvar srcpath = '/tmp/file.txt'\nvar dstpath = '/tmp/this/path/does/not/exist/file.txt'\nfs.ensureLink(srcpath, dstpath, function (err) {\n console.log(err) // => null\n // link has now been created, including the directory it is to be placed in\n})\n```\n\n\n### ensureSymlink(srcpath, dstpath, [type], callback)\n\nEnsures that the symlink exists. If the directory structure does not exist, it is created.\n\nSync: `ensureSymlinkSync()`\n\n\nExample:\n\n```js\nvar fs = require('fs-extra')\n\nvar srcpath = '/tmp/file.txt'\nvar dstpath = '/tmp/this/path/does/not/exist/file.txt'\nfs.ensureSymlink(srcpath, dstpath, function (err) {\n console.log(err) // => null\n // symlink has now been created, including the directory it is to be placed in\n})\n```\n\n\n### mkdirs(dir, callback)\n\nCreates a directory. If the parent hierarchy doesn't exist, it's created. Like `mkdir -p`.\n\nAlias: `mkdirp()`\n\nSync: `mkdirsSync()` / `mkdirpSync()`\n\n\nExamples:\n\n```js\nvar fs = require('fs-extra')\n\nfs.mkdirs('/tmp/some/long/path/that/prob/doesnt/exist', function (err) {\n if (err) return console.error(err)\n console.log(\"success!\")\n})\n\nfs.mkdirsSync('/tmp/another/path')\n```\n\n\n### move(src, dest, [options], callback)\n\nMoves a file or directory, even across devices.\n\nOptions:\nclobber (boolean): overwrite existing file or directory\nlimit (number): number of concurrent moves, see ncp for more information\n\nExample:\n\n```js\nvar fs = require('fs-extra')\n\nfs.move('/tmp/somefile', '/tmp/does/not/exist/yet/somefile', function (err) {\n if (err) return console.error(err)\n console.log(\"success!\")\n})\n```\n\n\n### outputFile(file, data, [options], callback)\n\nAlmost the same as `writeFile` (i.e. it [overwrites](http://pages.citebite.com/v2o5n8l2f5reb)), except that if the parent directory does not exist, it's created. `options` are what you'd pass to [`fs.writeFile()`](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback).\n\nSync: `outputFileSync()`\n\n\nExample:\n\n```js\nvar fs = require('fs-extra')\nvar file = '/tmp/this/path/does/not/exist/file.txt'\n\nfs.outputFile(file, 'hello!', function (err) {\n console.log(err) // => null\n\n fs.readFile(file, 'utf8', function (err, data) {\n console.log(data) // => hello!\n })\n})\n```\n\n\n\n### outputJson(file, data, [options], callback)\n\nAlmost the same as `writeJson`, except that if the directory does not exist, it's created.\n`options` are what you'd pass to [`jsonFile.writeFile()`](https://github.com/jprichardson/node-jsonfile#writefilefilename-options-callback).\n\nAlias: `outputJSON()`\n\nSync: `outputJsonSync()`, `outputJSONSync()`\n\n\nExample:\n\n```js\nvar fs = require('fs-extra')\nvar file = '/tmp/this/path/does/not/exist/file.txt'\n\nfs.outputJson(file, {name: 'JP'}, function (err) {\n console.log(err) // => null\n\n fs.readJson(file, function(err, data) {\n console.log(data.name) // => JP\n })\n})\n```\n\n\n\n### readJson(file, [options], callback)\n\nReads a JSON file and then parses it into an object. `options` are the same\nthat you'd pass to [`jsonFile.readFile`](https://github.com/jprichardson/node-jsonfile#readfilefilename-options-callback).\n\nAlias: `readJSON()`\n\nSync: `readJsonSync()`, `readJSONSync()`\n\n\nExample:\n\n```js\nvar fs = require('fs-extra')\n\nfs.readJson('./package.json', function (err, packageObj) {\n console.log(packageObj.version) // => 0.1.3\n})\n```\n\n`readJsonSync()` can take a `throws` option set to `false` and it won't throw if the JSON is invalid. Example:\n\n```js\nvar fs = require('fs-extra')\nvar file = path.join('/tmp/some-invalid.json')\nvar data = '{not valid JSON'\nfs.writeFileSync(file, data)\n\nvar obj = fs.readJsonSync(file, {throws: false})\nconsole.log(obj) // => null\n```\n\n\n### remove(dir, callback)\n\nRemoves a file or directory. The directory can have contents. Like `rm -rf`.\n\nSync: `removeSync()`\n\n\nExamples:\n\n```js\nvar fs = require('fs-extra')\n\nfs.remove('/tmp/myfile', function (err) {\n if (err) return console.error(err)\n\n console.log('success!')\n})\n\nfs.removeSync('/home/jprichardson') //I just deleted my entire HOME directory.\n```\n\n### walk()\n\n**walk(dir, [streamOptions])**\n\nThe function `walk()` from the module [`klaw`](https://github.com/jprichardson/node-klaw).\n\nReturns a [Readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable) that iterates\nthrough every file and directory starting with `dir` as the root. Every `read()` or `data` event\nreturns an object with two properties: `path` and `stats`. `path` is the full path of the file and\n`stats` is an instance of [fs.Stats](https://nodejs.org/api/fs.html#fs_class_fs_stats).\n\nStreams 1 (push) example:\n\n```js\nvar items = [] // files, directories, symlinks, etc\nfse.walk(TEST_DIR)\n .on('data', function (item) {\n items.push(item.path)\n })\n .on('end', function () {\n console.dir(items) // => [ ... array of files]\n })\n```\n\nStreams 2 & 3 (pull) example:\n\n```js\nvar items = [] // files, directories, symlinks, etc\nfse.walk(TEST_DIR)\n .on('readable', function () {\n var item\n while ((item = this.read())) {\n items.push(item.path)\n }\n })\n .on('end', function () {\n console.dir(items) // => [ ... array of files]\n })\n```\n\nIf you're not sure of the differences on Node.js streams 1, 2, 3 then I'd\nrecommend this resource as a good starting point: https://strongloop.com/strongblog/whats-new-io-js-beta-streams3/.\n\n**See [`klaw` documentation](https://github.com/jprichardson/node-klaw) for more detailed usage.**\n\n\n### writeJson(file, object, [options], callback)\n\nWrites an object to a JSON file. `options` are the same that\nyou'd pass to [`jsonFile.writeFile()`](https://github.com/jprichardson/node-jsonfile#writefilefilename-options-callback).\n\nAlias: `writeJSON()`\n\nSync: `writeJsonSync()`, `writeJSONSync()`\n\nExample:\n\n```js\nvar fs = require('fs-extra')\nfs.writeJson('./package.json', {name: 'fs-extra'}, function (err) {\n console.log(err)\n})\n```\n\n\nThird Party\n-----------\n\n### Promises\n\nUse [Bluebird](https://github.com/petkaantonov/bluebird). See https://github.com/petkaantonov/bluebird/blob/master/API.md#promisification. `fs-extra` is\nexplicitly listed as supported.\n\n```js\nvar Promise = require('bluebird')\nvar fs = Promise.promisifyAll(require('fs-extra'))\n```\n\nOr you can use the package [`fs-extra-promise`](https://github.com/overlookmotel/fs-extra-promise) that marries the two together.\n\n\n### TypeScript\n\nIf you like TypeScript, you can use `fs-extra` with it: https://github.com/borisyankov/DefinitelyTyped/tree/master/fs-extra\n\n\n### File / Directory Watching\n\nIf you want to watch for changes to files or directories, then you should use [chokidar](https://github.com/paulmillr/chokidar).\n\n\n### Misc.\n\n- [mfs](https://github.com/cadorn/mfs) - Monitor your fs-extra calls.\n\n\n\nHacking on fs-extra\n-------------------\n\nWanna hack on `fs-extra`? Great! Your help is needed! [fs-extra is one of the most depended upon Node.js packages](http://nodei.co/npm/fs-extra.png?downloads=true&downloadRank=true&stars=true). This project\nuses [JavaScript Standard Style](https://github.com/feross/standard) - if the name or style choices bother you,\nyou're gonna have to get over it :) If `standard` is good enough for `npm`, it's good enough for `fs-extra`.\n\n[](https://github.com/feross/standard)\n\nWhat's needed?\n- First, take a look at existing issues. Those are probably going to be where the priority lies.\n- More tests for edge cases. Specifically on different platforms. There can never be enough tests.\n- Really really help with the Windows tests. See appveyor outputs for more info.\n- Improve test coverage. See coveralls output for more info.\n- A directory walker. Probably this one: https://github.com/thlorenz/readdirp imported into `fs-extra`.\n- After the directory walker is integrated, any function that needs to traverse directories like\n`copy`, `remove`, or `mkdirs` should be built on top of it.\n\nNote: If you make any big changes, **you should definitely post an issue for discussion first.**\n\n\nNaming\n------\n\nI put a lot of thought into the naming of these functions. Inspired by @coolaj86's request. So he deserves much of the credit for raising the issue. See discussion(s) here:\n\n* https://github.com/jprichardson/node-fs-extra/issues/2\n* https://github.com/flatiron/utile/issues/11\n* https://github.com/ryanmcgrath/wrench-js/issues/29\n* https://github.com/substack/node-mkdirp/issues/17\n\nFirst, I believe that in as many cases as possible, the [Node.js naming schemes](http://nodejs.org/api/fs.html) should be chosen. However, there are problems with the Node.js own naming schemes.\n\nFor example, `fs.readFile()` and `fs.readdir()`: the **F** is capitalized in *File* and the **d** is not capitalized in *dir*. Perhaps a bit pedantic, but they should still be consistent. Also, Node.js has chosen a lot of POSIX naming schemes, which I believe is great. See: `fs.mkdir()`, `fs.rmdir()`, `fs.chown()`, etc.\n\nWe have a dilemma though. How do you consistently name methods that perform the following POSIX commands: `cp`, `cp -r`, `mkdir -p`, and `rm -rf`?\n\nMy perspective: when in doubt, err on the side of simplicity. A directory is just a hierarchical grouping of directories and files. Consider that for a moment. 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.\n\nSo, if you want to remove a file or a directory regardless of whether it has contents, just call `fs.remove(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)`.\n\n\nCredit\n------\n\n`fs-extra` wouldn't be possible without using the modules from the following authors:\n\n- [Isaac Shlueter](https://github.com/isaacs)\n- [Charlie McConnel](https://github.com/avianflu)\n- [James Halliday](https://github.com/substack)\n- [Andrew Kelley](https://github.com/andrewrk)\n\n\n\n\nLicense\n-------\n\nLicensed under MIT\n\nCopyright (c) 2011-2015 [JP Richardson](https://github.com/jprichardson)\n\n[1]: http://nodejs.org/docs/latest/api/fs.html\n\n\n[jsonfile]: https://github.com/jprichardson/node-jsonfile\n",
"readmeFilename": "README.md",
"repository": {
"type": "git",
"url": "git+https://github.com/jprichardson/node-fs-extra.git"
},
"scripts": {
"coverage": "istanbul cover test.js",
"coveralls": "npm run coverage && coveralls < coverage/lcov.info",
"test": "standard && node test.js",
"test-find": "find ./lib/**/__tests__ -name *.test.js | xargs mocha"
},
"version": "0.26.3"
}