chiwaa 0.1.5 → 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.
package/README.md CHANGED
@@ -21,6 +21,9 @@ npx chiwaa deploy
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
23
  | `chiwaa stats` | 방문자 통계(오늘·최근 7일·많이 본 페이지·들어온 곳) |
24
+ | `chiwaa deploy --preview` | 운영 주소는 두고 `이름--preview.chiwaa.com` 에 미리보기 |
25
+ | `chiwaa lock` / `unlock` | 사이트 비밀번호 잠금(공개 전 나만 보기) |
26
+ | `chiwaa open` · `usage` | 관리 화면 열기 · 이번 달 사용량 |
24
27
  | `chiwaa agent` | AI 도구용 안내(AGENTS.md·CLAUDE.md) 만들기 — 처음 deploy 때 자동 |
25
28
  | `chiwaa whoami` / `logout` | 계정 확인 / 로그아웃 |
26
29
 
package/bin/chiwaa.js CHANGED
@@ -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
  // ---------- 그 밖 ----------
@@ -660,6 +662,68 @@ async function stats(args) {
660
662
  if (!s.total.views) console.log(c.dim("\n 아직 집계된 방문이 없습니다."));
661
663
  }
662
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
+
663
727
  async function whoami() {
664
728
  const r = await api("GET", "/api/v1/me");
665
729
  if (r.status !== 200) fail(r.data.error || "로그인 정보를 받지 못했습니다.");
@@ -679,6 +743,7 @@ const HELP = `chiwaa ${VERSION} — chiwaa.kr 에 사이트를 바로 올립니
679
743
  --name <이름> 사이트 이름(<이름>.chiwaa.com)
680
744
  --dir <폴더> 빌드 결과 폴더를 직접 지정
681
745
  --no-build 빌드하지 않고 그대로 올림
746
+ --preview 운영 주소는 두고 이름--preview.chiwaa.com 에 미리보기로 올림
682
747
  -y, --yes 묻지 않고 진행(AI 도구·자동화용)
683
748
  chiwaa login 브라우저로 로그인 (--token <토큰> 도 가능)
684
749
  chiwaa list 내 사이트 목록
@@ -697,6 +762,9 @@ const HELP = `chiwaa ${VERSION} — chiwaa.kr 에 사이트를 바로 올립니
697
762
  chiwaa domains add <도메인> 도메인 붙이기(x-y.net 도메인은 바로, 다른 곳 도메인은 넣을 DNS 레코드 안내)
698
763
  chiwaa domains check 연결됐는지 확인 · domains remove -y 로 연결 끊기
699
764
  chiwaa stats 방문자 통계(오늘·최근 7일, 많이 본 페이지, 들어온 곳) --days 30
765
+ chiwaa lock / unlock 사이트 비밀번호 잠금(아이디 chiwaa) / 풀기 — 공개 전 나만 보기
766
+ chiwaa open 관리 화면 열기 (--site 는 사이트 열기)
767
+ chiwaa usage 이번 달 전송량·한도, 요금제
700
768
  chiwaa agent AI 도구용 안내(AGENTS.md·CLAUDE.md)를 만들거나 새로 고침
701
769
  (처음 deploy 할 때 자동으로 만든다)
702
770
  chiwaa whoami 로그인한 계정
@@ -710,7 +778,7 @@ async function main() {
710
778
  const cmd = args._[0];
711
779
  if (args.version) return console.log(VERSION);
712
780
  if (args.help || !cmd || cmd === "help") return console.log(HELP);
713
- const cmds = { deploy, login, list, ls: list, versions, rollback, db, domains, domain: domains, stats, 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 };
714
782
  if (!cmds[cmd]) fail(`모르는 명령입니다: ${cmd}\n\n${HELP}`);
715
783
  await cmds[cmd](args);
716
784
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chiwaa",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "chiwaa.kr 에 사이트를 터미널에서 바로 올리는 도구",
5
5
  "bin": {
6
6
  "chiwaa": "bin/chiwaa.js"