Completed
Pull Request — master (#66)
by
unknown
02:44
created

src/cli/cms/structure/structure.js   A

Complexity

Total Complexity 9
Complexity/F 1.8

Size

Lines of Code 34
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

3 Functions

Rating   Name   Duplication   Size   Complexity  
A structure.js ➔ removeFolder 0 9 1
A structure.js ➔ addFolder 0 6 1
A structure.js ➔ editStructure 0 6 2
1
import path from 'path'
2
import mkdirp from 'mkdirp'
3
import execPromise from 'child-process-promise'
4
5
import {
6
  coreUtils,
0 ignored issues
show
Unused Code introduced by
The variable coreUtils seems to be never used. Consider removing it.
Loading history...
7
  cmsStructure,
8
  cmsData,
0 ignored issues
show
Unused Code introduced by
The variable cmsData seems to be never used. Consider removing it.
Loading history...
9
  config
10
} from '../../'
11
12
export function addFolder(folderPath) {
13
  mkdirp(path.join(config.root, folderPath), function (err) {
14
    if (err) console.error(err)
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...
15
  })
16
  return folderPath
17
}
18
19
export function removeFolder(folderPath) {
20
  execPromise.exec('rm -rf ' + path.join(config.root, folderPath)).then(function (result) {
21
    var stdout = result.stdout
22
    var stderr = result.stderr
23
    if(stdout) console.log('stdout: ', stdout)
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...
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...
24
    if(stderr) console.log('stderr: ', stderr)
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...
25
  })
26
  return folderPath
27
}
28
29
export function editStructure(type, folderPath) {
30
  if(type === 'add') cmsStructure.structure.addFolder(folderPath)
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...
31
  else cmsStructure.structure.removeFolder(folderPath)
32
  
33
  return folderPath
34
}
35