chiwaa 0.1.4 → 0.1.6

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 (3) hide show
  1. package/README.md +4 -0
  2. package/bin/chiwaa.js +103 -7
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -20,6 +20,10 @@ npx chiwaa deploy
20
20
  | `chiwaa rollback [버전]` | 한 단계 전 또는 지정 버전으로 되돌리기 |
21
21
  | `chiwaa db` · `db on` · `db create <표>` · `db rows <표>` | 사이트 DB(문의·방명록 등 글 저장) — 켜기·표 만들기·글 보기 |
22
22
  | `chiwaa domains` · `search` · `buy` · `add` · `check` | x-y.net 도메인 찾기·사기(결제는 x-y.net 결제창에서 직접)·붙이기 |
23
+ | `chiwaa stats` | 방문자 통계(오늘·최근 7일·많이 본 페이지·들어온 곳) |
24
+ | `chiwaa deploy --preview` | 운영 주소는 두고 `이름--preview.chiwaa.com` 에 미리보기 |
25
+ | `chiwaa lock` / `unlock` | 사이트 비밀번호 잠금(공개 전 나만 보기) |
26
+ | `chiwaa open` · `usage` | 관리 화면 열기 · 이번 달 사용량 |
23
27
  | `chiwaa agent` | AI 도구용 안내(AGENTS.md·CLAUDE.md) 만들기 — 처음 deploy 때 자동 |
24
28
  | `chiwaa whoami` / `logout` | 계정 확인 / 로그아웃 |
25
29
 
