|
|
|
|
@ -3,16 +3,42 @@ import os from 'os'; |
|
|
|
|
import util from 'util'; |
|
|
|
|
import path from 'path'; |
|
|
|
|
import fs from 'fs'; |
|
|
|
|
import https from 'https'; |
|
|
|
|
|
|
|
|
|
const execAsync = util.promisify(exec); |
|
|
|
|
|
|
|
|
|
class VersionCompiler { |
|
|
|
|
async processFilesForTarget(files) { |
|
|
|
|
const processFile = async function (file) { |
|
|
|
|
if (!file.getDisplayPath().match(/rocketchat\.info$/)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
const processVersionFile = async function (file) { |
|
|
|
|
const data = await new Promise((resolve, reject) => { |
|
|
|
|
https |
|
|
|
|
.get('https://releases.rocket.chat/v2/server/supportedVersions', function (response) { |
|
|
|
|
let data = ''; |
|
|
|
|
response.on('data', function (chunk) { |
|
|
|
|
data += chunk; |
|
|
|
|
}); |
|
|
|
|
response.on('end', function () { |
|
|
|
|
resolve(JSON.parse(data)); |
|
|
|
|
}); |
|
|
|
|
response.on('error', function (err) { |
|
|
|
|
console.error(err); |
|
|
|
|
if (process.env.NODE_ENV !== 'development') { |
|
|
|
|
reject(err); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
resolve({}); |
|
|
|
|
}); |
|
|
|
|
}) |
|
|
|
|
.end(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
file.addJavaScript({ |
|
|
|
|
data: `exports.supportedVersions = ${JSON.stringify(data)}`, |
|
|
|
|
path: `${file.getPathInPackage()}.js`, |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const processFile = async function (file) { |
|
|
|
|
let output = JSON.parse(file.getContentsAsString()); |
|
|
|
|
output.build = { |
|
|
|
|
date: new Date().toISOString(), |
|
|
|
|
@ -39,6 +65,9 @@ class VersionCompiler { |
|
|
|
|
subject: data.join('\n'), |
|
|
|
|
}; |
|
|
|
|
} catch (e) { |
|
|
|
|
if (process.env.NODE_ENV !== 'development') { |
|
|
|
|
throw e; |
|
|
|
|
} |
|
|
|
|
// no git
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -57,20 +86,34 @@ class VersionCompiler { |
|
|
|
|
output.commit.branch = branch.stdout.replace('\n', ''); |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
if (process.env.NODE_ENV !== 'development') { |
|
|
|
|
throw e; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// no branch
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
output = `exports.Info = ${JSON.stringify(output, null, 4)};
|
|
|
|
|
exports.minimumClientVersions = ${JSON.stringify(minimumClientVersions, null, 4)};`;
|
|
|
|
|
|
|
|
|
|
file.addJavaScript({ |
|
|
|
|
data: output, |
|
|
|
|
data: `exports.Info = ${JSON.stringify(output, null, 4)};
|
|
|
|
|
exports.minimumClientVersions = ${JSON.stringify(minimumClientVersions, null, 4)};`,
|
|
|
|
|
path: `${file.getPathInPackage()}.js`, |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
for await (const file of files) { |
|
|
|
|
await processFile(file); |
|
|
|
|
switch (true) { |
|
|
|
|
case file.getDisplayPath().endsWith('rocketchat.info'): { |
|
|
|
|
await processFile(file); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case file.getDisplayPath().endsWith('rocketchat-supported-versions.info'): { |
|
|
|
|
await processVersionFile(file); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
default: { |
|
|
|
|
throw new Error(`Unexpected file ${file.getDisplayPath()}`); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|