Merge pull request #70 from ONLYOFFICE/feature/scripts-caching
Added new caching rules for files in public/scripts
This commit is contained in:
commit
c202911fec
34
.gitignore
vendored
34
.gitignore
vendored
@ -7,38 +7,15 @@
|
||||
**/node_modules/
|
||||
**/storybook-static/
|
||||
**/dist
|
||||
/build/deploy
|
||||
|
||||
*.log
|
||||
/products/ASC.People/Data/
|
||||
/Data
|
||||
|
||||
Logs/
|
||||
**/.DS_Store
|
||||
.eslintcache
|
||||
build/deploy/
|
||||
|
||||
/public/debuginfo.md
|
||||
TestsResults/
|
||||
/Data.Test
|
||||
/build/install/RadicalePlugins/app_auth_plugin/app_auth_plugin.egg-info/PKG-INFO
|
||||
/build/install/RadicalePlugins/app_auth_plugin/app_auth_plugin.egg-info/SOURCES.txt
|
||||
/build/install/RadicalePlugins/app_auth_plugin/app_auth_plugin.egg-info/dependency_links.txt
|
||||
/build/install/RadicalePlugins/app_auth_plugin/app_auth_plugin.egg-info/top_level.txt
|
||||
/build/install/RadicalePlugins/app_auth_plugin/build/lib/app_auth_plugin/__init__.py
|
||||
/build/install/RadicalePlugins/app_rights_plugin/app_rights_plugin.egg-info/PKG-INFO
|
||||
/build/install/RadicalePlugins/app_rights_plugin/app_rights_plugin.egg-info/SOURCES.txt
|
||||
/build/install/RadicalePlugins/app_rights_plugin/app_rights_plugin.egg-info/dependency_links.txt
|
||||
/build/install/RadicalePlugins/app_rights_plugin/app_rights_plugin.egg-info/top_level.txt
|
||||
/build/install/RadicalePlugins/app_rights_plugin/build/lib/app_rights_plugin/__init__.py
|
||||
/build/install/RadicalePlugins/app_store_plugin/app_store_plugin.egg-info/PKG-INFO
|
||||
/build/install/RadicalePlugins/app_store_plugin/app_store_plugin.egg-info/SOURCES.txt
|
||||
/build/install/RadicalePlugins/app_store_plugin/app_store_plugin.egg-info/dependency_links.txt
|
||||
/build/install/RadicalePlugins/app_store_plugin/app_store_plugin.egg-info/top_level.txt
|
||||
/build/install/RadicalePlugins/app_store_plugin/build/lib/app_store_plugin/__init__.py
|
||||
/build/install/RadicalePlugins/app_store_plugin/build/lib/app_store_plugin/cache.py
|
||||
/build/install/RadicalePlugins/app_store_plugin/build/lib/app_store_plugin/delete.py
|
||||
/build/install/RadicalePlugins/app_store_plugin/build/lib/app_store_plugin/history.py
|
||||
/build/install/RadicalePlugins/app_store_plugin/build/lib/app_store_plugin/log.py
|
||||
/build/install/RadicalePlugins/app_store_plugin/build/lib/app_store_plugin/sync.py
|
||||
/build/install/RadicalePlugins/app_store_plugin/build/lib/app_store_plugin/upload.py
|
||||
|
||||
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
@ -51,6 +28,7 @@ TestsResults/
|
||||
**/.yarn/cache
|
||||
**/.yarn/install-state.gz
|
||||
licenses.csv
|
||||
publish/
|
||||
|
||||
|
||||
.idea
|
||||
packages/runtime.json
|
||||
|
55
common/scripts/before-build.js
Normal file
55
common/scripts/before-build.js
Normal file
@ -0,0 +1,55 @@
|
||||
const { join } = require("path");
|
||||
const { readdirSync, readFileSync, writeFileSync } = require("fs");
|
||||
const crypto = require("crypto");
|
||||
|
||||
function generateChecksum(str, algorithm, encoding) {
|
||||
return crypto
|
||||
.createHash(algorithm || "md5")
|
||||
.update(str, "utf8")
|
||||
.digest(encoding || "hex");
|
||||
}
|
||||
|
||||
const dstPath = join(__dirname, "../../packages", "runtime.json");
|
||||
const scriptsDir = join(__dirname, "../../public/scripts");
|
||||
|
||||
const getFileList = (dirName) => {
|
||||
let files = [];
|
||||
|
||||
const items = readdirSync(dirName, { withFileTypes: true });
|
||||
|
||||
for (const item of items) {
|
||||
if (item.name == ".DS_Store") continue;
|
||||
|
||||
if (item.isDirectory()) {
|
||||
files = [...files, ...getFileList(join(dirName, item.name))];
|
||||
} else {
|
||||
files.push({ path: join(dirName, item.name), name: item.name });
|
||||
}
|
||||
}
|
||||
|
||||
return files;
|
||||
};
|
||||
|
||||
const files = getFileList(scriptsDir);
|
||||
|
||||
const date = new Date();
|
||||
const dateString = `${date.getFullYear()}${
|
||||
date.getMonth() + 1
|
||||
}${date.getDate()}_${date.getHours()}${date.getMinutes()}${date.getSeconds()}`;
|
||||
|
||||
const data = {
|
||||
date: dateString,
|
||||
checksums: {},
|
||||
};
|
||||
|
||||
files.forEach((file) => {
|
||||
try {
|
||||
let content = readFileSync(file.path);
|
||||
let checksum = generateChecksum(content);
|
||||
data.checksums[file.name] = checksum;
|
||||
} catch (e) {
|
||||
console.error("Unable to generateChecksum file ", file.path, e);
|
||||
}
|
||||
});
|
||||
|
||||
writeFileSync(dstPath, JSON.stringify(data, null, 2));
|
@ -12,11 +12,11 @@
|
||||
"yarn": ">=3"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "yarn workspaces foreach -vptiR --from '{@docspace/client,@docspace/login,@docspace/editor}' run build",
|
||||
"build": "node ./common/scripts/before-build.js && yarn workspaces foreach -vptiR --from '{@docspace/client,@docspace/login,@docspace/editor}' run build",
|
||||
"bump": "yarn version apply --all",
|
||||
"clean": "yarn workspaces foreach -vptiR run clean",
|
||||
"deploy": "shx rm -rf ../publish/web && yarn workspaces foreach -ptR --from '{@docspace/client,@docspace/login,@docspace/editor}' run deploy && shx cp -r public ../publish/web/ && node common/scripts/minify-common-locales.js",
|
||||
"start": "yarn workspaces foreach -vptiR --from '{@docspace/client,@docspace/login,@docspace/editor}' run start",
|
||||
"start": "node ./common/scripts/before-build.js && yarn workspaces foreach -vptiR --from '{@docspace/client,@docspace/login,@docspace/editor}' run start",
|
||||
"start-prod": "yarn workspaces foreach -vptiR --from '{@docspace/client,@docspace/login,@docspace/editor}' run start-prod",
|
||||
"storybook": "yarn workspace @docspace/components storybook",
|
||||
"storybook-build": "yarn workspace @docspace/components run storybook-build",
|
||||
|
@ -69,10 +69,11 @@
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
<script src="/static/scripts/browserDetector.js"></script>
|
||||
<script src="<%= htmlWebpackPlugin.options.browserDetectorUrl %>"></script>
|
||||
<script async src="<%= htmlWebpackPlugin.options.tiffUrl %>"></script>
|
||||
<script>
|
||||
console.log("It's WEB CLIENT INIT");
|
||||
fetch("/static/scripts/config.json")
|
||||
fetch("<%= htmlWebpackPlugin.options.configUrl %>")
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error("HTTP error " + response.status);
|
||||
@ -84,10 +85,13 @@
|
||||
...config,
|
||||
};
|
||||
|
||||
if (window.navigator.userAgent.includes("ZoomWebKit") || window.navigator.userAgent.includes("ZoomApps")) {
|
||||
if (
|
||||
window.navigator.userAgent.includes("ZoomWebKit") ||
|
||||
window.navigator.userAgent.includes("ZoomApps")
|
||||
) {
|
||||
window.DocSpaceConfig.editor = {
|
||||
openOnNewPage: false,
|
||||
requestClose: true
|
||||
requestClose: true,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ import { withTranslation } from "react-i18next";
|
||||
import Article from "@docspace/common/components/Article";
|
||||
import {
|
||||
updateTempContent,
|
||||
loadScript,
|
||||
showLoader,
|
||||
hideLoader,
|
||||
} from "@docspace/common/utils";
|
||||
@ -84,20 +83,12 @@ const ClientContent = (props) => {
|
||||
const isFormGallery = location.pathname.split("/").includes("form-gallery");
|
||||
|
||||
React.useEffect(() => {
|
||||
loadScript("/static/scripts/tiff.min.js", "img-tiff-script");
|
||||
|
||||
loadClientInfo()
|
||||
.catch((err) => toastr.error(err))
|
||||
.finally(() => {
|
||||
setIsLoaded(true);
|
||||
|
||||
updateTempContent();
|
||||
});
|
||||
|
||||
return () => {
|
||||
const script = document.getElementById("img-tiff-script");
|
||||
document.body.removeChild(script);
|
||||
};
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
|
@ -17,6 +17,7 @@ const EmbeddingBody = ({ t, link, requestToken, roomId }) => {
|
||||
const [heightValue, setHeightValue] = useState("100%");
|
||||
|
||||
const config = {
|
||||
hash: `${API_JS_HASH}`,
|
||||
width: `${widthValue}`,
|
||||
height: `${heightValue}`,
|
||||
frameId: "ds-frame-embedding",
|
||||
|
@ -284,6 +284,7 @@ const PortalIntegration = (props) => {
|
||||
);
|
||||
|
||||
const [config, setConfig] = useState({
|
||||
hash: `${API_JS_HASH}`,
|
||||
width: `${width}${widthDimension.label}`,
|
||||
height: `${height}${heightDimension.label}`,
|
||||
frameId: "ds-frame",
|
||||
|
@ -9,22 +9,23 @@ const BundleAnalyzerPlugin =
|
||||
|
||||
const ExternalTemplateRemotesPlugin = require("external-remotes-plugin");
|
||||
const TerserPlugin = require("terser-webpack-plugin");
|
||||
const combineUrl = require("@docspace/common/utils/combineUrl");
|
||||
//const combineUrl = require("@docspace/common/utils/combineUrl");
|
||||
const minifyJson = require("@docspace/common/utils/minifyJson");
|
||||
const beforeBuild = require("@docspace/common/utils/beforeBuild");
|
||||
//const beforeBuild = require("@docspace/common/utils/beforeBuild");
|
||||
const sharedDeps = require("@docspace/common/constants/sharedDependencies");
|
||||
const fs = require("fs");
|
||||
const { readdir } = require("fs").promises;
|
||||
//const fs = require("fs");
|
||||
//const { readdir } = require("fs").promises;
|
||||
|
||||
const path = require("path");
|
||||
|
||||
const pkg = require("./package.json");
|
||||
const runtime = require("../runtime.json");
|
||||
const deps = pkg.dependencies || {};
|
||||
const homepage = pkg.homepage; //combineUrl(window.DocSpaceConfig?.proxy?.url, pkg.homepage);
|
||||
const title = pkg.title;
|
||||
const version = pkg.version;
|
||||
|
||||
const isAlreadyBuilding = false;
|
||||
const dateHash = runtime?.date || "";
|
||||
//const isAlreadyBuilding = false;
|
||||
|
||||
const config = {
|
||||
entry: "./src/index",
|
||||
@ -349,6 +350,15 @@ module.exports = (env, argv) => {
|
||||
publicPath: homepage,
|
||||
title: title,
|
||||
base: `${homepage}/`,
|
||||
browserDetectorUrl: `/static/scripts/browserDetector.js?hash=${
|
||||
runtime.checksums["browserDetector.js"] || dateHash
|
||||
}`,
|
||||
configUrl: `/static/scripts/config.json?hash=${
|
||||
runtime.checksums["config.json"] || dateHash
|
||||
}`,
|
||||
tiffUrl: `/static/scripts/tiff.min.js?hash=${
|
||||
runtime.checksums["tiff.min.js"] || dateHash
|
||||
}`,
|
||||
})
|
||||
);
|
||||
}
|
||||
@ -361,6 +371,7 @@ module.exports = (env, argv) => {
|
||||
return JSON.stringify(today.toISOString().split(".")[0] + "Z");
|
||||
}, true),
|
||||
IS_PERSONAL: env.personal || false,
|
||||
API_JS_HASH: JSON.stringify(runtime.checksums["api.js"] || dateHash),
|
||||
};
|
||||
|
||||
config.plugins.push(new DefinePlugin(defines));
|
||||
|
@ -56,7 +56,7 @@ export default function template(
|
||||
tempElm.style.backgroundColor =
|
||||
localStorage.theme === "Dark" ? "#333333" : "#f4f4f4";
|
||||
console.log("It's Editor INIT");
|
||||
fetch("/static/scripts/config.json")
|
||||
fetch("${CONFIG_URL}")
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error("HTTP error " + response.status);
|
||||
@ -415,7 +415,7 @@ export default function template(
|
||||
</div>
|
||||
<div id="root">${appComponent}</div>
|
||||
<noscript> You need to enable JavaScript to run this app. </noscript>
|
||||
<script src="/static/scripts/browserDetector.js"></script>
|
||||
<script src=${BROWSER_DETECTOR_URL}></script>
|
||||
${scripts}
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,7 +1,7 @@
|
||||
const { merge } = require("webpack-merge");
|
||||
const path = require("path");
|
||||
const ModuleFederationPlugin = require("webpack").container
|
||||
.ModuleFederationPlugin;
|
||||
const ModuleFederationPlugin =
|
||||
require("webpack").container.ModuleFederationPlugin;
|
||||
const DefinePlugin = require("webpack").DefinePlugin;
|
||||
const { WebpackManifestPlugin } = require("webpack-manifest-plugin");
|
||||
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
|
||||
@ -9,8 +9,10 @@ const ExternalTemplateRemotesPlugin = require("external-remotes-plugin");
|
||||
const CopyPlugin = require("copy-webpack-plugin");
|
||||
const TerserPlugin = require("terser-webpack-plugin");
|
||||
const minifyJson = require("@docspace/common/utils/minifyJson");
|
||||
const runtime = require("../../runtime.json");
|
||||
const dateHash = runtime?.date || "";
|
||||
|
||||
const beforeBuild = require("@docspace/common/utils/beforeBuild");
|
||||
//const beforeBuild = require("@docspace/common/utils/beforeBuild");
|
||||
|
||||
const sharedDeps = require("@docspace/common/constants/sharedDependencies");
|
||||
const baseConfig = require("./webpack.base.js");
|
||||
@ -159,6 +161,16 @@ module.exports = (env, argv) => {
|
||||
IS_DEVELOPMENT: argv.mode !== "production",
|
||||
PORT: process.env.PORT || 5013,
|
||||
IS_PERSONAL: env.personal || false,
|
||||
BROWSER_DETECTOR_URL: JSON.stringify(
|
||||
`/static/scripts/browserDetector.js?hash=${
|
||||
runtime.checksums["browserDetector.js"] || dateHash
|
||||
}`
|
||||
),
|
||||
CONFIG_URL: JSON.stringify(
|
||||
`/static/scripts/config.json?hash=${
|
||||
runtime.checksums["config.json"] || dateHash
|
||||
}`
|
||||
),
|
||||
}),
|
||||
];
|
||||
|
||||
|
@ -4,6 +4,8 @@ const path = require("path");
|
||||
const DefinePlugin = require("webpack").DefinePlugin;
|
||||
const TerserPlugin = require("terser-webpack-plugin");
|
||||
const CopyPlugin = require("copy-webpack-plugin");
|
||||
const runtime = require("../../runtime.json");
|
||||
const dateHash = runtime?.date || "";
|
||||
|
||||
const serverConfig = {
|
||||
target: "node",
|
||||
@ -74,6 +76,16 @@ module.exports = (env, argv) => {
|
||||
IS_DEVELOPMENT: argv.mode !== "production",
|
||||
PORT: 5013,
|
||||
IS_PERSONAL: env.personal || false,
|
||||
BROWSER_DETECTOR_URL: JSON.stringify(
|
||||
`/static/scripts/browserDetector.js?hash=${
|
||||
runtime.checksums["browserDetector.js"] || dateHash
|
||||
}`
|
||||
),
|
||||
CONFIG_URL: JSON.stringify(
|
||||
`/static/scripts/config.json?hash=${
|
||||
runtime.checksums["config.json"] || dateHash
|
||||
}`
|
||||
),
|
||||
}),
|
||||
];
|
||||
|
||||
|
2
packages/login/index.d.ts
vendored
2
packages/login/index.d.ts
vendored
@ -131,6 +131,8 @@ declare global {
|
||||
var PORT: number;
|
||||
var IS_PERSONAL: boolean;
|
||||
var IS_ROOMS_MODE: boolean;
|
||||
var BROWSER_DETECTOR_URL: string;
|
||||
var CONFIG_URL: string;
|
||||
|
||||
type assetsType = { [key: string]: string } | undefined;
|
||||
|
||||
|
@ -69,7 +69,7 @@ const template: Template = (
|
||||
${clientScripts}
|
||||
<script>
|
||||
console.log("It's Login INIT");
|
||||
fetch("/static/scripts/config.json")
|
||||
fetch("${CONFIG_URL}")
|
||||
.then((response) => {
|
||||
if (!response.ok) {
|
||||
throw new Error("HTTP error " + response.status);
|
||||
@ -125,7 +125,7 @@ const template: Template = (
|
||||
<body>
|
||||
<noscript> You need to enable JavaScript to run this app. </noscript>
|
||||
<div id="root">${appComponent}</div>
|
||||
<script src="/static/scripts/browserDetector.js"></script>
|
||||
<script src=${BROWSER_DETECTOR_URL}></script>
|
||||
${scripts}
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,20 +1,22 @@
|
||||
const { merge } = require("webpack-merge");
|
||||
const path = require("path");
|
||||
const ModuleFederationPlugin = require("webpack").container
|
||||
.ModuleFederationPlugin;
|
||||
const ModuleFederationPlugin =
|
||||
require("webpack").container.ModuleFederationPlugin;
|
||||
const DefinePlugin = require("webpack").DefinePlugin;
|
||||
const { WebpackManifestPlugin } = require("webpack-manifest-plugin");
|
||||
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
|
||||
const ExternalTemplateRemotesPlugin = require("external-remotes-plugin");
|
||||
const CopyPlugin = require("copy-webpack-plugin");
|
||||
const TerserPlugin = require("terser-webpack-plugin");
|
||||
const combineUrl = require("@docspace/common/utils/combineUrl");
|
||||
//const combineUrl = require("@docspace/common/utils/combineUrl");
|
||||
const minifyJson = require("@docspace/common/utils/minifyJson");
|
||||
const sharedDeps = require("@docspace/common/constants/sharedDependencies");
|
||||
const beforeBuild = require("@docspace/common/utils/beforeBuild");
|
||||
//const beforeBuild = require("@docspace/common/utils/beforeBuild");
|
||||
const baseConfig = require("./webpack.base.js");
|
||||
const runtime = require("../../runtime.json");
|
||||
const pkg = require("../package.json");
|
||||
const deps = pkg.dependencies || {};
|
||||
const dateHash = runtime?.date || "";
|
||||
|
||||
for (let dep in sharedDeps) {
|
||||
sharedDeps[dep].eager = true;
|
||||
@ -161,6 +163,16 @@ module.exports = (env, argv) => {
|
||||
PORT: process.env.PORT || 5011,
|
||||
IS_PERSONAL: env.personal || false,
|
||||
IS_ROOMS_MODE: env.rooms || false,
|
||||
BROWSER_DETECTOR_URL: JSON.stringify(
|
||||
`/static/scripts/browserDetector.js?hash=${
|
||||
runtime.checksums["browserDetector.js"] || dateHash
|
||||
}`
|
||||
),
|
||||
CONFIG_URL: JSON.stringify(
|
||||
`/static/scripts/config.json?hash=${
|
||||
runtime.checksums["config.json"] || dateHash
|
||||
}`
|
||||
),
|
||||
}),
|
||||
];
|
||||
|
||||
|
@ -4,6 +4,8 @@ const path = require("path");
|
||||
const DefinePlugin = require("webpack").DefinePlugin;
|
||||
const TerserPlugin = require("terser-webpack-plugin");
|
||||
const CopyPlugin = require("copy-webpack-plugin");
|
||||
const runtime = require("../../runtime.json");
|
||||
const dateHash = runtime?.date || "";
|
||||
|
||||
const serverConfig = {
|
||||
target: "node",
|
||||
@ -74,6 +76,16 @@ module.exports = (env, argv) => {
|
||||
PORT: process.env.PORT || 5011,
|
||||
IS_PERSONAL: env.personal || false,
|
||||
IS_ROOMS_MODE: env.rooms || false,
|
||||
BROWSER_DETECTOR_URL: JSON.stringify(
|
||||
`/static/scripts/browserDetector.js?hash=${
|
||||
runtime.checksums["browserDetector.js"] || dateHash
|
||||
}`
|
||||
),
|
||||
CONFIG_URL: JSON.stringify(
|
||||
`/static/scripts/config.json?hash=${
|
||||
runtime.checksums["config.json"] || dateHash
|
||||
}`
|
||||
),
|
||||
}),
|
||||
];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user