okai 0.0.12 → 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 +38 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -57,7 +57,7 @@ function parseArgs(...args) {
57
57
  break;
58
58
  }
59
59
  }
60
- else if (ret.type === "help" && ["help", "info", "init", "ls", "rm", "update"].includes(arg)) {
60
+ else if (ret.type === "help" && ["help", "info", "init", "ls", "rm", "update", "accept"].includes(arg)) {
61
61
  if (arg == "help")
62
62
  ret.type = "help";
63
63
  else if (arg == "info")
@@ -82,6 +82,10 @@ function parseArgs(...args) {
82
82
  ret.type = "list";
83
83
  ret.list = args[++i];
84
84
  }
85
+ else if (arg == "accept") {
86
+ ret.type = "accept";
87
+ ret.accept = args[++i];
88
+ }
85
89
  }
86
90
  else if (arg.endsWith('.d.ts')) {
87
91
  if (ret.type == "help")
@@ -317,6 +321,10 @@ Options:
317
321
  console.log(`Removed: ${tsdPath}`);
318
322
  process.exit(0);
319
323
  }
324
+ if (command.type == "accept") {
325
+ await acceptGist(command, command.accept);
326
+ process.exit(0);
327
+ }
320
328
  if (command.type === 'prompt') {
321
329
  try {
322
330
  if (!info.serviceModelDir)
@@ -340,6 +348,19 @@ Options:
340
348
  process.exit(1);
341
349
  }
342
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
+ }
343
364
  async function fetchGistFiles(command) {
344
365
  const url = new URL('/models/gist', command.baseUrl);
345
366
  if (command.cached) {
@@ -389,6 +410,7 @@ function convertToProjectGist(info, gist) {
389
410
  content,
390
411
  type,
391
412
  size,
413
+ raw_url: fullPath,
392
414
  };
393
415
  }
394
416
  else if (writeFileName.startsWith('MyApp/Migrations/') && info.migrationsDir) {
@@ -399,6 +421,7 @@ function convertToProjectGist(info, gist) {
399
421
  content,
400
422
  type,
401
423
  size,
424
+ raw_url: fullPath,
402
425
  });
403
426
  }
404
427
  else {
@@ -410,6 +433,7 @@ function convertToProjectGist(info, gist) {
410
433
  content,
411
434
  type,
412
435
  size,
436
+ raw_url: fullPath,
413
437
  });
414
438
  }
415
439
  }
@@ -511,6 +535,11 @@ function chooseFile(ctx, info, gist) {
511
535
  const { screen, titleBar, fileList, preview, statusBar, result } = ctx;
512
536
  const file = gist.files[result.selectedFile];
513
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
+ }
514
543
  const tsd = file.content;
515
544
  const tsdAst = toAst(tsd);
516
545
  const csAst = toMetadataTypes(tsdAst);
@@ -557,7 +586,14 @@ function chooseFile(ctx, info, gist) {
557
586
  const script = path.basename(process.argv[1]);
558
587
  console.log(`\nTo regenerate classes, update '${tsdFileName}' then run:`);
559
588
  console.log(`$ ${script} ${tsdFileName}\n\n`);
560
- process.exit(0);
589
+ if (acceptTask) {
590
+ acceptTask.then(r => {
591
+ process.exit(0);
592
+ });
593
+ }
594
+ else {
595
+ process.exit(0);
596
+ }
561
597
  }
562
598
  function writeFile(info, filename, content) {
563
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.12",
4
+ "version": "0.0.14",
5
5
  "bin": "./dist/okai.js",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",