oneblink / aws-s3.js

our simplified wrapper for common AWS S3 operations
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

blinkmobile/aws-s3 npm module Build Status Greenkeeper badge AppVeyor Status

our simplified wrapper for common AWS S3 operations

Getting Started

npm install @blinkmobile/aws-s3 aws-sdk
const upload = require('@blinkmobile/aws-s3').upload;
const AWS = require('aws-sdk');

Requirements

AWS SDK for Javascript, version >= v2.3.9

Usage

const task = upload({
  // common options
  cwd: '', // current working directory to search, defaults to `process.cwd()`
  prune: false, // true => delete S3 Objects that don't match local files
  s3: new AWS.S3({ /* ... */ }),

  // advanced options
  dryRun: false, // true bypasses write calls with simulated success events
  filePaths: [''], // paths relative to rootPath, defaults to glob(['**/*'])
  fs: null, // defaults to `require('fs')`
  bucketPathPrefix: '' // upload objects to base path in S3 bucket
});

const EventEmitter = require('events');
console.assert(task instanceof EventEmitter);
console.assert(task.promise instanceof Promise);

.blinkmignore

We ignore certain files and directories by default.

The "cwd" directory may also contain a ".blinkmignore" file. This file is like a .gitignore file.

This file should contain globs, which we combine with the above defaults for the "ignore" option for glob.

Example:

# we ignore comments and empty lines

do-not-upload/**/anything-in-this-directory/**/*
or-this-file.txt

API

upload (options: UploadOptions) => Task
interface Task extends EventEmitter {
  filePaths: String[],
  files: Map,
  objects: Map,
  promise: Promise
}

Note: until task.promise resolves / rejects, other properties may not be available. EventEmitter methods are always available.

interface UploadOptions {
  cwd? : String, // defaults to process.cwd()
  dryRun = false: Boolean,
  filePaths?: String[], // defaults to glob(['**/*'])
  fs? : Object, // defaults to require('fs')
  prune = false : Boolean,
  s3: AWS.S3,
  skip = true : Boolean,
  bucketPathPrefix?: String // defaults to ''
}

Events

const task = upload({ /* ... */ });
task.on('error', (error, fileName) => {
  // TODO: ...
});

Roadmap