Package the portable DSH profiles, local plugins, desktop integration, Firefox wrapper, and ownership-aware installer lifecycle. Bundle checksum-pinned OpenVSCode, editor extensions, translation assets, and cloudflared so unreliable upstream artifact downloads cannot break a clean installation.
57 lines
2.4 KiB
Python
57 lines
2.4 KiB
Python
import json
|
|
import sys
|
|
import xml.etree.ElementTree as element_tree
|
|
import zipfile
|
|
from pathlib import Path
|
|
|
|
source_directory = Path(sys.argv[1])
|
|
archive_path = Path(sys.argv[2])
|
|
package = json.loads((source_directory / "package.json").read_text())
|
|
namespace = "http://schemas.microsoft.com/developer/vsx-schema/2011"
|
|
element_tree.register_namespace("", namespace)
|
|
|
|
|
|
def add_element(parent, name, attributes=None, text=None):
|
|
child = element_tree.SubElement(parent, f"{{{namespace}}}{name}", attributes or {})
|
|
child.text = text
|
|
return child
|
|
|
|
|
|
manifest = element_tree.Element(f"{{{namespace}}}PackageManifest", {"Version": "2.0.0"})
|
|
metadata = add_element(manifest, "Metadata")
|
|
add_element(metadata, "Identity", {
|
|
"Language": "en-US",
|
|
"Id": package["name"],
|
|
"Version": package["version"],
|
|
"Publisher": package["publisher"],
|
|
})
|
|
add_element(metadata, "DisplayName", text=package.get("displayName", package["name"]))
|
|
add_element(metadata, "Description", text=package.get("description", package["name"]))
|
|
properties = add_element(metadata, "Properties")
|
|
add_element(properties, "Property", {
|
|
"Id": "Microsoft.VisualStudio.Code.Engine",
|
|
"Value": package["engines"]["vscode"],
|
|
})
|
|
extension_kind = package.get("extensionKind")
|
|
if extension_kind:
|
|
add_element(properties, "Property", {
|
|
"Id": "Microsoft.VisualStudio.Code.ExtensionKind",
|
|
"Value": ",".join(extension_kind),
|
|
})
|
|
installation = add_element(manifest, "Installation")
|
|
add_element(installation, "InstallationTarget", {"Id": "Microsoft.VisualStudio.Code"})
|
|
add_element(manifest, "Dependencies")
|
|
assets = add_element(manifest, "Assets")
|
|
add_element(assets, "Asset", {
|
|
"Type": "Microsoft.VisualStudio.Code.Manifest",
|
|
"Path": "extension/package.json",
|
|
"Addressable": "true",
|
|
})
|
|
content_types = '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="json" ContentType="application/json"/><Default Extension="js" ContentType="application/javascript"/><Default Extension="vsixmanifest" ContentType="text/xml"/></Types>'
|
|
|
|
with zipfile.ZipFile(archive_path, "w", zipfile.ZIP_DEFLATED) as archive:
|
|
archive.writestr("extension.vsixmanifest", element_tree.tostring(manifest, encoding="utf-8"))
|
|
archive.writestr("[Content_Types].xml", content_types)
|
|
for path in sorted(source_directory.rglob("*")):
|
|
if path.is_file():
|
|
archive.write(path, f"extension/{path.relative_to(source_directory).as_posix()}")
|