@luutuankiet/gsd-reader 0.2.23 → 0.2.25
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 +57 -3
- package/package.json +1 -1
package/cli.cjs
CHANGED
|
@@ -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');
|
|
@@ -120,7 +173,8 @@ async function commandDump() {
|
|
|
120
173
|
const worklogBase64 = Buffer.from(worklogContent, 'utf-8').toString('base64');
|
|
121
174
|
const projectBase64 = Buffer.from(projectContent, 'utf-8').toString('base64');
|
|
122
175
|
const architectureBase64 = Buffer.from(architectureContent, 'utf-8').toString('base64');
|
|
123
|
-
|
|
176
|
+
// Absolute path from origin machine — persists when static dump is served remotely
|
|
177
|
+
const dumpBasePath = path.dirname(resolvedWorklog);
|
|
124
178
|
const injectScript = `<script>window.__WORKLOG_CONTENT_B64__ = "${worklogBase64}";window.__PROJECT_CONTENT_B64__ = "${projectBase64}";window.__ARCHITECTURE_CONTENT_B64__ = "${architectureBase64}";window.__GSD_BASE_PATH__ = "${dumpBasePath}";</script>`;
|
|
125
179
|
indexHtml = indexHtml.replace('</head>', `${injectScript}\n</head>`);
|
|
126
180
|
fs.writeFileSync(indexPath, indexHtml);
|
|
@@ -284,8 +338,8 @@ function commandServe() {
|
|
|
284
338
|
const WORKLOG = positionalArgs[0] || './gsd-lite/WORK.md';
|
|
285
339
|
const WORKLOG_PATH = path.resolve(WORKLOG);
|
|
286
340
|
const ARTIFACT_DIR = path.dirname(WORKLOG_PATH);
|
|
287
|
-
//
|
|
288
|
-
const BASE_PATH = path.dirname(
|
|
341
|
+
// Absolute path to gsd-lite directory on the origin machine
|
|
342
|
+
const BASE_PATH = path.dirname(WORKLOG_PATH);
|
|
289
343
|
const PROJECT_PATH = path.join(ARTIFACT_DIR, 'PROJECT.md');
|
|
290
344
|
const ARCHITECTURE_PATH = path.join(ARTIFACT_DIR, 'ARCHITECTURE.md');
|
|
291
345
|
|