From 27c29efb81a7d511ae3ab9cc7b684a93e404326d Mon Sep 17 00:00:00 2001 From: Joe Uhren Date: Sat, 9 Jul 2022 13:53:33 -0600 Subject: [PATCH] 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 --- README.md | 36 ++++++++++- scripts/update_explorer.js | 119 ++++++++++++++++++++----------------- 2 files changed, 101 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index e158425a..e15b11d3 100644 --- a/README.md +++ b/README.md @@ -766,7 +766,41 @@ Automatically download and install the newest explorer source code, update out-o Update the explorer with the following command: -`npm run update-explorer` +``` +npm run update-explorer +``` + +or (useful for crontab): + +``` +cd /path/to/explorer && /path/to/node ./scripts/update_explorer.js +``` + +**NOTE:** The update script also supports a couple optional parameters. + +Use the following command if you want to update the explorer code only, without checking for out-of-date dependencies: + +``` +npm run update-explorer "explorer-only" +``` + +or (useful for crontab): + +``` +cd /path/to/explorer && /path/to/node ./scripts/update_explorer.js "explorer-only" +``` + +Use the following command if you want to upgrade outdated dependencies only, without checking for explorer code updates: + +``` +npm run update-explorer "dependencies-only" +``` + +or (useful for crontab): + +``` +cd /path/to/explorer && /path/to/node ./scripts/update_explorer.js "dependencies-only" +``` #### Backup Database Script diff --git a/scripts/update_explorer.js b/scripts/update_explorer.js index b48de0c7..8f7ba955 100644 --- a/scripts/update_explorer.js +++ b/scripts/update_explorer.js @@ -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'); - - // update to newest explorer source - console.log('Downloading newest explorer code.. Please wait..\n'); - - 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'); - - // 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 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'); + + 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'); + + // 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'); } -} 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 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(); + // check if this was an explorer-only update + if (argument == 'explorer-only') { + // add a new line for better spacing + console.log(''); + } } -// 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 if the script should check for outdated dependencies +if (argument == '' || argument == 'dependencies-only') { + var outdatedPkgs = null; - // 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; + } } }