Skip to content

Commit

Permalink
Add new arguments to the update script
Browse files Browse the repository at this point in the history
-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
  • Loading branch information
joeuhren committed Jul 9, 2022
1 parent e5d4c63 commit 27c29ef
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 54 deletions.
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
119 changes: 66 additions & 53 deletions scripts/update_explorer.js
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
}
}
}

Expand Down

0 comments on commit 27c29ef

Please # to comment.