ShtukbaseStandard
archivo del paquete→ .shtukbase/packages/tui/actions/open.ts

actions/open.ts

24 líneas, 1.1 KB.

El archivo tal como está en el paquete: el código y sus comentarios no se traducen.

  1. // shtuk run tui open [address]: opens the terminal front on this project (and on a page, when an address is given).
  2. // Without a terminal it says so in one line and exits 2 instead of hanging.
  3. import { spawnSync } from 'node:child_process';
  4. import { needBin, reachNode, splitArgs } from '../lib/tui.ts';
  5. import { address } from './shot.ts';
  6. const root = process.cwd();
  7. const { free, ownNode } = splitArgs(process.argv.slice(2));
  8. const addr = address(free[0]);
  9. if (!process.stdin.isTTY || !process.stdout.isTTY) {
  10. console.log(`tui open: a terminal is needed (input or output is not a terminal now); one screen without a terminal: shtuk run tui shot screen${addr ? ' ' + addr : ''}`);
  11. process.exit(2);
  12. }
  13. const bin = needBin(root);
  14. const node = await reachNode(bin, root, { ownNode });
  15. if (typeof node === 'string') {
  16. console.log(`tui: ${node}`);
  17. process.exit(2);
  18. }
  19. const args = [...bin.prefix, ...(bin.prefix.length ? [] : ['browse']), '--space', root];
  20. if (addr) args.push(addr);
  21. const r = spawnSync(bin.path, args, { cwd: root, stdio: 'inherit', env: { ...process.env, ...node.env } });
  22. node.stop();
  23. process.exit(r.status ?? 1);