Completed
Push — master ( 650d4b...e332e4 )
by Doğa
03:54
created

gulpfile.js/tasks/replaceVersion.js   A

Complexity

Total Complexity 6
Complexity/F 3

Size

Lines of Code 33
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
B module.exports 0 28 1
1
const gulp = require('gulp')
2
const gutil = require('gulp-util')
3
const pjson = require('../../package.json')
4
const replace = require('replace-in-file')
5
6
module.exports = function (config) {
7
  gulp.task('replaceVersion', function (cb) {
8
    try {
9
      // read current version from package.json
10
      config.replaceVersion.php.to = pjson.version
11
      gutil.log(`Replacing ${config.replaceVersion.php.from} with ${config.replaceVersion.php.to} in all PHP files.`)
12
      const changedFilesPhp = replace.sync(config.replaceVersion.php)
13
      for (const file of changedFilesPhp) {
14
        gutil.log(`Updated ${file}`)
15
      }
16
17
      // replace WordPress theme version in style.css
18
      gutil.log('Updating WordPress theme version.')
19
      config.replaceVersion.wordpress.to += pjson.version
20
      const changedFilesWp = replace.sync(config.replaceVersion.wordpress)
21
      if (changedFilesWp.length > 0) {
22
        for (const file of changedFilesWp) {
23
          gutil.log(`Updated ${file}`)
24
        }
25
      } else {
26
        gutil.log(gutil.colors.yellow('No changes made! Was the version already changed?'))
27
      }
28
    } catch (error) {
29
      gutil.error('An error occurred:', error)
30
    }
31
    cb()
32
  })
33
}
34