Пример #1
0
    def get_suggestion_native_modules(self):
        path = os.path
        NODE_MODULES_LIST = path.join(pkg_path,'node_modules.list')
        try:
            if os.path.exists(NODE_MODULES_LIST) :
                print('cache file exists')
                source = open(NODE_MODULES_LIST)
                results= json.loads(source.read())
                source.close()
            else :
                # load native node modules from node
                jsresult = popen.get_node_output([node_path,
                  path.join(pkg_path, 'node_scripts/get_native_bindings.js')]);

                jsresult = jsresult.strip().replace("'", '"')

                # write list to cache file
                results = json.loads(jsresult)
                source = open(NODE_MODULES_LIST,'w')
                source.write(jsresult)
                source.close()
                print('write cache file success')

            result = [
                        [[ni, ni, 'is_native'] for ni in results],
                        ["native: " + ni for ni in results]
                      ]
            return result
        
        except Exception:
          print('load native bindings fail')
          return [[], []]
  def run( self, edit, name ):
    jsresult = popen.get_node_output(['node', os.path.join(pkg_path,'node_scripts/get_target_repo_installed_version.js'), str(name)])

    res = jsresult.strip()

    if res :
      for sel in self.view.sel() :
        self.view.replace(edit, sel, res)
Пример #3
0
    def write_es6_import( module_candidate_name, module_rel_path, module_flag ):
      lens = 0
      spos = 0
      region = view.sel()[0]
      line   = view.line(region)

      if module_flag == 'is_relative_file' :
        # parse file exports

        path = os.path

        module_export_names = popen.get_node_output([node_path, 
            path.normpath(path.join(pkg_path,'node_scripts/get_exports_names.js')),
            path.normpath(path.join(path.dirname(self.full_name), module_rel_path))
          ])

        module_export_names = module_export_names.strip()

        if len(module_export_names) == 0 :
          module_export_names = '* as ' + module_candidate_name

        print('module_export_names', module_export_names)

        require_directive = 'import {0} from {1};'.format(module_export_names, get_path(module_rel_path))
      else :
        require_directive = 'import {0} from {1};'.format(module_candidate_name, get_path(module_rel_path))

      print(require_directive)


      if re.search(self.re_require, getthisline(line)) != None :
        print('this line is require')
        spos = line.b
        lens = view.insert(edit, line.b, '\n'+require_directive)
      elif re.search(self.re_require, getlastline(line)) != None :
        print('last line is require')
        spos = line.a
        lens = view.insert(edit, line.a, require_directive)
      else :
        print('last line not require')
        spos = line.b
        if re.search(re_empty, getlastline(line)) :
          lens = view.insert(edit, line.b, require_directive )
        else :
          lens = view.insert(edit, line.b, '\n'+require_directive)
def get_module_last_version(name):
  res = popen.get_node_output(['node', os.path.join(pkg_path,'node_scripts/get_target_repo_installed_version.js'), str(name)])
  return res.strip()