Skip to content

Commit

Permalink
Finished task
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeobrien committed Dec 16, 2013
1 parent 66f8cf1 commit f4c2415
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 79 deletions.
44 changes: 24 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,30 @@ assembly information:

```js
assemblyinfo: {
// Can either be a solution, project or assembly info file
files: ['src/MySolution.sln',
'src/MyProject/MyProject.csproj',
'src/MyProject/Properties/AssemblyInfo.cs'],

// Filename to search for when a solution or project is
// specified above. Default is AssemblyInfo.cs.
filename: 'MyCustomAssemblyInfo.cs',

// Standard assembly info attributes
title: 'Planet Express Website',
description: 'Shipping and tracking website.',
configuration: 'Release',
company: 'Planet Express',
product: 'Planet Express Website',
copyright: 'Copyright 3002 © Planet Express',
trademark: 'Planet Express',
culture: 'div-MV',
version: '2.0',
fileVersion: '2.0.3.2345'
options: {
// Can either be a solution, project or assembly info file
files: ['src/MySolution.sln',
'src/MyProject/MyProject.csproj',
'src/MyProject/Properties/AssemblyInfo.cs'],

// Filename to search for when a solution or project is
// specified above. Default is AssemblyInfo.cs.
filename: 'MyCustomAssemblyInfo.cs',

// Standard assembly info
info: {
title: 'Planet Express Website',
description: 'Shipping and tracking website.',
configuration: 'Release',
company: 'Planet Express',
product: 'Planet Express Website',
copyright: 'Copyright 3002 © Planet Express',
trademark: 'Planet Express',
culture: 'div-MV',
version: '2.0',
fileVersion: '2.0.3.2345'
}
}
}
```

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
"grunt-mocha-test": "~0.8.1",
"rewire": "~2.0.0",
"wrench": "~1.5.4",
"temp": "~0.6.0"
"temp": "~0.6.0",
"sinon": "~1.7.3",
"underscore": "~1.5.2"
},
"peerDependencies": {
"grunt": "0.4.x"
Expand Down
33 changes: 28 additions & 5 deletions tasks/task.js
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);
});
};
90 changes: 45 additions & 45 deletions test/assemblyInfo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,56 @@ var expect = require('expect.js'),
path = require('path'),
wrench = require('wrench');

