-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad68fb2
commit 3900230
Showing
3 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const fs = require('fs'), | ||
path = require('path'), | ||
config = { | ||
files: ['bower.json', 'package.json', 'index.html'] | ||
}; | ||
|
||
/** | ||
* Convert node arguments into an object | ||
* @return {Object} Arguments | ||
*/ | ||
const argvToObject = () => { | ||
const args = {}; | ||
let arg = null; | ||
process.argv.forEach((val, index) => { | ||
if(/^--/.test(val)) { | ||
arg = { | ||
index: index, | ||
name: val.replace(/^--/, '') | ||
} | ||
return; | ||
} | ||
|
||
if(arg && ((arg.index+1 === index ))) { | ||
args[arg.name] = val; | ||
} | ||
}); | ||
|
||
return args; | ||
}; | ||
|
||
/** | ||
* Loop through passed files updating version number | ||
* @param {Object} config | ||
*/ | ||
const updateVersion = (config) => { | ||
const args = argvToObject(); | ||
const currentVersion = args.current; | ||
const newVersion = args.new; | ||
config.files.forEach((file) => { | ||
const filePath = path.join(__dirname, file); | ||
const regex = new RegExp(currentVersion, 'g'); | ||
|
||
let contents = fs.readFileSync(filePath, 'utf-8'); | ||
contents = contents.replace(regex, newVersion); | ||
fs.writeFileSync(filePath, contents); | ||
}); | ||
|
||
console.log(`Updated version to ${newVersion}`); | ||
}; | ||
|
||
updateVersion(config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Example usage: npm --newVersion=2.7.2 run version | ||
|
||
const fs = require('fs'), | ||
path = require('path'), | ||
config = { | ||
files: ['bower.json', 'package.json', 'index.html'] | ||
}; | ||
|
||
/** | ||
* Convert node arguments into an object | ||
* @return {Object} Arguments | ||
*/ | ||
const argvToObject = () => { | ||
const args = {}; | ||
let arg = null; | ||
process.argv.forEach((val, index) => { | ||
if(/^--/.test(val)) { | ||
arg = { | ||
index: index, | ||
name: val.replace(/^--/, '') | ||
} | ||
return; | ||
} | ||
|
||
if(arg && ((arg.index+1 === index ))) { | ||
args[arg.name] = val; | ||
} | ||
}); | ||
|
||
return args; | ||
}; | ||
|
||
const updateVersion = (config) => { | ||
const args = argvToObject(); | ||
const currentVersion = args.current; | ||
const newVersion = args.new; | ||
console.log(args); | ||
config.files.forEach((file) => { | ||
const filePath = path.join(__dirname, file); | ||
const regex = new RegExp(currentVersion, 'g'); | ||
|
||
let contents = fs.readFileSync(filePath, 'utf-8'); | ||
contents = contents.replace(regex, newVersion); | ||
fs.writeFileSync(filePath, contents); | ||
}); | ||
|
||
console.log(`Updated version to ${newVersion}`); | ||
}; | ||
|
||
updateVersion(config); |