@@ -2,50 +2,22 @@ import * as _ from 'lodash';
2
2
import * as path from 'path' ;
3
3
import * as Base from 'yeoman-generator' ;
4
4
5
- export default class GeneratorTypescriptReact extends Base {
6
- private readonly destinationName : string ;
7
- private readonly copyWithoutTemplating : ( templateNames : string [ ] , directory ?: string ) => void ;
8
- private readonly copyWithTemplating : ( templateData : object , templateNames : string [ ] , directory ?: string ) => void ;
9
-
5
+ class GeneratorTypescriptReact extends Base {
10
6
private humanReadableName : string ;
11
7
private kebabCaseName : string ;
12
8
13
- constructor ( ) {
14
- super ( ...arguments ) ;
15
-
16
- this . destinationName = path . basename ( this . destinationRoot ( ) ) ;
17
-
18
- this . copyWithTemplating = ( templateData , templateNames , directory = '.' ) => {
19
- templateNames . forEach ( filename => {
20
- this . fs . copyTpl (
21
- this . templatePath ( path . join ( directory , '_' + filename ) ) ,
22
- this . destinationPath ( path . join ( directory , filename ) ) ,
23
- templateData ,
24
- ) ;
25
- } ) ;
26
- } ;
27
-
28
- this . copyWithoutTemplating = ( templateNames , directory = '.' ) => {
29
- templateNames . forEach ( filename => {
30
- this . fs . copy (
31
- this . templatePath ( path . join ( directory , '_' + filename ) ) ,
32
- this . destinationPath ( path . join ( directory , filename ) ) ,
33
- ) ;
34
- } ) ;
35
- } ;
36
- }
37
-
38
9
prompting ( ) {
10
+ const destinationName = path . basename ( this . destinationRoot ( ) ) ;
39
11
return this . prompt ( [ {
40
12
type : 'input' ,
41
13
name : 'kebab' ,
42
14
message : 'What is the Package Name for this app?' ,
43
- default : _ . kebabCase ( this . destinationName ) ,
15
+ default : _ . kebabCase ( destinationName ) ,
44
16
} , {
45
17
type : 'input' ,
46
18
name : 'human' ,
47
19
message : 'What is the Human-Readable Name for this app?' ,
48
- default : _ . startCase ( this . destinationName ) ,
20
+ default : _ . startCase ( destinationName ) ,
49
21
} ] )
50
22
. then ( answers => {
51
23
this . kebabCaseName = answers . kebab ;
@@ -59,27 +31,54 @@ export default class GeneratorTypescriptReact extends Base {
59
31
humanReadableName : this . humanReadableName ,
60
32
} ;
61
33
62
- this . copyWithoutTemplating ( [
34
+ this . _copyWithoutTemplating ( [
63
35
'.editorconfig' , '.npmignore' , 'circle.yml' , 'LICENSE' ,
64
36
'tsconfig.json' , 'tsconfig-build.json' , 'tslint.json' ,
65
37
] ) ;
66
- this . copyWithTemplating ( allTemplateData , [ '.gitignore' , 'package.json' , 'README.md' ] ) ;
38
+ this . _copyWithTemplating ( allTemplateData , [ '.gitignore' , 'package.json' , 'README.md' ] ) ;
67
39
68
- this . copyWithoutTemplating ( [ 'demo.less' , 'index.tsx' ] , 'demo' ) ;
69
- this . copyWithTemplating ( allTemplateData , [ 'Demo.tsx' ] , 'demo' ) ;
40
+ this . _copyWithoutTemplating ( [ 'demo.less' , 'index.tsx' ] , 'demo' ) ;
41
+ this . _copyWithTemplating ( allTemplateData , [ 'Demo.tsx' ] , 'demo' ) ;
70
42
71
- this . copyWithTemplating ( allTemplateData , [ 'index.ts' ] , 'src' ) ;
43
+ this . _copyWithTemplating ( allTemplateData , [ 'index.ts' ] , 'src' ) ;
72
44
73
- this . copyWithoutTemplating ( [ 'index.less' ] , 'styles' ) ;
45
+ this . _copyWithoutTemplating ( [ 'index.less' ] , 'styles' ) ;
74
46
75
- this . copyWithoutTemplating ( [ 'mocha.opts' , 'registerTsNode.js' ] , 'test' ) ;
76
- this . copyWithTemplating ( allTemplateData , [ 'spec.ts' ] , 'test' ) ;
47
+ this . _copyWithoutTemplating ( [ 'mocha.opts' , 'registerTsNode.js' ] , 'test' ) ;
48
+ this . _copyWithTemplating ( allTemplateData , [ 'spec.ts' ] , 'test' ) ;
77
49
78
- this . copyWithoutTemplating ( [ 'base.ts' , 'bundle.ts' , 'constants.ts' , 'hot.ts' ] , 'webpack' ) ;
79
- this . copyWithTemplating ( allTemplateData , [ 'index-template.html' ] , 'webpack' ) ;
50
+ this . _copyWithoutTemplating ( [ 'base.ts' , 'bundle.ts' , 'constants.ts' , 'hot.ts' ] , 'webpack' ) ;
51
+ this . _copyWithTemplating ( allTemplateData , [ 'index-template.html' ] , 'webpack' ) ;
80
52
}
81
53
82
54
install ( ) {
83
55
this . spawnCommandSync ( 'yarn' , [ 'install' ] , { cwd : this . destinationRoot ( ) } ) ;
84
56
}
57
+
58
+ end ( ) {
59
+ this . log ( ) ;
60
+ this . log ( 'To start devving, use webpack-dev-server:' ) ;
61
+ this . log ( ' yarn start' ) ;
62
+ }
63
+
64
+ private _copyWithTemplating ( templateData : object , templateNames : string [ ] , directory : string = '.' ) {
65
+ templateNames . forEach ( filename => {
66
+ this . fs . copyTpl (
67
+ this . templatePath ( path . join ( directory , '_' + filename ) ) ,
68
+ this . destinationPath ( path . join ( directory , filename ) ) ,
69
+ templateData ,
70
+ ) ;
71
+ } ) ;
72
+ }
73
+
74
+ private _copyWithoutTemplating ( templateNames : string [ ] , directory : string = '.' ) {
75
+ templateNames . forEach ( filename => {
76
+ this . fs . copy (
77
+ this . templatePath ( path . join ( directory , '_' + filename ) ) ,
78
+ this . destinationPath ( path . join ( directory , filename ) ) ,
79
+ ) ;
80
+ } ) ;
81
+ }
85
82
}
83
+
84
+ export = GeneratorTypescriptReact ;
0 commit comments