@@ -15,7 +15,7 @@ def generator_key
1515 inputs do
1616 empty_typescript_react_project_config EmptyTypescriptReactProjectConfig , :required
1717 # TODO: should be able to delete this and inherit it
18- output_directory :string
18+ output_directory :string , default : "."
1919 end
2020
2121 def execute
@@ -27,12 +27,19 @@ def execute
2727 stats
2828 end
2929
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
3033 def output_directory
31- inputs [ :output_directory ] || default_output_directory
34+ project_directory
3235 end
3336
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 } "
3643 end
3744
3845 def generate_file_contents
@@ -48,8 +55,11 @@ def run_pre_generation_tasks
4855 def run_npx_create_react_app
4956 puts "created empty project with create-react-app..."
5057
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
5363 run_cmd_and_write_output ( cmd )
5464 end
5565 end
@@ -65,18 +75,20 @@ def add_necessary_dev_dependencies_for_eslint
6575 "eslint-plugin-promise@^6.1.1 " \
6676 "typescript@^4.0.0 "
6777
68- run_cmd_and_write_output ( cmd )
78+ Dir . chdir project_directory do
79+ run_cmd_and_write_output ( cmd )
80+ end
6981 end
7082
7183 def run_post_generation_tasks
72- Dir . chdir output_directory do
73- eslint_fix
74- end
84+ eslint_fix
7585 end
7686
7787 def eslint_fix
7888 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
8092 end
8193 end
8294 end
0 commit comments