Skip to content

Commit 0b19d66

Browse files
implemented VSIX template
* does note require vsce or node * vsce can be used by passing it explicitly
1 parent 8ba7769 commit 0b19d66

File tree

7 files changed

+78
-13
lines changed

7 files changed

+78
-13
lines changed

tests/test_gen.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ def test_vscode_gen_cli_vsix(workflow_grammar_path, tmpdir):
4646
assert (Path(str(tmpdir)) / "{}.vsix".format(project_name)).exists()
4747

4848

49+
def test_vscode_gen_cli_vsix_vsce(workflow_grammar_path, tmpdir):
50+
project_name = "tx-workflow"
51+
_, err = _vscode_gen_cli(
52+
workflow_grammar_path,
53+
output_path=str(tmpdir),
54+
project__name=project_name,
55+
vsix="True",
56+
vsce="vsce",
57+
)
58+
59+
assert err is None
60+
assert (Path(str(tmpdir)) / "{}.vsix".format(project_name)).exists()
61+
62+
4963
def test_vscode_gen_cli_bad_args(workflow_grammar_path):
5064
output, err = _vscode_gen_cli(workflow_grammar_path)
5165
assert 'Error: Missing option: "--project_name".' in output

textx_gen_vscode/generators.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import subprocess
44
import tempfile
55
from functools import partial
6-
from os import getcwd
6+
from os import getcwd, rename
77
from os.path import abspath, dirname, join, relpath
88
from pathlib import Path
99

@@ -49,8 +49,8 @@ def _copy(
4949
):
5050
"""Populates jinja template."""
5151
if src.endswith("template"):
52-
template_rel_path = relpath(src, template_path)
53-
template = jinja_env.get_template(template_rel_path)
52+
template_rel_path = Path(src).relative_to(template_path)
53+
template = jinja_env.get_template(template_rel_path.as_posix())
5454
dest = dest.replace(".template", "")
5555
with open(dest, "w") as f:
5656
f.write(
@@ -77,7 +77,7 @@ def generate_vscode_extension(
7777
vsix=False,
7878
output_path="",
7979
skip_keywords=False,
80-
vsce="vsce",
80+
vsce=None,
8181
):
8282
"""Generate minimal extension from template files and given information.
8383
@@ -88,6 +88,7 @@ def generate_vscode_extension(
8888

8989
with tempfile.TemporaryDirectory() as tmpdirname:
9090
tmp = join(tmpdirname, "tmp")
91+
extension = join(tmp, "extension")
9192

9293
# Copy files from ./template directory while populating *.template
9394
shutil.copytree(
@@ -107,7 +108,7 @@ def generate_vscode_extension(
107108
# Generate syntax highlighting
108109
for lang in languages:
109110
lang_name = lang.name.lower()
110-
lang_syntax_path = Path(tmp) / "syntaxes" / "{}.json".format(lang_name)
111+
lang_syntax_path = Path(extension) / "syntaxes" / "{}.json".format(lang_name)
111112
lang_syntax_path.write_text(
112113
generate_textmate_syntax(
113114
lang.metamodel, lang_name, skip_keywords=skip_keywords
@@ -120,13 +121,17 @@ def generate_vscode_extension(
120121

121122
# Create installable .vsix file
122123
if vsix:
123-
subprocess.run(
124-
[vsce, "package", "-o", "{}.vsix".format(archive_dest)],
125-
cwd=tmp,
126-
stdout=subprocess.DEVNULL,
127-
stderr=subprocess.DEVNULL,
128-
shell=platform.system() == "Windows",
129-
)
124+
if vsce:
125+
subprocess.run(
126+
[vsce, "package", "-o", "{}.vsix".format(archive_dest)],
127+
cwd=extension,
128+
stdout=subprocess.DEVNULL,
129+
stderr=subprocess.DEVNULL,
130+
shell=platform.system() == "Windows",
131+
)
132+
else:
133+
shutil.make_archive(archive_dest, "zip", tmp)
134+
rename("{}.zip".format(archive_dest), "{}.vsix".format(archive_dest))
130135
# Create .tar file
131136
else:
132-
shutil.make_archive(archive_dest, "gztar", tmp)
137+
shutil.make_archive(archive_dest, "gztar", extension)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
3+
<Default Extension=".js" ContentType="application/javascript"/><Default Extension=".json" ContentType="application/json"/><Default Extension=".vsixmanifest" ContentType="text/xml"/>
4+
</Types>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
3+
<Metadata>
4+
<Identity Language="en-US" Id="{{project_name.replace('_', '-')|lower}}" Version="0.1.0" Publisher="{{publisher}}"/>
5+
<DisplayName>{{project_name.replace('_', '-')|lower}}</DisplayName>
6+
<Description xml:space="preserve">{{description}}</Description>
7+
<Tags>{% for lang in languages %}{{lang.name|lower}},__ext_{{lang.pattern.split('.')[-1]}}{%- if loop.index != languages|length -%},{%- endif %}{% endfor %}</Tags>
8+
<Categories></Categories>
9+
<GalleryFlags>Public</GalleryFlags>
10+
<Badges></Badges>
11+
<Properties>
12+
<Property Id="Microsoft.VisualStudio.Code.Engine" Value="^1.32.3" />
13+
<Property Id="Microsoft.VisualStudio.Code.ExtensionDependencies" Value="" />
14+
<Property Id="Microsoft.VisualStudio.Code.ExtensionPack" Value="" />
15+
<Property Id="Microsoft.VisualStudio.Code.LocalizedLanguages" Value="" />
16+
17+
<Property Id="Microsoft.VisualStudio.Services.Links.Source" Value="{{repository}}" />
18+
<Property Id="Microsoft.VisualStudio.Services.Links.Getstarted" Value="{{repository}}" />
19+
20+
<Property Id="Microsoft.VisualStudio.Services.Links.GitHub" Value="{{repository}}" />
21+
22+
23+
24+
25+
26+
27+
<Property Id="Microsoft.VisualStudio.Services.GitHubFlavoredMarkdown" Value="true" />
28+
29+
30+
</Properties>
31+
32+
33+
</Metadata>
34+
<Installation>
35+
<InstallationTarget Id="Microsoft.VisualStudio.Code"/>
36+
</Installation>
37+
<Dependencies/>
38+
<Assets>
39+
<Asset Type="Microsoft.VisualStudio.Code.Manifest" Path="extension/package.json" Addressable="true" />
40+
41+
</Assets>
42+
</PackageManifest>
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)