D2Lang

[D2Lang] 6. window에서 D2 CLI 설치 및 내보내기(svg, png)를 알아보자!

o0zrone 2023. 5. 4. 12:40
728x90

window의 경우 msi를 설치해서 사용하는 방법과 WSL(윈도우 하위 시스템)에 설치하는 방법이나 도커에서 돌리는 방법이 있습니다.

 

여기서는 msi로 설치할 것 입니다.

 

https://github.com/terrastruct/d2/releases

위의 링크에 들어가시면

아래와 같이 나오는데 Assetes window msi파일을 다운 받으시고 설치하시면 됩니다.

설치를 위한 깃헙 사이트

확인 누르시고 설치를 완료하시면 d2 명령어를 사용할 수 있으며 ”d2 --version”를 사용하여 제대로 설치가 되었는지 확인해 봅니다.

 cmd창에서 d2 --version을 입력해보시면 아래와 같이 출력됩니다.

D:\>d2 --version
v0.4.1

저의 경우 설치한 버전인 0.4.1이 정상적으로 설치 되었음을 확인할 수 있습니다.

 

아래와 같이 d2lang이라는 파일을 만들고 x -> y라는 내용의 test.d2를 만들어 줍니다.

그리고 d2 -w test.d2 result.svg를 통해 내보내주는데 -w옵션으로 만들어지는 과정을 출력하고 result.svg를 내보내줍니다.

D:\>mkdir d2lang

D:\>cd d2lang

D:\d2lang>echo x -^> y > test.d2

D:\d2lang>d2 -w test.d2 result.svg
[32msuccess[0m: listening on http://127.0.0.1:9515
[34minfo[0m: compiling test.d2...
[32msuccess[0m: successfully compiled test.d2 to result.svg in 384.7745ms
[34minfo[0m: broadcasting update to 0 clients
[32msuccess[0m: GET / 200 392B 0s
[32msuccess[0m: GET /static/watch.js 200 2,374B 63.9696ms
[32msuccess[0m: GET /static/watch.css 200 206B 62.6163ms
[32msuccess[0m: GET /watch 101 0B 0s
[32msuccess[0m: GET /favicon.ico 200 392B 0s

D:\d2lang>d2 test.d2 result1.svg
[32msuccess[0m: successfully compiled test.d2 to result1.svg in 377.1504ms

-w를 사용한 경우 아래와 같이 결과를 브라우저에 띄워주면 파일을 생성해줍니다.

사용하지 않은 경우에는 파일만 생성해줍니다.

svg 결과 1

이번엔 png로 내보내겠습니다.

그냥 내보내려는 경우 아래와 같이 에러가 뜨는데

D:\d2lang>d2 -w test.d2 result.png
[0m[0m2023-05-01 11:29:00.638 [34m[INFO][0m [35m(default.stdlib)[0m       [36m<./..\..\github.com\playwright-community\playwright-go\run.go:107> (*PlaywrightDriver).DownloadDriver[0m        "Downloading driver to C:\\Users\\UserName\\AppData\\Local\\ms-playwright-go\\1.20.0-beta-1647057403000"
[31merr[0m: failed to install Playwright: could not install driver: could not install driver: could not download driver: Get "https://playwright.azureedge.net/builds/driver/next/playwright-1.20.0-beta-1647057403000-win32_x64.zip": read tcp 192.168.0.2:9754->13.107.238.49:443: wsarecv: An existing connection was forcibly closed by the remote host.

위의 내용에 있는 링크에서 압축 파일을 직접 다운하여 C:\\Users\\UserName\\AppData\\Local\\ms-playwright-go\\1.20.0-beta-1647057403000"에 압축 파일의 내용을 그대로 넣어주면 해결됩니다.

버전이 다른 경우 경로와 링크가 다를 수 있습니다. 본인의 링크를 확인하여 넣어주세요.

Get의 "~"에 있는 링크입니다.

could not download driver: Get "https://playwright.azureedge.net/builds/driver/next/playwright-1.20.0-beta-1647057403000-win32_x64.zip": read tcp 192.168.0.2:9754->13.107.238.49:443: wsarecv: An existing connection was forcibly closed by the remote host.

아래와 같이 압축 파일의 내용을 그대로 넣으면 됩니다.

그러면 다음과 같이 정상적으로 내보내집니다.

D:\d2lang>d2 -w test.d2 result.png
success: listening on http://127.0.0.1:10003
info: compiling test.d2...
success: successfully compiled test.d2 to result.png in 411.8471ms
info: broadcasting update to 0 clients
success: GET / 200 392B 0s
success: GET /static/watch.js 200 2,374B 64.9473ms
success: GET /static/watch.css 200 206B 64.3403ms
success: GET /watch 101 0B 0s
success: GET /favicon.ico 200 392B 357.2µs

result png 1

이상으로 마치겠습니다.