2017-07-05 10:03:10 +02:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
2018-10-27 17:45:19 +02:00
|
|
|
|
2017-07-05 10:03:10 +02:00
|
|
|
const config = {
|
2018-10-28 10:59:30 +01:00
|
|
|
files: ['public/index.html'],
|
2017-07-05 10:03:10 +02:00
|
|
|
};
|
2017-02-09 15:23:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert node arguments into an object
|
|
|
|
* @return {Object} Arguments
|
|
|
|
*/
|
|
|
|
const argvToObject = () => {
|
|
|
|
const args = {};
|
|
|
|
let arg = null;
|
|
|
|
process.argv.forEach((val, index) => {
|
2018-10-27 17:45:19 +02:00
|
|
|
if (/^--/.test(val)) {
|
2017-02-09 15:23:20 +01:00
|
|
|
arg = {
|
2018-10-27 17:45:19 +02:00
|
|
|
index,
|
|
|
|
name: val.replace(/^--/, ''),
|
|
|
|
};
|
2017-02-09 15:23:20 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-27 17:45:19 +02:00
|
|
|
if (arg && arg.index + 1 === index) {
|
2017-02-09 15:23:20 +01:00
|
|
|
args[arg.name] = val;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return args;
|
|
|
|
};
|
|
|
|
|
2017-07-05 10:03:10 +02:00
|
|
|
/**
|
|
|
|
* Loop through files updating the current version
|
|
|
|
* @param {Object} config
|
|
|
|
*/
|
2018-10-27 17:45:19 +02:00
|
|
|
const updateVersion = ({ files }) => {
|
2017-02-09 15:23:20 +01:00
|
|
|
const args = argvToObject();
|
2018-10-28 10:59:30 +01:00
|
|
|
const version = args.current;
|
2017-07-05 10:03:10 +02:00
|
|
|
|
2018-10-28 10:59:30 +01:00
|
|
|
console.log(`Updating version to ${version}`);
|
2017-07-05 10:03:10 +02:00
|
|
|
|
2018-10-27 17:45:19 +02:00
|
|
|
files.forEach(file => {
|
2017-02-09 15:23:20 +01:00
|
|
|
const filePath = path.join(__dirname, file);
|
2018-10-28 10:59:30 +01:00
|
|
|
const regex = new RegExp(/\?version=(.*?)\"/, 'g');
|
2017-02-09 15:23:20 +01:00
|
|
|
|
|
|
|
let contents = fs.readFileSync(filePath, 'utf-8');
|
2018-10-28 10:59:30 +01:00
|
|
|
contents = contents.replace(regex, `?version=${version}"`);
|
2017-02-09 15:23:20 +01:00
|
|
|
fs.writeFileSync(filePath, contents);
|
|
|
|
});
|
|
|
|
|
2018-10-28 10:59:30 +01:00
|
|
|
console.log(`Updated version to ${version}`);
|
2017-02-09 15:23:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
updateVersion(config);
|