tdp-glob-file-copier

A tiny, simple NodeJS script to copy files from source to destination in a config object using glob file paths. Intended to simplify elements of NodeJS/NPM installer scripts.


Keywords
nodejs, npm, glob, copy, config, file, install, installer, javascript
License
CC-BY-SA-3.0
Install
npm install tdp-glob-file-copier@0.1.2-alpha

Documentation

TDPGlobFileCopier

Overview

TDPGlobFileCopier is a very simple NodeJS/NPM module which takes a collection of source/destination file paths/globs which it uses to copy files from source to destination, creating any missing destination directories. The aim of the module is to simplify and genericise the file copying element of my (and hopefully other peoples) NodeJS/NPM install scripts - really just avoiding duplication of effort.
This module is not yet properly recursive, for that I will need to find/write a recursive glob function. This means that for glob source paths, sub directories will not be included so you will need to create a source/destination config item for them.

Version

Master: 0.1.2-alpha

Warnings

  • This module is somewhat insecure currently e.g. some config params are used in shell commands. Also, several elements require root/sudoer permissions (e.g. chmod, chown, chgrp) so please bear this in mind and if using this module, consider this resposibily!
  • This module is in the early stages and may change significantly, however it should not affect 3rd party usage too seriously - but please check! I will make a considered effort to stay true to semantic versioning which will help (i.e. major changes in external interfaces wil; be reflected in a commensurate change of version number)
  • This module will not work on non-*nix-like operating systems e.g. windows. This may or may not change in future, see below!

Operating system support

Operating system support is likely to be a major issue for this module and as I always mention in my projects, I do not design or test for correct function on non-*nix-like OS's (e.g. Windows). If you want to test/develop and submit pull requests for Windows support then I will certainly consider them but likely only if they have minimal to no impact on performance and reliability for *nix-like OSs. The reason for this is simply that I personally don't consider Windows to be a serious server operating system and thus a good direction in which to spend my time and i'm not trying to offend anyone. I realise that others may completely differ in opinion and you're always welcome (obviously) to fork the repo and create your own version with Windows support. If my time were unlimited then I would likely spend some time on Windows support but sadly it's not.

Dependencies

TDPGlobFileCopier itself has few dependencies (which are NPM modules):

Issues/problems

Please log any issues/problems in Github issues for this project.

Installation

Installation is simple:

  1. From your command line (under the relevant user account): npm install tdp-glob-file-copier

Usage

Once you have installed the NPM module, you can require() the module as normal in your script e.g.

var tdpgfc=require("tdp-glob-file-copier");
tdpgfc.run("/path/to/config/file.js");

Configuration

Via JavaScript object

Configuration via object is a simple matter of passing a JavaScript object to the run() function e.g.:

var tdpgfc=require("tdp-glob-file-copier");
var config=
{
    operations:
    {
        fileTypeOne:
        {
            source:"/path/to/files/of/type/one/*",
            destination:"/dest/for/files/of/type/one/"
        },
        fileTypeTwo:
        {
            source:"/path/to/files/of/type/two/*",
            destination:"/dest/for/files/of/type/two/"
        }
    },
    logging:
    {
        transport:"Console",
        options:{
            level:"debug",
            colorize:true,
            timestamp:false
        }
    }
};
tdpgfc.run(config);

Via config file

Configuration via config file is as simple as passing a path to the config file to the run() function e.g.:

var tdpgfc=require("tdp-glob-file-copier");
tdpgfc.run("/path/to/config/file.js");

The config file is a very simple JavaScript object in a nodejs module which is a collection of source/destination pairs e.g.:

var config=
{
    operations:
    {
        fileTypeOne:
        {
            source:"/path/to/files/of/type/one/*",
            destination:"/dest/for/files/of/type/one/"
        },
        fileTypeTwo:
        {
            source:"/path/to/files/of/type/two/*",
            destination:"/dest/for/files/of/type/two/"
        }
    },
    logging:
    {
        transport:"Console",
        options:{
            level:"debug",
            colorize:true,
            timestamp:false
        }
    }
};

module.exports=config;

Configuration notes:

  • File source/destination pairs are configured in config.operations
  • Logging options in config.logging are simply winston options
  • The first dimension key names in config.operations (fileTypeOne and fileTypeTwo in the above example) are arbitrary and should be used for your reference only
  • All paths are relative to where you run the host file from
  • The value of source can be either a single path/file or a glob'able path/pattern
  • The value of destination must be a directory, this will be created (recursively) if it does not exist

To do

  • Log remaining issues and the below in github issues
  • Test NPM module installation
  • Create some meaningful tests
  • Make copying (optionally) properly recursive
  • Optimise code

License

TDPGlobFileCopier is issued under a Creative Commons attribution share-alike license. This means you can share and adapt the code provided you attribute the original author(s) and you share your resulting source code. If, for some specific reason you need to use this library under a different license then please contact me and i'll see what I can do - though I should mention that I am committed to all my code being open-source so closed licenses will almost certainly not be possible.