{
  "name": "file-utils",
  "version": "0.1.5",
  "description": "Sync file utility for Node.js command line tools",
  "main": "index.js",
  "directories": {
    "test": "tests"
  },
  "scripts": {
    "test": "grunt test"
  },
  "license": "MIT",
  "dependencies": {
    "lodash": "~2.1.0",
    "iconv-lite": "~0.2.11",
    "rimraf": "~2.2.2",
    "glob": "~3.2.6",
    "minimatch": "~0.2.12",
    "findup-sync": "~0.1.2",
    "isbinaryfile": "~0.1.9"
  },
  "devDependencies": {
    "temporary": "~0.0.4",
    "grunt-contrib-jshint": "~0.6.4",
    "grunt-contrib-nodeunit": "~0.2.0",
    "grunt-contrib-watch": "~0.5.3",
    "grunt-release": "~0.3.3"
  },
  "repository": {
    "type": "git",
    "url": "git://github.com/SBoudrias/file-utils.git"
  },
  "keywords": [
    "file",
    "utils",
    "scaffold",
    "tool",
    "cli"
  ],
  "author": {
    "name": "Simon Boudrias"
  },
  "bugs": {
    "url": "https://github.com/SBoudrias/file-utils/issues"
  },
  "readme": "file-utils [![](https://travis-ci.org/SBoudrias/file-utils.png)](https://travis-ci.org/SBoudrias/file-utils)\r\n==========\r\n\r\nThis is a Grunt.file forks to allow the creation of scoped file utilities and the ability to add write filters.\r\n\r\nSame as Grunt.file, this is a set of _synchronous_ utility. As so, it should **never** be used on a Node.js server. This is meant for users/command line utilities.\r\n\r\n\r\nFile API\r\n=========\r\n\r\nUpcoming. Meanwhile, check [Grunt.file documentation](http://gruntjs.com/api/grunt.file) as the same methods are available.\r\n\r\n#### Setting options - `file.option( name, [ value ])`\r\n\r\n```\r\n// Set option\r\nfile.option('write', false);\r\n\r\n// Get option\r\nfile.option('write');\r\n```\r\n\r\n**Available Options**\r\n- `write` (Boolean): If write is set to `false`, then no file will be written or deleted. Useful for test run without side effets.\r\n- `logger` (Logger object): Used internally to log information to the console. **API still work in progress**\r\n- `encoding` (String): Defaults `utf8`. Set the default encoding used for reading/writing. Note most methods allow you to overwridde it for a single run.\r\n- `force` (Boolean): `force: true` Force the deletion of folders and file outside the utility scope (or CWD if no scope).\r\n\r\n\r\nENV scope and filters\r\n=========\r\n\r\n### Creating an Env - file#createEnv([ options ]);\r\n\r\n```javascript\r\nvar file = require('file-utils');\r\n\r\nvar env = file.createEnv({\r\n  base: 'my/scoped/path',\r\n  dest: 'destination/path' // optionnal\r\n});\r\n```\r\n\r\nThe `base` directory will prefix any paths passed to `mkdir`, `recurse`, `read`, `readJSON`, `write`, `delete` methods.\r\n\r\nThe `dest` directory will prefix the `destination` path provided in the `copy` method. Note that this option is optionnal and will default to the current working directory.\r\n\r\nIf [options (`logger`, `write`, etc)](#setting-options---fileoption-name--value-) are not passed, each `Env` instance inherit those of its parent.\r\n\r\nWrite Filters\r\n---------\r\n\r\nWrite filters are applied on `env.write` and `env.copy`.\r\n\r\nThey're used to modifiy the content or the filepath of a file.\r\n\r\n#### Add a write filter - `env.registerWriteFilter( name, filter )`\r\n\r\n**options**\r\n- `name` (String): The name under which registering the filter\r\n- `filter` (Function): The filter function\r\n\r\nThe filter function take a file object as parameter. This file object is a hash containing a `path` and a `contents` property. You can modify these two property as you like and returning the modified object.\r\n\r\n```javascript\r\nenv.registerWriteFilter( 'coffee', function( file ) {\r\n  if (!path.extname(file) !== '.js') return file;\r\n\r\n  file.path = file.path.replace(/(\\.js)$/, '.coffee');\r\n  file.content = convertJsToCoffee( file.contents );\r\n\r\n  return file;\r\n});\r\n```\r\n\r\n#### Remove a write filter - `env.removeWriteFilter( name )`\r\n\r\n```javascript\r\nenv.removeWriteFilter('coffee');\r\n```\r\n\r\n#### Async filter\r\n\r\nThe filter can also be asynchronous. This is done by calling `this.async()` and passing the return value to the callback provided.\r\n\r\n```javascript\r\nenv.registerWriteFilter( 'coffee', function( file ) {\r\n  var done = this.async();\r\n\r\n  // some process\r\n  setTimeout(function() {\r\n    done({ path: '/newfile', contents: 'filtered content' });\r\n  }, 1000);\r\n});\r\n```\r\n\r\n**Caution:** Using an asynchronous filter will change the way write and copy method are called to. This will make both of those method to run asynchronously too.\r\n\r\nValidation Filters\r\n----------\r\n\r\nValidation filters are applied on `env.write` and `env.copy`.\r\n\r\nThey're used to allow or disallow the write action.\r\n\r\n#### Add a validation filter - `env.registerValidationFilter( name, filter )`\r\n\r\n**options**\r\n- `name` (String): The name under which registering the filter\r\n- `filter` (Function): The filter function\r\n\r\nThe filter function take a file object as parameter. This file object is a hash containing a `path` (String) and a `contents` (String if text file, Buffer otherwise) property.\r\n\r\nReturn `true` to allow the file to be written. Return `false` or an error message `String` to disallow the write action.\r\n\r\n```javascript\r\nenv.registerValidationFilter( 'checkConflicts', function( toOutput ) {\r\n  if ( file.exists(toOutput.path) ) {\r\n    return 'file is already present';\r\n  }\r\n  return true;\r\n});\r\n```\r\n\r\nJust like the write filters, [this filter can be asynchronous](#async-filter).\r\n\r\n#### Remove a validation filter - `env.removeValidationFilter( name )`\r\n\r\n```javascript\r\nenv.removeValidationFilter('checkConflicts');\r\n```\r\n\r\n\r\nTodos\r\n=========\r\n\r\n- Real Logging system\r\n",
  "readmeFilename": "README.md",
  "homepage": "https://github.com/SBoudrias/file-utils",
  "_id": "file-utils@0.1.5",
  "dist": {
    "shasum": "699523e282d1786e3db071a236bd7411fd81027c"
  },
  "_from": "file-utils@~0.1.5",
  "_resolved": "https://registry.npmjs.org/file-utils/-/file-utils-0.1.5.tgz"
}
