diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2019-02-27 16:05:00 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2019-03-01 16:22:24 +0100 |
| commit | 3f5426c08aedcb88e131b0be94308ccb342fc1d4 (patch) | |
| tree | c947b36ecdfb404a2d2b605864c3e74afe26576d /gui/scripts | |
| parent | 4de28cdf229c0016d7e05f24abc8c7aeac6e9dba (diff) | |
| download | mullvadvpn-3f5426c08aedcb88e131b0be94308ccb342fc1d4.tar.xz mullvadvpn-3f5426c08aedcb88e131b0be94308ccb342fc1d4.zip | |
Move desktop to the root
Diffstat (limited to 'gui/scripts')
| -rw-r--r-- | gui/scripts/extract-translations.js | 48 | ||||
| -rw-r--r-- | gui/scripts/serve.js | 92 | ||||
| -rwxr-xr-x | gui/scripts/update-translations.sh | 25 |
3 files changed, 165 insertions, 0 deletions
diff --git a/gui/scripts/extract-translations.js b/gui/scripts/extract-translations.js new file mode 100644 index 0000000000..07383ae553 --- /dev/null +++ b/gui/scripts/extract-translations.js @@ -0,0 +1,48 @@ +const { GettextExtractor, JsExtractors, HtmlExtractors } = require('gettext-extractor'); +const path = require('path'); + +const extractor = new GettextExtractor(); +const outputPotFile = path.resolve(__dirname, '../locales/messages.pot'); +const comments = { + otherLineLeading: true, + sameLineLeading: true, + regex: /^TRANSLATORS:\s*(.*)$/, +}; + +extractor + .createJsParser([ + JsExtractors.callExpression('gettext', { + arguments: { + text: 0, + }, + comments, + }), + JsExtractors.callExpression('pgettext', { + arguments: { + context: 0, + text: 1, + }, + comments, + }), + JsExtractors.callExpression('ngettext', { + arguments: { + text: 0, + textPlural: 1, + }, + comments, + }), + JsExtractors.callExpression('npgettext', { + arguments: { + context: 0, + text: 1, + textPlural: 2, + }, + comments, + }), + ]) + .parseFilesGlob('./src/**/*.@(ts|tsx)', { + cwd: path.resolve(__dirname, '..'), + }); + +extractor.savePotFile(outputPotFile); +extractor.printStats(); diff --git a/gui/scripts/serve.js b/gui/scripts/serve.js new file mode 100644 index 0000000000..e2b91813dc --- /dev/null +++ b/gui/scripts/serve.js @@ -0,0 +1,92 @@ +const { spawn } = require('child_process'); +const path = require('path'); +const TscWatchClient = require('tsc-watch/client'); +const electron = require('electron'); +const browserSync = require('browser-sync'); +const browserSyncConnectUtils = require('browser-sync/dist/connect-utils'); +const bsync = browserSync.create(); + +const getRootUrl = (options) => { + const port = options.get('port'); + return `http://localhost:${port}`; +}; + +const getClientUrl = (options) => { + const pathname = browserSyncConnectUtils.clientScript(options); + return getRootUrl(options) + pathname; +}; + +function runElectron(browserSyncUrl) { + const child = spawn(electron, ['.', '--enable-logging'], { + env: { + ...{ + NODE_ENV: 'development', + BROWSER_SYNC_CLIENT_URL: browserSyncUrl, + }, + ...process.env, + }, + stdio: 'inherit', + }); + child.once('close', () => { + process.exit(); + }); + + return child; +} + +function startBrowserSync() { + bsync.init( + { + ui: false, + // Port 35829 = LiveReload's default port 35729 + 100. + // If the port is occupied, Browsersync uses next free port automatically. + port: 35829, + ghostMode: false, + open: false, + notify: false, + logSnippet: false, + socket: { + // Use the actual port here. + domain: getRootUrl, + }, + }, + (err, bs) => { + if (err) return console.error(err); + + const browserSyncUrl = getClientUrl(bs.options); + + let child = runElectron(browserSyncUrl); + + bsync + .watch(['build/src/config.json', 'build/src/main/**/*', 'build/src/shared/**/*']) + .on('change', () => { + child.removeAllListeners('close'); + child.once('close', () => { + child = runElectron(browserSyncUrl); + }); + child.kill(); + }); + + bsync + .watch(['build/src/renderer/**/*', path.resolve('../components/build/**')]) + .on('change', bsync.reload); + }, + ); +} + +function prepareWatchArguments(projectPath) { + return ['--noClear', '--sourceMap', '--project', projectPath]; +} + +const appWatcher = new TscWatchClient(); +const componentsWatcher = new TscWatchClient(); + +componentsWatcher.on('first_success', () => { + appWatcher.start(...prepareWatchArguments(path.resolve(__dirname, '..'))); +}); + +appWatcher.on('first_success', () => { + startBrowserSync(); +}); + +componentsWatcher.start(...prepareWatchArguments(path.resolve(__dirname, '../../components'))); diff --git a/gui/scripts/update-translations.sh b/gui/scripts/update-translations.sh new file mode 100755 index 0000000000..030d0c78a8 --- /dev/null +++ b/gui/scripts/update-translations.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# This script creates or updates the existing gettext catalogues using the POT template located +# under locales/messages.pot + +ROOT_DIR=$(dirname $(dirname "${BASH_SOURCE[0]}")) +POT_FILE="$ROOT_DIR/locales/messages.pot" + +for PO_FILE_DIR in $ROOT_DIR/locales/* ; do + if [ -d $PO_FILE_DIR ] ; then + PO_FILE="$PO_FILE_DIR/messages.po" + GITKEEP_FILE="$PO_FILE_DIR/.gitkeep" + + if [ -f $PO_FILE ] ; then + echo "Update $PO_FILE_DIR\c" + msgmerge --no-fuzzy-matching --update $PO_FILE $POT_FILE + else + if [ -f $GITKEEP_FILE ] ; then + echo "Remove $GITKEEP_FILE to initialize the new translation" + else + msginit --input $POT_FILE --output $PO_FILE --no-translator + fi + fi + fi +done |
