mirror of
https://github.com/wassname/generator-react-webpack.git
synced 2026-09-07 16:50:47 +08:00
Switch the generation of everything so we generate tests and they can actually pass.
This commit is contained in:
+10
-1
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
+2
-2
@@ -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
|
||||
);
|
||||
};
|
||||
|
||||
+2
-10
@@ -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'));
|
||||
}
|
||||
|
||||
+8
-1
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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/'<% } %>
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -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/'<% } %>
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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 %>; <% } %>
|
||||
|
||||
@@ -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 %>; <% } %>
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user