forked from riot/compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump.js
47 lines (38 loc) · 1.1 KB
/
bump.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
Usage: node bump [directory [searchString]]
Replace all ocurrecences of searchString with the version in package.json
directory defaults to "dist/"
searchString defaults to "WIP"
*/
var
version = require('./package.json').version,
path = require('path'),
fs = require('fs')
var
repStr = process.argv[3] || 'WIP',
fpath = process.argv[2] || 'dist/',
count = 0,
re = RegExp('\\b' + repStr.replace(/(?=[[\]()*+?.^$|])/g, '\\') + '\\b', 'g')
process.exitCode = 0
version = 'v' + version
console.log('bump %s for %s', version, path.join(fpath, '*.js'))
fs.readdirSync(fpath).forEach(function (name) {
if (path.extname(name) === '.js') {
name = path.join(fpath, name)
console.log(name)
fs.readFile(name, 'utf8', function (err, src) {
if (err) throw err
fs.writeFile(name, src.replace(re, version), 'utf8', function (err2) {
if (err2) throw err2
})
})
count++
}
})
if (!count) {
console.error('Error: There\'s no .js files in %s', fpath)
process.exitCode = 1
}
process.on('exit', function (code) {
if (code) process.exit(code)
})