diff --git a/action/index.js b/action/index.js index 4801117..8fadfdc 100644 --- a/action/index.js +++ b/action/index.js @@ -3,6 +3,7 @@ var util = require('util'); var ScriptBase = require('../script-base.js'); var ActionGenerator = module.exports = function ActionGenerator(args, options, config) { + args[0] += 'ActionCreators'; ScriptBase.apply(this, arguments); } @@ -13,5 +14,13 @@ ActionGenerator.prototype.createActionFile = function createActionFile() { this.es6 = this.options.es6; - this.generateAction(); + console.log(this.name); + + this.generateSourceAndTest( + 'Action', + 'spec/Action', + void(0), + 'actions', + false + ); } diff --git a/component/index.js b/component/index.js index 7e13d34..59cdc95 100644 --- a/component/index.js +++ b/component/index.js @@ -3,7 +3,6 @@ var util = require('util'); var ScriptBase = require('../script-base.js'); var ComponentGenerator = module.exports = function ComponentGenerator(args, options, config) { - ScriptBase.apply(this, arguments); }; @@ -18,6 +17,7 @@ ComponentGenerator.prototype.createComponentFile = function createComponentFile( 'Component', 'spec/Component', 'styles/Component', - 'components' + 'components', + true ); }; diff --git a/script-base.js b/script-base.js index c80eab1..383f03a 100644 --- a/script-base.js +++ b/script-base.js @@ -88,16 +88,8 @@ Generator.prototype.htmlTemplate = function (src, dest) { ]); }; -Generator.prototype.generateSourceAndTest = function (appTemplate, testTemplate, stylesTemplate, targetDirectory) { +Generator.prototype.generateSourceAndTest = function (appTemplate, testTemplate, stylesTemplate, targetDirectory, includeStyles) { this.appTemplate(appTemplate, path.join(targetDirectory, this._.capitalizeFile(this.name))); this.testTemplate(testTemplate, path.join(targetDirectory, this._.capitalizeFile(this.name))); - this.stylesTemplate(stylesTemplate, path.join(this._.capitalizeFile(this.name))); + if(includeStyles) this.stylesTemplate(stylesTemplate, path.join(this._.capitalizeFile(this.name))); }; - -Generator.prototype.generateAction = function() { - this.appTemplate('Action', path.join('actions', this._.capitalizeFile(this.name) + 'ActionCreators')); -} - -Generator.prototype.generateStore = function() { - this.appTemplate('Store', path.join('stores', this._.capitalizeFile(this.name) + 'Store')); -} diff --git a/store/index.js b/store/index.js index 21b00d5..324b32b 100644 --- a/store/index.js +++ b/store/index.js @@ -3,6 +3,7 @@ var util = require('util'); var ScriptBase = require('../script-base.js'); var ActionGenerator = module.exports = function ActionGenerator(args, options, config) { + args[0] += 'Store'; ScriptBase.apply(this, arguments); } @@ -14,5 +15,11 @@ ActionGenerator.prototype.createActionFile = function createActionFile() { this.es6 = this.options.es6; this.dispatcherName = this._.capitalizeFile(this.config.get('app-name')) + 'AppDispatcher'; - this.generateStore(); + this.generateSourceAndTest( + 'Store', + 'spec/Store', + void(0), + 'stores', + false + ); } diff --git a/templates/common/_webpack.config.js b/templates/common/_webpack.config.js index a008b76..fb0734c 100644 --- a/templates/common/_webpack.config.js +++ b/templates/common/_webpack.config.js @@ -31,7 +31,9 @@ module.exports = { extensions: ['', '.js'], alias: { 'styles': '../../../src/styles', - 'components': '../../../src/scripts/components/' + 'components': '../../../src/scripts/components/'<% if(flux) { %>, + 'stores': '../../../src/scripts/stores/', + 'actions': '../../../src/scripts/actions/'<% } %> } }, module: { diff --git a/templates/common/_webpack.dist.config.js b/templates/common/_webpack.dist.config.js index 35d2255..bcf602c 100644 --- a/templates/common/_webpack.dist.config.js +++ b/templates/common/_webpack.dist.config.js @@ -36,7 +36,9 @@ module.exports = { extensions: ['', '.js'], alias: { 'styles': '../../../src/styles', - 'components': '../../../src/scripts/components/' + 'components': '../../../src/scripts/components/'<% if(flux) { %>, + 'stores': '../../../src/scripts/stores/', + 'actions': '../../../src/scripts/actions/'<% } %> } }, diff --git a/templates/common/karma.conf.js b/templates/common/karma.conf.js index d1d9054..b44935c 100644 --- a/templates/common/karma.conf.js +++ b/templates/common/karma.conf.js @@ -8,10 +8,14 @@ module.exports = function (config) { frameworks: ['jasmine'], files: [ 'test/helpers/**/*.js', - 'test/spec/components/**/*.js' + 'test/spec/components/**/*.js'<% if(flux) { %>, + 'test/spec/stores/**/*.js', + 'test/spec/actions/**/*.js'<% } %> ], preprocessors: { - 'test/spec/components/**/*.js': ['webpack'] + 'test/spec/components/**/*.js': ['webpack']<% if(flux) { %>, + 'test/spec/stores/**/*.js': ['webpack'], + 'test/spec/actions/**/*.js': ['webpack']<% } %> }, webpack: { cache: true, @@ -48,7 +52,9 @@ module.exports = function (config) { resolve: { alias: { 'styles': path.join(process.cwd(), './src/styles/'), - 'components': path.join(process.cwd(), './src/scripts/components/') + 'components': path.join(process.cwd(), './src/scripts/components/')<% if(flux) { %>, + 'stores': '../../../src/scripts/stores/', + 'actions': '../../../src/scripts/actions/'<% } %> } } }, diff --git a/templates/javascript/Action.js b/templates/javascript/Action.js index 5196153..de0c5d3 100644 --- a/templates/javascript/Action.js +++ b/templates/javascript/Action.js @@ -1,8 +1,8 @@ 'use strict'; -var <% classedName + 'ActionCreators' %> = { +var <%= classedName %> = { } -<% if (es6) { %> export default <%= classedName + 'ActionCreators' %>; <% } -else { %>module.exports = <%= classedName + 'ActionCreators' %>; <% } %> +<% if (es6) { %> export default <%= classedName %>; <% } +else { %>module.exports = <%= classedName %>; <% } %> diff --git a/templates/javascript/Store.js b/templates/javascript/Store.js index 9f59eaf..98d0467 100644 --- a/templates/javascript/Store.js +++ b/templates/javascript/Store.js @@ -4,11 +4,11 @@ var EventEmitter = require('events').EventEmitter; var assign = require('object-assign'); var <%= dispatcherName %> = require('../dispatcher/<%= dispatcherName %>'); -var <%= classedName + 'Store' %> = assign({}, EventEmitter.prototype, { +var <%= classedName %> = assign({}, EventEmitter.prototype, { }); -<%= classedName + 'Store' %>.dispatchToken = <%= dispatcherName %>.register(function(action) { +<%= classedName %>.dispatchToken = <%= dispatcherName %>.register(function(action) { switch(action.type) { default: @@ -16,5 +16,5 @@ var <%= classedName + 'Store' %> = assign({}, EventEmitter.prototype, { }); -<% if (es6) { %> export default <%= classedName + 'Store' %>; <% } -else { %>module.exports = <%= classedName + 'Store' %>; <% } %> +<% if (es6) { %> export default <%= classedName %>; <% } +else { %>module.exports = <%= classedName %>; <% } %> diff --git a/templates/spec/Action.js b/templates/spec/Action.js new file mode 100644 index 0000000..c768f48 --- /dev/null +++ b/templates/spec/Action.js @@ -0,0 +1,13 @@ +'use strict'; + +describe('<%= classedName %>', function() { + var action; + + beforeEach(function() { + action = require('actions/<%= classedFileName %>.js'); + }); + + it('should be defined', function() { + expect(action).toBeDefined(); + }); +}); diff --git a/templates/spec/Store.js b/templates/spec/Store.js new file mode 100644 index 0000000..a945396 --- /dev/null +++ b/templates/spec/Store.js @@ -0,0 +1,13 @@ +'use strict'; + +describe('<%= classedName %>', function() { + var store; + + beforeEach(function() { + store = require('stores/<%= classedFileName %>.js'); + }); + + it('should be defined', function() { + expect(store).toBeDefined(); + }); +});