Skip to content

Commit

Permalink
Updating new output and copy behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
arobson committed Sep 22, 2012
1 parent 53f913b commit a783200
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 121 deletions.
127 changes: 70 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ This plugin will read the output path or list of output paths. For each path in

### Example Source Structure

/src
| a.js
| b.css
| c.html
| - subdir
| d.js
| e.css
| f.html
/src
| a.js
| b.css
| c.html
| - subdir
| d.js
| e.css
| f.html

### Build File 1

Expand All @@ -31,14 +31,14 @@ This plugin will read the output path or list of output paths. For each path in

**output structure**

/lib
| a.js
| b.css
| c.html
| - subdir
| d.js
| e.css
| f.html
/lib
| a.js
| b.css
| c.html
| - subdir
| d.js
| e.css
| f.html

### Build File 2

Expand All @@ -50,43 +50,47 @@ This plugin will read the output path or list of output paths. For each path in

**output structure**

/lib
| a.js
| b.css
| c.html
| - subdir
| d.js
| e.css
| f.html

/output
| a.js
| b.css
| c.html
| - subdir
| d.js
| e.css
| f.html
/lib
| a.js
| b.css
| c.html
| - subdir
| d.js
| e.css
| f.html

/site
| a.js
| b.css
| c.html
| - subdir
| d.js
| e.css
| f.html

## Additional Copy Control
You can further control what build files get copied to where using the "anvil.output": { "copy": {} } build option. The copy property is a hash where the key is a minimatch (glob) format of the files to be copied and the value is a path or paths to copy all matched files to.
You can further control what build files get copied to where using an object to control output.

In the object format, the full property can be a single string or a list of strings for full output behavior as described previously.

The partial property is a hash where the key is a minimatch (glob) format of the files to be copied and the value is a path or paths to copy all matched files to.

### Example Source Structure

/src
| a.js
| b.css
| c.html
| - subdir
| d.js
| e.css
| f.html
/src
| a.js
| b.css
| c.html
| - subdir
| d.js
| e.css
| f.html

### Build File 1
'''
{
"anvil.output": {
"copy": {
"output": {
"parital": {
"**/*.js": "js"
}
}
Expand All @@ -95,17 +99,18 @@ You can further control what build files get copied to where using the "anvil.ou

***output structure***

/js
| a.js
| b.js
/js
| a.js
| b.js

Note: the files output in the matter are output flat and to not retain the structure they were pulled from.
Note: the files copied using partial do not retain the structure they were pulled from.

### Build File 2
'''
{
"anvil.output": {
"copy": {
"output": {
"full": "lib"
"partial": {
"**/*.css": "css",
"**/*.html": "html"
}
Expand All @@ -114,10 +119,18 @@ Note: the files output in the matter are output flat and to not retain the struc
'''

***output structure***

/css
| b.css
| e.css
/html
| c.html
| f.html
/lib
| a.js
| b.css
| c.html
| - subdir
| d.js
| e.css
| f.html

/css
| b.css
| e.css
/html
| c.html
| f.html
73 changes: 41 additions & 32 deletions lib/output.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
anvil.output - An anvil core plugin that pushes complete files to output
version: 0.0.4
version: 0.0.5
author: Alex Robson <alex@sharplearningcurve.com> (http://sharplearningcurve.com)
copyright: 2011 - 2012
license: Dual licensed
Expand All @@ -14,15 +14,14 @@ module.exports = function( _, anvil ) {
return anvil.plugin( {
name: "anvil.output",
activity: "push",
config: {
copy: {
}
},
output: {},
commander: [
[ "--clean", "Cleans all full output directories" ]
],
clean: function( done ) {
var self = this,
list = _.isArray( anvil.config.output ) ? anvil.config.output : [ anvil.config.output ],
base = path.resolve( "./" );
anvil.scheduler.parallel( list, function( directory, done ) {
var self = this;
anvil.scheduler.parallel( this.output.full, function( directory, done ) {
directory = directory.replace( /[{]relative[}]/, "" );
anvil.log.event( "cleaning " + directory );
anvil.fs.cleanDirectory( directory, function( err ) {
if( err ) {
Expand All @@ -34,29 +33,25 @@ module.exports = function( _, anvil ) {
},

configure: function( config, command, done ) {
var self = this,
all = self.copy[ "**/*" ],
outputList = _.isArray( anvil.config.output ) ? anvil.config.output : [ anvil.config.output ];
outputList = _.map( outputList, function( outputPath ) {
return path.join( outputPath, "{relative}" );
var self = this;
this.normalizeConfig();
if( command[ "clean" ] ) {
this.clean( function() {
anvil.events.raise( "all.stop", 0 );
} );
if( all ) {
all = all.concat( outputList );
} else {
self.config.copy[ "**/*" ] = outputList;
anvil.events.on( "file.deleted", function( change, path, base ) {
if( base === anvil.config.source ) {
self['delete']( path );
}
} );
done();
}
anvil.events.on( "file.deleted", function( change, path, base ) {
if( base === anvil.config.source ) {
self['delete']( path );
}
} );
done();
},

copy: function( done ) {
var self = this,
list = this.getOutputList(),
base = path.resolve( "./" );
list = this.getOutputList();
anvil.scheduler.parallel( list, function( spec, done ) {
var files = self.getFilesForPattern( spec.pattern );
anvil.scheduler.parallel( spec.directories, function( directory, done ) {
Expand Down Expand Up @@ -91,18 +86,32 @@ module.exports = function( _, anvil ) {
},

getOutputList: function() {
var self = this;
return _.map( self.config.copy, function( directories, pattern ) {
directories = _.isArray( directories ) ? directories : [ directories ];
return { pattern: pattern, directories: directories };
var partials = _.map( this.output.partial, function( directories, pattern ) {
directories = _.isArray( directories ) ? directories : [ directories ];
return { pattern: pattern, directories: directories };
} );
return partials.concat( { pattern: "**/*", directories: this.output.full } );
},

normalizeConfig: function() {
var output = anvil.config.output;
this.output.partial = {};
if( _.isString( output ) ) {
this.output.full = [ output ];
} else if( _.isArray( output ) ) {
this.output.full = output;
} else {
this.output = _.extend( this.output, output );
this.output.full = _.isArray( this.output.full ) ? this.output.full : [ this.output.full ];
}
this.output.full = _.map( this.output.full, function( fullPath ) {
return fullPath.match( /[{]relative[}]/ ) ? fullPath : fullPath + "/{relative}";
} );
},

run: function( done ) {
var self = this;
this.clean( function() {
self.copy( done );
} );
self.copy( done );
}
} );
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Alex Robson <alex@sharplearningcurve.com> (http://sharplearningcurve.com)",
"name": "anvil.output",
"description": "An anvil core plugin that pushes complete files to output",
"version": "0.0.4",
"version": "0.0.5",
"repository": {
"type": "git",
"url": "git://github.com/arobson/anvil.output.git"
Expand Down
Loading

0 comments on commit a783200

Please sign in to comment.