Completed
Push — master ( 3b3ae1...61dd3f )
by greg
01:50
created

src/cli/cms/data/update-json.js   A

Complexity

Total Complexity 7
Complexity/F 7

Size

Lines of Code 38
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
c 1
b 0
f 0
nc 9
dl 0
loc 38
rs 10
noi 7
wmc 7
mnd 2
bc 6
fnc 1
bpm 6
cpm 7

1 Function

Rating   Name   Duplication   Size   Complexity  
A update-json.js ➔ ??? 0 6 2
1
import path from 'path'
2
import {
3
  config
4
  ,FileParser
5
  ,fileUtils
0 ignored issues
show
Unused Code introduced by
The variable fileUtils seems to be never used. Consider removing it.
Loading history...
6
  ,folderUtils
0 ignored issues
show
Unused Code introduced by
The variable folderUtils seems to be never used. Consider removing it.
Loading history...
7
  ,save
0 ignored issues
show
Unused Code introduced by
The variable save seems to be never used. Consider removing it.
Loading history...
8
  ,Hooks
9
} from '../../'
10
11
var pConfig = {}
12
Array.prototype.forEach.call(process.argv, (item) => {
13
  if (item.indexOf('=') > -1) {
14
    var ar = item.split('=')
15
    pConfig[ar[0]] = ar[1]
16
  }
17
})
18
19
if(typeof pConfig.ABE_WEBSITE !== 'undefined' && pConfig.ABE_WEBSITE !== null) {
20
  if(pConfig.ABE_WEBSITE) config.set({root: pConfig.ABE_WEBSITE.replace(/\/$/, '') + '/'})
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
21
22
  var allJson
23
24
  pConfig.FILEPATH = path.join(config.root, config.data.url, pConfig.FILEPATH ? pConfig.FILEPATH.replace(config.root) : '')
25
26
  if(pConfig.FILETYPE) {
27
    allJson = FileParser.getFilesByType(pConfig.FILEPATH, pConfig.FILETYPE)
28
  }
29
  else {
30
    allJson = FileParser.getFiles(pConfig.FILEPATH, true, 20, /\.json/)
31
  }
32
33
  var allJson = Hooks.instance.trigger('beforeUpdateJson', allJson)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable allJson already seems to be declared on line 22. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
34
35
}else {
36
  console.log('ABE_WEBSITE is not defined use node process.js ABE_WEBSITE=/pat/to/website')
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...
37
  process.exit(0)
0 ignored issues
show
Compatibility Debugging Code Best Practice introduced by
Use of process.exit() is discouraged as it will potentially stop the complete node.js application. Consider quitting gracefully instead by throwing an Error.
Loading history...
38
}
39