Skip to content

Commit

Permalink
send script version to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
jemikanegara committed Jun 27, 2024
1 parent 8faa50d commit 70961de
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion browser.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const { getTranslations, isBrowser } = require("./index.js");
const { BRAND } = require("./utils/configs.js");
const { BRAND, PREV_SCRIPT_VERSION } = require("./utils/configs.js");
// const { checkPage } = require("./utils/translation/checkPage.js");

if (isBrowser()) {
window.translationScriptTag = document.currentScript;
window.translationScriptPrevVersion = PREV_SCRIPT_VERSION // called prev version because it will bumped after published to npm

// REQUIRED ATTRIBUTES
const DATA_API_KEY = `data-${BRAND}-key`
Expand Down
4 changes: 3 additions & 1 deletion utils/configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const OLD_EXCLUDE_CLASS = "weploy-exclude";
const DEFAULT_UNTRANSLATED_VALUE = "weploy-untranslated";
const MERGE_PREFIX = "weploy-merge";
const BRAND = process.env.BRAND || "globalseo";
const PREV_SCRIPT_VERSION = process.env.PREV_SCRIPT_VERSION || "0.0.0";

/** Translation Options */
var globalseoOptions;
Expand Down Expand Up @@ -136,5 +137,6 @@ module.exports = {
OLD_EXCLUDE_CLASS,
DEFAULT_UNTRANSLATED_VALUE,
MERGE_PREFIX,
BRAND
BRAND,
PREV_SCRIPT_VERSION
}
3 changes: 2 additions & 1 deletion utils/translation/getTranslationsFromAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ async function getTranslationsFromAPI(strings, language, apiKey) {
strings: strings,
language: language,
url: window.location.pathname,
scriptPrevVersion: window.translationScriptPrevVersion
};

console.log("weploy payload:", finalPayload)
console.log("globalseo payload:", finalPayload)

const stringifiedPayload = JSON.stringify(finalPayload);

Expand Down
3 changes: 3 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin'); // Add this line
const CircularDependencyPlugin = require('circular-dependency-plugin')
const webpack = require('webpack');
const packageJson = require('./package.json');
const prevVersion = packageJson.version;

module.exports = (env, argv) => {
return {
Expand Down Expand Up @@ -74,6 +76,7 @@ module.exports = (env, argv) => {
BRAND: JSON.stringify('globalseo'),
CSS_PATH: JSON.stringify('../../globalseo.css'),
CSS_PATH_RAW: JSON.stringify('../../globalseo.css?raw'),
PREV_SCRIPT_VERSION: JSON.stringify(prevVersion),
},
}),
],
Expand Down
3 changes: 3 additions & 0 deletions webpack.config.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin'); // Add this line
const CircularDependencyPlugin = require('circular-dependency-plugin')
const webpack = require('webpack');
const packageJson = require('./package.json');
const prevVersion = packageJson.version;

module.exports = (env, argv) => {
return {
Expand Down Expand Up @@ -74,6 +76,7 @@ module.exports = (env, argv) => {
BRAND: JSON.stringify('weploy'),
CSS_PATH: JSON.stringify('../../globalseo.css'),
CSS_PATH_RAW: JSON.stringify('../../globalseo.css?raw'),
PREV_SCRIPT_VERSION: JSON.stringify(prevVersion),
},
}),
],
Expand Down

0 comments on commit 70961de

Please sign in to comment.