Publish.js 967 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const Plugins = require('./Plugins')
  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. if (fse.existsSync(module.from)) {
  28. fse.copySync(module.from, module.to)
  29. } else {
  30. fse.copySync(module.from.replace('node_modules/', '../'), module.to)
  31. }
  32. if (this.options.verbose) {
  33. console.log(`Copied ${module.from} to ${module.to}`)
  34. }
  35. } catch (err) {
  36. console.error(`Error: ${err}`)
  37. }
  38. })
  39. }
  40. }
  41. (new Publish()).run()