Size: 2112 bytes.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
# cs/labs/typescript/hello_world_test.gpt.py
# cs/labs/typescript/hello_world_test.py
import os
import shutil
import subprocess
import tempfile
from pathlib import Path


def main() -> None:
    root = Path(__file__).resolve().parent
    with tempfile.TemporaryDirectory() as work:
        workdir = Path(work)
        for fname in ["hello_world.gpt.ts", "node_globals.d.ts", "tsconfig.json"]:
            shutil.copy(root / fname, workdir / fname)

        env = dict(os.environ)
        npm_cache = workdir / ".npm-cache"
        npm_cache.mkdir(parents=True, exist_ok=True)
        env.update(
            {
                "HOME": str(workdir),
                "NPM_CONFIG_CACHE": str(npm_cache),
            }
        )
        tsc = shutil.which("tsc")
        if tsc is None:
            npm = shutil.which("npm")
            if npm is None:
                raise SystemExit(
                    "tsc not found and npm missing; install TypeScript or use devcontainer"
                )
            pkg_dir = workdir / "npm"
            subprocess.run(
                [
                    npm,
                    "install",
                    "--prefix",
                    str(pkg_dir),
                    "--no-package-lock",
                    "typescript@5.6.3",
                ],
                check=True,
                env=env,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                text=True,
            )
            tsc = str(pkg_dir / "node_modules" / ".bin" / "tsc")

        subprocess.run(
            [tsc, "--project", "tsconfig.json", "--pretty", "false"],
            cwd=workdir,
            check=True,
            env=env,
        )
        result = subprocess.run(
            ["node", "dist/hello_world.gpt.js"],
            cwd=workdir,
            check=True,
            capture_output=True,
            text=True,
        )
        output = result.stdout.strip()
        if output != "Hello World!":
            raise SystemExit(f"unexpected output: '{output}'")


if __name__ == "__main__":
    main()
v0 (commit) © 2025 @p13i.io | Load balancer proxied to: cs-code-viewer-3:8080 in 4ms.