11import * as vscode from "vscode" ;
22import * as fs from "fs" ;
33import * as shell from "shelljs" ;
4- import * as path from "path" ;
54
6- import * as templates from "./template/component" ;
5+ import * as templatesJavascript from "./template/component" ;
6+ import * as templatesTypescript from "./template/componentsTypescrip" ;
77import config from "./config" ;
88
99export default class Model {
10+ getConfiguration ( ) : vscode . WorkspaceConfiguration {
11+ return vscode . workspace . getConfiguration ( config . namespace ) ;
12+ }
13+
14+ getTemplates ( ) {
15+ const configuration = this . getConfiguration ( ) ;
16+ return configuration . typescript ? templatesTypescript : templatesJavascript ;
17+ }
18+
1019 createComponent ( contextUri : string ) {
1120 vscode . window
1221 . showInputBox ( {
@@ -50,7 +59,7 @@ export default class Model {
5059 this . createFolder ( folderPath ) ;
5160 this . createIndexFile ( name , folderPath , true ) ;
5261 this . createComponentFile ( folderPath , name , true ) ;
53- this . createFile ( folderPath , ` ${ name } .styles.js` , templates . styles ) ;
62+ this . createStyleFile ( folderPath , name ) ;
5463
5564 vscode . window . showInformationMessage (
5665 "The component has been successfuly created."
@@ -59,30 +68,46 @@ export default class Model {
5968 }
6069
6170 createComponentFile ( path : string , name : string , fela : boolean ) {
62- const fullName = name + ".jsx" ;
63- const configuration = vscode . workspace . getConfiguration ( config . namespace ) ;
71+ const configuration = this . getConfiguration ( ) ;
72+ const templates = this . getTemplates ( ) ;
73+ const fullName = `${ name } .${ configuration . typescript ? "t" : "j" } sx` ;
6474
6575 let content ;
66- if ( fela && ! configuration . felaHooks ) {
76+ if ( fela && ! configuration . felaHooks ) {
6777 content = templates . felaComponent ( name , configuration . moduleDependencies ) ;
68- } else if ( fela && configuration . felaHooks ) {
69- content = templates . felaHookComponent ( name , configuration . moduleDependencies ) ;
78+ } else if ( fela && configuration . felaHooks ) {
79+ content = templates . felaHookComponent (
80+ name ,
81+ configuration . moduleDependencies
82+ ) ;
7083 } else {
7184 content = templates . component ( name , configuration . moduleDependencies ) ;
7285 }
7386
7487 this . createFile ( path , fullName , content ) ;
7588 }
7689
90+ createStyleFile ( path : string , name : string ) {
91+ const configuration = this . getConfiguration ( ) ;
92+ const templates = this . getTemplates ( ) ;
93+ const fullName = `${ name } .styles.${ configuration . typescript ? "t" : "j" } s` ;
94+
95+ this . createFile (
96+ path ,
97+ fullName ,
98+ templates . styles ( configuration . moduleDependencies )
99+ ) ;
100+ }
101+
77102 createIndexFile ( componentName : string , path : string , fela : boolean ) {
78- const name = "index.js" ;
79103 const configuration = vscode . workspace . getConfiguration ( config . namespace ) ;
104+ const name = `index.${ configuration . typescript ? "t" : "j" } s` ;
80105
81106 let content ;
82107 if ( ! fela || ( fela && configuration . felaHooks ) ) {
83- content = templates . index ( componentName ) ;
108+ content = templatesJavascript . index ( componentName ) ;
84109 } else {
85- content = templates . indexFela ( componentName ) ;
110+ content = templatesJavascript . indexFela ( componentName ) ;
86111 }
87112
88113 this . createFile ( path , name , content ) ;
0 commit comments