Publish.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env node
  2. 'use strict'
  3. const path = require('path')
  4. const fse = require('fs-extra')
  5. const Plugins = require('./Plugins')
  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. }
  22. default: {
  23. throw new Error(`Unknown option ${arg}`)
  24. }
  25. }
  26. }
  27. }
  28. run() {
  29. // Publish files
  30. Plugins.forEach(module => {
  31. const fseOptions = {
  32. // Skip copying dot files
  33. filter(src) {
  34. return !path.basename(src).startsWith('.')
  35. }
  36. }
  37. try {
  38. if (fse.existsSync(module.from)) {
  39. fse.copySync(module.from, module.to, fseOptions)
  40. } else {
  41. fse.copySync(module.from.replace('node_modules/', '../'), module.to, fseOptions)
  42. }
  43. if (this.options.verbose) {
  44. console.log(`Copied ${module.from} to ${module.to}`)
  45. }
  46. } catch (error) {
  47. console.error(`Error: ${error}`)
  48. }
  49. })
  50. }
  51. }
  52. (new Publish()).run()