Completed
Push — master ( 1f2ffc...cd17ec )
by Thomas
30s
created

lib/containers/Module.js   A

Complexity

Total Complexity 8
Complexity/F 4

Size

Lines of Code 30
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 8
dl 0
loc 30
rs 10
wmc 8
mnd 1
bc 4
fnc 2
bpm 2
cpm 4
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A Module.getManifest 0 15 2
1
'use strict'
2
3
const output = require('../output')
4
const path = require('path')
5
const jsonfile = require('jsonfile')
6
7
var Module = {}
8
9
/**
10
 * Get the manifest object for the module in the current directory.
11
 * @param {function(ModuleManifest)} callback
12
 * @param {string} basePath
13
 */
14
Module.getManifest = function (callback, basePath) {
15
  var modulePath = basePath ? path.join(basePath, 'module.json') : 'module.json'
16
  jsonfile.readFile(modulePath, function (err, module) {
17
    if (err) {
18
      output.err('Error reading module.json: ' + err)
19
      return
20
    }
21
    if (!('slug' in module) || !module.slug || typeof module.slug !== 'string' || !module.slug.length) {
22
      output.err('Please set a valid value for module.slug')
23
      return
24
    }
25
26
    callback(module)
27
  })
28
}
29
30
module.exports = Module
31