Total Complexity | 9 |
Complexity/F | 1.8 |
Lines of Code | 35 |
Function Count | 5 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | /* |
||
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') |
||
|
|||
33 | unlinkFn() |
||
34 | }).catch(function (response) { |
||
35 | spinner(response.response.data.error || 'Network error') |
||
36 | unlinkFn() |
||
37 | }) |
||
38 | }) |
||
39 | }) |
||
40 | } |
||
41 |