@@ -15,7 +15,7 @@ def generator_key
15
15
inputs do
16
16
empty_typescript_react_project_config EmptyTypescriptReactProjectConfig , :required
17
17
# TODO: should be able to delete this and inherit it
18
- output_directory :string
18
+ output_directory :string , default : "."
19
19
end
20
20
21
21
def execute
@@ -27,12 +27,19 @@ def execute
27
27
stats
28
28
end
29
29
30
+ # A bit confusing... we need to write the files to the output_directory/project_dir
31
+ # and the code that writes the generated files assumes that output_directory contains the place
32
+ # to write the files not the place to initiate the project
30
33
def output_directory
31
- inputs [ :output_directory ] || default_output_directory
34
+ project_directory
32
35
end
33
36
34
- def default_output_directory
35
- "."
37
+ def output_parent_directory
38
+ inputs [ :output_directory ]
39
+ end
40
+
41
+ def project_directory
42
+ "#{ output_parent_directory } /#{ empty_typescript_react_project_config . project_dir } "
36
43
end
37
44
38
45
def generate_file_contents
@@ -48,8 +55,11 @@ def run_pre_generation_tasks
48
55
def run_npx_create_react_app
49
56
puts "created empty project with create-react-app..."
50
57
51
- Dir . chdir output_directory do
52
- cmd = "npx create-react-app --template typescript whatever-frontend"
58
+ cmd = "npx create-react-app --template typescript #{ empty_typescript_react_project_config . project_dir } "
59
+
60
+ FileUtils . mkdir_p output_parent_directory
61
+
62
+ Dir . chdir output_parent_directory do
53
63
run_cmd_and_write_output ( cmd )
54
64
end
55
65
end
@@ -65,18 +75,20 @@ def add_necessary_dev_dependencies_for_eslint
65
75
"eslint-plugin-promise@^6.1.1 " \
66
76
"typescript@^4.0.0 "
67
77
68
- run_cmd_and_write_output ( cmd )
78
+ Dir . chdir project_directory do
79
+ run_cmd_and_write_output ( cmd )
80
+ end
69
81
end
70
82
71
83
def run_post_generation_tasks
72
- Dir . chdir output_directory do
73
- eslint_fix
74
- end
84
+ eslint_fix
75
85
end
76
86
77
87
def eslint_fix
78
88
cmd = "npx eslint 'src/**/*.{js,jsx,ts,tsx}' --fix"
79
- run_cmd_and_write_output ( cmd )
89
+ Dir . chdir project_directory do
90
+ run_cmd_and_write_output ( cmd )
91
+ end
80
92
end
81
93
end
82
94
end
0 commit comments