lib/containers/Module.js   A
last analyzed

Complexity

Total Complexity 8
Complexity/F 4

Size

Lines of Code 31
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 31
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
const createManifest = require('./ModuleManifest')
7
8
var Module = {}
9
10
/**
11
 * Get the manifest object for the module in the current directory.
12
 * @param {function(ModuleManifest)} callback
13
 * @param {string} basePath
14
 */
15
Module.getManifest = function (callback, basePath) {
16
  var modulePath = basePath ? path.join(basePath, 'module.json') : 'module.json'
17
  jsonfile.readFile(modulePath, function (err, module) {
18
    if (err) {
19
      output.err('Error reading module.json: ' + err)
20
      return
21
    }
22
    if (!('slug' in module) || !module.slug || typeof module.slug !== 'string' || !module.slug.length) {
23
      output.err('Please set a valid value for module.slug')
24
      return
25
    }
26
27
    callback(createManifest(module))
28
  })
29
}
30
31
module.exports = Module
32