UNPKG

926 BJavaScriptView Raw
1const { join } = require("path");
2const { readFileSync, existsSync, writeFileSync } = require("fs");
3const envOptionsCacheFileLocation = join(__dirname, "env.cache.json");
4
5module.exports = function (hookArgs) {
6 const platformInfo = hookArgs.shouldPrepareInfo && hookArgs.shouldPrepareInfo.platformInfo;
7 if (platformInfo && platformInfo.appFilesUpdaterOptions && platformInfo.appFilesUpdaterOptions.bundle) {
8
9 return (args, originalMethod) => {
10 return originalMethod(...args).then(originalShouldPrepare => {
11 const currentEnvString = JSON.stringify(platformInfo.env || {});
12 if (existsSync(envOptionsCacheFileLocation)) {
13 const oldEnvOptionsString = readFileSync(envOptionsCacheFileLocation).toString();
14 if (oldEnvOptionsString === currentEnvString) {
15 return originalShouldPrepare;
16 }
17 }
18
19 writeFileSync(envOptionsCacheFileLocation, currentEnvString);
20
21 return true;
22 });
23 };
24 }
25}