@luutuankiet/gsd-reader 0.2.22 → 0.2.24
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/cli.cjs +58 -5
- package/package.json +1 -1
package/cli.cjs
CHANGED
|
@@ -56,8 +56,8 @@ const positionalArgs = args.filter(a => !a.startsWith('--') && a !== command);
|
|
|
56
56
|
|
|
57
57
|
async function commandDump() {
|
|
58
58
|
const worklogPath = positionalArgs[0] || './gsd-lite/WORK.md';
|
|
59
|
-
const remote = getFlag('remote');
|
|
60
|
-
const user = getFlag('user');
|
|
59
|
+
const remote = getFlag('remote') || process.env.GSD_READER_REMOTE;
|
|
60
|
+
const user = getFlag('user') || process.env.GSD_READER_USER;
|
|
61
61
|
|
|
62
62
|
if (!remote) {
|
|
63
63
|
console.error('❌ --remote=URL is required');
|
|
@@ -93,6 +93,59 @@ async function commandDump() {
|
|
|
93
93
|
process.exit(1);
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
// --- Markdown mode (default) ---
|
|
97
|
+
// Sends raw markdown to server; server does the rendering.
|
|
98
|
+
// Use --legacy flag to fall back to tar.gz upload.
|
|
99
|
+
if (!hasFlag('legacy')) {
|
|
100
|
+
console.log('[dump] Reading markdown artifacts...');
|
|
101
|
+
const workContent = fs.readFileSync(resolvedWorklog, 'utf-8');
|
|
102
|
+
const projContent = fs.existsSync(resolvedProject) ? fs.readFileSync(resolvedProject, 'utf-8') : '';
|
|
103
|
+
const archContent = fs.existsSync(resolvedArchitecture) ? fs.readFileSync(resolvedArchitecture, 'utf-8') : '';
|
|
104
|
+
|
|
105
|
+
const payload = JSON.stringify({
|
|
106
|
+
work: workContent,
|
|
107
|
+
project: projContent,
|
|
108
|
+
architecture: archContent,
|
|
109
|
+
base_path: path.basename(path.dirname(resolvedWorklog)),
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Get password
|
|
113
|
+
let password = getFlag('pass') || process.env.GSD_READER_PASS;
|
|
114
|
+
if (!password && user) {
|
|
115
|
+
password = await promptPassword(`Password for ${user}: `);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const payloadBuf = Buffer.from(payload, 'utf-8');
|
|
119
|
+
const sizeKB = (payloadBuf.length / 1024).toFixed(0);
|
|
120
|
+
const uploadUrl = new URL(`/upload-markdown/${projectName}`, remote);
|
|
121
|
+
console.log(`[dump] Uploading ${sizeKB}KB markdown -> ${uploadUrl}`);
|
|
122
|
+
|
|
123
|
+
const uploadOptions = {
|
|
124
|
+
method: 'POST',
|
|
125
|
+
headers: {
|
|
126
|
+
'Content-Type': 'application/json',
|
|
127
|
+
'Content-Length': payloadBuf.length,
|
|
128
|
+
'User-Agent': 'Mozilla/5.0 (compatible; gsd-lite-reader/1.0)',
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
if (user && password) {
|
|
133
|
+
const auth = Buffer.from(`${user}:${password}`).toString('base64');
|
|
134
|
+
uploadOptions.headers['Authorization'] = `Basic ${auth}`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
const response = await httpRequest(uploadUrl, uploadOptions, payloadBuf);
|
|
139
|
+
console.log(`[dump] \u2705 Upload complete: ${response}`);
|
|
140
|
+
console.log(`[dump] View at: ${remote}/${projectName}/`);
|
|
141
|
+
} catch (err) {
|
|
142
|
+
console.error(`[dump] \u274C Upload failed: ${err.message}`);
|
|
143
|
+
process.exit(1);
|
|
144
|
+
}
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// --- Legacy mode (--legacy flag): build static site + tar.gz upload ---
|
|
96
149
|
// Step 1: Build the static site
|
|
97
150
|
console.log('[dump] Building static site...');
|
|
98
151
|
const distDir = path.join(__dirname, 'dist');
|
|
@@ -144,7 +197,7 @@ async function commandDump() {
|
|
|
144
197
|
console.log(`[dump] Archive created: ${(tarStats.size / 1024).toFixed(1)} KB`);
|
|
145
198
|
|
|
146
199
|
// Step 3: Get password
|
|
147
|
-
let password = getFlag('pass');
|
|
200
|
+
let password = getFlag('pass') || process.env.GSD_READER_PASS;
|
|
148
201
|
if (!password && user) {
|
|
149
202
|
password = await promptPassword(`Password for ${user}: `);
|
|
150
203
|
}
|
|
@@ -244,7 +297,7 @@ function promptPassword(prompt) {
|
|
|
244
297
|
|
|
245
298
|
async function httpRequest(url, options, data) {
|
|
246
299
|
const controller = new AbortController();
|
|
247
|
-
const timeout = setTimeout(() => controller.abort(),
|
|
300
|
+
const timeout = setTimeout(() => controller.abort(), 300000); // 5 min (intercontinental uploads)
|
|
248
301
|
|
|
249
302
|
try {
|
|
250
303
|
const res = await fetch(url, {
|
|
@@ -265,7 +318,7 @@ async function httpRequest(url, options, data) {
|
|
|
265
318
|
}
|
|
266
319
|
} catch (err) {
|
|
267
320
|
if (err.name === 'AbortError') {
|
|
268
|
-
throw new Error('Request timed out after
|
|
321
|
+
throw new Error('Request timed out after 300s. Check server/proxy status.');
|
|
269
322
|
}
|
|
270
323
|
throw err;
|
|
271
324
|
} finally {
|