]>
git.ipfire.org Git - ipfire.org.git/blob - src/scss/bootstrap-4.0.0-alpha.6/grunt/change-version.js
5ea59185a087abe2649762c050524330e496ea5d
6 * Script to update version number references in the project.
7 * Copyright 2017 The Bootstrap Authors
8 * Copyright 2017 Twitter, Inc.
9 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
14 var fs
= require('fs')
15 var path
= require('path')
16 var sh
= require('shelljs')
17 sh
.config
.fatal
= true
20 // Blame TC39... https://github.com/benjamingr/RegExp.escape/issues/37
21 RegExp
.quote = function (string
) {
22 return string
.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&')
24 RegExp
.quoteReplacement = function (string
) {
25 return string
.replace(/[$]/g, '$$')
30 function walkAsync(directory
, excludedDirectories
, fileCallback
, errback
) {
31 if (excludedDirectories
.has(path
.parse(directory
).base
)) {
34 fs
.readdir(directory
, function (err
, names
) {
39 names
.forEach(function (name
) {
40 var filepath
= path
.join(directory
, name
)
41 fs
.lstat(filepath
, function (err
, stats
) {
43 process
.nextTick(errback
, err
)
46 if (stats
.isSymbolicLink()) {
49 else if (stats
.isDirectory()) {
50 process
.nextTick(walkAsync
, filepath
, excludedDirectories
, fileCallback
, errback
)
52 else if (stats
.isFile()) {
53 process
.nextTick(fileCallback
, filepath
)
60 function replaceRecursively(directory
, excludedDirectories
, allowedExtensions
, original
, replacement
) {
61 original
= new RegExp(RegExp
.quote(original
), 'g')
62 replacement
= RegExp
.quoteReplacement(replacement
)
63 var updateFile
= !DRY_RUN
? function (filepath
) {
64 if (allowedExtensions
.has(path
.parse(filepath
).ext
)) {
65 sed('-i', original
, replacement
, filepath
)
67 } : function (filepath
) {
68 if (allowedExtensions
.has(path
.parse(filepath
).ext
)) {
69 console
.log('FILE: ' + filepath
)
72 console
.log('EXCLUDED:' + filepath
)
75 walkAsync(directory
, excludedDirectories
, updateFile
, function (err
) {
76 console
.error('ERROR while traversing directory!:')
83 if (args
.length
!== 2) {
84 console
.error('USAGE: change-version old_version new_version')
85 console
.error('Got arguments:', args
)
88 var oldVersion
= args
[0]
89 var newVersion
= args
[1]
90 var EXCLUDED_DIRS
= new Set([
95 var INCLUDED_EXTENSIONS
= new Set([
96 // This extension whitelist is how we avoid modifying binary files
107 replaceRecursively('.', EXCLUDED_DIRS
, INCLUDED_EXTENSIONS
, oldVersion
, newVersion
)
110 main(process
.argv
.slice(2))