Skip to content

Instantly share code, notes, and snippets.

@jcreamer898
Created October 21, 2012 04:33
Show Gist options
  • Save jcreamer898/3925768 to your computer and use it in GitHub Desktop.
Save jcreamer898/3925768 to your computer and use it in GitHub Desktop.
Build csharp with anvil.js
var spawn = require( "child_process" ).spawn;
var pluginFactory = function(_, anvil) {
return anvil.plugin({
// Name your plugin
name: "anvil.csharp",
// Activity list: "identify", "pull", "combine", "pre-process","compile", "post-process", "push", "test"
activity: "identify",
// Command all the things [ "-s, --somecommand", "Run this plugin for awesomesauce" ]
commander: [
[ "--csharp", "Run a scaffolder based on the config" ],
[ "--run", "Run a scaffolder based on the config" ]
],
config: {
target: "exe",
source: "*.cs",
run: false
},
// Configure all the things...
configure: function( config, command, done ) {
this.config.run = this.config.run || command.run;
done();
},
// Run all the things...
run: function( done ) {
var commands = this.buildCommands(),
csc = null, run = null;
csc = spawn( "csc", commands );
csc.stdout.on( "data", function( data ) {
console.log( data.toString() );
});
csc.stderr.on( "data", function (data) {
console.log( data.toString() );
});
csc.on( "exit", function( data ) {
console.log( "Done..." );
if ( this.config.run ) {
// run = spawn( "cmd", [ this.config.output ] );
}
done();
}.bind( this ));
},
buildCommands: function() {
var commands = [];
this.cleanPathCommands();
commands.push( "/target:" + this.config.target );
if ( this.config.output ) {
commands.push( "/out:" + this.config.output );
}
if ( this.config.references && this.config.references.length ) {
commands.push( "/r:" + this.config.references.join( ";" ) );
}
commands.push( anvil.config.source + "\\" + this.config.source );
return commands;
},
cleanPathCommands: function() {
var keys = [ "output", "source" ];
_.each( keys, function( key ) {
this.config[ key ].replace( /\//g, "\\");
}, this);
}
});
};
module.exports = pluginFactory;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment