our simplified wrapper for common AWS S3 operations
npm install @blinkmobile/aws-s3 aws-sdk
const upload = require('@blinkmobile/aws-s3').upload;
const AWS = require('aws-sdk');
AWS SDK for Javascript, version >= v2.3.9
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);
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
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 ''
}
skipped: fileName
uploading: fileName
uploaded: fileName
error: error
, fileName
deleting: fileName
deleted: fileName
const task = upload({ /* ... */ });
task.on('error', (error, fileName) => {
// TODO: ...
});