Add selectable CASAN IDE integrations
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Build the dependency-free CASAN VS Code extension as a deterministic VSIX."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import zipfile
|
||||
|
||||
|
||||
ROOT = os.path.dirname(os.path.abspath(__file__))
|
||||
HARNESS = os.environ.get(
|
||||
"CASAN_HARNESS_ROOT",
|
||||
os.path.abspath(os.path.join(ROOT, "..", "casan-harness")))
|
||||
SOURCE = os.path.join(HARNESS, "adapters", "vscode", "extension")
|
||||
|
||||
|
||||
CONTENT_TYPES = """<?xml version="1.0" encoding="utf-8"?>
|
||||
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
|
||||
<Default Extension="json" ContentType="application/json" />
|
||||
<Default Extension="js" ContentType="application/javascript" />
|
||||
<Default Extension="md" ContentType="text/markdown" />
|
||||
<Default Extension="vsixmanifest" ContentType="text/xml" />
|
||||
</Types>
|
||||
"""
|
||||
|
||||
|
||||
def manifest(package):
|
||||
identity = "%s.%s" % (package["publisher"], package["name"])
|
||||
return """<?xml version="1.0" encoding="utf-8"?>
|
||||
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011">
|
||||
<Metadata>
|
||||
<Identity Language="en-US" Id="{identity}" Version="{version}" Publisher="{publisher}" />
|
||||
<DisplayName>{display}</DisplayName>
|
||||
<Description xml:space="preserve">{description}</Description>
|
||||
<Tags>casan,governance,github copilot,chat</Tags>
|
||||
<Categories>Other</Categories>
|
||||
<Properties>
|
||||
<Property Id="Microsoft.VisualStudio.Code.Engine" Value="{engine}" />
|
||||
</Properties>
|
||||
</Metadata>
|
||||
<Installation>
|
||||
<InstallationTarget Id="Microsoft.VisualStudio.Code" Version="[1.98.0,)" />
|
||||
</Installation>
|
||||
<Dependencies />
|
||||
<Assets>
|
||||
<Asset Type="Microsoft.VisualStudio.Code.Manifest" Path="extension/package.json" Addressable="true" />
|
||||
</Assets>
|
||||
</PackageManifest>
|
||||
""".format(
|
||||
identity=identity,
|
||||
version=package["version"],
|
||||
publisher=package["publisher"],
|
||||
display=package["displayName"],
|
||||
description=package["description"],
|
||||
engine=package["engines"]["vscode"],
|
||||
)
|
||||
|
||||
|
||||
def build(output):
|
||||
with open(os.path.join(SOURCE, "package.json"), "r", encoding="utf-8") as handle:
|
||||
package = json.load(handle)
|
||||
os.makedirs(os.path.dirname(os.path.abspath(output)), exist_ok=True)
|
||||
entries = ["package.json", "extension.js", "README.md"]
|
||||
with zipfile.ZipFile(output, "w", compression=zipfile.ZIP_DEFLATED) as archive:
|
||||
def write_entry(name, data):
|
||||
info = zipfile.ZipInfo(name, date_time=(2020, 1, 1, 0, 0, 0))
|
||||
info.compress_type = zipfile.ZIP_DEFLATED
|
||||
info.external_attr = 0o644 << 16
|
||||
archive.writestr(info, data)
|
||||
|
||||
write_entry("[Content_Types].xml", CONTENT_TYPES)
|
||||
write_entry("extension.vsixmanifest", manifest(package))
|
||||
for name in entries:
|
||||
source = os.path.join(SOURCE, name)
|
||||
with open(source, "rb") as handle:
|
||||
write_entry("extension/" + name, handle.read())
|
||||
return output
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--output", default=os.path.join(ROOT, "dist",
|
||||
"casan-governed-chat.vsix"))
|
||||
args = parser.parse_args()
|
||||
print(build(args.output))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user