specdown-cli 0.1.3 → 0.1.5
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/dist/index.js +39 -59
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,22 +5,8 @@ import { Command } from "commander";
|
|
|
5
5
|
|
|
6
6
|
// src/lib/update-check.ts
|
|
7
7
|
import chalk from "chalk";
|
|
8
|
-
import { createRequire } from "module";
|
|
9
|
-
import { fileURLToPath } from "url";
|
|
10
|
-
import { dirname, join } from "path";
|
|
11
8
|
var PKG_NAME = "specdown-cli";
|
|
12
9
|
var REGISTRY_URL = `https://registry.npmjs.org/${PKG_NAME}/latest`;
|
|
13
|
-
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
14
|
-
function getCurrentVersion() {
|
|
15
|
-
try {
|
|
16
|
-
const require2 = createRequire(import.meta.url);
|
|
17
|
-
const pkgPath = join(dirname(fileURLToPath(import.meta.url)), "../../package.json");
|
|
18
|
-
const pkg = require2(pkgPath);
|
|
19
|
-
return pkg.version;
|
|
20
|
-
} catch {
|
|
21
|
-
return "0.0.0";
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
10
|
function compareVersions(current, latest) {
|
|
25
11
|
const parse = (v) => v.split(".").map(Number);
|
|
26
12
|
const [cMaj, cMin, cPat] = parse(current);
|
|
@@ -29,9 +15,8 @@ function compareVersions(current, latest) {
|
|
|
29
15
|
if (lMin !== cMin) return lMin > cMin;
|
|
30
16
|
return lPat > cPat;
|
|
31
17
|
}
|
|
32
|
-
function checkForUpdate() {
|
|
18
|
+
function checkForUpdate(current) {
|
|
33
19
|
if (process.env.npm_lifecycle_event === "npx" || process.env.CI) return;
|
|
34
|
-
const current = getCurrentVersion();
|
|
35
20
|
setImmediate(async () => {
|
|
36
21
|
try {
|
|
37
22
|
const controller = new AbortController();
|
|
@@ -53,19 +38,25 @@ function checkForUpdate() {
|
|
|
53
38
|
});
|
|
54
39
|
}
|
|
55
40
|
|
|
41
|
+
// src/index.ts
|
|
42
|
+
import { createRequire } from "module";
|
|
43
|
+
import { fileURLToPath } from "url";
|
|
44
|
+
import { dirname as dirname2, join as join2 } from "path";
|
|
45
|
+
|
|
56
46
|
// src/commands/login.ts
|
|
57
47
|
import http from "http";
|
|
58
48
|
import { exec } from "child_process";
|
|
59
49
|
import crypto from "crypto";
|
|
50
|
+
import { URL } from "url";
|
|
60
51
|
import chalk2 from "chalk";
|
|
61
52
|
import ora from "ora";
|
|
62
53
|
|
|
63
54
|
// src/lib/config.ts
|
|
64
55
|
import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
|
|
65
56
|
import { homedir } from "os";
|
|
66
|
-
import { join
|
|
67
|
-
var CONFIG_DIR =
|
|
68
|
-
var CONFIG_FILE =
|
|
57
|
+
import { join } from "path";
|
|
58
|
+
var CONFIG_DIR = join(homedir(), ".specdown");
|
|
59
|
+
var CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
69
60
|
function readConfig() {
|
|
70
61
|
if (!existsSync(CONFIG_FILE)) return null;
|
|
71
62
|
try {
|
|
@@ -116,47 +107,34 @@ async function login() {
|
|
|
116
107
|
const authUrl = `${APP_URL}/cli/auth?port=${port}&state=${state}`;
|
|
117
108
|
return new Promise((resolve, reject) => {
|
|
118
109
|
const server = http.createServer((req, res) => {
|
|
119
|
-
|
|
120
|
-
res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
|
|
121
|
-
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
122
|
-
if (req.method === "OPTIONS") {
|
|
123
|
-
res.writeHead(204);
|
|
124
|
-
res.end();
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
if (req.method !== "POST") {
|
|
110
|
+
if (req.method !== "GET") {
|
|
128
111
|
res.writeHead(405);
|
|
129
112
|
res.end();
|
|
130
113
|
return;
|
|
131
114
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (payload.state !== state) {
|
|
140
|
-
res.writeHead(403);
|
|
141
|
-
res.end(JSON.stringify({ error: "Invalid state" }));
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
writeConfig({
|
|
145
|
-
access_token: payload.access_token,
|
|
146
|
-
refresh_token: payload.refresh_token,
|
|
147
|
-
user_email: payload.email,
|
|
148
|
-
user_id: payload.user_id
|
|
149
|
-
});
|
|
150
|
-
res.writeHead(200);
|
|
151
|
-
res.end(JSON.stringify({ ok: true }));
|
|
152
|
-
spinner.succeed(chalk2.green(`Logged in as ${chalk2.bold(payload.email)}`));
|
|
153
|
-
server.close();
|
|
154
|
-
resolve();
|
|
155
|
-
} catch {
|
|
156
|
-
res.writeHead(400);
|
|
157
|
-
res.end(JSON.stringify({ error: "Bad request" }));
|
|
115
|
+
try {
|
|
116
|
+
const parsed = new URL(req.url ?? "/", `http://127.0.0.1:${port}`);
|
|
117
|
+
const params = parsed.searchParams;
|
|
118
|
+
if (params.get("state") !== state) {
|
|
119
|
+
res.writeHead(403, { "Content-Type": "text/plain" });
|
|
120
|
+
res.end("Invalid state");
|
|
121
|
+
return;
|
|
158
122
|
}
|
|
159
|
-
|
|
123
|
+
writeConfig({
|
|
124
|
+
access_token: params.get("access_token") ?? "",
|
|
125
|
+
refresh_token: params.get("refresh_token") ?? "",
|
|
126
|
+
user_email: params.get("email") ?? "",
|
|
127
|
+
user_id: params.get("user_id") ?? ""
|
|
128
|
+
});
|
|
129
|
+
res.writeHead(302, { Location: `${APP_URL}/cli/auth/success` });
|
|
130
|
+
res.end();
|
|
131
|
+
spinner.succeed(chalk2.green(`Logged in as ${chalk2.bold(params.get("email"))}`));
|
|
132
|
+
server.close();
|
|
133
|
+
resolve();
|
|
134
|
+
} catch {
|
|
135
|
+
res.writeHead(400);
|
|
136
|
+
res.end("Bad request");
|
|
137
|
+
}
|
|
160
138
|
});
|
|
161
139
|
const spinner = ora();
|
|
162
140
|
server.listen(port, "127.0.0.1", () => {
|
|
@@ -491,7 +469,7 @@ async function push(filePath, docPath) {
|
|
|
491
469
|
|
|
492
470
|
// src/commands/pull.ts
|
|
493
471
|
import { writeFileSync as writeFileSync2, mkdirSync as mkdirSync2 } from "fs";
|
|
494
|
-
import { dirname
|
|
472
|
+
import { dirname } from "path";
|
|
495
473
|
import chalk11 from "chalk";
|
|
496
474
|
import ora8 from "ora";
|
|
497
475
|
function normalizePath4(p) {
|
|
@@ -510,7 +488,7 @@ async function pull(docPath, outFile) {
|
|
|
510
488
|
}
|
|
511
489
|
const content = data.content ?? "";
|
|
512
490
|
if (outFile) {
|
|
513
|
-
const dir =
|
|
491
|
+
const dir = dirname(outFile);
|
|
514
492
|
if (dir !== ".") mkdirSync2(dir, { recursive: true });
|
|
515
493
|
writeFileSync2(outFile, content, "utf-8");
|
|
516
494
|
spinner.succeed(chalk11.green(`Saved to ${outFile}`));
|
|
@@ -658,9 +636,11 @@ async function search(query, opts) {
|
|
|
658
636
|
}
|
|
659
637
|
|
|
660
638
|
// src/index.ts
|
|
661
|
-
|
|
639
|
+
var _require = createRequire(import.meta.url);
|
|
640
|
+
var _pkg = _require(join2(dirname2(fileURLToPath(import.meta.url)), "../package.json"));
|
|
641
|
+
checkForUpdate(_pkg.version);
|
|
662
642
|
var program = new Command();
|
|
663
|
-
program.name("specdown").description("Manage SpecDown docs from your terminal").version(
|
|
643
|
+
program.name("specdown").description("Manage SpecDown docs from your terminal").version(_pkg.version);
|
|
664
644
|
program.command("login").description("Log in to SpecDown").action(login);
|
|
665
645
|
program.command("logout").description("Log out").action(logout);
|
|
666
646
|
program.command("whoami").description("Show current user and active project").action(whoami);
|