DocsPublish.js 820 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const Plugins = require('./DocsPlugins')
  2. const fse = require('fs-extra')
  3. class Publish {
  4. constructor() {
  5. this.options = {
  6. verbose: false
  7. }
  8. this.getArguments()
  9. }
  10. getArguments() {
  11. if (process.argv.length > 2) {
  12. let arg = process.argv[2]
  13. switch (arg) {
  14. case '-v':
  15. case '--verbose':
  16. this.options.verbose = true
  17. break
  18. default:
  19. throw new Error(`Unknown option ${arg}`)
  20. }
  21. }
  22. }
  23. run() {
  24. // Publish files
  25. Plugins.forEach((module) => {
  26. try {
  27. fse.copySync(module.from, module.to)
  28. if (this.options.verbose) {
  29. console.log(`Copied ${module.from} to ${module.to}`)
  30. }
  31. } catch (err) {
  32. console.error(`Error: ${err}`)
  33. }
  34. })
  35. }
  36. }
  37. (new Publish()).run()