Skip to content

Commit 9c96398

Browse files
committed
Add FOSS Meteor EE compatibility stubs
1 parent f8005a5 commit 9c96398

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

scripts/fossify.ts

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,111 @@ const validateLimitDts = `export declare const validateLimit: (...args: any[]) =
213213
export declare const validateWarnLimit: (...args: any[]) => boolean;
214214
`;
215215

216+
const meteorEeUtilitiesTs = `export class Utilities {
217+
\tstatic getI18nKeyForApp<TKey extends string, TAppId extends string>(key: TKey, appId: TAppId) {
218+
\t\treturn \`app-\${appId}.\${key}\` as const;
219+
\t}
220+
221+
\tstatic curl(
222+
\t\t{
223+
\t\t\tmethod,
224+
\t\t\tparams,
225+
\t\t\tauth,
226+
\t\t\theaders = {},
227+
\t\t\turl,
228+
\t\t\tquery,
229+
\t\t\tcontent,
230+
\t\t}: {
231+
\t\t\tmethod: string;
232+
\t\t\tparams?: Record<string, string>;
233+
\t\t\tauth?: string;
234+
\t\t\theaders?: Record<string, string>;
235+
\t\t\turl: string;
236+
\t\t\tquery?: Record<string, string>;
237+
\t\t\tcontent?: unknown;
238+
\t\t},
239+
\t\topts: {
240+
\t\t\tverbose?: boolean;
241+
\t\t\theaders?: boolean;
242+
\t\t} = {},
243+
\t) {
244+
\t\tconst newLine = '\\\\\\n ';
245+
\t\tconst cmd = ['curl'];
246+
247+
\t\tif (opts.verbose) {
248+
\t\t\tcmd.push('-v');
249+
\t\t}
250+
\t\tif (opts.headers) {
251+
\t\t\tcmd.push('-i');
252+
\t\t}
253+
254+
\t\tcmd.push('-X');
255+
\t\tcmd.push((method || 'GET').toUpperCase());
256+
257+
\t\tlet u = url;
258+
\t\tif (typeof params === 'object') {
259+
\t\t\tObject.entries(params).forEach(([key, value]) => {
260+
\t\t\t\tu = u.replace(\`:\${key}\`, value);
261+
\t\t\t});
262+
\t\t}
263+
\t\tif (typeof query === 'object') {
264+
\t\t\tconst queryString = Object.entries(query)
265+
\t\t\t\t.map(([key, value]) => \`\${key}=\${value}\`)
266+
\t\t\t\t.join('&');
267+
\t\t\tu += \`?\${queryString}\`;
268+
\t\t}
269+
\t\tcmd.push(u);
270+
271+
\t\tif (auth) {
272+
\t\t\tcmd.push(newLine);
273+
\t\t\tcmd.push('-u');
274+
\t\t\tcmd.push(auth);
275+
\t\t}
276+
277+
\t\tconst headerKeys: string[] = [];
278+
\t\tObject.entries(headers).forEach(([key, val]) => {
279+
\t\t\tkey = key.toLowerCase();
280+
\t\t\theaderKeys.push(key);
281+
\t\t\tcmd.push(newLine);
282+
\t\t\tcmd.push('-H');
283+
\t\t\tcmd.push(\`"\${key}\${val ? ': ' : ';'}\${val || ''}"\`);
284+
\t\t});
285+
286+
\t\tif (content) {
287+
\t\t\tif (typeof content === 'object') {
288+
\t\t\t\tif (!headerKeys.includes('content-type')) {
289+
\t\t\t\t\tcmd.push(newLine);
290+
\t\t\t\t\tcmd.push('"content-type: application/json"');
291+
\t\t\t\t}
292+
\t\t\t\tcontent = JSON.stringify(content);
293+
\t\t\t}
294+
295+
\t\t\tcmd.push(newLine);
296+
\t\t\tcmd.push('--data-binary');
297+
\t\t\tcmd.push(\`'\${content}'\`);
298+
\t\t}
299+
300+
\t\treturn cmd.join(' ');
301+
\t}
302+
}
303+
`;
304+
305+
const meteorEeDetermineFileTypeJs = `import { mime as MIME } from '../../../app/utils/lib/mimeTypes';
306+
307+
export function determineFileType(_buffer, name) {
308+
\tconst mime = MIME.lookup(name);
309+
310+
\tif (mime) {
311+
\t\treturn Array.isArray(mime) ? mime[0] : mime;
312+
\t}
313+
314+
\treturn 'application/octet-stream';
315+
}
316+
`;
317+
318+
const meteorEeLivechatHelperTs = `export const dispatchInquiryPosition = async (..._args: unknown[]): Promise<void> => undefined;
319+
`;
320+
216321
const writeFile = async (path: string, content: string): Promise<void> => {
217322
await fs.writeFile(path, content, 'utf8');
218323
};
@@ -245,6 +350,15 @@ const writeFossLicensePackage = async (): Promise<void> => {
245350
await writeFile(`${root}/dist/validation/validateLimit.d.ts`, validateLimitDts);
246351
};
247352

353+
const writeFossMeteorEeCompatibility = async (): Promise<void> => {
354+
await fs.mkdir('./apps/meteor/ee/lib/misc', { recursive: true });
355+
await fs.mkdir('./apps/meteor/ee/app/livechat-enterprise/server/lib', { recursive: true });
356+
357+
await writeFile('./apps/meteor/ee/lib/misc/Utilities.ts', meteorEeUtilitiesTs);
358+
await writeFile('./apps/meteor/ee/lib/misc/determineFileType.js', meteorEeDetermineFileTypeJs);
359+
await writeFile('./apps/meteor/ee/app/livechat-enterprise/server/lib/Helper.ts', meteorEeLivechatHelperTs);
360+
};
361+
248362
const fossify = async () => {
249363
console.log('Removing Premium Apps and Packages...');
250364
await fs.rmdir('./ee', removeOptions);
@@ -255,6 +369,9 @@ const fossify = async () => {
255369
console.log('Removing Premium code in the main app...');
256370
await fs.rmdir('./apps/meteor/ee', removeOptions);
257371

372+
console.log('Writing FOSS Meteor EE compatibility stubs...');
373+
await writeFossMeteorEeCompatibility();
374+
258375
console.log('Replacing main files...');
259376
await fs.unlink('./apps/meteor/startRocketChat.ts');
260377

0 commit comments

Comments
 (0)