/* globals process */ var Fs = require("fs"); var Fse = require("fs-extra"); var Path = require("path"); var OS = require("os"); var config = require("../lib/load-config"); var swap = function (s, o) { return s .replace(/\{\{([^}]+?)\}\}/g, function (all, token) { var content = o[token]; if (typeof(content) === 'number') { content = String(content); } if (typeof(content) !== 'string') { console.error("expected {{%s}}", token); throw new Error("invalid input"); } if (!content) { console.error("expected {{%s}}", token); throw new Error("insufficient input"); } return content; }); }; var Messages = require("../www/common/translations/messages.json"); var types = Messages.type; [ 'calendar', 'notifications', ].forEach(k => { types[k] = Messages[k]; }); // FIXME it would be better if these were just included in the translated list of types types.settings = Messages.settings_title; types.support = Messages.supportPage; types.profile = Messages.profilePage; var translations; try { translations = Fs.readdirSync('./www/common/translations/').filter(name => { return /messages\..*\.json$/.test(name); }); } catch (err) { console.error(err); } var preferredLanguage = config.preferredLanguage; var Preferred; var noScriptContent = [ Messages.ui_jsRequired ]; translations.forEach(name => { var path = `./www/common/translations/${name}`; var content; try { content = JSON.parse(Fs.readFileSync(path, 'utf-8')); } catch (err) { return void console.error(`Failed to parse ${path}`); } if (name === `messages.${preferredLanguage}.json`) { Preferred = content; } if (typeof(content.ui_jsRequired) !== 'string') { return; } noScriptContent.push(content.ui_jsRequired); }); var makeNoscript = (indent) => { var lines = noScriptContent.map(s => { return `${indent + indent}

${s}

`; }).join('\n'); return `${indent}`; }; var getKey = function (key, args) { var source; if (Preferred && Preferred[key]) { source = Preferred[key]; } else if (Messages && Messages[key]) { source = Messages[key]; } else { return '?'; } if (typeof(source) !== 'string') { return '?'; } if (!Array.isArray(args)) { return source; } return source.replace(/\{(\d+)\}/g, (str, p1) => { if (['string', 'number'].includes(typeof(p1))) { return args[p1]; } console.error("Only strings and numbers can be used in _getKey params.\nAborting..."); process.exit(1); }); }; var previewExists = function (name) { if (Fs.existsSync('./customize/images/opengraph_preview/')) { return Fs.existsSync(`./customize/images/opengraph_preview/${name}`); } return Fs.existsSync(`./customize.dist/images/opengraph_preview/${name}`); }; var imagePath = `/customize/images/opengraph_preview/`; var appImagePath = a => { var partial = previewExists(`og-${a}.png`) && `og-${a}.png` || `og-default.png`; return new URL(imagePath + partial, config.httpUnsafeOrigin).href; }; var buildPath = Path.resolve('./customize'); var tmpPath = Path.join(OS.tmpdir(), '/CRYPTPAD_TEMP_BUILD/'); var write = function (content, dest) { console.log(`Creating ${dest}`); var path = Path.join(tmpPath, dest); var dirPath = Path.dirname(path); Fse.mkdirpSync(dirPath); Fs.writeFileSync(path, content); console.log(); }; console.log("Creating target directories"); // remove tmp path so we start fresh Fse.removeSync(tmpPath); var appIndexesToBuild = [ 'sheet', 'doc', 'presentation', 'pad', 'kanban', 'code', 'form', 'poll', 'whiteboard', 'slide', 'file', 'calendar', 'drive', 'teams', 'contacts', 'notifications', 'checkup', 'file', 'profile', 'settings', 'support', // bounce ?? ]; var baseAppPath = './www/'; const ogData = ` `; var versionString = String(+new Date()); var processPage = (src) => { return src .replace(/(\s*)