chore: build meteor with cloud version (#31028)

pull/31043/head
Guilherme Gazzo 2 years ago committed by GitHub
parent f9ab65380d
commit d072fa74b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      apps/meteor/app/cloud/server/functions/supportedVersionsToken/supportedVersionsToken.ts
  2. 2
      apps/meteor/app/utils/rocketchat-supported-versions.info
  3. 4
      apps/meteor/client/definitions/info.d.ts
  4. 61
      apps/meteor/packages/rocketchat-version/plugin/compile-version.js

@ -7,6 +7,7 @@ import { serverFetch as fetch } from '@rocket.chat/server-fetch';
import { SystemLogger } from '../../../../../server/lib/logger/system';
import { settings } from '../../../../settings/server';
import { supportedVersions as supportedVersionsFromBuild } from '../../../../utils/rocketchat-supported-versions.info';
import { buildVersionUpdateMessage } from '../../../../version-check/server/functions/buildVersionUpdateMessage';
import { generateWorkspaceBearerHttpHeader } from '../getWorkspaceAccessToken';
import { supportedVersionsChooseLatest } from './supportedVersionsChooseLatest';
@ -128,6 +129,7 @@ const getSupportedVersionsToken = async () => {
const [versionsFromLicense, response] = await Promise.all([License.getLicense(), getSupportedVersionsFromCloud()]);
const supportedVersions = await supportedVersionsChooseLatest(
supportedVersionsFromBuild,
versionsFromLicense?.supportedVersions,
(response.success && response.result) || undefined,
);

@ -28,4 +28,8 @@ declare module '*.info' {
desktop: string;
mobile: string;
};
import type { SignedSupportedVersions } from '@rocket.chat/server-cloud-communication';
export const supportedVersions: SignedSupportedVersions;
}

@ -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()}`);
}
}
}
}
}

Loading…
Cancel
Save