Publish.js 1.2 KB

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