@@ -5,40 +5,51 @@ var yeoman = require('yeoman-generator');
5
5
var generalUtils = require ( './util.js' ) ;
6
6
7
7
var Generator = module . exports = function Generator ( ) {
8
- yeoman . generators . NamedBase . apply ( this , arguments ) ;
8
+ yeoman . generators . NamedBase . apply ( this , arguments ) ;
9
9
10
- // Add capitalize mixin
10
+ // Add capitalize mixin
11
11
this . _ . mixin ( { 'capitalize' : generalUtils . capitalize } ) ;
12
12
this . _ . mixin ( { 'capitalizeFile' : generalUtils . capitalizeFile } ) ;
13
- this . _ . mixin ( { 'capitalizeClass' : generalUtils . capitalizeClass } ) ;
14
- this . _ . mixin ( { 'lowercase' : generalUtils . lowercase } ) ;
13
+ this . _ . mixin ( { 'capitalizeClass' : generalUtils . capitalizeClass } ) ;
14
+ this . _ . mixin ( { 'lowercase' : generalUtils . lowercase } ) ;
15
15
16
- this . appname = path . basename ( process . cwd ( ) ) ;
16
+ this . appname = path . basename ( process . cwd ( ) ) ;
17
17
18
- this . appname = this . _ . slugify ( this . _ . humanize ( this . appname ) ) ;
19
- this . scriptAppName = this . _ . camelize ( this . _ . capitalize ( this . appname ) ) + generalUtils . appName ( this ) ;
20
- this . classedFileName = this . _ . capitalizeFile ( this . name ) ;
18
+ this . appname = this . _ . slugify ( this . _ . humanize ( this . appname ) ) ;
19
+ this . scriptAppName = this . _ . camelize ( this . _ . capitalize ( this . appname ) ) + generalUtils . appName ( this ) ;
20
+ this . classedFileName = this . _ . capitalizeFile ( this . name ) ;
21
21
this . classedName = this . _ . capitalizeClass ( this . name ) ;
22
22
this . stylesLanguage = this . config . get ( 'styles-language' ) ;
23
23
this . architecture = this . config . get ( 'architecture' ) ;
24
24
25
- if ( typeof this . options . appPath === 'undefined' ) {
26
- this . options . appPath = this . options . appPath || 'src' ;
27
- }
25
+ if ( typeof this . options . appPath === 'undefined' ) {
26
+ this . options . appPath = this . options . appPath || 'src' ;
27
+ }
28
28
29
- if ( typeof this . options . testPath === 'undefined' ) {
30
- this . options . testPath = this . options . testPath || 'test/spec' ;
31
- }
29
+ if ( typeof this . options . testPath === 'undefined' ) {
30
+ this . options . testPath = this . options . testPath || 'test/spec' ;
31
+ }
32
32
33
- if ( typeof this . options . stylesPath === 'undefined' ) {
34
- this . options . stylesPath = this . options . stylesPath || 'src/styles' ;
35
- }
33
+ if ( typeof this . options . stylesPath === 'undefined' ) {
34
+ this . options . stylesPath = this . options . stylesPath || 'src/styles' ;
35
+ }
36
36
37
- var sourceRoot = '/templates/' ;
38
- this . scriptSuffix = '.js' ;
39
- this . reactSuffix = '.js' ;
37
+ var sourceRoot = '/templates/' ;
38
+ this . scriptSuffix = '.js' ;
39
+ this . reactSuffix = '.js' ;
40
40
41
- this . stylesSuffix = '.css' ;
41
+ // Add support for generated file legacy fallback
42
+ // @see https://github.com/newtriks/generator-react-webpack/issues/99
43
+ this . reactComponentSuffix = this . config . get ( 'component-suffix' ) ;
44
+ switch ( this . reactComponentSuffix ) {
45
+ case 'jsx' :
46
+ this . reactComponentSuffix = '.jsx' ;
47
+ break ;
48
+ default :
49
+ this . reactComponentSuffix = '.js' ;
50
+ }
51
+
52
+ this . stylesSuffix = '.css' ;
42
53
43
54
switch ( this . stylesLanguage ) {
44
55
case 'sass' :
@@ -55,49 +66,49 @@ var Generator = module.exports = function Generator() {
55
66
break ;
56
67
}
57
68
58
- this . sourceRoot ( path . join ( __dirname , sourceRoot ) ) ;
69
+ this . sourceRoot ( path . join ( __dirname , sourceRoot ) ) ;
59
70
} ;
60
71
61
72
util . inherits ( Generator , yeoman . generators . NamedBase ) ;
62
73
63
74
Generator . prototype . appTemplate = function ( src , dest ) {
64
- yeoman . generators . Base . prototype . template . apply ( this , [
65
- path . join ( 'javascript' , src + this . scriptSuffix ) ,
66
- path . join ( this . options . appPath , dest ) + this . scriptSuffix
67
- ] ) ;
75
+ yeoman . generators . Base . prototype . template . apply ( this , [
76
+ path . join ( 'javascript' , src + this . scriptSuffix ) ,
77
+ path . join ( this . options . appPath , dest ) + this . scriptSuffix
78
+ ] ) ;
68
79
} ;
69
80
70
81
Generator . prototype . reactComponentTemplate = function ( src , dest ) {
71
- yeoman . generators . Base . prototype . template . apply ( this , [
72
- path . join ( 'javascript' , src + this . reactSuffix ) ,
73
- path . join ( this . options . appPath , dest ) + this . reactSuffix
74
- ] ) ;
82
+ yeoman . generators . Base . prototype . template . apply ( this , [
83
+ path . join ( 'javascript' , src + this . reactSuffix ) ,
84
+ path . join ( this . options . appPath , dest ) + this . reactComponentSuffix
85
+ ] ) ;
75
86
} ;
76
87
77
88
Generator . prototype . testTemplate = function ( src , dest ) {
78
- yeoman . generators . Base . prototype . template . apply ( this , [
79
- src + this . scriptSuffix ,
80
- path . join ( this . options . testPath , dest ) + this . scriptSuffix
81
- ] ) ;
89
+ yeoman . generators . Base . prototype . template . apply ( this , [
90
+ src + this . scriptSuffix ,
91
+ path . join ( this . options . testPath , dest ) + this . scriptSuffix
92
+ ] ) ;
82
93
} ;
83
94
84
95
Generator . prototype . stylesTemplate = function ( src , dest ) {
85
- yeoman . generators . Base . prototype . template . apply ( this , [
86
- src + this . stylesSuffix ,
87
- path . join ( this . options . stylesPath , dest ) + this . stylesSuffix
88
- ] ) ;
96
+ yeoman . generators . Base . prototype . template . apply ( this , [
97
+ src + this . stylesSuffix ,
98
+ path . join ( this . options . stylesPath , dest ) + this . stylesSuffix
99
+ ] ) ;
89
100
} ;
90
101
91
102
Generator . prototype . htmlTemplate = function ( src , dest ) {
92
- yeoman . generators . Base . prototype . template . apply ( this , [
93
- src ,
94
- path . join ( this . options . appPath , dest . toLowerCase ( ) )
95
- ] ) ;
103
+ yeoman . generators . Base . prototype . template . apply ( this , [
104
+ src ,
105
+ path . join ( this . options . appPath , dest . toLowerCase ( ) )
106
+ ] ) ;
96
107
} ;
97
108
98
109
Generator . prototype . generateSourceAndTest = function ( appTemplate , testTemplate , targetDirectory ) {
99
- this . appTemplate ( appTemplate , path . join ( targetDirectory , this . _ . capitalizeFile ( this . name ) ) ) ;
100
- this . testTemplate ( testTemplate , path . join ( targetDirectory , this . _ . capitalizeFile ( this . name ) ) ) ;
110
+ this . appTemplate ( appTemplate , path . join ( targetDirectory , this . _ . capitalizeFile ( this . name ) ) ) ;
111
+ this . testTemplate ( testTemplate , path . join ( targetDirectory , this . _ . capitalizeFile ( this . name ) ) ) ;
101
112
} ;
102
113
103
114
Generator . prototype . generateComponentTestAndStyle = function ( componentTemplate , testTemplate , stylesTemplate , targetDirectory ) {
0 commit comments