Completed
Push — master ( 9899df...273a12 )
by
unknown
02:23
created

src/cli/cms/data/meta.js   A

Complexity

Total Complexity 10
Complexity/F 10

Size

Lines of Code 31
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
C meta.js ➔ add 0 24 10
1
import extend from 'extend'
2
import {
3
  cmsData
4
  ,config
5
  ,dateSlug
6
} from '../../'
7
8
export function add(tpl, json, type, obj = {}, date = null, realType = 'draft') {
9
  let meta = config.meta.name
10
11
  // json[meta] = extend({}, json[meta])
12
  var currentDate = (typeof date !== 'undefined' && date !== null && date !== '') ? date : new Date()
13
  var abeUrl = (type === 'publish') ? json[meta].link : cmsData.fileAttr.add(json[meta].link, 'd' + dateSlug(currentDate.toISOString())) + ''
14
15
  if(typeof json[meta].date === 'undefined' || json[meta].date === null) {
16
    json[meta].date = currentDate
17
  }
18
  json[meta].latest = {
19
    date: currentDate,
20
    abeUrl: abeUrl
21
  }
22
  json[meta].status = realType === 'reject' ? 'draft' : realType
23
  if(typeof json[meta][type] === 'undefined' || json[meta][type] === null) {
24
    json[meta][type] = JSON.parse(JSON.stringify(obj))
25
    json[meta][type].date = currentDate
26
    json[meta][type].abeUrl = abeUrl
27
  }
28
  json[meta][type].latest = JSON.parse(JSON.stringify(obj))
29
  json[meta][type].latest.date = currentDate
30
  json[meta][type].latest.abeUrl = abeUrl
31
}