chiwaa 0.1.16 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/chiwaa.js +30 -4
  2. package/package.json +1 -1
package/bin/chiwaa.js CHANGED
@@ -92,11 +92,12 @@ function parseArgs(argv) {
92
92
  if (a.startsWith("--")) {
93
93
  const [k, v] = a.slice(2).split("=", 2);
94
94
  if (v !== undefined) out[k] = v;
95
- else if (["name", "token", "dir", "read", "write", "page", "days", "lines"].includes(k) && argv[i + 1] && !argv[i + 1].startsWith("-")) out[k] = argv[++i];
95
+ else if (["name", "token", "dir", "read", "write", "page", "days", "lines", "branch"].includes(k) && argv[i + 1] && !argv[i + 1].startsWith("-")) out[k] = argv[++i];
96
96
  else out[k] = true;
97
97
  } else if (a === "-y") out.yes = true;
98
98
  else if (a === "-h") out.help = true;
99
99
  else if (a === "-v") out.version = true;
100
+ else if (a === "-f") out.f = true;
100
101
  else out._.push(a);
101
102
  }
102
103
  return out;
@@ -839,10 +840,12 @@ async function stats(args) {
839
840
  // ---------- logs (서버 함수 기록) ----------
840
841
  async function logs(args) {
841
842
  const name = await siteName(args);
842
- const n = Math.min(Math.max(parseInt(args.lines, 10) || 30, 1), 500);
843
- const r = await api("GET", `/api/v1/sites/${encodeURIComponent(name)}/logs?lines=${n}${args.preview ? "&preview=1" : ""}`);
843
+ const n = Math.min(Math.max(parseInt(args.lines, 10) || 30, 1), 2000);
844
+ const q = `${args.preview ? "&preview=1" : ""}${args.branch ? `&branch=${encodeURIComponent(args.branch)}` : ""}`;
845
+ const r = await api("GET", `/api/v1/sites/${encodeURIComponent(name)}/logs?lines=${n}${q}`);
844
846
  if (r.status !== 200) fail(r.data.error || "기록을 받지 못했습니다.");
845
847
  const d = r.data;
848
+ if (d.kind === "container") return containerLogs(name, n, q, d, args.f || args.follow);
846
849
  console.log(c.bold(`${d.site} 서버 함수 기록`), c.dim(`(최근 ${n}건 · 1분쯤 늦을 수 있음)`));
847
850
  if (d.functions.length) console.log(c.dim(` 함수: ${d.functions.map((f) => "/api/" + f).join(" ")}`));
848
851
  if (!d.entries.length) return console.log(c.dim(" 아직 기록이 없습니다. 오류가 나거나 console.log 를 쓰면 여기에 남습니다."));
@@ -856,6 +859,29 @@ async function logs(args) {
856
859
  }
857
860
  }
858
861
 
862
+ // 컨테이너 앱 기록: 상태 한 줄 + 기록. -f 면 3초마다 새 줄만 이어서 보여 준다(Ctrl+C 로 끝).
863
+ async function containerLogs(name, n, q, d, follow) {
864
+ const st = d.status || {};
865
+ const state = st.error ? "상태 모름" : st.running ? `실행 중 · 메모리 ${st.memory_used || "?"} / ${st.memory_mb}MB` : "잠듦(다음 요청에서 깨어남)";
866
+ console.log(c.bold(`${d.site} 앱 기록`), c.dim(`(${state})`));
867
+ const print = (text, seen) => {
868
+ const lines = String(text || "").split("\n").filter((l) => l.trim());
869
+ let start = 0;
870
+ if (seen) { const i = lines.lastIndexOf(seen); start = i >= 0 ? i + 1 : 0; }
871
+ for (const l of lines.slice(start)) console.log(l.replace(/^(\S+)Z /, (m, t) => c.dim(t.slice(5, 19).replace("T", " ") + " ")));
872
+ return lines.length ? lines[lines.length - 1] : seen;
873
+ };
874
+ let last = print(d.text, null);
875
+ if (!d.text || !String(d.text).trim()) console.log(c.dim(" 아직 기록이 없습니다. 앱이 console.log·print 로 쓰거나 오류가 나면 여기에 남습니다."));
876
+ if (!follow) return;
877
+ console.log(c.dim("— 이어서 봅니다(Ctrl+C 로 끝)"));
878
+ for (;;) {
879
+ await new Promise((res) => setTimeout(res, 3000));
880
+ const r = await api("GET", `/api/v1/sites/${encodeURIComponent(name)}/logs?lines=200${q}`);
881
+ if (r.status === 200 && r.data.kind === "container") last = print(r.data.text, last);
882
+ }
883
+ }
884
+
859
885
  // ---------- env (서버 함수 비밀값) ----------
860
886
  async function env(args) {
861
887
  const sub = args._[1] || "ls";
@@ -1042,7 +1068,7 @@ const HELP = `chiwaa ${VERSION} — chiwaa.kr 에 사이트를 바로 올립니
1042
1068
  chiwaa domains check 연결됐는지 확인 · domains remove -y 로 연결 끊기
1043
1069
  chiwaa stats 방문자 통계(오늘·최근 7일, 많이 본 페이지, 들어온 곳) --days 30
1044
1070
  chiwaa files 사진 목록·용량 · files put 사진.jpg(주인 사진 올리기) · files on|off(방문자 사진 올리기)
1045
- chiwaa logs 서버 함수 기록(오류·console.log) --lines 100, --preview
1071
+ chiwaa logs 컨테이너 앱 기록(-f 이어서 보기, --branch <브랜치>) 또는 서버 함수 기록 --lines 100, --preview
1046
1072
  chiwaa env 서버 함수 비밀값 목록 · env set 이름(값은 안 보이게 입력) · env rm 이름
1047
1073
  chiwaa lock / unlock 사이트 비밀번호 잠금(아이디 chiwaa) / 풀기 — 공개 전 나만 보기
1048
1074
  chiwaa open 관리 화면 열기 (--site 는 사이트 열기)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chiwaa",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "chiwaa.kr 에 사이트를 터미널에서 바로 올리는 도구",
5
5
  "bin": {
6
6
  "chiwaa": "bin/chiwaa.js"