DocsPublish.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env node
  2. 'use strict'
  3. const path = require('path')
  4. const fse = require('fs-extra')
  5. const Plugins = require('./DocsPlugins')
  6. class Publish {
  7. constructor() {
  8. this.options = {
  9. verbose: false
  10. }
  11. this.getArguments()
  12. }
  13. getArguments() {
  14. if (process.argv.length > 2) {
  15. const arg = process.argv[2]
  16. switch (arg) {
  17. case '-v':
  18. case '--verbose':
  19. this.options.verbose = true
  20. break
  21. default:
  22. throw new Error(`Unknown option ${arg}`)
  23. }
  24. }
  25. }
  26. run() {
  27. // Publish files
  28. Plugins.forEach(module => {
  29. try {
  30. fse.copySync(module.from, module.to, {
  31. // Skip copying dot files
  32. filter(src) {
  33. return !path.basename(src).startsWith('.')
  34. }
  35. })
  36. if (this.options.verbose) {
  37. console.log(`Copied ${module.from} to ${module.to}`)
  38. }
  39. } catch (error) {
  40. console.error(`Error: ${error}`)
  41. }
  42. })
  43. }
  44. }
  45. (new Publish()).run()