Skip to content

Instantly share code, notes, and snippets.

@thachnuida
Last active April 11, 2018 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thachnuida/fe83cda3a006490cce89fc883c830177 to your computer and use it in GitHub Desktop.
Save thachnuida/fe83cda3a006490cce89fc883c830177 to your computer and use it in GitHub Desktop.
Import child module in child folder for js
import sublime
import sublime_plugin
import os
import re
class ImportChildModulesCommand(sublime_plugin.TextCommand):
def replace_module_name(self, m):
return m.group(2).upper()
def run(self, edit):
current_folder = os.path.dirname(self.view.file_name())
for file in os.listdir(current_folder):
child_path = os.path.join(current_folder, file);
if os.path.isdir(child_path):
# get module in child folder
for child_file in os.listdir(child_path):
if child_file.endswith('.module.js'):
file_name = os.path.splitext(child_file)[0]
file_path = file + '/' + file_name
module_name = re.sub(r'(\.|-|_)(.)', self.replace_module_name, file_name)
self.view.insert(edit, 0, "import {0} from './{1}';\n".format(module_name, file_path))
# Sample result
# import vendorledgerModule from './vendorledger/vendorledger.module';
# import tenantledgerModule from './tenantledger/tenantledger.module';
# import ownerledgerModule from './ownerledger/ownerledger.module';
# import depositslipModule from './depositslip/depositslip.module';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment