New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload 10 files at a time, plus other minor changes #5

Closed
wants to merge 2 commits into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+28 −31
Diff settings

Always

Just for now

Viewing a subset of changes. View all
Prev

Remove maskBaseDir and destPrefix options

I've replaced the plugin's current technique of taking an array of
sources and options to generate the destination with support for the
standard Grunt source/destination mapping.

The maskBaseDir and destPrefix options required users to learn
options specific to this task that could be accomplished using Grunt's
standardized file mapping utilities instead. Allowing the user to use
Grunt's file configuration means:
    1. The user doesn't have to learn something new.
    2. The user can weild Grunt's much more powerful options.
    3. There is less code in the plugin.

For example, these are equivalent:

Old way, using makeBaseDir and destPrefix:

    css: {
      options: {
        destPrefix: '<%= pkg.version %>/'
        maskBaseDir: '../web/Content/'
      },
      src: ['../web/Content/**/*','!../web/Content/themes/**/*']
    }

New way, using standard Grunt conventions:

    css: {
      files: [{
        expand: true,
        cwd: '../web/Content',
        dest: '<%= pkg.version %>/',
        src: ['**/*', '!themes/**/*']
      }]
    }
  • Loading branch information...
altano committed Jul 5, 2013
commit 15efc3dc42339376ab9c2eaf7d7da84001e07bc8
View
@@ -27,8 +27,6 @@ grunt-azureblob is a multi task that implicity iterates over all of its name sub
containerDelete: false, // deletes container if it exists
containerOptions: {publicAccessLevel: "blob", timeoutIntervalInMs: 10000}, // container options
copySimulation: false, // do everything but physically touch storage blob when true
destPrefix: '', // prefix to use for blob name e.g. 'v0.0.1/'
maskBaseDir: '', // mask off directory portion to map files to root in storage container
metadata: {cacheControl: 'public, max-age=31556926'}, // file metadata properties
gzip: false, // gzip files (when true: only js / css will be gzip'd)
maxNumberOfConcurrentUploads: 10 // Maximum number of concurrent uploads
@@ -55,21 +53,28 @@ module.exports = function(grunt) {
containerDelete: false,
metadata: {cacheControl: 'public, max-age=31556926'}, // max-age 1 year for all entries
gzip: true,
copySimulation: true, // set true: dry-run for what copy would look like in output
destPrefix: '<%= pkg.version %>/'
copySimulation: true // set true: dry-run for what copy would look like in output
},
css :{
options: {
maskBaseDir: '../web/Content/' // strip off this prefix from files
},
src: ['../web/Content/**/*','!../web/Content/themes/**/*'] // copy all files from Content (exclude themes dir)
files: [{
expand: true,
cwd: '../web/Content',
filter: 'isFile',
dest: '<%= pkg.version %>/',
src: ['**/*', '!themes/**/*'] // copy all files from Content (exclude themes dir)
}]
},
js :{
options: {
containerDelete: false,
maskBaseDir: '../web/scripts/'
containerDelete: false
},
src: ['../web/scripts/vendor*.js']
files: [{
expand: true,
cwd: '../web/scripts',
filter: 'isFile',
dest: '<%= pkg.version %>/',
src: ['vendor*.js']
}]
}
}
});
View
@@ -19,8 +19,6 @@ module.exports = function(grunt) {
containerOptions: {publicAccessLevel: "blob", timeoutIntervalInMs: 10000}, // container options
metadata: {cacheControl: 'public, max-age=31556926'}, // file metadata properties
copySimulation: false,
destPrefix: '', // detination path prefix to use for blob name e.g. 'v0.0.1/'
maskBaseDir: '',
gzip: false, // gzip files
maxNumberOfConcurrentUploads: 10 // Maximum number of concurrent uploads
}),
@@ -49,7 +47,7 @@ module.exports = function(grunt) {
// returns a q promise
function iterateFiles() {
var deferred = Q.defer(),
files = self.filesSrc.filter(fileExists); // filesSrc can include dir's, not just files
files = self.files.filter(fileExistsAndIsWellFormed); // filesSrc can include dir's, not just files
grunt.verbose.writeln(util.format('\tprocess (%s) files', files.length));
@@ -143,8 +141,9 @@ module.exports = function(grunt) {
}
// Iterator called from grunt.util.async.forEachLimit - for each source file in task
function copyFile(source, callback) {
var destination = source, // set default destination same as source
function copyFile(file, callback) {
var source = file.src,
destination = file.dest,
meta = options.metadata,
srcFile = path.basename(source),
gzip = options.gzip,
@@ -156,19 +155,6 @@ module.exports = function(grunt) {
gzip = false;
}
// ensure trailing slash is present in destination
if (options.maskBaseDir) {
destination = source.replace(options.maskBaseDir,'');
}
if (options.destPrefix && options.destPrefix.length > 0 && options.destPrefix.substr(-1) !== '/') {
options.destPrefix += '/';
}
if (options.destPrefix) {
destination = options.destPrefix + destination;
}
// configure proper azure metadata for file
meta.contentType = mime.lookup(source);
meta.contentTypeHeader = mime.lookup(source);
@@ -248,8 +234,14 @@ module.exports = function(grunt) {
return deferred.promise;
}
function fileExists (dest) {
return fs.statSync(dest).isFile() && fs.existsSync(dest);
function fileExistsAndIsWellFormed(file) {
if (file.src.length !== 1) {
grunt.fail.warn('File mapping must contain exactly one source to one destination.');
}
file.src = file.src[0];
return fs.statSync(file.src).isFile() && fs.existsSync(file.src);
}
});
ProTip! Use n and p to navigate between commits in a pull request.