From 708fcea34fd305eff51a533fa01df949dc33b94b Mon Sep 17 00:00:00 2001 From: ColCh Date: Fri, 20 Feb 2015 16:01:05 +0300 Subject: [PATCH 01/12] Slight refactor test helper to access name --- test/test-creation.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/test-creation.js b/test/test-creation.js index 04f7089..7f6e746 100644 --- a/test/test-creation.js +++ b/test/test-creation.js @@ -156,9 +156,8 @@ describe('react-webpack generator', function() { }); describe('Subgenerators', function() { - var generatorTest = function(generatorType, specType, targetDirectory, scriptNameFn, specNameFn, suffix, done) { + var generatorTest = function(name, generatorType, specType, targetDirectory, scriptNameFn, specNameFn, suffix, done) { - var name = 'Foo'; var deps = [path.join('../..', generatorType)]; genOptions.appPath += '/scripts' @@ -179,7 +178,7 @@ describe('react-webpack generator', function() { it('should generate a new component', function(done) { react.run({}, function() { - generatorTest('component', 'component', 'components', _.capitalize, _.capitalize, '', done); + generatorTest('Foo', 'component', 'component', 'components', _.capitalize, _.capitalize, '', done); }); }); From 554d2dd56bd21eb677a71bf60482b38bae99a181 Mon Sep 17 00:00:00 2001 From: ColCh Date: Fri, 20 Feb 2015 16:22:58 +0300 Subject: [PATCH 02/12] Modify appPath to support multiple function call --- test/test-creation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-creation.js b/test/test-creation.js index 7f6e746..126072a 100644 --- a/test/test-creation.js +++ b/test/test-creation.js @@ -159,7 +159,7 @@ describe('react-webpack generator', function() { var generatorTest = function(name, generatorType, specType, targetDirectory, scriptNameFn, specNameFn, suffix, done) { var deps = [path.join('../..', generatorType)]; - genOptions.appPath += '/scripts' + genOptions.appPath = 'src/scripts' var reactGenerator = helpers.createGenerator('react-webpack:' + generatorType, deps, [name], genOptions); From 6b443cca488fd0a4dc0d46afc370afdee9407503 Mon Sep 17 00:00:00 2001 From: ColCh Date: Fri, 20 Feb 2015 16:23:33 +0300 Subject: [PATCH 03/12] Added test case for subcomponent --- test/test-creation.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/test-creation.js b/test/test-creation.js index 126072a..684502e 100644 --- a/test/test-creation.js +++ b/test/test-creation.js @@ -182,6 +182,13 @@ describe('react-webpack generator', function() { }); }); + it('should generate a subcomponent', function(done) { + react.run({}, function() { + var subComponentNameFn = function () { return 'Bar'; }; + generatorTest('Foo/Bar', 'component', 'component', 'components', subComponentNameFn, subComponentNameFn, '', done); + }); + }); + }); }); From 1cef6abd460eb49d69cfd78284ac0fed4c3b58be Mon Sep 17 00:00:00 2001 From: ColCh Date: Fri, 20 Feb 2015 16:54:29 +0300 Subject: [PATCH 04/12] Added test case for aliases definition within config --- test/test-creation.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/test-creation.js b/test/test-creation.js index 684502e..720a908 100644 --- a/test/test-creation.js +++ b/test/test-creation.js @@ -109,6 +109,18 @@ describe('react-webpack generator', function() { }); }); + it('should generate JS config with aliases', function(done) { + react.run({}, function() { + assert.fileContent([ + // style aliases + ['webpack.config.js', /resolve[\S\s]+alias[\S\s]+styles/m], + ['karma.conf.js', /resolve[\S\s]+alias[\S\s]+styles/m], + ['webpack.dist.config.js', /resolve[\S\s]+alias[\S\s]+styles/m] + ]); + done(); + }); + }); + }); describe('Generator', function () { From 5a2e43ac6a595b242f7c2e7254c395cb507a2745 Mon Sep 17 00:00:00 2001 From: ColCh Date: Fri, 20 Feb 2015 16:55:17 +0300 Subject: [PATCH 05/12] Added assertion for style require'ing via alias within component file --- test/test-creation.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test-creation.js b/test/test-creation.js index 720a908..2892f93 100644 --- a/test/test-creation.js +++ b/test/test-creation.js @@ -180,6 +180,7 @@ describe('react-webpack generator', function() { helpers.assertFileContent([ [path.join('src/scripts', targetDirectory, name + '.js'), new RegExp('var ' + scriptNameFn(name) + suffix, 'g')], + [path.join('src/scripts', targetDirectory, name + '.js'), new RegExp('require\\(\'styles\\/' + name + suffix + '\\.[^\']+' + '\'\\)', 'g')], [path.join('test/spec', targetDirectory, name + '.js'), new RegExp('describe\\(\'' + specNameFn(name) + suffix + '\'', 'g')] ]); From 4980430552655c6a46a8c500c46a7f8153c95ca4 Mon Sep 17 00:00:00 2001 From: ColCh Date: Fri, 20 Feb 2015 16:56:00 +0300 Subject: [PATCH 06/12] Added alias definition for 'styles' in configs --- templates/common/_webpack.config.js | 5 ++++- templates/common/_webpack.dist.config.js | 3 +++ templates/common/karma.conf.js | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/templates/common/_webpack.config.js b/templates/common/_webpack.config.js index b23c0b0..74a69c6 100644 --- a/templates/common/_webpack.config.js +++ b/templates/common/_webpack.config.js @@ -28,7 +28,10 @@ module.exports = { }, resolve: { - extensions: ['', '.js'] + extensions: ['', '.js'], + alias: { + 'styles': './src/styles' + } }, module: { preLoaders: [{ diff --git a/templates/common/_webpack.dist.config.js b/templates/common/_webpack.dist.config.js index 2e89773..74bb5b9 100644 --- a/templates/common/_webpack.dist.config.js +++ b/templates/common/_webpack.dist.config.js @@ -34,6 +34,9 @@ module.exports = { resolve: { extensions: ['', '.js'] + alias: { + 'styles': './src/styles' + } }, module: { diff --git a/templates/common/karma.conf.js b/templates/common/karma.conf.js index 8d35617..a6271ae 100644 --- a/templates/common/karma.conf.js +++ b/templates/common/karma.conf.js @@ -42,6 +42,11 @@ module.exports = function (config) { test: /\.css$/, loader: 'style-loader!css-loader' }] + }, + resolve: { + alias: { + 'styles': './src/styles' + } } }, webpackServer: { From 68a1dcf447081ad506870dcb11f861c0214bb6dd Mon Sep 17 00:00:00 2001 From: ColCh Date: Fri, 20 Feb 2015 16:56:33 +0300 Subject: [PATCH 07/12] Use provided 'style' alias within App file --- templates/javascript/App.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/javascript/App.js b/templates/javascript/App.js index 565df16..e00b3a7 100644 --- a/templates/javascript/App.js +++ b/templates/javascript/App.js @@ -4,8 +4,8 @@ var React = require('react/addons'); var ReactTransitionGroup = React.addons.TransitionGroup; // CSS -require('../../styles/normalize.css'); -require('../../styles/main.css'); +require('styles/normalize.css'); +require('styles/main.css'); var imageURL = require('../../images/yeoman.png'); From dde3dd7b731c9d6f3e372fbc5b978d62e01a66a5 Mon Sep 17 00:00:00 2001 From: ColCh Date: Fri, 20 Feb 2015 16:56:43 +0300 Subject: [PATCH 08/12] Use provided 'style' alias within Component file --- templates/javascript/Component.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/javascript/Component.js b/templates/javascript/Component.js index 2a19744..77b901f 100644 --- a/templates/javascript/Component.js +++ b/templates/javascript/Component.js @@ -2,11 +2,11 @@ var React = require('react/addons'); -<% if (stylesLanguage === 'css') { %>require('../../styles/<%= classedFileName %>.css');<% } %><% -if (stylesLanguage === 'sass') { %>require('../../styles/<%= classedFileName %>.sass');<% } %><% -if (stylesLanguage === 'scss') { %>require('../../styles/<%= classedFileName %>.scss');<% } %><% -if (stylesLanguage === 'less') { %>require('../../styles/<%= classedFileName %>.less');<% } %><% -if (stylesLanguage === 'stylus') { %>require('../../styles/<%= classedFileName %>.styl');<% } %> +<% if (stylesLanguage === 'css') { %>require('styles/<%= classedFileName %>.css');<% } %><% +if (stylesLanguage === 'sass') { %>require('styles/<%= classedFileName %>.sass');<% } %><% +if (stylesLanguage === 'scss') { %>require('styles/<%= classedFileName %>.scss');<% } %><% +if (stylesLanguage === 'less') { %>require('styles/<%= classedFileName %>.less');<% } %><% +if (stylesLanguage === 'stylus') { %>require('styles/<%= classedFileName %>.styl');<% } %> var <%= classedName %> = React.createClass({ render: function () { From d507bf17722518a2c9784bfb11cd2f4992993b86 Mon Sep 17 00:00:00 2001 From: ColCh Date: Fri, 20 Feb 2015 17:07:58 +0300 Subject: [PATCH 09/12] Added test case for 'components' alias definition within configs --- test/test-creation.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/test-creation.js b/test/test-creation.js index 2892f93..84b14e1 100644 --- a/test/test-creation.js +++ b/test/test-creation.js @@ -115,7 +115,11 @@ describe('react-webpack generator', function() { // style aliases ['webpack.config.js', /resolve[\S\s]+alias[\S\s]+styles/m], ['karma.conf.js', /resolve[\S\s]+alias[\S\s]+styles/m], - ['webpack.dist.config.js', /resolve[\S\s]+alias[\S\s]+styles/m] + ['webpack.dist.config.js', /resolve[\S\s]+alias[\S\s]+styles/m], + // script/components aliases + ['webpack.config.js', /resolve[\S\s]+alias[\S\s]+components/m], + ['karma.conf.js', /resolve[\S\s]+alias[\S\s]+components/m], + ['webpack.dist.config.js', /resolve[\S\s]+alias[\S\s]+components/m] ]); done(); }); From a2568e8cd55bc55de92873bdfb108c48103fd5b5 Mon Sep 17 00:00:00 2001 From: ColCh Date: Fri, 20 Feb 2015 17:09:05 +0300 Subject: [PATCH 10/12] Assert require'ing 'components/%COMPONENT%' within subgenerators test case --- test/test-creation.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test-creation.js b/test/test-creation.js index 84b14e1..55b40a2 100644 --- a/test/test-creation.js +++ b/test/test-creation.js @@ -185,6 +185,8 @@ describe('react-webpack generator', function() { [path.join('src/scripts', targetDirectory, name + '.js'), new RegExp('var ' + scriptNameFn(name) + suffix, 'g')], [path.join('src/scripts', targetDirectory, name + '.js'), new RegExp('require\\(\'styles\\/' + name + suffix + '\\.[^\']+' + '\'\\)', 'g')], + [path.join('test/spec', targetDirectory, 'TempTestApp' + '.js'), new RegExp('require\\(\'components\\/' + 'TempTestApp' + suffix + '\\.[^\']+' + '\'\\)', 'g')], + [path.join('test/spec', targetDirectory, name + '.js'), new RegExp('require\\(\'components\\/' + name + suffix + '\\.[^\']+' + '\'\\)', 'g')], [path.join('test/spec', targetDirectory, name + '.js'), new RegExp('describe\\(\'' + specNameFn(name) + suffix + '\'', 'g')] ]); From 12e16a61a42d2b8fca5cde3d5c7217c67e223a9c Mon Sep 17 00:00:00 2001 From: ColCh Date: Fri, 20 Feb 2015 17:09:32 +0300 Subject: [PATCH 11/12] Provide 'components' alias within configs --- templates/common/_webpack.config.js | 3 ++- templates/common/_webpack.dist.config.js | 3 ++- templates/common/karma.conf.js | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/templates/common/_webpack.config.js b/templates/common/_webpack.config.js index 74a69c6..f17dac9 100644 --- a/templates/common/_webpack.config.js +++ b/templates/common/_webpack.config.js @@ -30,7 +30,8 @@ module.exports = { resolve: { extensions: ['', '.js'], alias: { - 'styles': './src/styles' + 'styles': './src/styles', + 'components': './src/scripts/components/' } }, module: { diff --git a/templates/common/_webpack.dist.config.js b/templates/common/_webpack.dist.config.js index 74bb5b9..42f7c6c 100644 --- a/templates/common/_webpack.dist.config.js +++ b/templates/common/_webpack.dist.config.js @@ -35,7 +35,8 @@ module.exports = { resolve: { extensions: ['', '.js'] alias: { - 'styles': './src/styles' + 'styles': './src/styles', + 'components': './src/scripts/components/' } }, diff --git a/templates/common/karma.conf.js b/templates/common/karma.conf.js index a6271ae..639c17f 100644 --- a/templates/common/karma.conf.js +++ b/templates/common/karma.conf.js @@ -45,7 +45,8 @@ module.exports = function (config) { }, resolve: { alias: { - 'styles': './src/styles' + 'styles': './src/styles', + 'components': './src/scripts/components/' } } }, From cbef9655779e8ed4476881e1033df083ae1c7d0b Mon Sep 17 00:00:00 2001 From: ColCh Date: Fri, 20 Feb 2015 17:09:55 +0300 Subject: [PATCH 12/12] Use provided 'components' alias within app files --- templates/spec/App.js | 2 +- templates/spec/Component.js | 2 +- templates/spec/main.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/spec/App.js b/templates/spec/App.js index 3009095..5e36029 100644 --- a/templates/spec/App.js +++ b/templates/spec/App.js @@ -9,7 +9,7 @@ describe('<%= classedName %>', function () { container.id = 'content'; document.body.appendChild(container); - <%= scriptAppName %> = require('../../../src/scripts/components/<%= scriptAppName %>.js'); + <%= scriptAppName %> = require('components/<%= scriptAppName %>.js'); component = React.createElement(<%= scriptAppName %>); }); diff --git a/templates/spec/Component.js b/templates/spec/Component.js index 28ddd87..d639438 100644 --- a/templates/spec/Component.js +++ b/templates/spec/Component.js @@ -5,7 +5,7 @@ describe('<%= classedName %>', function () { var <%= classedName %>, component; beforeEach(function () { - <%= classedName %> = require('../../../src/scripts/components/<%= classedFileName %>.js'); + <%= classedName %> = require('components/<%= classedFileName %>.js'); component = React.createElement(<%= classedName %>); }); diff --git a/templates/spec/main.js b/templates/spec/main.js index ac35635..4b86f3d 100644 --- a/templates/spec/main.js +++ b/templates/spec/main.js @@ -4,7 +4,7 @@ describe('main', function () { var main, component; beforeEach(function () { - main = require('../../../src/scripts/components/main.jsx'); + main = require('components/main.jsx'); component = main(); });