compile.ts 699 B

12345678910111213141516171819202122232425262728
  1. import { main as pbjs } from 'protobufjs/cli/pbjs'
  2. import { main as pbts } from 'protobufjs/cli/pbts'
  3. import path from 'path'
  4. import fs from 'fs'
  5. const OUT_DIR = path.resolve(__dirname, '../compiled')
  6. pbjs(
  7. ['--target', 'static-module', '-w', 'commonjs', '-o', `${OUT_DIR}/index.js`, '--force-long', 'proto/*.proto'],
  8. function (err) {
  9. if (err) {
  10. throw err
  11. }
  12. console.log(`${OUT_DIR}/index.js updated`)
  13. }
  14. )
  15. pbts([`${OUT_DIR}/*.js`], function (err, output) {
  16. if (err) {
  17. throw err
  18. }
  19. // Fix missing Long import
  20. output = `import { Long } from 'long'\n${output}`
  21. fs.writeFileSync(`${OUT_DIR}/index.d.ts`, output)
  22. console.log(`${OUT_DIR}/index.d.ts updated`)
  23. })