@luutuankiet/gsd-reader 0.2.23 → 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 +53 -0
- 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');
|