forked from mikeobrien/grunt-dotnet-assembly-info
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66f8cf1
commit f4c2415
Showing
6 changed files
with
172 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,34 @@ | ||
var path = require('path'), | ||
msbuild = require('./msbuild.js'), | ||
assemblyInfo = require('./assemblyInfo.js'); | ||
|
||
module.exports = function(grunt) { | ||
grunt.registerTask('assemblyinfo', 'Sets .NET assembly information.', function() { | ||
var options = this.options(); | ||
var keys = Object.keys(options); | ||
var options = this.options({ filename: 'AssemblyInfo.cs' }); | ||
var attrs; | ||
|
||
if (!options.info || (attrs = Object.keys(options.info)).length < 1) | ||
grunt.warn('No assembly info options set.'); | ||
|
||
console.log(' Setting ' + options.filename + ' with:'); | ||
console.log(); | ||
attrs.forEach(function(attr) { console.log(' ' + attr + ': ' + options.info[attr]); }); | ||
console.log(); | ||
|
||
var files = []; | ||
options.files.forEach(function(file) { | ||
switch (path.extname(file.trim())) { | ||
case '.sln': files = files.concat(msbuild.getSolutionFiles(file, options.filename)); break; | ||
case '.csproj': files = files.concat(msbuild.getProjectFiles(file, options.filename)); break; | ||
default: files.push(file); | ||
} | ||
}); | ||
|
||
if (keys.length < 1) grunt.warn('No assembly info options set.'); | ||
console.log('Files:'); | ||
console.log(); | ||
files.forEach(function(file) { console.log(file); }); | ||
console.log(); | ||
|
||
console.log('Setting assembly info to:'); | ||
keys.forEach(function(option) { console.log(' ' + option + ': ' + options[option]); }); | ||
assemblyInfo.setFileAttrbutes(files, options.info); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,74 @@ | ||
var expect = require('expect.js'); | ||
var expect = require('expect.js'), | ||
sinon = require('sinon'), | ||
_ = require('underscore'), | ||
task = require('../tasks/task.js'), | ||
fs = require('fs'), | ||
temp = require('temp'), | ||
wrench = require('wrench'); | ||
|
||
function runTask(options) { | ||
var grunt = { registerTask: sinon.spy() }; | ||
task(grunt); | ||
var context = { options: function(defaults) { return _.extend(options, defaults); } }; | ||
grunt.registerTask.firstCall.args[2].apply(context); | ||
} | ||
|
||
describe('task', function(){ | ||
|
||
it('should be awesome', function(){ | ||
console.log('oh hai'); | ||
expect(1).to.be(1); | ||
}); | ||
var data; | ||
var attribute = '[assembly: AssemblyTitle("This is the title")]'; | ||
|
||
beforeEach(function() { | ||
temp.track(); | ||
data = temp.mkdirSync() + '/Data/'; | ||
wrench.copyDirSyncRecursive('test/Data', data); | ||
}); | ||
|
||
afterEach(function() { | ||
temp.cleanup(); | ||
}); | ||
|
||
it('should set assembly info on a solution', function() { | ||
|
||
runTask({ | ||
files: [data + 'Solution/Solution.sln'], | ||
info: { title: 'This is the title' } | ||
}); | ||
|
||
var file1 = data + 'Solution/Properties/AssemblyInfo.cs', | ||
file2 = data + 'Solution/Project.WebApplication/Properties/AssemblyInfo.cs', | ||
file3 = data + 'Project.WpfApplication/Properties/AssemblyInfo.cs'; | ||
|
||
expect(fs.readFileSync(file1, 'utf8')).to.contain(attribute); | ||
expect(fs.readFileSync(file2, 'utf8')).to.contain(attribute); | ||
expect(fs.readFileSync(file3, 'utf8')).to.contain(attribute); | ||
|
||
}); | ||
|
||
it('should set assembly info on a project', function() { | ||
|
||
runTask({ | ||
files: [data + 'Project.WpfApplication/Project.WpfApplication.csproj'], | ||
info: { title: 'This is the title' } | ||
}); | ||
|
||
var file = data + 'Project.WpfApplication/Properties/AssemblyInfo.cs'; | ||
|
||
expect(fs.readFileSync(file, 'utf8')).to.contain(attribute); | ||
|
||
}); | ||
|
||
it('should set assembly info on a file', function() { | ||
|
||
runTask({ | ||
files: [data + 'Project.WpfApplication/Properties/AssemblyInfo.cs'], | ||
info: { title: 'This is the title' } | ||
}); | ||
|
||
var file = data + 'Project.WpfApplication/Properties/AssemblyInfo.cs'; | ||
|
||
expect(fs.readFileSync(file, 'utf8')).to.contain(attribute); | ||
|
||
}); | ||
|
||
}); |