Skip to content

Commit

Permalink
add js/ts support
Browse files Browse the repository at this point in the history
  • Loading branch information
Илья Лебедев committed Jul 24, 2019
1 parent 7269b7a commit 526b245
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rozental_as_a_service/rozental.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from rozental_as_a_service.files_utils import get_all_filepathes_recursively
from rozental_as_a_service.strings_extractors import (
extract_from_python_src, extract_from_markdown, extract_from_html,
extract_from_js,
)

log = logging.getLogger(__name__)
Expand All @@ -42,6 +43,7 @@ def extract_all_constants_from_path(path: str, exclude: List[str]) -> List[str]:
(extract_from_python_src, ['py']),
(extract_from_markdown, ['md']),
(extract_from_html, ['html']),
(extract_from_js, ['js', 'ts', 'tsx']),
]

string_constants: List[str] = []
Expand Down
9 changes: 9 additions & 0 deletions rozental_as_a_service/strings_extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from bs4 import BeautifulSoup
from markdown import markdown
from esprima import tokenize, Error

from rozental_as_a_service.ast_utils import extract_all_constants_from_ast

Expand All @@ -26,3 +27,11 @@ def extract_from_markdown(raw_content: str) -> List[str]:
html = re.sub(r'<pre>(.*?)</pre>', ' ', html)
html = re.sub(r'<code>(.*?)</code>', ' ', html)
return extract_from_html(html)


def extract_from_js(raw_content: str) -> List[str]:
try:
tokens = tokenize(raw_content)
except Error:
return []
return list({t.value for t in tokens if t.type == 'String'})
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def get_long_description() -> str:
'requests>=2.22.0',
'Markdown>=3.1.1',
'beautifulsoup4>=4.8.0',
'esprima==4.0.1',
],
entry_points={
'console_scripts': [
Expand Down

0 comments on commit 526b245

Please sign in to comment.