Add new arguments to the update script
-Use the cmd `npm run update-explorer "explorer-only"` to update the explorer code only, without checking for out-of-date dependencies -Use the cmd `npm run update-explorer "dependencies-only"` to update outdated dependencies only, without checking for explorer code updates -Updated the README with the 2 new script arguments
This commit is contained in:
+63
-50
@@ -1,5 +1,6 @@
|
||||
const { execSync } = require('child_process');
|
||||
const fs = require('fs');
|
||||
const argument = (process.argv[2] != null && process.argv[2] != '' && (process.argv[2] == 'explorer-only' || process.argv[2] == 'dependencies-only') ? process.argv[2] : '');
|
||||
|
||||
var reloadWebserver = false;
|
||||
|
||||
@@ -13,72 +14,84 @@ function compile_css() {
|
||||
execSync('node ./scripts/compile_css.js', {stdio : 'inherit'});
|
||||
}
|
||||
|
||||
// check if the .git directory and .git/refs/heads/master file exist
|
||||
if (fs.existsSync('./.git') && fs.existsSync('./.git/refs/heads/master')) {
|
||||
// get the current commit hash
|
||||
var commit = fs.readFileSync('./.git/refs/heads/master');
|
||||
// check if the script should check for code updates
|
||||
if (argument == '' || argument == 'explorer-only') {
|
||||
// check if the .git directory and .git/refs/heads/master file exist
|
||||
if (fs.existsSync('./.git') && fs.existsSync('./.git/refs/heads/master')) {
|
||||
// get the current commit hash
|
||||
var commit = fs.readFileSync('./.git/refs/heads/master');
|
||||
|
||||
// update to newest explorer source
|
||||
console.log('Downloading newest explorer code.. Please wait..\n');
|
||||
// update to newest explorer source
|
||||
console.log('Downloading newest explorer code.. Please wait..\n');
|
||||
|
||||
try {
|
||||
console.log('Git response:');
|
||||
execSync('git pull', {stdio : 'inherit'});
|
||||
try {
|
||||
console.log('Git response:');
|
||||
execSync('git pull', {stdio : 'inherit'});
|
||||
|
||||
// get the current commit hash to see if it has changed
|
||||
var new_commit = fs.readFileSync('./.git/refs/heads/master');
|
||||
// get the current commit hash to see if it has changed
|
||||
var new_commit = fs.readFileSync('./.git/refs/heads/master');
|
||||
|
||||
// check if the commit values are the same
|
||||
if (new_commit.toString() == commit.toString()) {
|
||||
// explorer code was already up-to-date
|
||||
console.log('\nExplorer code is already up-to-date');
|
||||
} else {
|
||||
console.log('\nExplorer code successfully updated');
|
||||
reloadWebserver = true;
|
||||
// check if the commit values are the same
|
||||
if (new_commit.toString() == commit.toString()) {
|
||||
// explorer code was already up-to-date
|
||||
console.log('\nExplorer code is already up-to-date');
|
||||
} else {
|
||||
console.log('\nExplorer code successfully updated');
|
||||
reloadWebserver = true;
|
||||
}
|
||||
} catch(err) {
|
||||
console.log('\nError updating explorer code. Maybe git is not installed globally or you made some custom changes to the explorer code?');
|
||||
}
|
||||
} catch(err) {
|
||||
console.log('\nError updating explorer code. Maybe git is not installed globally or you made some custom changes to the explorer code?');
|
||||
} else {
|
||||
console.log('WARNING: Explorer code not cloned from github and cannot be automatically updated!');
|
||||
console.log('Skipping explorer code update');
|
||||
}
|
||||
|
||||
// check if this was an explorer-only update
|
||||
if (argument == 'explorer-only') {
|
||||
// add a new line for better spacing
|
||||
console.log('');
|
||||
}
|
||||
} else {
|
||||
console.log('WARNING: Explorer code not cloned from github and cannot be automatically updated!');
|
||||
console.log('Skipping explorer code update');
|
||||
}
|
||||
|
||||
var outdatedPkgs = null;
|
||||
// check if the script should check for outdated dependencies
|
||||
if (argument == '' || argument == 'dependencies-only') {
|
||||
var outdatedPkgs = null;
|
||||
|
||||
// check for outdated packages
|
||||
try {
|
||||
console.log('\nChecking for outdated packages.. Please wait..');
|
||||
execSync('npm outdated');
|
||||
|
||||
// all packages are up-to-date
|
||||
console.log('\nAll explorer packages are up-to-date');
|
||||
} catch (err) {
|
||||
outdatedPkgs = err.stdout.toString().trim();
|
||||
}
|
||||
|
||||
// add a new line for better spacing
|
||||
console.log('');
|
||||
|
||||
// check if there were any outdated packages
|
||||
if (outdatedPkgs != null) {
|
||||
// update npm modules to latest versions according to package.json rules
|
||||
console.log('Updating out-of-date explorer packages.. Please wait..\n');
|
||||
execSync('npm update');
|
||||
|
||||
// check for outdated packages (again)
|
||||
// check for outdated packages
|
||||
try {
|
||||
console.log((argument == 'dependencies-only' ? '' : '\n') +'Checking for outdated packages.. Please wait..');
|
||||
execSync('npm outdated');
|
||||
|
||||
// all packages are up-to-date
|
||||
console.log('All explorer packages are up-to-date\n');
|
||||
reloadWebserver = true;
|
||||
console.log('\nAll explorer packages are up-to-date');
|
||||
} catch (err) {
|
||||
console.log(`The following packages are still out-of-date:\n${err.stdout.toString().trim()}\n`);
|
||||
outdatedPkgs = err.stdout.toString().trim();
|
||||
}
|
||||
|
||||
// check if any of the packages were updated
|
||||
if (err.stdout.toString().trim() == outdatedPkgs)
|
||||
// add a new line for better spacing
|
||||
console.log('');
|
||||
|
||||
// check if there were any outdated packages
|
||||
if (outdatedPkgs != null) {
|
||||
// update npm modules to latest versions according to package.json rules
|
||||
console.log('Updating out-of-date explorer packages.. Please wait..\n');
|
||||
execSync('npm update');
|
||||
|
||||
// check for outdated packages (again)
|
||||
try {
|
||||
execSync('npm outdated');
|
||||
|
||||
// all packages are up-to-date
|
||||
console.log('All explorer packages are up-to-date\n');
|
||||
reloadWebserver = true;
|
||||
} catch (err) {
|
||||
console.log(`The following packages are still out-of-date:\n${err.stdout.toString().trim()}\n`);
|
||||
|
||||
// check if any of the packages were updated
|
||||
if (err.stdout.toString().trim() == outdatedPkgs)
|
||||
reloadWebserver = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user