Completed
Push — master ( 7dd2d9...fd97ea )
by Thomas
49s queued 27s
created

lib/commands/modules/publish.js   A

Complexity

Total Complexity 9
Complexity/F 1.8

Size

Lines of Code 35
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 9
c 1
b 0
f 0
nc 8
mnd 1
bc 6
fnc 5
dl 0
loc 35
rs 10
bpm 1.2
cpm 1.8
noi 1

1 Function

Rating   Name   Duplication   Size   Complexity  
B module.exports 0 27 1
1
/*
2
 * Copyright (c) 2018 Includable.
3
 * Created by Thomas Schoffelen.
4
 */
5
6
const FormData = require('form-data')
7
const fs = require('fs')
8
9
const API = require('../../util/API')
10
const output = require('../../output')
11
const runHelpers = require('../../run-helpers')
12
const Module = require('../../containers/Module')
13
14
module.exports = function () {
15
  API.checkSignedIn()
16
17
  Module.getManifest(function (manifest) {
18
    if (!('name' in manifest) || !manifest.name || typeof manifest.name !== 'string' || !manifest.name.length) {
19
      output.err('Please set a valid value for key `name` in module.json')
20
      return
21
    }
22
23
    runHelpers.createZipArchive('.', function (zipFile, size, unlinkFn) {
24
      const spinner = output.wait(runHelpers.logSyncMessage('Uploading module (' + size + ')', true))
25
26
      const data = new FormData(null)
27
      data.append('file', fs.createReadStream(zipFile))
28
29
      API.post('/modules/publish', data, {headers: data.getHeaders()}).then(function (response) {
30
        spinner()
31
        output.success('+ ' + response.data.data.message)
32
        console.log('It can take up to three minutes before your update is propagated everywhere')
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
33
        unlinkFn()
34
      }).catch(function (response) {
35
        spinner(response.response.data.error || 'Network error')
36
        unlinkFn()
37
      })
38
    })
39
  })
40
}
41