Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

feat: consume shouldprepare hook #447

Merged
merged 1 commit into from
Mar 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/before-shouldPrepare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { join } = require("path");
const { readFileSync, existsSync, writeFileSync } = require("fs");
const envOptionsCacheFileLocation = join(__dirname, "env.cache.json");

module.exports = function (hookArgs) {
const platformInfo = hookArgs.shouldPrepareInfo && hookArgs.shouldPrepareInfo.platformInfo;
if (platformInfo && platformInfo.appFilesUpdaterOptions && platformInfo.appFilesUpdaterOptions.bundle) {
return (args, originalMethod) => {
return originalMethod(...args).then(originalShouldPrepare => {
const currentEnvString = JSON.stringify(platformInfo.env || {});
if (existsSync(envOptionsCacheFileLocation)) {
const oldEnvOptionsString = readFileSync(envOptionsCacheFileLocation).toString();
if (oldEnvOptionsString === currentEnvString) {
return originalShouldPrepare;
}
}

writeFileSync(envOptionsCacheFileLocation, currentEnvString);

return true;
});
};
}
}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"script": "lib/before-watchPatterns.js",
"inject": true
},
{
"type": "before-shouldPrepare",
"script": "lib/before-shouldPrepare.js",
"inject": true
},
{
"type": "after-prepare",
"script": "lib/after-prepare.js",
Expand Down