diff --git a/.gitignore b/.gitignore index 2464c52c..c395d3c9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules .DS_Store npm-debug.log -.npmignore \ No newline at end of file +.npmignore +.tmp \ No newline at end of file diff --git a/app/index.js b/app/index.js index cb309e2f..381a3ae1 100644 --- a/app/index.js +++ b/app/index.js @@ -2,7 +2,7 @@ var yeoman = require('yeoman-generator'); var yosay = require('yosay'); var chalk = require('chalk'); - +var path = require('path'); var AspnetGenerator = yeoman.generators.Base.extend({ init: function () { @@ -17,6 +17,10 @@ var AspnetGenerator = yeoman.generators.Base.extend({ name: 'type', message: 'What type of application do you want to create?', choices: [ + { + name: 'Empty Application', + value: 'empty' + }, { name: 'Console Application', value: 'console' @@ -37,7 +41,7 @@ var AspnetGenerator = yeoman.generators.Base.extend({ name: 'Class Library', value: 'classlib' }, - { + { name: 'Unit test project', value: 'unittest' } @@ -55,6 +59,9 @@ var AspnetGenerator = yeoman.generators.Base.extend({ var done = this.async(); var app = ''; switch (this.type) { + case 'empty': + app = 'EmptyApplication'; + break; case 'console': app = 'ConsoleApplication'; break; @@ -70,7 +77,7 @@ var AspnetGenerator = yeoman.generators.Base.extend({ case 'classlib': app = 'ClassLibrary' break; - case 'unittest': + case 'unittest': app = 'UnitTest' break; } @@ -78,7 +85,7 @@ var AspnetGenerator = yeoman.generators.Base.extend({ name: 'applicationName', message: 'What\'s the name of your ASP.NET application?', default: app - } ]; + }]; this.prompt(prompts, function (props) { this.applicationName = props.applicationName; @@ -86,38 +93,28 @@ var AspnetGenerator = yeoman.generators.Base.extend({ }.bind(this)); }, - retrieveContent: function () { - var done = this.async(); - var self = this; - this.remote('OmniSharp', 'generator-aspnet', 'release', function (err, remote) { - if(err) { - self.log.error(err); - process.exit(1); - } - done(); - }, true); - }, - writing: function () { + this.sourceRoot(path.join(__dirname, '../samples/')); + this.mkdir(this.applicationName); switch (this.type) { - case 'console': - this.directory(this.cacheRoot() + '/OmniSharp/generator-aspnet/release/samples/console', this.applicationName); + + case 'empty': + this.template(this.type + '/startup.cs', this.applicationName + '/Startup.cs', { + namespace: this.applicationName + }); + + this.copy(this.type + '/project.json', this.applicationName + '/project.json'); + break; + + case 'console': case 'web': - this.directory(this.cacheRoot() + '/OmniSharp/generator-aspnet/release/samples/web', this.applicationName); - break; case 'mvc': - this.directory(this.cacheRoot() + '/OmniSharp/generator-aspnet/release/samples/mvc', this.applicationName); - break; case 'nancy': - this.directory(this.cacheRoot() + '/OmniSharp/generator-aspnet/release/samples/nancy', this.applicationName); - break; case 'classlib': - this.directory(this.cacheRoot() + '/OmniSharp/generator-aspnet/release/samples/classlib', this.applicationName); - break; - case 'unittest': - this.directory(this.cacheRoot() + '/OmniSharp/generator-aspnet/release/samples/unittest', this.applicationName); + case 'unittest': + this.directory(this.type, this.applicationName); break; default: this.log('Unknown project type'); @@ -125,7 +122,7 @@ var AspnetGenerator = yeoman.generators.Base.extend({ }, end: function () { - this.log(this.cacheRoot()); + //this.log(this.cacheRoot()); if (!this.options['skip-install']) { this.log('\r\n'); this.log('Your project is now created, you can use the following commands to get going'); @@ -136,6 +133,8 @@ var AspnetGenerator = yeoman.generators.Base.extend({ this.log('\r\n'); } } + + }); -module.exports = AspnetGenerator; +module.exports = AspnetGenerator; \ No newline at end of file diff --git a/package.json b/package.json index 53ac16fe..9fb36905 100644 --- a/package.json +++ b/package.json @@ -1,43 +1,43 @@ { - "name": "generator-aspnet", - "version": "0.0.27", - "description": "Yeoman generator for ASP.NET 5 apps", - "license": "Apache License 2.0", - "main": "app/index.js", - "repository": "OmniSharp/generator-aspnet", - "contributors": [ - { - "name": "Sourabh Shirhatti", - "email": "shirhatti@outlook.com", - "url": "https://github.com/shirhatti" - }, - { - "name": "Sayed Hashimi", - "email": "sayed.hashimi@gmail.com" - }, - { - "name": "Shayne Boyer", - "email": "spboyer@live.com", - "url": "https://github.com/spboyer" - }, - { - "name": "Jonathan Channon", - "email": "jonathan@jonathanchannon.com" - }, - { - "name": "Peter Blazejewicz", - "email": "peter.blazejewicz@gmail.com", - "url": "https://github.com/peterblazejewicz" - }, - { - "name": "Suhas Joshi", - "email": "suhasbjoshi@hotmail.com" + "name": "generator-aspnet", + "version": "0.0.27", + "description": "Yeoman generator for ASP.NET 5 apps", + "license": "Apache License 2.0", + "main": "app/index.js", + "repository": "OmniSharp/generator-aspnet", + "contributors": [ + { + "name": "Sourabh Shirhatti", + "email": "shirhatti@outlook.com", + "url": "https://github.com/shirhatti" + }, + { + "name": "Sayed Hashimi", + "email": "sayed.hashimi@gmail.com" + }, + { + "name": "Shayne Boyer", + "email": "spboyer@live.com", + "url": "https://github.com/spboyer" + }, + { + "name": "Jonathan Channon", + "email": "jonathan@jonathanchannon.com" + }, + { + "name": "Peter Blazejewicz", + "email": "peter.blazejewicz@gmail.com", + "url": "https://github.com/peterblazejewicz" + }, + { + "name": "Suhas Joshi", + "email": "suhasbjoshi@hotmail.com" } ], - "engines": { - "node": ">=0.10.0" - }, - "keywords": [ + "engines": { + "node": ">=0.10.0" + }, + "keywords": [ "yeoman-generator", "ASP.NET", "aspnet", @@ -45,12 +45,20 @@ "net", "vNext" ], - "dependencies": { - "yeoman-generator": "~0.18.5", - "yosay": "^0.1.0", - "chalk": "~0.4.0" - }, - "peerDependencies": { - "yo": ">=1.0.0" - } -} + "dependencies": { + "chai": "^1.10.0", + "chalk": "~0.4.0", + "fs-extra": "^0.16.3", + "gulp": "^3.8.10", + "mocha": "^2.1.0", + "yeoman-generator": "~0.18.5", + "yosay": "^0.1.0" + }, + "peerDependencies": { + "yo": ">=1.0.0" + }, + "scripts": { + "test": "mocha" + } + +} \ No newline at end of file diff --git a/samples/empty/Startup.cs b/samples/empty/Startup.cs new file mode 100644 index 00000000..33a10b69 --- /dev/null +++ b/samples/empty/Startup.cs @@ -0,0 +1,14 @@ +using System; +using Microsoft.AspNet.Builder; +using Microsoft.AspNet.Http; + +namespace <%= namespace %> +{ + public class Startup + { + public void Configure(IApplicationBuilder app) + { + // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 + } + } +} diff --git a/samples/empty/project.json b/samples/empty/project.json new file mode 100644 index 00000000..3aad53db --- /dev/null +++ b/samples/empty/project.json @@ -0,0 +1,21 @@ +{ + "webroot": "wwwroot", + "version": "1.0.0-*", + "exclude": [ + "wwwroot" + ], + "packExclude": [ + "node_modules", + "bower_components", + "**.kproj", + "**.user", + "**.vspscc" + ], + "dependencies": { + "Microsoft.AspNet.Server.IIS": "1.0.0-beta2" + }, + "frameworks": { + "aspnet50": {}, + "aspnetcore50": {} + } +} \ No newline at end of file diff --git a/samples/web/bin/Debug/aspnet50/web.dll b/samples/web/bin/Debug/aspnet50/web.dll deleted file mode 100644 index 9049a280..00000000 Binary files a/samples/web/bin/Debug/aspnet50/web.dll and /dev/null differ diff --git a/samples/web/bin/Debug/aspnet50/web.xml b/samples/web/bin/Debug/aspnet50/web.xml deleted file mode 100644 index d1e1c429..00000000 --- a/samples/web/bin/Debug/aspnet50/web.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - web - - - - diff --git a/samples/web/bin/Debug/web.0.1-alpha-SNAPSHOT.nupkg b/samples/web/bin/Debug/web.0.1-alpha-SNAPSHOT.nupkg deleted file mode 100644 index 63b1ab62..00000000 Binary files a/samples/web/bin/Debug/web.0.1-alpha-SNAPSHOT.nupkg and /dev/null differ diff --git a/samples/web/bin/Debug/web.0.1-alpha-SNAPSHOT.symbols.nupkg b/samples/web/bin/Debug/web.0.1-alpha-SNAPSHOT.symbols.nupkg deleted file mode 100644 index 795b8b38..00000000 Binary files a/samples/web/bin/Debug/web.0.1-alpha-SNAPSHOT.symbols.nupkg and /dev/null differ diff --git a/script-base.js b/script-base.js index 824268f2..c18366c8 100644 --- a/script-base.js +++ b/script-base.js @@ -5,22 +5,22 @@ var yeoman = require('yeoman-generator'); var chalk = require('chalk'); var NamedGenerator = module.exports = function NamedGenerator() { - yeoman.generators.NamedBase.apply(this, arguments); + yeoman.generators.NamedBase.apply(this, arguments); - var sourceRoot = '/templates/'; - this.sourceRoot(path.join(__dirname, sourceRoot)); + var sourceRoot = '/templates/'; + this.sourceRoot(path.join(__dirname, sourceRoot)); }; util.inherits(NamedGenerator, yeoman.generators.NamedBase); -NamedGenerator.prototype.generateTemplateFile = function(templateFile, targetFile, templateData) { - this.log('You called the aspnet subgenerator with the arg ' + this.name); +NamedGenerator.prototype.generateTemplateFile = function (templateFile, targetFile, templateData) { + this.log('You called the aspnet subgenerator with the arg ' + this.name); - if(templateData !== null){ - this.template(templateFile, targetFile, templateData); - } else { - this.template(templateFile, targetFile); - } + if (templateData !== null) { + this.template(templateFile, targetFile, templateData); + } else { + this.template(templateFile, targetFile); + } - this.log(targetFile + ' created.') + this.log(targetFile + ' created.') } \ No newline at end of file diff --git a/test/subgenerators.js b/test/subgenerators.js new file mode 100644 index 00000000..bba61a01 --- /dev/null +++ b/test/subgenerators.js @@ -0,0 +1,138 @@ +var util = require('./test-utility'); + +/* + * Test for all subgenerators NOT requiring a name argument + */ +describe('Subgenerators without arguments tests', function () { + + describe('aspnet:PackageJson', function () { + util.goCreate('PackageJson'); + util.fileCheck('should create package json file', 'package.json'); + }); + + describe('aspnet:Gulpfile', function () { + util.goCreate('Gulpfile'); + util.fileCheck('should create gulp file', 'gulpfile.js'); + }); + + describe('aspnet:BowerJson', function () { + util.goCreate('BowerJson'); + util.fileCheck('should create bower file', 'bower.json'); + }); + + describe('aspnet:Config', function () { + util.goCreate('Config'); + util.fileCheck('should create config json file', 'config.json'); + }); + + describe('aspnet:StartupClass', function () { + util.goCreate('StartupClass'); + util.fileCheck('should create Startup.cs file', 'Startup.cs'); + }); +}); + +/* + * Test for all subgenerators requiring a name argument + */ +describe('Subgenerators with named arguments tests', function () { + + describe('aspnet:Class', function () { + var arg = 'MyClass'; + var filename = 'MyClass.cs'; + + util.goCreateWithArgs('Class', [arg]); + util.fileCheck('should create ' + filename + ' file', filename); + util.fileContentCheck(filename, 'Check file content', /[ ]*public[ ]*class[ ]*MyClass/); + + }); + + describe('aspnet:CoffeeScript', function () { + var arg = 'file'; + var filename = 'file.coffee'; + + util.goCreateWithArgs('CoffeeScript', [arg]); + util.fileCheck('should create ' + filename + ' file', filename); + + }); + + describe('aspnet:Gruntfile', function () { + var arg = 'gruntfile'; + var filename = 'gruntfile.js'; + + util.goCreateWithArgs('Gruntfile', [arg]); + util.fileCheck('should create ' + filename + ' file', filename); + + }); + + describe('aspnet:HTMLPage', function () { + var arg = 'mypage'; + var filename = 'mypage.html'; + + util.goCreateWithArgs('HTMLPage', [arg]); + util.fileCheck('should create ' + filename + ' file', filename); + + }); + + describe('aspnet:JavaScript', function () { + var arg = 'file'; + var filename = 'file.js'; + + util.goCreateWithArgs('JavaScript', [arg]); + util.fileCheck('should create ' + filename + ' file', filename); + + }); + + describe('aspnet:JSON', function () { + var arg = 'file'; + var filename = 'file.json'; + + util.goCreateWithArgs('JSON', [arg]); + util.fileCheck('should create ' + filename + ' file', filename); + + }); + + describe('aspnet:MvcController', function () { + var arg = 'file'; + var filename = 'file.cs'; + + util.goCreateWithArgs('MvcController', [arg]); + util.fileCheck('should create ' + filename + ' file', filename); + + }); + + describe('aspnet:MvcView', function () { + var arg = 'file'; + var filename = 'file.cshtml'; + + util.goCreateWithArgs('MvcView', [arg]); + util.fileCheck('should create ' + filename + ' file', filename); + + }); + + describe('aspnet:TextFile', function () { + var arg = 'file'; + var filename = 'file.txt'; + + util.goCreateWithArgs('TextFile', [arg]); + util.fileCheck('should create ' + filename + ' file', filename); + + }); + + describe('aspnet:TypeScript', function () { + var arg = 'file'; + var filename = 'file.ts'; + + util.goCreateWithArgs('TypeScript', [arg]); + util.fileCheck('should create ' + filename + ' file', filename); + + }); + + describe('aspnet:WebApiController', function () { + var arg = 'file'; + var filename = 'file.cs'; + + util.goCreateWithArgs('WebApiController', [arg]); + util.fileCheck('should create ' + filename + ' file', filename); + + }); +}); \ No newline at end of file diff --git a/test/test-core.js b/test/test-core.js new file mode 100644 index 00000000..9362e829 --- /dev/null +++ b/test/test-core.js @@ -0,0 +1,206 @@ + var yeoman = require('yeoman-generator'); + var path = require('path'); + var mockGen; + var assert = yeoman.assert; + var util = require('./test-utility'); + + /* + * can be imported + */ + describe('aspnet 5 generator', function () { + it('can be imported', function () { + var app = require('../app'); + yeoman.assert.notEqual(app, undefined); + }) + }) + + + /* + * yo aspnet Empty Application + */ + describe('aspnet - Empty Application', function () { + + util.goCreateApplication('empty', 'emptyTest'); + + describe('Checking directories', function () { + it('Application directory created', function () { + assert.file('emptyTest/'); + }); + }); + + var files = ['emptyTest/project.json', 'emptyTest/Startup.cs']; + describe('Checking files', function () { + for (i = 0; i < files.length; i++) { + util.filesCheck(files[i]); + } + }); + + + }); + + /* + * yo aspnet Class Library + */ + describe('aspnet - Class Library', function () { + + util.goCreateApplication('classlib', 'classTest'); + + describe('Checking directories', function () { + it('Application directory created', function () { + assert.file('classTest/'); + }); + }); + + var files = ['classTest/project.json', 'classTest/Class1.cs']; + describe('Checking files', function () { + for (i = 0; i < files.length; i++) { + util.filesCheck(files[i]); + } + }); + + }); + + + /* + * yo aspnet Console Application + */ + describe('aspnet - Console Application', function () { + + util.goCreateApplication('console', 'consoleTest'); + + describe('Checking directories', function () { + it('Application directory created', function () { + assert.file('consoleTest/'); + }); + }); + + var files = ['consoleTest/project.json', 'consoleTest/Program.cs']; + describe('Checking files', function () { + for (i = 0; i < files.length; i++) { + util.filesCheck(files[i]); + } + }); + + }); + + /* + * yo aspnet Unit Test Application + */ + describe('aspnet - Unit Test Application', function () { + + util.goCreateApplication('unittest', 'unittestTest'); + + describe('Checking directories', function () { + it('Application directory created', function () { + assert.file('unittestTest/'); + }); + }); + + var files = ['unittestTest/project.json', 'unittestTest/SampleTest.cs']; + describe('Checking files', function () { + for (i = 0; i < files.length; i++) { + util.filesCheck(files[i]); + } + }); + + }); + + /* + * yo aspnet Web Application + */ + describe('aspnet - Web Application', function () { + + util.goCreateApplication('web', 'webTest'); + + describe('Checking directories', function () { + it('Application directory created', function () { + assert.file('webTest/'); + }); + + it('wwwroot directory created', function () { + assert.file('webTest/wwwroot'); + }); + }); + + + var files = ['webtest/project.json', 'webtest/Startup.cs']; + describe('Checking files', function () { + for (i = 0; i < files.length; i++) { + util.filesCheck(files[i]); + } + }); + + }); + + /* + * yo aspnet Nancy Application + */ + describe('aspnet - Nancy Application', function () { + + util.goCreateApplication('nancy', 'nancyTest'); + + describe('Checking directories', function () { + it('Application directory created', function () { + assert.file('nancyTest/'); + }); + }); + + + var files = ['nancyTest/project.json', 'nancyTest/Startup.cs', 'nancyTest/HomeModule.cs']; + describe('Checking files', function () { + for (i = 0; i < files.length; i++) { + util.filesCheck(files[i]); + } + }); + + }); + + /* + * yo aspnet MVC Application + */ + describe('aspnet - MVC Application', function () { + + util.goCreateApplication('mvc', 'mvcTest'); + + describe('Checking directories', function () { + it('Application directory created', function () { + assert.file('mvcTest/'); + }); + + it('Controllers directory created', function () { + assert.file('mvcTest/Controllers'); + }); + + it('Models directory created', function () { + assert.file('mvcTest/Models'); + }); + + it('Views directory created', function () { + assert.file('mvcTest/Views'); + assert.file('mvcTest/Views/Home'); + assert.file('mvcTest/Views/Shared'); + }); + + it('wwwroot directory created', function () { + assert.file('mvcTest/wwwroot'); + }); + }); + + + var files = [ + 'mvcTest/project.json', + 'mvcTest/Startup.cs', + 'mvcTest/Controllers/HomeController.cs', + 'mvcTest/Models/User.cs', + 'mvcTest/Views/Home/Index.cshtml', + 'mvcTest/Views/Shared/_Layout.cshtml' + ]; + + + describe('Checking files', function () { + for (i = 0; i < files.length; i++) { + util.filesCheck(files[i]); + } + }); + + }); \ No newline at end of file diff --git a/test/test-utility.js b/test/test-utility.js new file mode 100644 index 00000000..c6609ed6 --- /dev/null +++ b/test/test-utility.js @@ -0,0 +1,111 @@ +var util = (function () { + + var yeoman = require('yeoman-generator'); + var path = require('path'); + var assert; + var mockGen; + + function goCreate(subgenerator) { + before(function (done) { + + assert = yeoman.assert; + mockGen = yeoman.test; + + mockGen.run(path.join(__dirname, '../' + subgenerator)) + .inDir(path.join(__dirname, './.tmp')) + .on('end', done); + }); + }; + + function goCreateWithArgs(subgenerator, args) { + before(function (done) { + assert = yeoman.assert; + mockGen = yeoman.test; + + mockGen.run(path.join(__dirname, '../' + subgenerator)) + .inDir(path.join(__dirname, './.tmp')) + .withArguments(args) + .on('end', done); + }); + }; + + function goCreateApplication(type, applicationName) { + before(function (done) { + + assert = yeoman.assert; + mockGen = yeoman.test; + + var mockPrompt = { + type: type, + applicationName: applicationName + }; + + mockGen.run(path.join(__dirname, '../app')) + + .inDir(path.join(__dirname, './.tmp')) + .withPrompt(mockPrompt) + .on('end', done); + }); + + }; + + function dirsCheck(dirs) { + describe('Directories Creation', function () { + + for (i = 0; i < dirs.length; i++) { + it(dirs[i] + ' created.', function () { + assert.file(dirs[i]); + }); + } + + }); + + }; + + function filesCheck(file) { + + + it(file + ' created.', function () { + assert.file(file); + }); + + }; + + function dirCheck(message, dir) { + describe('Directory Creation', function () { + it(message, function () { + assert.file(dir); + }); + }); + }; + + function fileCheck(message, file) { + describe('File Creation', function () { + it(message, function () { + assert.file(file); + }); + }); + }; + + function fileContentCheck(file, message, content) { + it(message, function () { + assert.fileContent(file, content); + }); + }; + + + var methods = { + goCreateApplication: goCreateApplication, + goCreate: goCreate, + goCreateWithArgs: goCreateWithArgs, + fileCheck: fileCheck, + filesCheck: filesCheck, + dirCheck: dirCheck, + dirsCheck: dirsCheck, + fileContentCheck: fileContentCheck + } + + return methods; +})(); + +module.exports = util; \ No newline at end of file