{"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"},"_id":"file-utils@0.1.5","dist":{"shasum":"dc8153c855387cb4dacb0a1725531fa444a6b48c","tarball":"http://registry-npm.ywwl.com/file-utils/download/file-utils-0.1.5.tgz","integrity":"sha512-DFNaKyVV63vP3KB2KDks91O1k46DfguUMv9mtGRzomzPVeB7k41u2aKrD8U4Kcg1UnCXLIZ+VYA3Bb3PjcnWeg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGZPZqYsvSWFdwHSI4pMS5EtEHg2JPZVjgwzcdKVBog1AiEAn++J8dL8q8mhNydpyYucXflKhAvkKLPgEmyfdfDBHeI="}],"size":23922,"noattachment":false,"key":"/file-utils/-/file-utils-0.1.5.tgz"},"_from":".","_npmVersion":"1.3.5","_npmUser":{"name":"sboudrias","email":"admin@simonboudrias.com"},"maintainers":[{"name":"sboudrias","email":"admin@simonboudrias.com"}],"readme":"file-utils [![](https://travis-ci.org/SBoudrias/file-utils.png)](https://travis-ci.org/SBoudrias/file-utils)\n==========\n\nThis is a Grunt.file forks to allow the creation of scoped file utilities and the ability to add write filters.\n\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.\n\n\nFile API\n=========\n\nUpcoming. Meanwhile, check [Grunt.file documentation](http://gruntjs.com/api/grunt.file) as the same methods are available.\n\n#### Setting options - `file.option( name, [ value ])`\n\n```\n// Set option\nfile.option('write', false);\n\n// Get option\nfile.option('write');\n```\n\n**Available Options**\n- `write` (Boolean): If write is set to `false`, then no file will be written or deleted. Useful for test run without side effets.\n- `logger` (Logger object): Used internally to log information to the console. **API still work in progress**\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.\n- `force` (Boolean): `force: true` Force the deletion of folders and file outside the utility scope (or CWD if no scope).\n\n\nENV scope and filters\n=========\n\n### Creating an Env - file#createEnv([ options ]);\n\n```javascript\nvar file = require('file-utils');\n\nvar env = file.createEnv({\n  base: 'my/scoped/path',\n  dest: 'destination/path' // optionnal\n});\n\n// Alternatively, they can be functions returning a path:\n\nvar env = file.createEnv({\n  base: function() {\n    return 'my/scoped/path';\n  },\n  dest: function() { // optionnal\n    return 'destination/path';\n  }\n});\n```\n\nThe `base` directory will prefix any paths passed to `mkdir`, `recurse`, `read`, `readJSON`, `write`, `delete`, `exists`, `isLink`, `isDir` and `isFile` methods.\n\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.\n\nIf [options (`logger`, `write`, etc)](#setting-options---fileoption-name--value-) are not passed, each `Env` instance inherit those of its parent.\n\nWrite Filters\n---------\n\nWrite filters are applied on `env.write` and `env.copy`.\n\nThey're used to modifiy the content or the filepath of a file.\n\n#### Add a write filter - `env.registerWriteFilter( name, filter )`\n\n**options**\n- `name` (String): The name under which registering the filter\n- `filter` (Function): The filter function\n\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.\n\n```javascript\nenv.registerWriteFilter( 'coffee', function( file ) {\n  if (!path.extname(file) !== '.js') return file;\n\n  file.path = file.path.replace(/(\\.js)$/, '.coffee');\n  file.content = convertJsToCoffee( file.contents );\n\n  return file;\n});\n```\n\n#### Remove a write filter - `env.removeWriteFilter( name )`\n\n```javascript\nenv.removeWriteFilter('coffee');\n```\n\n#### Async filter\n\nThe filter can also be asynchronous. This is done by calling `this.async()` and passing the return value to the callback provided.\n\n```javascript\nenv.registerWriteFilter( 'coffee', function( file ) {\n  var done = this.async();\n\n  // some process\n  setTimeout(function() {\n    done({ path: '/newfile', contents: 'filtered content' });\n  }, 1000);\n});\n```\n\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.\n\nValidation Filters\n----------\n\nValidation filters are applied on `env.write` and `env.copy`.\n\nThey're used to allow or disallow the write action.\n\n#### Add a validation filter - `env.registerValidationFilter( name, filter )`\n\n**options**\n- `name` (String): The name under which registering the filter\n- `filter` (Function): The filter function\n\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.\n\nReturn `true` to allow the file to be written. Return `false` or an error message `String` to disallow the write action.\n\n```javascript\nenv.registerValidationFilter( 'checkConflicts', function( toOutput ) {\n  if ( file.exists(toOutput.path) ) {\n    return 'file is already present';\n  }\n  return true;\n});\n```\n\nJust like the write filters, [this filter can be asynchronous](#async-filter).\n\n#### Remove a validation filter - `env.removeValidationFilter( name )`\n\n```javascript\nenv.removeValidationFilter('checkConflicts');\n```\n\n\nTodos\n=========\n\n- Real Logging system\n","publish_time":1384801341807,"_cnpm_publish_time":1384801341807,"dist-tags":{"latest":"0.2.2"}}