Completed
Push — master ( 2575ab...439767 )
by
unknown
02:46
created

src/cli/cms/templates/assets.js   A

Complexity

Total Complexity 15
Complexity/F 5

Size

Lines of Code 62
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
B assets.js ➔ copy 0 46 3
1
import fse from 'fs-extra'
2
import dircompare from 'dir-compare'
3
import mkdirp from 'mkdirp'
4
import moment from 'moment'
5
import path from 'path'
6
7
import {
8
  cmsData
0 ignored issues
show
Unused Code introduced by
The variable cmsData seems to be never used. Consider removing it.
Loading history...
9
  ,cmsOperations
0 ignored issues
show
Unused Code introduced by
The variable cmsOperations seems to be never used. Consider removing it.
Loading history...
10
  ,coreUtils
0 ignored issues
show
Unused Code introduced by
The variable coreUtils seems to be never used. Consider removing it.
Loading history...
11
  ,FileParser
12
  ,config
13
  ,Hooks
0 ignored issues
show
Unused Code introduced by
The variable Hooks seems to be never used. Consider removing it.
Loading history...
14
  ,Manager
0 ignored issues
show
Unused Code introduced by
The variable Manager seems to be never used. Consider removing it.
Loading history...
15
} from '../../'
16
17
export function copy(pathAssets) {
18
  var publicFolders = FileParser.getAssetsFolder(pathAssets)
19
  let publish = config.publish.url
20
  var dest = path.join(config.root, publish)
21
  try {
22
    var directory = fse.lstatSync(dest)
23
    if (!directory.isDirectory()) {
24
      mkdirp.sync(dest)
25
    }
26
  } catch (e) {
27
    mkdirp.sync(dest)
28
  }
29
30
  Array.prototype.forEach.call(publicFolders, (publicFolder) => {
31
    var res = dircompare.compareSync(publicFolder, dest, {compareSize: true})
32
33
    res.diffSet.forEach(function (entry) {
34
      var state = {
35
        'equal' : '==',
36
        'left' : '->',
37
        'right' : '<-',
38
        'distinct' : '<>'
39
      }[entry.state]
40
41
      var name1 = entry.name1 ? entry.name1 : ''
42
      var name2 = entry.name2 ? entry.name2 : ''
43
44
      let exclude =  new RegExp(config.files.exclude)
45
      if(!exclude.test(name1) && !exclude.test(name2) && entry.type1 !== 'directory' && entry.type2 !== 'directory') {
46
        
47
        if(typeof entry.path1 !== 'undefined' && entry.path1 !== null) {
48
          var original = entry.path1
49
          var basePath = original.replace(publicFolder, '')
50
          var move = path.join(dest, basePath)
51
52
          if(entry.type2 === 'missing' || entry.state === 'distinct') {
53
            fse.removeSync(move)
54
            fse.copySync(original, move)
55
          }
56
        }
57
      }
58
    })
59
  })
60
61
  return publicFolders
62
}