generate-cli-doc.js 766 B

1234567891011121314151617181920212223242526
  1. const childProcess = require('child_process')
  2. const path = require('path')
  3. const fs = require('fs')
  4. const rustCliPath = path.join(
  5. __dirname,
  6. '../../tooling/cli.rs/target/debug/cargo-tauri'
  7. )
  8. const templatePath = path.join(__dirname, '../../docs/.templates/cli.md')
  9. const targetPath = path.join(__dirname, '../../docs/api/cli.md')
  10. const template = fs.readFileSync(templatePath, 'utf8')
  11. const commands = ['info', 'init', 'plugin init', 'dev', 'build']
  12. let doc = template
  13. for (const cmd of commands) {
  14. const output = childProcess
  15. .execSync(`${rustCliPath} ${cmd} --help`)
  16. .toString()
  17. .split('\n')
  18. output.splice(0, 2)
  19. output.splice(-1)
  20. doc = doc.replace(`{${cmd}}`, '```\n' + output.join('\n') + '\n```')
  21. }
  22. fs.writeFileSync(targetPath, doc)