okai 0.0.13 → 0.0.15
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 +57 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -322,9 +322,7 @@ Options:
|
|
322
322
|
process.exit(0);
|
323
323
|
}
|
324
324
|
if (command.type == "accept") {
|
325
|
-
|
326
|
-
url.searchParams.append('add', command.accept);
|
327
|
-
fetch(url);
|
325
|
+
await acceptGist(command, command.accept);
|
328
326
|
process.exit(0);
|
329
327
|
}
|
330
328
|
if (command.type === 'prompt') {
|
@@ -350,6 +348,19 @@ Options:
|
|
350
348
|
process.exit(1);
|
351
349
|
}
|
352
350
|
}
|
351
|
+
async function acceptGist(command, id) {
|
352
|
+
try {
|
353
|
+
const url = new URL(`/gist/${id}/accept`, command.baseUrl);
|
354
|
+
const r = await fetch(url, {
|
355
|
+
method: 'POST',
|
356
|
+
});
|
357
|
+
const res = await r.text();
|
358
|
+
}
|
359
|
+
catch (err) {
|
360
|
+
if (command.verbose)
|
361
|
+
console.error(err);
|
362
|
+
}
|
363
|
+
}
|
353
364
|
async function fetchGistFiles(command) {
|
354
365
|
const url = new URL('/models/gist', command.baseUrl);
|
355
366
|
if (command.cached) {
|
@@ -399,6 +410,7 @@ function convertToProjectGist(info, gist) {
|
|
399
410
|
content,
|
400
411
|
type,
|
401
412
|
size,
|
413
|
+
raw_url: fullPath,
|
402
414
|
};
|
403
415
|
}
|
404
416
|
else if (writeFileName.startsWith('MyApp/Migrations/') && info.migrationsDir) {
|
@@ -409,6 +421,7 @@ function convertToProjectGist(info, gist) {
|
|
409
421
|
content,
|
410
422
|
type,
|
411
423
|
size,
|
424
|
+
raw_url: fullPath,
|
412
425
|
});
|
413
426
|
}
|
414
427
|
else {
|
@@ -420,6 +433,7 @@ function convertToProjectGist(info, gist) {
|
|
420
433
|
content,
|
421
434
|
type,
|
422
435
|
size,
|
436
|
+
raw_url: fullPath,
|
423
437
|
});
|
424
438
|
}
|
425
439
|
}
|
@@ -510,8 +524,34 @@ async function createGistPreview(title, gist) {
|
|
510
524
|
screen.render();
|
511
525
|
}
|
512
526
|
});
|
527
|
+
fileList.on('keypress', (ch, key) => {
|
528
|
+
const boxHeight = preview.height;
|
529
|
+
const currentScroll = preview.getScroll();
|
530
|
+
const contentHeight = preview.getLines().length;
|
531
|
+
// Calculate scroll amount (half the box height)
|
532
|
+
const scrollAmount = Math.floor(boxHeight / 2);
|
533
|
+
// Page Up handler
|
534
|
+
if (key.name === 'pageup') {
|
535
|
+
// Calculate new scroll position, ensuring it doesn't go below 0
|
536
|
+
const newScrollPosition = Math.max(0, currentScroll - scrollAmount);
|
537
|
+
preview.setScroll(newScrollPosition);
|
538
|
+
screen.render();
|
539
|
+
}
|
540
|
+
// Page Down handler
|
541
|
+
if (key.name === 'pagedown') {
|
542
|
+
// Calculate max scroll position to prevent scrolling beyond content
|
543
|
+
const maxScroll = Math.max(0, contentHeight - boxHeight);
|
544
|
+
// Calculate new scroll position, ensuring it doesn't exceed max
|
545
|
+
const newScrollPosition = Math.min(maxScroll, currentScroll + scrollAmount);
|
546
|
+
preview.setScroll(newScrollPosition);
|
547
|
+
screen.render();
|
548
|
+
}
|
549
|
+
});
|
513
550
|
// Handle key events
|
514
551
|
screen.key(['q', 'C-c'], () => process.exit(0));
|
552
|
+
// screen.on('keypress', (ch, key) => {
|
553
|
+
// console.log('keypress', ch, key)
|
554
|
+
// })
|
515
555
|
// Focus on file list
|
516
556
|
fileList.focus();
|
517
557
|
// Render screen
|
@@ -520,7 +560,13 @@ async function createGistPreview(title, gist) {
|
|
520
560
|
function chooseFile(ctx, info, gist) {
|
521
561
|
const { screen, titleBar, fileList, preview, statusBar, result } = ctx;
|
522
562
|
const file = gist.files[result.selectedFile];
|
563
|
+
screen.destroy();
|
523
564
|
console.clear();
|
565
|
+
let acceptTask = null;
|
566
|
+
if (file.raw_url) {
|
567
|
+
const acceptUrl = path.join(file.raw_url, 'accept');
|
568
|
+
acceptTask = fetch(acceptUrl, { method: 'POST' });
|
569
|
+
}
|
524
570
|
const tsd = file.content;
|
525
571
|
const tsdAst = toAst(tsd);
|
526
572
|
const csAst = toMetadataTypes(tsdAst);
|
@@ -567,7 +613,14 @@ function chooseFile(ctx, info, gist) {
|
|
567
613
|
const script = path.basename(process.argv[1]);
|
568
614
|
console.log(`\nTo regenerate classes, update '${tsdFileName}' then run:`);
|
569
615
|
console.log(`$ ${script} ${tsdFileName}\n\n`);
|
570
|
-
|
616
|
+
if (acceptTask) {
|
617
|
+
acceptTask.then(r => {
|
618
|
+
process.exit(0);
|
619
|
+
});
|
620
|
+
}
|
621
|
+
else {
|
622
|
+
process.exit(0);
|
623
|
+
}
|
571
624
|
}
|
572
625
|
function writeFile(info, filename, content) {
|
573
626
|
let fullPath = path.join(process.cwd(), filename);
|