forked from google/model-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostinstall.js
34 lines (32 loc) · 1.13 KB
/
postinstall.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const fs = require('fs');
const THREE_REGEX = /three@[~^]?([\dvx*]+(?:[-.](?:[\dx*]+|alpha|beta))*)/gm;
let NEW_THREE_VERSION;
const THREE_PACKAGE_REGEX = /"three": ".*"/g;
fs.readFile(
'packages/model-viewer/package.json', {encoding: 'utf8'}, (err, data) => {
NEW_THREE_VERSION = `three@${
THREE_PACKAGE_REGEX.exec(data)[0].split(' ')[1].replaceAll('"', '')}`;
console.log(NEW_THREE_VERSION);
});
function updateThreeVersion(filePath) {
fs.readFile(filePath, {encoding: 'utf8'}, (err, data) => {
if (err) {
console.error(err);
return;
}
const OLD_THREE_VERSION = THREE_REGEX.exec(data)[0];
if (!OLD_THREE_VERSION || !NEW_THREE_VERSION) {
console.error(
'Tried to replace ', OLD_THREE_VERSION, ' with ', NEW_THREE_VERSION);
return;
}
data = data.replaceAll(OLD_THREE_VERSION, NEW_THREE_VERSION);
fs.writeFile(filePath, data, {encoding: 'utf8'}, (err) => {
if (err)
console.log(err);
});
});
}
updateThreeVersion('packages/model-viewer-effects/README.md');
updateThreeVersion(
'packages/modelviewer.dev/examples/postprocessing/index.html');