Completed
Push — master ( 652c21...99e276 )
by greg
10:52 queued 08:59
created

folder-utils.js ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
c 6
b 0
f 0
nc 1
nop 0
dl 0
loc 1
cc 1
rs 10
1
import fse from 'fs-extra'
2
import dircompare from 'dir-compare'
3
import mkdirp from 'mkdirp'
4
import moment from 'moment'
5
6
import {
7
	fileUtils,
8
	fileAttr,
0 ignored issues
show
Unused Code introduced by
The variable fileAttr seems to be never used. Consider removing it.
Loading history...
9
	config
10
} from '../../'
11
12
export default class FolderUtils {
13
14
  constructor() {}
15
16
  static isFolder(path) {
17
    try{
18
      var stat = fse.statSync(path)
19
20
      if (stat && stat.isDirectory()) {
21
        return true
22
      }
23
    }catch(e){
24
      return false
25
    }
26
    return false
27
  }
28
29
  static createFile(path, content = {}) {
30
    if(path.indexOf('.json') > -1) {
31
      fse.writeJsonSync(path, content, { space: 2, encoding: 'utf-8' })
32
    }
33
  }
34
35
  static createFolder(path) {
36
    if(!FolderUtils.isFolder(path)) {
37
      mkdirp.sync(path)
38
    }
39
  }
40
41
  static getFolderPath(path) {
42
    var folders = path.replace(config.root, '')
43
    folders = folders.replace(/^\//, '')
44
    folders = folders.split('/')
45
    folders.shift()
46
    folders = folders.join('/')
47
    folders = fileUtils.removeLast(folders)
48
    return folders
49
  }
50
51
  static folderInfos(pathFolder) {
52
    var pathArr = pathFolder.split('/')
53
    var name = pathArr[pathArr.length - 1]
54
55
    var rootArr = config.root.split('/')
56
    var website = rootArr[pathArr.length - 1]
57
    return {
58
      'name': name,
59
      'path': pathFolder,
60
      'website': website,
61
      'cleanPath': fileUtils.cleanPath(pathFolder.replace(config.root, '')),
62
      'type': 'folder'
63
    }
64
  }
65
  
66
}
67