From 6ea454112e7d04e4f2427b0b0e81e64a2927339e Mon Sep 17 00:00:00 2001 From: Joey Payne Date: Sat, 14 May 2016 15:07:26 -0600 Subject: [PATCH] Fix #137: Package.json overwritten if in default location --- command_line.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/command_line.py b/command_line.py index 0ef5480..2be2afe 100644 --- a/command_line.py +++ b/command_line.py @@ -867,7 +867,7 @@ def process_export_setting(self, ex_setting, output_dir, - def make_output_dirs(self): + def make_output_dirs(self, write_json=True): output_dir = utils.path_join(self.output_dir(), self.project_name()) temp_dir = utils.path_join(TEMP_DIR, 'webexectemp') @@ -876,7 +876,9 @@ def make_output_dirs(self): self.clean_dirs(temp_dir, output_dir) self.copy_files_to_project_folder() - self.write_package_json() + + if write_json: + self.write_package_json() app_loc = self.get_app_nw_loc(temp_dir, output_dir) @@ -1177,11 +1179,11 @@ def run_script(self, script): self.progress_text = '\nThe script {} does not exist. Not running.'.format(script) - def export(self): + def export(self, write_json=True): self.get_files_to_download() res = self.try_to_download_files() if res: - self.make_output_dirs() + self.make_output_dirs(write_json) script = self.get_setting('custom_script').value self.run_script(script) self.progress_text = '\nDone!\n' @@ -1452,12 +1454,23 @@ def my_excepthook(type_, value, tback): if setting is not None: setting.value = val + write_json = False + if args.load_json is True: command_base.load_package_json() elif args.load_json: command_base.load_package_json(args.load_json) - command_base.export() + project_dir = command_base.project_dir() + json_path = os.path.abspath(os.path.expanduser(args.load_json)) + left_over_path = json_path.replace(project_dir, '') + + # Write package.json if it's not already in the root + # of the project + if left_over_path != 'package.json': + write_json = True + + command_base.export(write_json) if __name__ == '__main__': main()