gulp-azure-storage
Advanced tools
Comparing version 0.0.7 to 0.1.0
#!/usr/bin/env node | ||
var upload = require('../lib/upload'); | ||
var es = require('event-stream'); | ||
var vfs = require('vinyl-fs'); | ||
@@ -10,7 +12,12 @@ var argv = require('optimist') | ||
upload(argv.account, argv.key, argv.container, argv.prefix || '', argv._, function (err) { | ||
if (err) { | ||
vfs.src(argv._, { base: process.cwd() }) | ||
.pipe(upload({ | ||
account: argv.account, | ||
key: argv.key, | ||
container: argv.container, | ||
prefix: argv.prefix | ||
})) | ||
.on('error', function (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
}); | ||
}); |
@@ -1,1 +0,2 @@ | ||
module.exports = require('./lib/download'); | ||
module.exports.download = require('./lib/download'); | ||
module.exports.upload = require('./lib/upload'); |
@@ -7,34 +7,55 @@ var azure = require('azure-storage'); | ||
module.exports = function (account, key, container, prefix, filePaths, callback) { | ||
prefix = prefix ? prefix.replace(/\/+$/, '') + '/' : ''; | ||
var service = azure.createBlobService(account, key); | ||
module.exports = function (opts) { | ||
if (!opts.account) { | ||
throw new Error('Missing account option.'); | ||
} | ||
service.createContainerIfNotExists(container, function (err) { | ||
if (err) { return callback(err); } | ||
if (!opts.key) { | ||
throw new Error('Missing key option.'); | ||
} | ||
var q = queue({ concurrency: 4, timeout: 1000 * 60 * 2 }); | ||
if (!opts.container) { | ||
throw new Error('Missing container option.'); | ||
} | ||
vfs | ||
.src(filePaths.map(function(arg) { return arg + '/**/*'; })) | ||
.pipe(es.through(function (data) { | ||
if (data.contents) { | ||
q.push(function (cb) { | ||
service.createBlockBlobFromLocalFile(container, prefix + data.relative, data.path, { | ||
metadata: { | ||
fsmode: data.stat.mode | ||
} | ||
}, cb); | ||
var prefix = opts.prefix || ''; | ||
var service = azure.createBlobService(opts.account, opts.key); | ||
var q = queue({ concurrency: 4, timeout: 1000 * 60 * 2 }); | ||
var count = 0; | ||
var stream = es.through(function(file) { | ||
if (file.isDirectory()) { | ||
return; | ||
} | ||
q.push(function(cb) { | ||
service.createBlockBlobFromLocalFile(opts.container, prefix + file.relative, file.path, { | ||
metadata: { fsmode: file.stat.mode } | ||
}, cb); | ||
})}, function () { | ||
var that = this; | ||
service.createContainerIfNotExists(opts.container, function (err) { | ||
if (err) { that.emit('error', err); } | ||
if (!opts.quiet && q.length > 0) { | ||
var bar = new ProgressBar('uploading [:bar] :percent', { total: q.length }); | ||
bar.tick(0); | ||
q.on('success', function () { | ||
count++; | ||
bar.tick(); | ||
}); | ||
} | ||
}, function () { | ||
var that = this; | ||
var bar = new ProgressBar('uploading [:bar] :percent', { total: q.length }); | ||
bar.tick(0); | ||
q.on('success', function () { bar.tick(); }); | ||
q.on('error', function (err) { that.emit('error', err); }); | ||
q.start(function () { that.emit('end'); }); | ||
})) | ||
.on('end', function () { callback(); }); | ||
}); | ||
}; | ||
q.start(function () { | ||
if (!opts.quiet) { | ||
console.log(count + ' files uploaded.'); | ||
} | ||
that.emit('end'); | ||
}); | ||
}); | ||
}); | ||
return stream; | ||
}; |
{ | ||
"name": "gulp-azure-storage", | ||
"version": "0.0.7", | ||
"version": "0.1.0", | ||
"description": "Gulp plugin to download and upload files to/from the Azure blob storage", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -15,24 +15,14 @@ gulp-azure-storage | ||
### Upload | ||
Simply pipe in a gulp stream: | ||
There's a script included with the module that allows you to upload some files to an azure container: | ||
```bash | ||
$ ./node_modules/.bin/upload-to-azure \ | ||
--account ACCOUNT_NAME \ | ||
--key ACCOUNT_KEY \ | ||
--container CONTAINER_NAME \ | ||
file1.txt \ | ||
file2.txt | ||
```javascript | ||
gulp.task(['default'], function() { | ||
return gulp.src('bin/**') | ||
.pipe(azure.upload({ | ||
account: ACCOUNT_NAME, | ||
key: ACCOUNT_KEY, | ||
container: CONTAINER_NAME | ||
})); | ||
}); | ||
``` | ||
You can also provide a **relative** folder to upload every file in that folder structure, instead of every file, one by one: | ||
```bash | ||
$ ./node_modules/.bin/upload-to-azure \ | ||
--account ACCOUNT_NAME \ | ||
--key ACCOUNT_KEY \ | ||
--container CONTAINER_NAME \ | ||
folder | ||
``` | ||
### Download | ||
@@ -47,3 +37,3 @@ | ||
gulp.task(['default'], function() { | ||
return azure({ | ||
return azure.download({ | ||
account: ACCOUNT_NAME, | ||
@@ -56,2 +46,15 @@ key: ACCOUNT_KEY, | ||
### CLI | ||
There's a script included with the module that allows you to upload some files to an azure container: | ||
```bash | ||
$ upload-to-azure \ | ||
--account ACCOUNT_NAME \ | ||
--key ACCOUNT_KEY \ | ||
--container CONTAINER_NAME \ | ||
file1.txt \ | ||
file2.txt | ||
``` | ||
## Options | ||
@@ -67,2 +70,2 @@ | ||
- `quiet` - shhh | ||
- `buffer` - `boolean` for whether to buffer the blobs or stream them | ||
- `buffer` - `boolean` for whether to buffer the blobs or stream them (only for download) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6929
159
67