describe('assemblyInfo', function(){

var source = fs.readFileSync('test/Data/Solution/Properties/AssemblyInfo.cs', 'utf8');

var result =
'using System.Reflection;\r\n' +
'\r\n' +
'// General Information about an assembly is controlled through the following \r\n' +
'[assembly: AssemblyTitle("This is the title")]\r\n' +
'[assembly: AssemblyDescription("This is the description")]\r\n' +
'[assembly: AssemblyConfiguration("This is the configuration")]\r\n' +
'[assembly: AssemblyCompany("This is the company")]\r\n' +
'[assembly: AssemblyProduct("This is the product")]\r\n' +
'[assembly: AssemblyCopyright("This is the copyright")]\r\n' +
'[assembly: AssemblyTrademark("This is the trademark")]\r\n' +
'[assembly: AssemblyCulture("This is the culture")]\r\n' +
'\r\n' +
'// COM, set the ComVisible attribute to true on that type.\r\n' +
'[assembly: ComVisible(false)]\r\n' +
'\r\n' +
'// The following GUID is for the ID of the typelib if this project is exposed to COM\r\n' +
'[assembly: Guid("5e92281a-f318-4b4c-87f4-dba1a0f4ef48")]\r\n' +
'\r\n' +
'// Version information for an assembly consists of the following four values:\r\n' +
'[assembly: AssemblyVersion("This is the version")]\r\n' +
'[assembly: AssemblyFileVersion("This is the file version")]';

var values = {
title: 'This is the title',
description: 'This is the description',
configuration: 'This is the configuration',
company: 'This is the company',
product: 'This is the product',
copyright: 'This is the copyright',
trademark: 'This is the trademark',
culture: 'This is the culture',
version: 'This is the version',
fileVersion: 'This is the file version'
};
var source = fs.readFileSync('test/Data/Solution/Properties/AssemblyInfo.cs', 'utf8');

var result =
'using System.Reflection;\r\n' +
'\r\n' +
'// General Information about an assembly is controlled through the following \r\n' +
'[assembly: AssemblyTitle("This is the title")]\r\n' +
'[assembly: AssemblyDescription("This is the description")]\r\n' +
'[assembly: AssemblyConfiguration("This is the configuration")]\r\n' +
'[assembly: AssemblyCompany("This is the company")]\r\n' +
'[assembly: AssemblyProduct("This is the product")]\r\n' +
'[assembly: AssemblyCopyright("This is the copyright")]\r\n' +
'[assembly: AssemblyTrademark("This is the trademark")]\r\n' +
'[assembly: AssemblyCulture("This is the culture")]\r\n' +
'\r\n' +
'// COM, set the ComVisible attribute to true on that type.\r\n' +
'[assembly: ComVisible(false)]\r\n' +
'\r\n' +
'// The following GUID is for the ID of the typelib if this project is exposed to COM\r\n' +
'[assembly: Guid("5e92281a-f318-4b4c-87f4-dba1a0f4ef48")]\r\n' +
'\r\n' +
'// Version information for an assembly consists of the following four values:\r\n' +
'[assembly: AssemblyVersion("This is the version")]\r\n' +
'[assembly: AssemblyFileVersion("This is the file version")]';

var values = {
title: 'This is the title',
description: 'This is the description',
configuration: 'This is the configuration',
company: 'This is the company',
product: 'This is the product',
copyright: 'This is the copyright',
trademark: 'This is the trademark',
culture: 'This is the culture',
version: 'This is the version',
fileVersion: 'This is the file version'
};

describe('assemblyInfo', function() {

var data;

beforeEach(function() {
//temp.track();
data = temp.mkdirSync() + '/Data';
temp.track();
data = temp.mkdirSync() + '/Data/';
wrench.copyDirSyncRecursive('test/Data', data);
});

afterEach(function() {
//temp.cleanup();
temp.cleanup();
});

it('should set info attributes', function() {
Expand All @@ -66,9 +66,9 @@ describe('assemblyInfo', function(){

it('should set info attributes in files', function() {

var file1 = data + '/Solution/Properties/AssemblyInfo.cs',
file2 = data + '/Solution/Project.WebApplication/Properties/AssemblyInfo.cs',
file3 = data + '/Project.WpfApplication/Properties/AssemblyInfo.cs';
var file1 = data + 'Solution/Properties/AssemblyInfo.cs',
file2 = data + 'Solution/Project.WebApplication/Properties/AssemblyInfo.cs',
file3 = data + 'Project.WpfApplication/Properties/AssemblyInfo.cs';

assemblyInfo.setFileAttrbutes([file1, file2, file3], values);

Expand Down
6 changes: 3 additions & 3 deletions test/msbuild.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var expect = require('expect.js'),

describe('msbuild', function() {

it('should enumerate solution projects', function(){
it('should enumerate solution projects', function() {

var projects = msbuild.getSolutionProjects('test/Data/Solution/Solution.sln');
expect(projects.length).to.be(3);
Expand All @@ -13,15 +13,15 @@ describe('msbuild', function() {

});

it('should enumerate project files', function(){
it('should enumerate project files', function() {

var files = msbuild.getProjectFiles('test/Data/Project.WpfApplication/Project.WpfApplication.csproj', 'AssemblyInfo.cs');
expect(files.length).to.be(1);
expect(files[0]).to.be('test/Data/Project.WpfApplication/Properties/AssemblyInfo.cs');

});

it('should enumerate solution files', function(){
it('should enumerate solution files', function() {

var files = msbuild.getSolutionFiles('test/Data/Solution/Solution.sln', 'AssemblyInfo.cs');
expect(files.length).to.be(3);
Expand Down
74 changes: 69 additions & 5 deletions test/task.spec.js
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);

});

});

0 comments on commit f4c2415

Please sign in to comment.