Completed
Push — master ( 8a8e53...266fe4 )
by Thomas
10s
created

lib/upgrades/10-11.js   A

Complexity

Total Complexity 9
Complexity/F 3

Size

Lines of Code 61
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

2 Functions

Rating   Name   Duplication   Size   Complexity  
C module.exports 0 49 7
A 10-11.js ➔ removeArrayItem 0 5 1
1
'use strict'
2
3
const path = require('path')
4
const eol = require('eol')
5
const fs = require('fs')
6
7
const removeArrayItem = function (arr, itemToRemove) {
8
  return arr.filter(function (item) {
9
    return item !== itemToRemove
10
  })
11
}
12
13
module.exports = function () {
14
  /*
15
   * Version 1.0 to 1.1
16
   *
17
   *  move .scholica -> .inc/containers/default.json
18
   *  move .scholica.dev -> .inc/containers/beta.json
19
   *  move .phpstorm.meta.php -> .inc/meta/.phpstorm.meta.php
20
   *  file .inc/version
21
   *  edit .gitignore
22
   */
23
24
  if (!fs.existsSync('.inc')) {
25
    fs.mkdirSync('.inc')
26
27
    fs.mkdirSync(path.join('.inc', 'containers'))
28
    if (fs.existsSync('.scholica')) {
29
      fs.renameSync('.scholica', path.join('.inc', 'containers', 'default.json'))
30
    }
31
    if (fs.existsSync('.scholica.beta')) {
32
      fs.renameSync('.scholica.beta', path.join('.inc', 'containers', 'beta.json'))
33
    }
34
35
    fs.mkdirSync(path.join('.inc', 'meta'))
36
    if (fs.existsSync('.phpstorm.meta.php')) {
37
      fs.renameSync('.phpstorm.meta.php', path.join('.inc', 'meta', '.phpstorm.meta.php'))
38
    }
39
40
    if (fs.existsSync('.gitignore')) {
41
      var lines = fs.readFileSync('.gitignore', 'utf8')
42
      lines = eol.split(lines)
43
      lines = removeArrayItem(lines, '/.scholica')
44
      lines = removeArrayItem(lines, '/.scholica.beta')
45
      lines = removeArrayItem(lines, '.scholica')
46
      lines = removeArrayItem(lines, '.scholica.beta')
47
      lines = removeArrayItem(lines, '.phpstorm.meta.php')
48
      lines = removeArrayItem(lines, '.container')
49
      lines = removeArrayItem(lines, '.container.dev')
50
      if (!lines[lines.length - 1].length) {
51
        lines[lines.length - 1] = '.inc'
52
      } else {
53
        lines.push('.inc')
54
      }
55
      lines.push('')
56
      fs.writeFileSync('.gitignore', lines.join(eol.auto), 'utf8')
57
    }
58
59
    fs.writeFileSync(path.join('.inc', 'version'), '11', 'utf8')
60
  }
61
}
62