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

module.exports   B

Complexity

Conditions 5
Paths 27

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
c 1
b 0
f 0
nc 27
nop 1
dl 0
loc 26
rs 8.439
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