Completed
Push — master ( 3f76fd...7863ed )
by Thomas
30s
created

module.exports   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 16
rs 9.4285
c 2
b 1
f 0
1
'use strict'
2
3
/*
4
 * Version 1.0 to 1.1
5
 *
6
 *  move .scholica -> .inc/containers/default.json
7
 *  move .scholica.dev -> .inc/containers/beta.json
8
 *  move .phpstorm.meta.php -> .inc/meta/.phpstorm.meta.php
9
 *  file .inc/version
10
 *  edit .gitignore
11
 */
12
13
const path = require('path')
14
const eol = require('eol')
15
const fs = require('fs')
16
17
const removeArrayItem = function (arr, itemToRemove) {
18
  return arr.filter(function (item) {
19
    return item !== itemToRemove
20
  })
21
}
22
23
const updateGitignore = function () {
24
  if (!fs.existsSync('.gitignore')) {
25
    return
26
  }
27
28
  var lines = fs.readFileSync('.gitignore', 'utf8')
29
  lines = eol.split(lines)
30
  lines = removeArrayItem(lines, '/.scholica')
31
  lines = removeArrayItem(lines, '/.scholica.beta')
32
  lines = removeArrayItem(lines, '.scholica')
33
  lines = removeArrayItem(lines, '.scholica.beta')
34
  lines = removeArrayItem(lines, '.phpstorm.meta.php')
35
  lines = removeArrayItem(lines, '.container')
36
  lines = removeArrayItem(lines, '.container.dev')
37
38
  if (!lines[lines.length - 1].length) {
39
    lines[lines.length - 1] = '.inc'
40
  } else {
41
    lines.push('.inc')
42
  }
43
44
  lines.push('')
45
46
  fs.writeFileSync('.gitignore', lines.join(eol.auto), 'utf8')
47
}
48
49
const moveContainerFiles = function () {
50
  if (fs.existsSync('.scholica')) {
51
    fs.renameSync('.scholica', path.join('.inc', 'containers', 'default.json'))
52
  }
53
  if (fs.existsSync('.scholica.beta')) {
54
    fs.renameSync('.scholica.beta', path.join('.inc', 'containers', 'beta.json'))
55
  }
56
}
57
58
module.exports = function () {
59
  if (!fs.existsSync('.inc')) {
60
    fs.mkdirSync('.inc')
61
    fs.mkdirSync(path.join('.inc', 'containers'))
62
    fs.mkdirSync(path.join('.inc', 'meta'))
63
64
    moveContainerFiles()
65
    updateGitignore()
66
67
    if (fs.existsSync('.phpstorm.meta.php')) {
68
      fs.renameSync('.phpstorm.meta.php', path.join('.inc', 'meta', '.phpstorm.meta.php'))
69
    }
70
71
    fs.writeFileSync(path.join('.inc', 'version'), '11', 'utf8')
72
  }
73
}
74