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

Commit 347beb3

Browse files
author
Dimitar Kerezov
committed
feat: consume shouldprepare hook
1 parent 847a56f commit 347beb3

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Diff for: lib/before-shouldPrepare.js

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

Diff for: package.json

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
"script": "lib/before-watchPatterns.js",
3131
"inject": true
3232
},
33+
{
34+
"type": "before-shouldPrepare",
35+
"script": "lib/before-shouldPrepare.js",
36+
"inject": true
37+
},
3338
{
3439
"type": "after-prepare",
3540
"script": "lib/after-prepare.js",

0 commit comments

Comments
 (0)