@demogo-cn/cli 0.2.5 → 0.2.7

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
@@ -6,7 +6,7 @@ DemoGo CLI lets AI coding tools publish a local project to DemoGo and return a s
6
6
 
7
7
  Current MVP delivery uses a local install package.
8
8
 
9
- 1. Unzip `demogo-cli-v0.2.5.zip`.
9
+ 1. Unzip `demogo-cli-v0.2.7.zip`.
10
10
  2. Open a terminal in the extracted folder.
11
11
  3. Run:
12
12
 
@@ -32,6 +32,16 @@ Reset it only when it is lost, invalid, or exposed in chat/logs.
32
32
 
33
33
  ## Deploy
34
34
 
35
+ Run the command from a clean project folder. Do not run it directly from Desktop, Downloads, Documents, or the user home folder.
36
+
37
+ Use without installing:
38
+
39
+ ```bash
40
+ npx --yes @demogo-cn/cli deploy
41
+ ```
42
+
43
+ Or use the installed command:
44
+
35
45
  ```bash
36
46
  demogo deploy
37
47
  ```
@@ -42,16 +52,18 @@ For a specific folder or project name:
42
52
  demogo deploy --dir <project-folder> --name <project-name>
43
53
  ```
44
54
 
55
+ If you only have one HTML file, put that file in a clean folder and publish that folder. You do not need to rename the file to `index.html`.
56
+
45
57
  ## Current Boundary
46
58
 
47
59
  DemoGo supports static pages, single HTML pages, built frontend output, and frontend source projects that can build static output. It does not host long-running backend services, databases, payment systems, login systems, WebSocket services, or SSR runtimes.
48
60
 
49
61
  ## npm / npx Status
50
62
 
51
- After npm publication, AI coding tools can run:
63
+ AI coding tools can run:
52
64
 
53
65
  ```bash
