Completed
Pull Request — master (#2)
by Thomas
27s
created

10-11.js ➔ removeArrayItem   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
dl 0
loc 5
rs 9.4285
nop 2

1 Function

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