{"_id":"file-utils","_rev":"97766","name":"file-utils","description":"Sync file utility for Node.js command line tools","dist-tags":{"latest":"0.2.2"},"maintainers":[{"name":"sboudrias","email":""}],"time":{"modified":"2021-06-03T10:32:52.000Z","created":"2013-10-05T19:04:56.526Z","0.2.2":"2015-02-06T08:12:23.354Z","0.2.1":"2014-08-26T06:23:34.768Z","0.2.0":"2014-01-16T21:57:57.104Z","0.1.5":"2013-11-18T19:02:21.807Z","0.1.4":"2013-11-15T20:36:40.900Z","0.1.3":"2013-11-14T22:52:18.929Z","0.1.2":"2013-10-21T01:40:48.358Z","0.1.1":"2013-10-20T00:20:12.916Z","0.1.0":"2013-10-16T00:24:38.031Z","0.0.1":"2013-10-05T19:04:56.526Z"},"users":{"itonyyo":true},"author":{"name":"Simon Boudrias"},"repository":{"type":"git","url":"https://github.com/SBoudrias/file-utils"},"versions":{"0.2.2":{"name":"file-utils","version":"0.2.2","description":"Sync file utility for Node.js command line tools","directories":{"test":"tests"},"scripts":{"test":"grunt test"},"license":"MIT","dependencies":{"findup-sync":"^0.2.1","glob":"^4.3.5","iconv-lite":"^0.4.3","isbinaryfile":"^2.0.1","lodash":"^2.4.1","minimatch":"^2.0.1","rimraf":"^2.2.2"},"devDependencies":{"grunt":"^0.4.5","grunt-cli":"^0.1.13","grunt-contrib-jshint":"^0.10.0","grunt-contrib-nodeunit":"^0.4.1","grunt-contrib-watch":"^0.6.1","grunt-release":"^0.10.0","temporary":"0.0.8"},"repository":{"type":"git","url":"https://github.com/SBoudrias/file-utils"},"keywords":["file","fs","utils","util","scaffold","tool","cli"],"author":{"name":"Simon Boudrias"},"engines":{"node":">=0.10.0"},"files":["lib","index.js"],"gitHead":"9e59b23f7394f6d875e1cb4843b43efcd391ef7b","bugs":{"url":"https://github.com/SBoudrias/file-utils/issues"},"homepage":"https://github.com/SBoudrias/file-utils","_id":"file-utils@0.2.2","_shasum":"4b7967bb2079ada4d4a7f5454206ecb5c0d4c589","_from":".","_npmVersion":"2.4.1","_nodeVersion":"0.10.32","_npmUser":{"name":"sboudrias","email":"admin@simonboudrias.com"},"maintainers":[{"name":"sboudrias","email":""}],"dist":{"shasum":"4b7967bb2079ada4d4a7f5454206ecb5c0d4c589","size":8458,"noattachment":false,"key":"/file-utils/-/file-utils-0.2.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/file-utils/download/file-utils-0.2.2.tgz"},"publish_time":1423210343354,"_cnpm_publish_time":1423210343354,"_hasShrinkwrap":false},"0.2.1":{"name":"file-utils","version":"0.2.1","description":"Sync file utility for Node.js command line tools","main":"index.js","directories":{"test":"tests"},"scripts":{"test":"grunt test"},"license":"MIT","dependencies":{"findup-sync":"~0.1.2","glob":"~3.2.6","iconv-lite":"~0.4.3","isbinaryfile":"~2.0.1","lodash":"~2.4.1","minimatch":"~0.2.12","rimraf":"~2.2.2"},"devDependencies":{"grunt":"^0.4.5","grunt-cli":"^0.1.13","grunt-contrib-jshint":"^0.10.0","grunt-contrib-nodeunit":"^0.4.1","grunt-contrib-watch":"^0.6.1","grunt-release":"^0.7.0","temporary":"~0.0.4"},"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"},"engines":{"node":">=0.10.0"},"homepage":"https://github.com/SBoudrias/file-utils","_id":"file-utils@0.2.1","_shasum":"4978d430f2ecc0c93f262c266c106de9e007a871","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"sboudrias","email":"admin@simonboudrias.com"},"maintainers":[{"name":"sboudrias","email":""}],"dist":{"shasum":"4978d430f2ecc0c93f262c266c106de9e007a871","size":24249,"noattachment":false,"key":"/file-utils/-/file-utils-0.2.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/file-utils/download/file-utils-0.2.1.tgz"},"publish_time":1409034214768,"_cnpm_publish_time":1409034214768,"_hasShrinkwrap":false},"0.2.0":{"name":"file-utils","version":"0.2.0","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.4.1","iconv-lite":"~0.2.11","rimraf":"~2.2.2","glob":"~3.2.6","minimatch":"~0.2.12","findup-sync":"~0.1.2","isbinaryfile":"~2.0.0"},"devDependencies":{"temporary":"~0.0.4","grunt-contrib-jshint":"~0.8.0","grunt-contrib-nodeunit":"~0.2.0","grunt-contrib-watch":"~0.5.3","grunt-release":"~0.6.0"},"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"},"engines":{"node":">=0.10.0"},"readmeFilename":"README.md","_id":"file-utils@0.2.0","dist":{"shasum":"0372c89b19bd96fc9a02a180c91fad29e4dbacaa","size":28205,"noattachment":false,"key":"/file-utils/-/file-utils-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/file-utils/download/file-utils-0.2.0.tgz"},"_from":".","_npmVersion":"1.3.5","_npmUser":{"name":"sboudrias","email":"admin@simonboudrias.com"},"maintainers":[{"name":"sboudrias","email":""}],"publish_time":1389909477104,"_cnpm_publish_time":1389909477104,"_hasShrinkwrap":false},"0.1.5":{"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"},"readmeFilename":"README.md","_id":"file-utils@0.1.5","dist":{"shasum":"dc8153c855387cb4dacb0a1725531fa444a6b48c","size":23922,"noattachment":false,"key":"/file-utils/-/file-utils-0.1.5.tgz","tarball":"http://registry.cnpm.dingdandao.com/file-utils/download/file-utils-0.1.5.tgz"},"_from":".","_npmVersion":"1.3.5","_npmUser":{"name":"sboudrias","email":"admin@simonboudrias.com"},"maintainers":[{"name":"sboudrias","email":""}],"publish_time":1384801341807,"_cnpm_publish_time":1384801341807,"_hasShrinkwrap":false},"0.1.4":{"name":"file-utils","version":"0.1.4","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"},"readmeFilename":"README.md","_id":"file-utils@0.1.4","dist":{"shasum":"9ecc8f7e6945a28ee0e23cefa423a8368dd099cd","size":23817,"noattachment":false,"key":"/file-utils/-/file-utils-0.1.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/file-utils/download/file-utils-0.1.4.tgz"},"_from":".","_npmVersion":"1.3.5","_npmUser":{"name":"sboudrias","email":"admin@simonboudrias.com"},"maintainers":[{"name":"sboudrias","email":""}],"publish_time":1384547800900,"_cnpm_publish_time":1384547800900,"_hasShrinkwrap":false},"0.1.3":{"name":"file-utils","version":"0.1.3","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"},"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"},"readmeFilename":"README.md","_id":"file-utils@0.1.3","dist":{"shasum":"83e3c95d53d1f1204f6e3a2ac933b8be4f8cdae6","size":23640,"noattachment":false,"key":"/file-utils/-/file-utils-0.1.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/file-utils/download/file-utils-0.1.3.tgz"},"_from":".","_npmVersion":"1.3.5","_npmUser":{"name":"sboudrias","email":"admin@simonboudrias.com"},"maintainers":[{"name":"sboudrias","email":""}],"publish_time":1384469538929,"_cnpm_publish_time":1384469538929,"_hasShrinkwrap":false},"0.1.2":{"name":"file-utils","version":"0.1.2","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"},"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"},"readmeFilename":"README.md","_id":"file-utils@0.1.2","dist":{"shasum":"99673d8aaa0efd3884ea5649cffcfc7412808e41","size":23548,"noattachment":false,"key":"/file-utils/-/file-utils-0.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/file-utils/download/file-utils-0.1.2.tgz"},"_from":".","_npmVersion":"1.3.8","_npmUser":{"name":"sboudrias","email":"admin@simonboudrias.com"},"maintainers":[{"name":"sboudrias","email":""}],"publish_time":1382319648358,"_cnpm_publish_time":1382319648358,"_hasShrinkwrap":false},"0.1.1":{"name":"file-utils","version":"0.1.1","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"},"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"},"readmeFilename":"README.md","_id":"file-utils@0.1.1","dist":{"shasum":"61990c1aecda0c38c37dfdfaca018c4a99c0fc7e","size":23550,"noattachment":false,"key":"/file-utils/-/file-utils-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/file-utils/download/file-utils-0.1.1.tgz"},"_from":".","_npmVersion":"1.3.8","_npmUser":{"name":"sboudrias","email":"admin@simonboudrias.com"},"maintainers":[{"name":"sboudrias","email":""}],"publish_time":1382228412916,"_cnpm_publish_time":1382228412916,"_hasShrinkwrap":false},"0.1.0":{"name":"file-utils","version":"0.1.0","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"},"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"},"readmeFilename":"README.md","_id":"file-utils@0.1.0","dist":{"shasum":"0141877d85bb2562639c7178b2e629f59d5a8eff","size":23556,"noattachment":false,"key":"/file-utils/-/file-utils-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/file-utils/download/file-utils-0.1.0.tgz"},"_from":".","_npmVersion":"1.3.5","_npmUser":{"name":"sboudrias","email":"admin@simonboudrias.com"},"maintainers":[{"name":"sboudrias","email":""}],"publish_time":1381883078031,"_cnpm_publish_time":1381883078031,"_hasShrinkwrap":false},"0.0.1":{"name":"file-utils","version":"0.0.1","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"},"devDependencies":{"temporary":"~0.0.4","grunt-contrib-jshint":"~0.6.4","grunt-contrib-nodeunit":"~0.2.0","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"},"readmeFilename":"README.md","_id":"file-utils@0.0.1","dist":{"shasum":"2585cafcc4cc30a89f4e9c72781a0307236930a5","size":21820,"noattachment":false,"key":"/file-utils/-/file-utils-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/file-utils/download/file-utils-0.0.1.tgz"},"_from":".","_npmVersion":"1.3.8","_npmUser":{"name":"sboudrias","email":"admin@simonboudrias.com"},"maintainers":[{"name":"sboudrias","email":""}],"publish_time":1380999896526,"_cnpm_publish_time":1380999896526,"_hasShrinkwrap":false}},"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","_attachments":{},"homepage":"https://github.com/SBoudrias/file-utils","bugs":{"url":"https://github.com/SBoudrias/file-utils/issues"},"license":"MIT"}