Allow users to store custom dist destinations in dist/.destination.json

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
This commit is contained in:
Rick Waldron 2012-06-05 13:10:01 -04:00
parent e0cdeac87b
commit 8265fa0837
3 changed files with 65 additions and 18 deletions

1
.gitignore vendored
View File

@ -7,6 +7,7 @@ dist
*.patch *.patch
/*.html /*.html
.DS_Store .DS_Store
dist/.destination.json
dist/.sizecache.json dist/.sizecache.json
build/.sizecache.json build/.sizecache.json
node_modules node_modules

View File

@ -98,6 +98,20 @@ With this example, the output files would be:
``` ```
If you want to add a permanent copy destination, create a file in `dist/` called ".destination.json". Inside the file, paste and customize the following:
```json
{
"/Absolute/path/to/other/destination": true
}
```
Additionally, both methods can be combined.
Updating Submodules Updating Submodules
------------------- -------------------

View File

@ -1,9 +1,25 @@
// Resources /**
// https://gist.github.com/2489540 * Resources
*
* https://gist.github.com/2489540
*
*/
/*global config:true, task:true*/ /*global config:true, task:true*/
module.exports = function( grunt ) { module.exports = function( grunt ) {
// readOptionalJSON
// by Ben Alman
// https://gist.github.com/2876125
function readOptionalJSON( filepath ) {
var data = {};
try {
data = grunt.file.readJSON(filepath);
grunt.log.write( "Reading data from " + filepath + "..." ).ok();
} catch(e) {}
return data;
}
var task = grunt.task; var task = grunt.task;
var file = grunt.file; var file = grunt.file;
var utils = grunt.utils; var utils = grunt.utils;
@ -20,6 +36,7 @@ module.exports = function( grunt ) {
grunt.initConfig({ grunt.initConfig({
pkg: "<json:package.json>", pkg: "<json:package.json>",
dst: readOptionalJSON("dist/.destination.json"),
meta: { meta: {
banner: "/*! jQuery v@<%= pkg.version %> jquery.com | jquery.org/license */" banner: "/*! jQuery v@<%= pkg.version %> jquery.com | jquery.org/license */"
}, },
@ -234,32 +251,47 @@ module.exports = function( grunt ) {
// Allow custom dist file locations // Allow custom dist file locations
grunt.registerTask( "dist", function() { grunt.registerTask( "dist", function() {
var keys, dir; var flags, paths, stored;
keys = Object.keys( this.flags ); // Check for stored destination paths
// ( set in dist/.destination.json )
stored = Object.keys( config("dst") );
if ( keys.length ) { // Allow command line input as well
flags = Object.keys( this.flags );
// If a custom dist dir wasn't specified // Combine all output target paths
// there is nothing to do. paths = [].concat( stored, flags ).filter(function( path ) {
if ( keys[0] === "*" ) { return path !== "*";
return; });
}
dir = keys[0];
if ( !/\/$/.test( dir ) ) { // Proceed only if there are actual
dir += "/"; // paths to write to
} if ( paths.length ) {
// 'distpaths' is declared at the top of the // 'distpaths' is declared at the top of the
// module.exports function scope. // module.exports function scope. It is an array
// of default files that jQuery creates
distpaths.forEach(function( filename ) { distpaths.forEach(function( filename ) {
var created = dir + filename.replace( "dist/", "" ); paths.forEach(function( path ) {
var created;
file.write( created, file.read( filename ) ); if ( !/\/$/.test( path ) ) {
path += "/";
}
log.writeln( "File '" + created + "' created." ); created = path + filename.replace( "dist/", "" );
if ( !/^\//.test( path ) ) {
log.error( "File '" + created + "' was NOT created." );
return;
}
file.write( created, file.read(filename) );
log.writeln( "File '" + created + "' created." );
});
}); });
} }
}); });