okai 0.0.13 → 0.0.14

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.
Files changed (2) hide show
  1. package/dist/index.js +30 -4
  2. 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
- const url = new URL('/models/accept', command.baseUrl);
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
  }
@@ -521,6 +535,11 @@ function chooseFile(ctx, info, gist) {
521
535
  const { screen, titleBar, fileList, preview, statusBar, result } = ctx;
522
536
  const file = gist.files[result.selectedFile];
523
537
  console.clear();
538
+ let acceptTask = null;
539
+ if (file.raw_url) {
540
+ const acceptUrl = path.join(file.raw_url, 'accept');
541
+ acceptTask = fetch(acceptUrl, { method: 'POST' });
542
+ }
524
543
  const tsd = file.content;
525
544
  const tsdAst = toAst(tsd);
526
545
  const csAst = toMetadataTypes(tsdAst);
@@ -567,7 +586,14 @@ function chooseFile(ctx, info, gist) {
567
586
  const script = path.basename(process.argv[1]);
568
587
  console.log(`\nTo regenerate classes, update '${tsdFileName}' then run:`);
569
588
  console.log(`$ ${script} ${tsdFileName}\n\n`);
570
- process.exit(0);
589
+ if (acceptTask) {
590
+ acceptTask.then(r => {
591
+ process.exit(0);
592
+ });
593
+ }
594
+ else {
595
+ process.exit(0);
596
+ }
571
597
  }
572
598
  function writeFile(info, filename, content) {
573
599
  let fullPath = path.join(process.cwd(), filename);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "okai",
3
3
  "type": "module",
4
- "version": "0.0.13",
4
+ "version": "0.0.14",
5
5
  "bin": "./dist/okai.js",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",