diff --git a/browser.js b/browser.js index 199d224..dd2da82 100644 --- a/browser.js +++ b/browser.js @@ -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` diff --git a/utils/configs.js b/utils/configs.js index b843a4a..dbca4c1 100644 --- a/utils/configs.js +++ b/utils/configs.js @@ -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; @@ -136,5 +137,6 @@ module.exports = { OLD_EXCLUDE_CLASS, DEFAULT_UNTRANSLATED_VALUE, MERGE_PREFIX, - BRAND + BRAND, + PREV_SCRIPT_VERSION } diff --git a/utils/translation/getTranslationsFromAPI.js b/utils/translation/getTranslationsFromAPI.js index 363ee4f..fa9251b 100644 --- a/utils/translation/getTranslationsFromAPI.js +++ b/utils/translation/getTranslationsFromAPI.js @@ -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); diff --git a/webpack.config.js b/webpack.config.js index b5b34fd..95fec65 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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 { @@ -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), }, }), ], diff --git a/webpack.config.old.js b/webpack.config.old.js index 5b5ea34..a6c6df3 100644 --- a/webpack.config.old.js +++ b/webpack.config.old.js @@ -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 { @@ -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), }, }), ],