Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves client version #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const app = express();

app.set('view engine', 'ejs');

const getVersions = async () => {
const getVersionFiles = async() => {
return new Promise((resolve, reject) => {
fs.readdir(path.join(__dirname, 'versions'), {
encoding: 'utf-8'
Expand All @@ -33,11 +33,19 @@ const getVersions = async () => {
if (rollbar) rollbar.error(err);
return reject(err);
}
resolve(files.map(file => file.replace('.json', '')));

resolve(files);
});
});
};

const getVersions = async () => {
return new Promise((resolve) => {
getVersionFiles()
.then((files) => resolve(files.map(file => file.replace('.json', ''))));
});
};

const getServerVersion = async () => {
return new Promise((resolve) => {
execCmd('git rev-parse HEAD')
Expand All @@ -49,7 +57,24 @@ const getServerVersion = async () => {
const getClientVersion = async () => {
return new Promise((resolve) => {
execCmd('cd /opt/evnotipi && sudo git rev-parse HEAD')
.then(resolve)
.then((currentVersion) => {
getVersionFiles()
.then(async (files) => {
for (const file in files) {
if (files.hasOwnProperty(file)) {
const version = files[file].replace('.json', '');

const data = await getVersion(version);

if (data.commit === currentVersion) {
return resolve(version);
}
}
}

resolve(currentVersion);
});
})
.catch(() => resolve('?'));
});
};
Expand Down