Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

rewrite-files

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rewrite-files

Rewrite file contents in-place using pattern matching or a list of files


Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

rewrite-files

Rewrite file contents in-place.

NPM

Use glob matching to discover a list of files, or specify them directly. Write a transformer function that receives filenames and file contents, which can asynchronously indicate the new file contents when done.

This can be usefully paired with something like falafel to parse JS into an AST and rewrite code.

Install

npm install --save rewrite-files

Examples

var rewriteFiles = require('rewrite-files');

function rewrite(fileName, contents, callback) {
  var newContents = '<wrap ' + contents + '>';
  callback(null, newContents);
}

exports.upgrade = function(next) {
  var basePath = config.get('webapp.js.src.basePath');
  var pattern = path.join(basePath, '**/*.js');
  rewriteFiles.withPattern(pattern, rewrite, function(err) {
    next(err ? (err.stack || err) : null);
  });
};

Methods

rewriteFiles

rewriteFiles(files, transformer, callback);
  • files: Array of filenames to operate on
  • tranformer: Function
    • Called like: transformer(fileName, fileContents, callback)
    • fileContents is a string
    • Should call callback like: callback(err, newContents)
    • newContents should be a string
  • callback: Function
    • Called like: callback(err)

rewriteFiles.withPattern

rewriteFiles.withPattern(pattern, transformer, callback);
  • pattern: Glob pattern used to extract list of files
  • tranformer: Function
    • Called like: transformer(fileName, fileContents, callback)
    • fileContents is a string
    • Should call callback like: callback(err, newContents)
    • newContents should be a string
  • callback: Function
    • Called like: callback(err)

License

MIT

Keywords

FAQs

Package last updated on 05 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc