pdlab-cli 0.1.1 → 0.1.2
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 +11 -3
- package/dist/index.js +18 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,13 @@ npm install -g pdlab-cli
|
|
|
17
17
|
## 快速开始
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
|
|
20
|
+
pdlab login
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
默认连官方部署 `https://1836.online`,装完直接就能用。
|
|
24
|
+
自建实例才需要指定地址,指定过一次之后会记在配置文件里:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
21
27
|
pdlab login --api-url https://your-1836-instance.example.com
|
|
22
28
|
```
|
|
23
29
|
|
|
@@ -71,8 +77,10 @@ pdlab post list --project-id <项目 id>
|
|
|
71
77
|
{ "apiUrl": "https://your-1836-instance.example.com", "token": "pdlab_…" }
|
|
72
78
|
```
|
|
73
79
|
|
|
74
|
-
API 地址的解析顺序:`--api-url` 参数 > `PDLAB_API_URL` 环境变量 >
|
|
75
|
-
|
|
80
|
+
API 地址的解析顺序:`--api-url` 参数 > `PDLAB_API_URL` 环境变量 > 配置文件 > 默认地址
|
|
81
|
+
(`https://1836.online`)。所有命令都支持 `--api-url`,
|
|
82
|
+
包括 `project` / `post` 这些资源命令。`pdlab config get` 会同时打出配置文件里写了什么、
|
|
83
|
+
以及这次实际会用哪个地址。
|
|
76
84
|
|
|
77
85
|
读命令(`project list` / `get`、`post list` / `get`)会在**已登录时带上凭证**,
|
|
78
86
|
可见范围因此按你的身份走:有审核权限才能 `post list --status pending`,
|
package/dist/index.js
CHANGED
|
@@ -37,6 +37,7 @@ var import_os = require("os");
|
|
|
37
37
|
var import_path = require("path");
|
|
38
38
|
var CONFIG_DIR = process.env.PDLAB_CONFIG_DIR ?? (0, import_path.join)((0, import_os.homedir)(), ".pdlab");
|
|
39
39
|
var CONFIG_FILE = (0, import_path.join)(CONFIG_DIR, "config.json");
|
|
40
|
+
var DEFAULT_API_URL = "https://1836.online";
|
|
40
41
|
function readConfig() {
|
|
41
42
|
if (!(0, import_fs.existsSync)(CONFIG_FILE)) return {};
|
|
42
43
|
try {
|
|
@@ -55,11 +56,7 @@ function updateConfig(patch) {
|
|
|
55
56
|
return next;
|
|
56
57
|
}
|
|
57
58
|
function resolveApiUrl(flagValue) {
|
|
58
|
-
const apiUrl = flagValue ?? process.env.PDLAB_API_URL ?? readConfig().apiUrl;
|
|
59
|
-
if (!apiUrl) {
|
|
60
|
-
console.error("\u672A\u914D\u7F6E API \u5730\u5740\u3002\u8BF7\u5148\u8FD0\u884C `pdlab login` / `pdlab register`\uFF0C\u6216\u8BBE\u7F6E PDLAB_API_URL \u73AF\u5883\u53D8\u91CF\u3002");
|
|
61
|
-
process.exit(1);
|
|
62
|
-
}
|
|
59
|
+
const apiUrl = flagValue ?? process.env.PDLAB_API_URL ?? readConfig().apiUrl ?? DEFAULT_API_URL;
|
|
63
60
|
return apiUrl.replace(/\/+$/, "");
|
|
64
61
|
}
|
|
65
62
|
function optionalToken() {
|
|
@@ -142,7 +139,7 @@ async function pollCliAuth(code, apiUrl) {
|
|
|
142
139
|
|
|
143
140
|
// src/commands/login.ts
|
|
144
141
|
function registerLoginCommand(program2) {
|
|
145
|
-
program2.command("login").description("\u5728\u6D4F\u89C8\u5668\u91CC\u5B8C\u6210\u4E00\u6B21\u6027\u6388\u6743\uFF0C\u767B\u5F55 pdlab CLI\uFF08token \u957F\u671F\u6709\u6548\uFF0C\u76F4\u5230\u88AB\u64A4\u9500\uFF09").option("--api-url <url>", "API \u670D\u52A1\u5668\u5730\u5740\uFF0C\
|
|
142
|
+
program2.command("login").description("\u5728\u6D4F\u89C8\u5668\u91CC\u5B8C\u6210\u4E00\u6B21\u6027\u6388\u6743\uFF0C\u767B\u5F55 pdlab CLI\uFF08token \u957F\u671F\u6709\u6548\uFF0C\u76F4\u5230\u88AB\u64A4\u9500\uFF09").option("--api-url <url>", "API \u670D\u52A1\u5668\u5730\u5740\uFF0C\u9ED8\u8BA4\u662F\u5B98\u65B9\u90E8\u7F72\uFF0C\u81EA\u5EFA\u5B9E\u4F8B\u624D\u9700\u8981\u586B").action(async (opts) => {
|
|
146
143
|
const apiUrl = resolveApiUrl(opts.apiUrl);
|
|
147
144
|
const start = await apiRequest("/api/cli/auth/start", {
|
|
148
145
|
method: "POST",
|
|
@@ -174,7 +171,7 @@ function registerLoginCommand(program2) {
|
|
|
174
171
|
// src/commands/register.ts
|
|
175
172
|
var import_open2 = __toESM(require("open"));
|
|
176
173
|
function registerRegisterCommand(program2) {
|
|
177
|
-
program2.command("register").description("\u5728\u6D4F\u89C8\u5668\u91CC\u5B8C\u6210\u6CE8\u518C\u7533\u8BF7\uFF08\u6CE8\u518C\u540E\u9700\u7BA1\u7406\u5458\u5BA1\u6838\uFF0CCLI \u4E0D\u4F1A\u81EA\u52A8\u767B\u5F55\uFF09").option("--api-url <url>", "API \u670D\u52A1\u5668\u5730\u5740\uFF0C\
|
|
174
|
+
program2.command("register").description("\u5728\u6D4F\u89C8\u5668\u91CC\u5B8C\u6210\u6CE8\u518C\u7533\u8BF7\uFF08\u6CE8\u518C\u540E\u9700\u7BA1\u7406\u5458\u5BA1\u6838\uFF0CCLI \u4E0D\u4F1A\u81EA\u52A8\u767B\u5F55\uFF09").option("--api-url <url>", "API \u670D\u52A1\u5668\u5730\u5740\uFF0C\u9ED8\u8BA4\u662F\u5B98\u65B9\u90E8\u7F72\uFF0C\u81EA\u5EFA\u5B9E\u4F8B\u624D\u9700\u8981\u586B").action(async (opts) => {
|
|
178
175
|
const apiUrl = resolveApiUrl(opts.apiUrl);
|
|
179
176
|
const start = await apiRequest("/api/cli/auth/start", {
|
|
180
177
|
method: "POST",
|
|
@@ -227,8 +224,19 @@ function registerWhoamiCommand(program2) {
|
|
|
227
224
|
function registerConfigCommand(program2) {
|
|
228
225
|
const config = program2.command("config").description("\u67E5\u770B/\u4FEE\u6539\u672C\u5730\u914D\u7F6E\uFF08~/.pdlab/config.json\uFF09");
|
|
229
226
|
config.command("get").description("\u6253\u5370\u5F53\u524D\u914D\u7F6E").action(() => {
|
|
230
|
-
const { token,
|
|
231
|
-
console.log(
|
|
227
|
+
const { token, apiUrl } = readConfig();
|
|
228
|
+
console.log(
|
|
229
|
+
JSON.stringify(
|
|
230
|
+
{
|
|
231
|
+
apiUrl,
|
|
232
|
+
token: token ? "***" : void 0,
|
|
233
|
+
effectiveApiUrl: resolveApiUrl(),
|
|
234
|
+
defaultApiUrl: DEFAULT_API_URL
|
|
235
|
+
},
|
|
236
|
+
null,
|
|
237
|
+
2
|
|
238
|
+
)
|
|
239
|
+
);
|
|
232
240
|
});
|
|
233
241
|
config.command("set <key> <value>").description("\u8BBE\u7F6E\u4E00\u9879\u914D\u7F6E\uFF0C\u76EE\u524D\u652F\u6301\uFF1Aapi-url").action((key, value) => {
|
|
234
242
|
if (key !== "api-url") {
|
|
@@ -335,7 +343,7 @@ function handleCommandError(error, examples) {
|
|
|
335
343
|
|
|
336
344
|
// src/commands/options.ts
|
|
337
345
|
function withApiUrl(cmd) {
|
|
338
|
-
return cmd.option("--api-url <url>", "API \u670D\u52A1\u5668\u5730\u5740\uFF0C\u8986\u76D6 PDLAB_API_URL
|
|
346
|
+
return cmd.option("--api-url <url>", "API \u670D\u52A1\u5668\u5730\u5740\uFF0C\u8986\u76D6 PDLAB_API_URL\u3001\u914D\u7F6E\u6587\u4EF6\u4E0E\u9ED8\u8BA4\u5730\u5740");
|
|
339
347
|
}
|
|
340
348
|
|
|
341
349
|
// src/commands/project.ts
|