tsc.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env node
  2. const { spawn } = require('child_process')
  3. exports.runTscWatch = () => {
  4. return new Promise((resolve, reject) => {
  5. let subprocess = spawn('npm run tsc:watch', [], {
  6. shell: true, // above command is executed in bash
  7. stdio: [ 'ignore', 'pipe', 2 ] // ignore input, collect stdout, passthru stderr
  8. })
  9. subprocess.stdout.on('data', (data) => {
  10. let s = data.toString()
  11. process.stdout.write(s) // no newline
  12. if (s.match(/watching/i)) { // find string "Watching for file changes"
  13. resolve()
  14. }
  15. })
  16. subprocess.on('close', (code) => {
  17. if (code !== 0) {
  18. reject() // tsc closed with an error, most likely on startup
  19. } else {
  20. resolve() // if for some reason "watching" message wasn't caught
  21. }
  22. })
  23. })
  24. }
  25. exports.runTsc = () => {
  26. return new Promise((resolve, reject) => {
  27. let subprocess = spawn('npm run tsc', [], {
  28. shell: true, // above command is executed in bash
  29. stdio: [ 'ignore', 1, 2 ] // ignore input, passthru stdout, passthru stderr
  30. })
  31. subprocess.on('close', (code) => {
  32. if (code !== 0) {
  33. reject() // tsc closed with an error, most likely on startup
  34. } else {
  35. resolve() // if for some reason "watching" message wasn't caught
  36. }
  37. })
  38. })
  39. }