diff --git a/NamedBase.js b/NamedBase.js
new file mode 100644
index 0000000..8fdf3a6
--- /dev/null
+++ b/NamedBase.js
@@ -0,0 +1,18 @@
+/* jshint node:true */
+var yeoman = require('yeoman-generator');
+var path = require('path');
+
+module.exports = yeoman.generators.NamedBase.extend({
+ constructor: function () {
+ // By calling `NamedBase` here, we get the argument to the subgenerator call
+ // as `this.name`.
+ yeoman.generators.NamedBase.apply(this, arguments);
+
+ this.appname = this.config.get('appname');
+ this.subdir = '';
+ if (this._.contains(this.name, '/')) {
+ this.subdir = path.dirname(this.name);
+ this.name = path.basename(this.name);
+ }
+ }
+});
diff --git a/app/index.js b/app/index.js
index eb100c2..c8f86b0 100644
--- a/app/index.js
+++ b/app/index.js
@@ -1,190 +1,191 @@
/*jshint node:true*/
-var util = require('util');
var path = require('path');
var yeoman = require('yeoman-generator');
-var DojoGenerator = module.exports = function DojoGenerator(args, options) {
- yeoman.generators.Base.apply(this, arguments);
-
- this.argument('appname', { type: String, required: false });
- this.appname = this._.slugify(this.appname || path.basename(process.cwd()));
-
- this.on('end', function () {
- this.installDependencies({
- skipInstall: options['skip-install'],
- callback: function () {
- // Once dgrid is installed, grab the dependencies from package.json
- // and use `bowerInstall` to install them
- if (this.dgrid) {
- var dgridDeps = require(path.join(process.cwd(), 'src', 'dgrid', 'package.json')).dependencies;
- this.bowerInstall([
- 'put-selector#~' + dgridDeps['put-selector'],
- 'xstyle#~' + dgridDeps.xstyle
- ], {
- save: true
- });
- }
- }.bind(this)
+module.exports = yeoman.generators.Base.extend({
+ constructor: function (args, options) {
+ yeoman.generators.Base.apply(this, arguments);
+
+ this.argument('appname', { type: String, required: false });
+ this.appname = this._.slugify(this.appname || path.basename(process.cwd()));
+
+ this.on('end', function () {
+ this.installDependencies({
+ skipInstall: options['skip-install'],
+ callback: function () {
+ // Once dgrid is installed, grab the dependencies from package.json
+ // and use `bowerInstall` to install them
+ if (this.dgrid) {
+ var dgridDeps = this.dest.readJSON('src/dgrid/package.json').dependencies;
+ this.bowerInstall([
+ 'put-selector#~' + dgridDeps['put-selector'],
+ 'xstyle#~' + dgridDeps.xstyle
+ ], {
+ save: true
+ });
+ }
+ }.bind(this)
+ });
});
- });
- this.pkg = JSON.parse(this.readFileAsString(path.join(__dirname, '../package.json')));
-};
-
-util.inherits(DojoGenerator, yeoman.generators.Base);
+ this.config.defaults({
+ appname: this.appname
+ });
+ },
-DojoGenerator.prototype.askFor = function askFor() {
- var cb = this.async(),
- _ = this._;
+ askFor: function askFor() {
+ var cb = this.async(),
+ _ = this._;
- function dgridIncluded(answers) {
- return _.contains(answers.features, 'dgrid');
- }
+ function dgridIncluded(answers) {
+ return _.contains(answers.features, 'dgrid');
+ }
- var prompts = [{
- name: 'dojoVersion',
- message: 'What version of Dojo will be used?',
- 'default': '1.10.0'
- }, {
- type: 'checkbox',
- name: 'features',
- message: 'What packages would you like to include?',
- choices: [{
- name: 'Dijit',
- value: 'dijit',
- checked: true
+ var prompts = [{
+ name: 'dojoVersion',
+ message: 'What version of Dojo will be used?',
+ 'default': '1.10.0'
}, {
- name: 'DojoX',
- value: 'dojox',
- checked: false
+ type: 'checkbox',
+ name: 'features',
+ message: 'What packages would you like to include?',
+ choices: [{
+ name: 'Dijit',
+ value: 'dijit',
+ checked: true
+ }, {
+ name: 'DojoX',
+ value: 'dojox',
+ checked: false
+ }, {
+ name: 'dgrid',
+ value: 'dgrid',
+ checked: true
+ }, {
+ name: 'Stylus',
+ value: 'stylus',
+ checked: true
+ }]
}, {
- name: 'dgrid',
- value: 'dgrid',
- checked: true
+ name: 'dgridVersion',
+ message: 'What version of dgrid?',
+ when: dgridIncluded,
+ 'default': '0.3.15'
}, {
- name: 'Stylus',
- value: 'stylus',
- checked: true
- }]
- }, {
- name: 'dgridVersion',
- message: 'What version of dgrid?',
- when: dgridIncluded,
- 'default': '0.3.15'
- }, {
- type: 'confirm',
- name: 'nib',
- message: 'Include nib when compiling Stylus files?',
- when: function (answers) {
- return _.contains(answers.features, 'stylus');
- },
- 'default': true
- }, {
- type: 'list',
- name: 'compression',
- message: 'What type of compression should be used when building?',
- choices: [{
- name: 'Shrinksafe',
- value: 'shrinksafe'
+ type: 'confirm',
+ name: 'nib',
+ message: 'Include nib when compiling Stylus files?',
+ when: function (answers) {
+ return _.contains(answers.features, 'stylus');
+ },
+ 'default': true
}, {
- name: 'Closure',
- value: 'closure'
+ type: 'list',
+ name: 'compression',
+ message: 'What type of compression should be used when building?',
+ choices: [{
+ name: 'Shrinksafe',
+ value: 'shrinksafe'
+ }, {
+ name: 'Closure',
+ value: 'closure'
+ }, {
+ name: 'Uglify',
+ value: 'uglify'
+ }],
+ 'default': 1
}, {
- name: 'Uglify',
- value: 'uglify'
- }],
- 'default': 1
- }, {
- type: 'confirm',
- name: 'travisci',
- message: 'Will you be using Travis-CI?',
- 'default': false
- }, {
- name: 'sauceUsername',
- message: 'What is your SauceLabs username?',
- when: function (answers) {
- return answers.travisci;
- },
- 'default': process.env.SAUCE_USERNAME || ''
- }, {
- name: 'sauceAccessKey',
- message: 'What is your SauceLabs access key?',
- when: function (answers) {
- return answers.travisci;
- },
- 'default': process.env.SAUCE_ACCESS_KEY || ''
- }];
-
- this.prompt(prompts, function (props) {
- this.dojoVersion = props.dojoVersion;
- this.travisci = props.travisci;
- this.sauceUsername = props.sauceUsername;
- this.sauceAccessKey = props.sauceAccessKey;
-
- this.dijit = _.contains(props.features, 'dijit');
- this.dojox = _.contains(props.features, 'dojox');
- this.dgrid = _.contains(props.features, 'dgrid');
- this.stylus = _.contains(props.features, 'stylus');
- this.nib = props.nib;
-
- this.dgridVersion = props.dgridVersion;
- this.putSelectorVersion = props.putSelectorVersion;
- this.xstyleVersion = props.xstyleVersion;
- this.compression = props.compression;
- cb();
- }.bind(this));
-};
-
-DojoGenerator.prototype.app = function app() {
- this.mkdir('src');
- this.mkdir('profiles');
-
- this.template('Gruntfile.js', 'Gruntfile.js');
- this.template('_package.json', 'package.json');
- this.template('_bower.json', 'bower.json');
-
- this.template('src/index.html', 'src/index.html');
- this.template('src/dojoConfig.js', 'src/dojoConfig.js');
-
- this.template('profiles/app.profile.js', 'profiles/' + this.appname + '.profile.js');
-};
-
-DojoGenerator.prototype.appPackage = function appPackage() {
- var appPath = 'src/' + this.appname;
- this.mkdir(appPath);
-
- this.mkdir(appPath + '/resources');
- this.mkdir(appPath + '/tests');
-
- this.template('src/app/main.js', appPath + '/main.js');
- this.template('src/app/_package.json', appPath + '/package.json');
- this.template('src/app/_package.js', appPath + '/package.js');
-
- if (this.stylus) {
- this.template('src/app/resources/main.styl', appPath + '/resources/main.styl');
- }
- else {
- this.template('src/app/resources/main.css', appPath + '/resources/main.css');
- }
- this.template('src/app/tests/unit.js', appPath + '/tests/unit.js');
- this.template('src/app/tests/functional.js', appPath + '/tests/functional.js');
- this.template('src/app/tests/dojoConfig.js', appPath + '/tests/dojoConfig.js');
- this.template('src/app/tests/intern.js', appPath + '/tests/intern.js');
- this.template('src/app/tests/ready.js', appPath + '/tests/ready.js');
- this.template('src/app/tests/remoteReady.js', appPath + '/tests/remoteReady.js');
-};
-
-DojoGenerator.prototype.runtime = function runtime() {
- this.copy('bowerrc', '.bowerrc');
- this.template('gitignore', '.gitignore');
- this.copy('gitattributes', '.gitattributes');
-
- if (this.travisci) {
- this.template('travis.yml', '.travis.yml');
+ type: 'confirm',
+ name: 'travisci',
+ message: 'Will you be using Travis-CI?',
+ 'default': false
+ }, {
+ name: 'sauceUsername',
+ message: 'What is your SauceLabs username?',
+ when: function (answers) {
+ return answers.travisci;
+ },
+ 'default': process.env.SAUCE_USERNAME || ''
+ }, {
+ name: 'sauceAccessKey',
+ message: 'What is your SauceLabs access key?',
+ when: function (answers) {
+ return answers.travisci;
+ },
+ 'default': process.env.SAUCE_ACCESS_KEY || ''
+ }];
+
+ this.prompt(prompts, function (props) {
+ this.dojoVersion = props.dojoVersion;
+ this.travisci = props.travisci;
+ this.sauceUsername = props.sauceUsername;
+ this.sauceAccessKey = props.sauceAccessKey;
+
+ this.dijit = _.contains(props.features, 'dijit');
+ this.dojox = _.contains(props.features, 'dojox');
+ this.dgrid = _.contains(props.features, 'dgrid');
+ this.stylus = _.contains(props.features, 'stylus');
+ this.nib = props.nib;
+
+ this.dgridVersion = props.dgridVersion;
+ this.putSelectorVersion = props.putSelectorVersion;
+ this.xstyleVersion = props.xstyleVersion;
+ this.compression = props.compression;
+ cb();
+ }.bind(this));
+ },
+
+ app: function app() {
+ this.mkdir('src');
+ this.mkdir('profiles');
+
+ this.template('Gruntfile.js', 'Gruntfile.js');
+ this.template('_package.json', 'package.json');
+ this.template('_bower.json', 'bower.json');
+
+ this.template('src/index.html', 'src/index.html');
+ this.template('src/dojoConfig.js', 'src/dojoConfig.js');
+
+ this.template('profiles/app.profile.js', 'profiles/' + this.appname + '.profile.js');
+ },
+
+ appPackage: function appPackage() {
+ var appPath = 'src/' + this.appname;
+ this.mkdir(appPath);
+
+ this.mkdir(appPath + '/resources');
+ this.mkdir(appPath + '/tests');
+
+ this.template('src/app/main.js', appPath + '/main.js');
+ this.template('src/app/_package.json', appPath + '/package.json');
+ this.template('src/app/_package.js', appPath + '/package.js');
+
+ if (this.stylus) {
+ this.template('src/app/resources/main.styl', appPath + '/resources/main.styl');
+ }
+ else {
+ this.template('src/app/resources/main.css', appPath + '/resources/main.css');
+ }
+ this.template('src/app/tests/unit.js', appPath + '/tests/unit.js');
+ this.template('src/app/tests/functional.js', appPath + '/tests/functional.js');
+ this.template('src/app/tests/dojoConfig.js', appPath + '/tests/dojoConfig.js');
+ this.template('src/app/tests/intern.js', appPath + '/tests/intern.js');
+ this.template('src/app/tests/ready.js', appPath + '/tests/ready.js');
+ this.template('src/app/tests/remoteReady.js', appPath + '/tests/remoteReady.js');
+ },
+
+ runtime: function () {
+ this.copy('bowerrc', '.bowerrc');
+ this.template('gitignore', '.gitignore');
+ this.copy('gitattributes', '.gitattributes');
+
+ if (this.travisci) {
+ this.template('travis.yml', '.travis.yml');
+ }
+ },
+
+ projectfiles: function () {
+ this.copy('editorconfig', '.editorconfig');
+ this.copy('jshintrc', '.jshintrc');
}
-};
-
-DojoGenerator.prototype.projectfiles = function projectfiles() {
- this.copy('editorconfig', '.editorconfig');
- this.copy('jshintrc', '.jshintrc');
-};
+});
diff --git a/package.json b/package.json
index d4b31ab..fa299fb 100644
--- a/package.json
+++ b/package.json
@@ -22,14 +22,11 @@
"test": "./node_modules/.bin/intern-client config=tests/intern"
},
"dependencies": {
- "yeoman-generator": "~0.13.0"
+ "yeoman-generator": "^0.16.0"
},
"devDependencies": {
"intern": "2.0.2"
},
- "peerDependencies": {
- "yo": ">=1.0.0-rc.1"
- },
"engines": {
"node": ">=0.8.0",
"npm": ">=1.2.10"
diff --git a/test/index.js b/test/index.js
index a986e2d..021167a 100644
--- a/test/index.js
+++ b/test/index.js
@@ -1,61 +1,51 @@
/* jshint node:true */
-var util = require('util');
-var yeoman = require('yeoman-generator');
+var NamedBase = require('../NamedBase');
var path = require('path');
-var TestGenerator = module.exports = function TestGenerator(args, options) {
- // By calling `NamedBase` here, we get the argument to the subgenerator call
- // as `this.name`.
- yeoman.generators.NamedBase.apply(this, arguments);
-
- this.appname = this._.slugify(path.basename(process.cwd()));
- this.subdir = '';
- if (this._.contains(this.name, '/')) {
- this.subdir = path.dirname(this.name);
- this.name = this._.slugify(path.basename(this.name));
- }
-
- var projectRoot = process.cwd();
-
- var basePath = path.join(projectRoot, 'src'),
- appPath = path.join(basePath, this.appname),
- testsPath = path.join(appPath, 'tests'),
- testPath = path.join(testsPath, this.subdir),
- relativeBaseUrl = path.relative(testPath, basePath),
- relativeAppUrl = path.relative(testPath, appPath),
- relativeTestsUrl = path.relative(testPath, testsPath);
-
- if (path.sep === '\\') {
- relativeBaseUrl = relativeBaseUrl.replace('\\', '/');
- relativeAppUrl = relativeAppUrl.replace('\\', '/');
- relativeTestsUrl = relativeTestsUrl.replace('\\', '/');
- }
- if (relativeTestsUrl) {
- relativeTestsUrl += '/';
- }
-
- this.functional = options.functional;
- this.testDirPath = testPath;
- this.appUrl = relativeAppUrl;
- this.testsUrl = relativeTestsUrl;
- this.baseUrl = relativeBaseUrl;
-
- this.on('end', function () {
- console.log('Don\'t forget to add ' + path.join(this.appname, 'tests', this.subdir, this.name) +
- ' to the dependency list in ' +
- path.join('src', this.appname, 'tests', (this.functional ? 'functional' : 'unit') + '.js'));
- }.bind(this));
-};
-
-util.inherits(TestGenerator, yeoman.generators.NamedBase);
-
-TestGenerator.prototype.files = function files() {
- var testPath = path.join('src', this.appname, 'tests', this.subdir);
- if (this.functional) {
- this.template('functional.js', path.join(testPath, this.name + '.js'));
- this.template('functional.html', path.join(testPath, this.name + '.html'));
- }
- else {
- this.template('unit.js', path.join(testPath, this.name + '.js'));
+module.exports = NamedBase.extend({
+ constructor: function (args, options) {
+ NamedBase.apply(this, arguments);
+
+ var projectRoot = this.destinationRoot();
+
+ var basePath = path.join(projectRoot, 'src'),
+ appPath = path.join(basePath, this.appname),
+ testsPath = path.join(appPath, 'tests'),
+ testPath = path.join(testsPath, options.functional ? 'functional' : 'unit', this.subdir),
+ relativeBaseUrl = path.relative(testPath, basePath),
+ relativeAppUrl = path.relative(testPath, appPath),
+ relativeTestsUrl = path.relative(testPath, testsPath);
+
+ if (path.sep === '\\') {
+ relativeBaseUrl = relativeBaseUrl.replace('\\', '/');
+ relativeAppUrl = relativeAppUrl.replace('\\', '/');
+ relativeTestsUrl = relativeTestsUrl.replace('\\', '/');
+ }
+
+ this.functional = options.functional;
+ this.testDirPath = testPath;
+ this.appUrl = relativeAppUrl;
+ this.testsUrl = relativeTestsUrl;
+ this.baseUrl = relativeBaseUrl;
+
+ this.on('end', function () {
+ var type = this.functional ? 'functional' : 'unit';
+
+ console.log(
+ 'Don\'t forget to add ./' +
+ type + '/' + (this.subdir ? this.subdir + '/' : '') + this.name +
+ ' to the dependency list in ' +
+ path.join('src', this.appname, 'tests', type + '.js'));
+ }.bind(this));
+ },
+ files: function () {
+ var modulePath = path.join(this.testDirPath, this.name + '.js');
+ if (this.functional) {
+ this.template('functional.js', modulePath);
+ this.template('functional.html', path.join(this.testDirPath, this.name + '.html'));
+ }
+ else {
+ this.template('unit.js', modulePath);
+ }
}
-};
+});
diff --git a/test/templates/functional.html b/test/templates/functional.html
index 032bda2..a4ddcfd 100644
--- a/test/templates/functional.html
+++ b/test/templates/functional.html
@@ -12,7 +12,7 @@
// Initialize the HTML page to test
}
-
+