Skip to content

Commit

Permalink
fix get lwc templates bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lushang committed Mar 27, 2020
1 parent ed412e4 commit 1ef3499
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@


def load_templates():
"""
Load code template files from haoide package to working project .templates folder
"""
settings = context.get_settings()
target_dir = os.path.join(settings["workspace"], ".templates")
if not os.path.exists(target_dir):
Expand All @@ -36,13 +39,16 @@ def load_templates():
lwc_dir = os.path.join(target_dir, "Lwc") # Check exist lwc logic
lwc_ele_dir = os.path.join(target_dir, "LwcElement") # Check exist lwc element logic

# for the updating of Lwc, old project should update the template files
if not os.path.isfile(templates_dir) or not os.path.exists(lwc_dir) or not os.path.exists(lwc_ele_dir):
# get the installed haoide package directory
source_dir = os.path.join(
sublime.installed_packages_path(),
"haoide.sublime-package"
)

if os.path.isfile(source_dir) and os.path.exists(lwc_dir) and os.path.exists(lwc_ele_dir):
if os.path.isfile(source_dir):
# default situation, installed haoide package, copy files from zip file sub folders
zfile = zipfile.ZipFile(source_dir, 'r')
for filename in zfile.namelist():
if filename.endswith('/'):
Expand All @@ -61,8 +67,9 @@ def load_templates():

zfile.close()
else:
# when develop haoide, use local package templates files
source_dir = os.path.join(
sublime.packages_path(), "haoide", "config", "templates"
sublime.packages_path(), "haoide2/config/templates"
)
copy_files_in_folder(source_dir, target_dir)

Expand Down

0 comments on commit 1ef3499

Please sign in to comment.