@ygor/files
A bulk file transformer.
Last updated 2 years ago by shannonmoeller .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @ygor/files 
SYNC missed versions from official npm registry.

@ygor/files

NPM version Downloads Build Status Coverage Status

A no-frills file transformer. Built on promises to work wonderfully with async and await in Node.js 8 and above. Part of the Ygor toolkit.

Node is the CLI, npm is the plugin system. Go nuts.

Install

$ npm install --save-dev @ygor/files

Usage

const { find, read, write } = require('@ygor/files');
const { transform } = require('babel-core');

find('src/**/*.js')
  .map(read())
  .map(async file => {
    const { code } = await transform(file.contents);

    file.contents = code;

    return file;
  })
  .map(write('dest'))
  .then(console.log);

API

find(patterns [, options]): List<File>

Finds files on the file system by the given glob patterns. The results are returned as an array-aware promise (List) of virtual file objects (File).

const files = await find('**/*.js');

read([options]): Function(File): File

Creates a helper to read the contents of a given File object from the file system. Useful as a map function on a list of files.

const files = await find('**/*.js')
    .map(read());
const files = await find('**/*.js')
    // Same as above
    .map(read('utf8'));
const files = await find('**/*.png')
    // Use `null` to read binary files
    .map(read(null));
const files = await find('**/*.png')
    // fs.readFile options object
    .map(read({
        encoding: null,
        flag: 'r'
    }));

write([options]): Function(File): File

  • options {String|Object} Destination directory (relative to the original location or an absolute path), or fs.writeFile options. (default: '.')

Creates a helper to write the contents of a given File object to the file system. Useful as a map function on a list of files.

const files = await find('**/*.js')
    .map(read())
    // Overwrite original file
    .map(write());
const files = await find('**/*.js')
    .map(read())
    // Copy file to new location
    .map(write('dest'));
const files = await find('**/*.js')
    .map(read())
    // fs.writeFile options object
    .map(write({
        cwd: 'dest',
        flag: 'w'
    }));

ygor


MIT © Shannon Moeller

Current Tags

  • 5.0.0-5                                ...           beta (2 years ago)
  • 6.0.1                                ...           latest (2 years ago)

19 Versions

  • 6.0.1                                ...           2 years ago
  • 6.0.0                                ...           2 years ago
  • 5.4.0                                ...           2 years ago
  • 5.3.0                                ...           2 years ago
  • 5.2.3                                ...           2 years ago
  • 5.2.1                                ...           2 years ago
  • 5.1.6                                ...           2 years ago
  • 5.1.5                                ...           2 years ago
  • 5.1.4                                ...           2 years ago
  • 5.1.0                                ...           2 years ago
  • 5.0.0                                ...           2 years ago
  • 5.0.0-9                                ...           2 years ago
  • 5.0.0-8                                ...           2 years ago
  • 5.0.0-7                                ...           2 years ago
  • 5.0.0-6                                ...           2 years ago
  • 5.0.0-5                                ...           2 years ago
  • 5.0.0-4                                ...           2 years ago
  • 5.0.0-3                                ...           2 years ago
  • 5.0.0-2                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 20
Dependencies (4)
Dev Dependencies (0)
None
Dependents (1)

Copyright 2014 - 2017 © taobao.org |