54
- npx @demogo-cn/cli deploy
66
+ npx --yes @demogo-cn/cli deploy
55
67
  ```
56
68
 
57
69
  Or install it globally:
package/bin/demogo.js CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  MAX_BYTES,
8
8
  VERSION,
9
9
  assertDirectory,
10
+ assertSafeProjectDirectory,
10
11
  collectFiles,
11
12
  createProjectArchive,
12
13
  deployArchive,
@@ -121,6 +122,7 @@ async function handleDeploy(args) {
121
122
  }
122
123
 
123
124
  await assertDirectory(projectDir);
125
+ assertSafeProjectDirectory(projectDir);
124
126
  const fileList = await collectFiles(projectDir);
125
127
  if (!fileList.length) fail("当前目录没有可发布文件。");
126
128
 
@@ -132,7 +134,10 @@ async function handleDeploy(args) {
132
134
  await createProjectArchive(projectDir, fileList, archivePath);
133
135
  const archiveStats = await stat(archivePath);
134
136
  if (archiveStats.size > MAX_BYTES) {
135
- fail(`打包后文件超过 50MB,请减少大文件后重试。当前约 ${formatBytes(archiveStats.size)}。`);
137
+ fail([
138
+ `打包后文件超过 50MB,当前约 ${formatBytes(archiveStats.size)}。`,
139
+ "你可能在错误目录执行了发布。请切换到真正的项目目录,或使用 --dir 指定干净项目文件夹。"
140
+ ].join("\n"));
136
141
  }
137
142
  console.log(`项目包已生成:${formatBytes(archiveStats.size)}`);
138
143
  console.log("DemoGo 正在生成试用链接...");
package/lib/core.js CHANGED
@@ -2,9 +2,19 @@
2
2
  import { mkdir, readdir, readFile, stat, writeFile } from "node:fs/promises";
3
3
  import path from "node:path";
4
4
 
5
- export const VERSION = "0.2.5";
6
- export const MAX_FILES = 800;
7
- export const MAX_BYTES = 50 * 1024 * 1024;
5
+ export const VERSION = "0.2.7";
6
+ export const MAX_FILES = 800;
7
+ export const MAX_BYTES = 50 * 1024 * 1024;
8
+
9
+ export const unsafeProjectDirectoryNames = new Set([
10
+ "desktop",
11
+ "downloads",
12
+ "documents",
13
+ "onedrive",
14
+ "桌面",
15
+ "下载",
16
+ "文档"
17
+ ]);
8
18
 
9
19
  const EXCLUDED_DIRS = new Set([
10
20
  ".git",
@@ -42,14 +52,36 @@ const SENSITIVE_EXTENSIONS = [
42
52
  ".cer"
43
53
  ];
44
54
 
45
- export async function assertDirectory(dir) {
46
- try {
47
- const stats = await stat(dir);
48
- if (!stats.isDirectory()) throw new Error(`不是项目目录:${dir}`);
49
- } catch {
50
- throw new Error(`找不到项目目录:${dir}`);
51
- }
52
- }
55
+ export async function assertDirectory(dir) {
56
+ try {
57
+ const stats = await stat(dir);
58
+ if (!stats.isDirectory()) throw new Error(`不是项目目录:${dir}`);
59
+ } catch {
60
+ throw new Error(`找不到项目目录:${dir}`);
61
+ }
62
+ }
63
+
64
+ export function assertSafeProjectDirectory(dir) {
65
+ const resolved = path.resolve(dir);
66
+ const home = path.resolve(process.env.USERPROFILE || process.env.HOME || "");
67
+ const baseName = path.basename(resolved).toLowerCase();
68
+
69
+ if (home && resolved === home) {
70
+ throw new Error([
71
+ "当前目录像是用户主目录,不适合直接发布。",
72
+ "请新建一个干净文件夹,只放要发布的项目文件,然后在该文件夹里运行发布命令。",
73
+ "也可以使用:npx --yes @demogo-cn/cli deploy --dir <项目目录>"
74
+ ].join("\n"));
75
+ }
76
+
77
+ if (unsafeProjectDirectoryNames.has(baseName)) {
78
+ throw new Error([
79
+ `当前目录是 ${path.basename(resolved)},通常会包含很多无关文件,不适合直接发布。`,
80
+ "请新建一个干净文件夹,只放要发布的项目文件;如果只有一个 HTML 文件,也可以让 AI 先创建临时目录再发布。",
81
+ "也可以使用:npx --yes @demogo-cn/cli deploy --dir <项目目录>"
82
+ ].join("\n"));
83
+ }
84
+ }
53
85
 
54
86
  export async function collectFiles(rootDir) {
55
87
  const files = [];
@@ -69,15 +101,24 @@ export async function collectFiles(rootDir) {
69
101
  if (!entry.isFile()) continue;
70
102
  const stats = await stat(fullPath);
71
103
  totalBytes += stats.size;
72
- if (files.length >= MAX_FILES) throw new Error(`项目文件超过 ${MAX_FILES} 个,请精简后再发布。`);
73
- if (totalBytes > MAX_BYTES) throw new Error("项目文件超过 50MB,请删除大文件后再发布。");
104
+ if (files.length >= MAX_FILES) throw new Error(projectTooLargeMessage(`项目文件超过 ${MAX_FILES} 个。`));
105
+ if (totalBytes > MAX_BYTES) throw new Error(projectTooLargeMessage("项目文件超过 50MB"));
74
106
  files.push({ fullPath, relativePath, size: stats.size });
75
107
  }
76
108
  }
77
109
 
78
- await walk(rootDir);
79
- return files;
80
- }
110
+ await walk(rootDir);
111
+ return files;
112
+ }
113
+
114
+ export function projectTooLargeMessage(reason) {
115
+ return [
116
+ `${reason}你可能在桌面、下载、文档或用户根目录执行了发布。`,
117
+ "请切换到真正的项目目录,或新建一个干净文件夹,只放要发布的项目文件。",
118
+ "如果只有一个 HTML 文件,不需要改名为 index.html,可以把它单独放进干净目录后发布。",
119
+ "也可以使用:npx --yes @demogo-cn/cli deploy --dir <项目目录>"
120
+ ].join("\n");
121
+ }
81
122
 
82
123
  export function summarizeProject(projectDir, files) {
83
124
  const totalBytes = files.reduce((sum, file) => sum + file.size, 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@demogo-cn/cli",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "DemoGo CLI for generating shareable trial links from AI-built pages.",
5
5
  "type": "module",
6
6
  "bin": {