Publish.js 816 字节
Newer Older
A
Abdullah Almsaeed 已提交
1
const Plugins = require('./Plugins')
2
const fse     = require('fs-extra')
A
Abdullah Almsaeed 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

class Publish {
  constructor() {
    this.options = {
      verbose: false
    }

    this.getArguments()
  }

  getArguments() {
    if (process.argv.length > 2) {
      let arg = process.argv[2]
      switch (arg) {
        case '-v':
        case '--verbose':
          this.options.verbose = true
          break
        default:
          throw new Error(`Unknown option ${arg}`)
      }
    }
  }

  run() {
    // Publish files
    Plugins.forEach((module) => {
R
REJack 已提交
30 31 32 33
      try {
        fse.copySync(module.from, module.to)

        if (this.options.verbose) {
A
Abdullah Almsaeed 已提交
34
          console.log(`Copied ${module.from} to ${module.to}`)
A
Abdullah Almsaeed 已提交
35
        }
R
REJack 已提交
36 37 38
      } catch (err) {
        console.error(`Error: ${err}`)
      }
A
Abdullah Almsaeed 已提交
39 40 41 42 43
    })
  }
}

(new Publish()).run()