package/bin/chiwaa.js CHANGED
@@ -92,7 +92,7 @@ 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"].includes(k) && argv[i + 1] && !argv[i + 1].startsWith("-")) out[k] = argv[++i];
95
+ else if (["name", "token", "dir", "read", "write", "page", "days"].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;
@@ -255,10 +255,10 @@ function buildIfNeeded(dir, args) {
255
255
 
256
256
  // ---------- 사이트 정하기 ----------
257
257
  // 사용자가 직접 정한 이름은 바꾸지 않는다 — 규칙에 안 맞으면 거절한다(대문자만 소문자로)
258
- const NAME_RULE = "사이트 이름은 영문 소문자·숫자·하이픈(-)으로 2~30자, 첫 글자는 영문이나 숫자여야 합니다. 예: my-shop, cafe2026";
258
+ const NAME_RULE = "사이트 이름은 영문 소문자·숫자·하이픈(-)으로 2~30자, 첫 글자는 영문이나 숫자여야 합니다(하이픈 두 개 연속은 안 됨). 예: my-shop, cafe2026";
259
259
  function checkName(s) {
260
260
  const n = String(s).trim().toLowerCase();
261
- if (!/^[a-z0-9][a-z0-9-]{1,29}$/.test(n)) fail(`쓸 수 없는 사이트 이름입니다: ${s}
261
+ if (!/^[a-z0-9][a-z0-9-]{1,29}$/.test(n) || n.includes("--")) fail(`쓸 수 없는 사이트 이름입니다: ${s}
262
262
  ${NAME_RULE}`);
263
263
  return n;
264
264
  }
@@ -285,7 +285,7 @@ async function resolveSite(dir, args) {
285
285
  for (;;) {
286
286
  const a = await ask(`사이트 이름 ${c.dim(`(엔터 = ${name}.chiwaa.com)`)}: `);
287
287
  if (!a) break;
288
- if (/^[a-z0-9][a-z0-9-]{1,29}$/.test(a.toLowerCase())) { name = a.toLowerCase(); break; }
288
+ if (/^[a-z0-9][a-z0-9-]{1,29}$/.test(a.toLowerCase()) && !a.includes("--")) { name = a.toLowerCase(); break; }
289
289
  console.log(c.red("✗"), NAME_RULE);
290
290
  }
291
291
  const r = await api("GET", `/api/v1/sites/${encodeURIComponent(name)}`);
@@ -379,13 +379,15 @@ async function deploy(args) {
379
379
  console.log(c.dim(`올리는 중: ${path.relative(process.cwd(), out) || "."} — 파일 ${fileCount}개, ${(total / 1048576).toFixed(1)}MB`));
380
380
  const gz = makeTarGz(files);
381
381
  const t0 = Date.now();
382
- const r = await api("POST", `/api/v1/sites/${encodeURIComponent(site.name)}/deploy`, {
382
+ const preview = !!args.preview;
383
+ const r = await api("POST", `/api/v1/sites/${encodeURIComponent(site.name)}/deploy${preview ? "?preview=1" : ""}`, {
383
384
  body: gz,
384
385
  headers: { "Content-Type": "application/gzip" },
385
386
  });
386
387
  if (r.status !== 200 || !r.data.ok) fail(r.data.message || r.data.error || `배포하지 못했습니다 (${r.status}).`);
387
- console.log(c.green("✓"), `배포 완료 ${c.dim(`(${((Date.now() - t0) / 1000).toFixed(1)}초)`)}`);
388
+ console.log(c.green("✓"), `${preview ? "미리보기 " : ""}배포 완료 ${c.dim(`(${((Date.now() - t0) / 1000).toFixed(1)}초)`)}`);
388
389
  console.log(`\n ${c.bold(c.cyan(r.data.url))}\n`);
390
+ if (preview) console.log(c.dim("운영 주소는 그대로입니다. 괜찮으면 --preview 없이 다시 deploy 하세요. (미리보기는 검색엔진에 나오지 않음)\n"));
389
391
  }
390
392
 
391
393
  // ---------- 그 밖 ----------
@@ -633,6 +635,95 @@ async function domains(args) {
633
635
  fail(`모르는 domains 명령입니다: ${sub}\n 쓸 수 있는 것: (없음=상태) · search · buy · add · check · remove`);
634
636
  }
635
637
 
638
+ // ---------- stats (방문자 통계) ----------
639
+ async function stats(args) {
640
+ const name = await siteName(args);
641
+ const days = Math.min(Math.max(parseInt(args.days, 10) || 7, 1), 90);
642
+ const r = await api("GET", `/api/v1/sites/${encodeURIComponent(name)}/stats?days=${days}`);
643
+ if (r.status !== 200) fail(r.data.error || "통계를 받지 못했습니다.");
644
+ const s = r.data;
645
+ const n = (x) => Number(x).toLocaleString("ko-KR");
646
+ console.log(c.bold(`${s.site} 방문자`), c.dim(`(최근 ${days}일 · 10분마다 갱신 · 로봇 제외)`));
647
+ console.log(` 오늘 방문자 ${c.bold(n(s.today.visitors))}명 · 보기 ${n(s.today.views)}회`);
648
+ console.log(` ${days}일 합계 방문자 ${n(s.total.visitors)}명 · 보기 ${n(s.total.views)}회 · 휴대폰 ${s.mobile_pct}%\n`);
649
+ const top = Math.max(1, ...s.days.map((d) => d.visitors));
650
+ for (const d of s.days.slice(-14)) {
651
+ const bar = "█".repeat(Math.round((d.visitors / top) * 30)) || (d.visitors ? "▏" : "");
652
+ console.log(` ${d.date.slice(5)} ${String(d.visitors).padStart(6)}명 ${c.cyan(bar)}`);
653
+ }
654
+ const list = (title, obj) => {
655
+ const e = Object.entries(obj || {});
656
+ if (!e.length) return;
657
+ console.log(`\n ${title}`);
658
+ for (const [k, v] of e.slice(0, 5)) console.log(` ${String(v).padStart(6)} ${k}`);
659
+ };
660
+ list("많이 본 페이지", s.pages);
661
+ list("들어온 곳", s.refs);
662
+ if (!s.total.views) console.log(c.dim("\n 아직 집계된 방문이 없습니다."));
663
+ }
664
+
665
+ // ---------- lock / unlock / open / usage ----------
666
+ function readSecret(prompt) {
667
+ if (!process.stdin.isTTY) {
668
+ // AI·자동화: 표준입력으로 받는다(명령 줄에 비밀번호를 적지 않게)
669
+ return new Promise((res) => {
670
+ let d = "";
671
+ process.stdin.setEncoding("utf8");
672
+ process.stdin.on("data", (x) => (d += x));
673
+ process.stdin.on("end", () => res(d.split(/\r?\n/)[0]));
674
+ });
675
+ }
676
+ return new Promise((res) => {
677
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true });
678
+ let muted = false;
679
+ rl._writeToOutput = (str) => { if (!muted) rl.output.write(str); };
680
+ rl.question(prompt, (a) => { rl.close(); process.stdout.write("\n"); res(a); });
681
+ muted = true;
682
+ });
683
+ }
684
+
685
+ async function lock(args) {
686
+ const name = await siteName(args);
687
+ const pw = await readSecret("잠금 비밀번호(6자 이상, 화면에 안 보임): ");
688
+ if (!pw || pw.length < 6) fail("비밀번호는 6자 이상이어야 합니다. (AI·자동화에서는 표준입력으로: echo 비밀번호 | npx chiwaa lock)");
689
+ const r = await api("POST", `/api/v1/sites/${encodeURIComponent(name)}/lock`, { body: { password: pw } });
690
+ if (r.status !== 200) fail(r.data.message || r.data.error || "잠그지 못했습니다.");
691
+ console.log(c.green("✓"), r.data.message);
692
+ }
693
+
694
+ async function unlock(args) {
695
+ const name = await siteName(args);
696
+ const r = await api("POST", `/api/v1/sites/${encodeURIComponent(name)}/unlock`);
697
+ if (r.status !== 200) fail(r.data.message || r.data.error || "잠금을 풀지 못했습니다.");
698
+ console.log(c.green("✓"), r.data.message);
699
+ }
700
+
701
+ async function open(args) {
702
+ const name = await siteName(args);
703
+ const r = await api("GET", `/api/v1/sites/${encodeURIComponent(name)}`);
704
+ if (r.status !== 200) fail(r.data.error || "사이트 정보를 받지 못했습니다.");
705
+ const url = args.site ? r.data.url : r.data.manage_url;
706
+ console.log(`${args.site ? "사이트" : "관리 화면"}: ${c.cyan(url)}`);
707
+ if (!args["no-browser"]) openBrowser(url);
708
+ }
709
+
710
+ async function usage() {
711
+ const r = await api("GET", "/api/v1/usage");
712
+ if (r.status !== 200) fail(r.data.error || "사용량을 받지 못했습니다.");
713
+ const u = r.data;
714
+ const until = u.expires_at ? ` · ${u.expires_at.slice(0, 10)}까지${u.launch_event ? "(출시 이벤트 무료)" : ""}` : "";
715
+ console.log(c.bold(`${u.plan_name} 요금제`) + c.dim(`${until} · 사이트 ${u.sites.length}개 (한도 ${u.sites_limit})`));
716
+ console.log(c.dim("\n 이번 달 전송량(사이트마다) 저장 한도"));
717
+ const sz = (mb) => (mb >= 1024 ? `${+(mb / 1024).toFixed(1)}GB` : `${mb}MB`);
718
+ for (const s of u.sites) {
719
+ const lim = s.traffic_limit_gb * 1024;
720
+ const pct = lim ? Math.min(100, Math.round((s.traffic_mb / lim) * 100)) : 0;
721
+ const bar = "█".repeat(Math.round(pct / 5)).padEnd(20, "·");
722
+ console.log(` ${s.domain.padEnd(32)} ${bar} ${sz(s.traffic_mb)} / ${s.traffic_limit_gb}GB ${sz(s.storage_mb).padStart(6)}${s.locked ? c.dim(" (잠김)") : ""}`);
723
+ }
724
+ console.log(c.dim("\n한도를 넘어도 추가 요금은 없고, 그 사이트만 그달 말까지 느려집니다."));
725
+ }
726
+
636
727
  async function whoami() {
637
728
  const r = await api("GET", "/api/v1/me");
638
729
  if (r.status !== 200) fail(r.data.error || "로그인 정보를 받지 못했습니다.");
@@ -652,6 +743,7 @@ const HELP = `chiwaa ${VERSION} — chiwaa.kr 에 사이트를 바로 올립니
652
743
  --name <이름> 사이트 이름(<이름>.chiwaa.com)
653
744
  --dir <폴더> 빌드 결과 폴더를 직접 지정
654
745
  --no-build 빌드하지 않고 그대로 올림
746
+ --preview 운영 주소는 두고 이름--preview.chiwaa.com 에 미리보기로 올림
655
747
  -y, --yes 묻지 않고 진행(AI 도구·자동화용)
656
748
  chiwaa login 브라우저로 로그인 (--token <토큰> 도 가능)
657
749
  chiwaa list 내 사이트 목록
@@ -669,6 +761,10 @@ const HELP = `chiwaa ${VERSION} — chiwaa.kr 에 사이트를 바로 올립니
669
761
  chiwaa domains buy <도메인> x-y.net 신청·결제 화면 열기(결제는 직접)
670
762
  chiwaa domains add <도메인> 도메인 붙이기(x-y.net 도메인은 바로, 다른 곳 도메인은 넣을 DNS 레코드 안내)
671
763
  chiwaa domains check 연결됐는지 확인 · domains remove -y 로 연결 끊기
764
+ chiwaa stats 방문자 통계(오늘·최근 7일, 많이 본 페이지, 들어온 곳) --days 30
765
+ chiwaa lock / unlock 사이트 비밀번호 잠금(아이디 chiwaa) / 풀기 — 공개 전 나만 보기
766
+ chiwaa open 관리 화면 열기 (--site 는 사이트 열기)
767
+ chiwaa usage 이번 달 전송량·한도, 요금제
672
768
  chiwaa agent AI 도구용 안내(AGENTS.md·CLAUDE.md)를 만들거나 새로 고침
673
769
  (처음 deploy 할 때 자동으로 만든다)
674
770
  chiwaa whoami 로그인한 계정
@@ -682,7 +778,7 @@ async function main() {
682
778
  const cmd = args._[0];
683
779
  if (args.version) return console.log(VERSION);
684
780
  if (args.help || !cmd || cmd === "help") return console.log(HELP);
685
- const cmds = { deploy, login, list, ls: list, versions, rollback, db, domains, domain: domains, agent, whoami, logout };
781
+ const cmds = { deploy, login, list, ls: list, versions, rollback, db, domains, domain: domains, stats, lock, unlock, open, usage, agent, whoami, logout };
686
782
  if (!cmds[cmd]) fail(`모르는 명령입니다: ${cmd}\n\n${HELP}`);
687
783
  await cmds[cmd](args);
688
784
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chiwaa",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "chiwaa.kr 에 사이트를 터미널에서 바로 올리는 도구",
5
5
  "bin": {
6
6
  "chiwaa": "bin/chiwaa.js"