DocsPublish.js 1.2 KB

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