-
Notifications
You must be signed in to change notification settings - Fork 17
/
gulpfile.js
66 lines (61 loc) · 1.66 KB
/
gulpfile.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const path = require('path');
const fs = require('fs');
const RELEASE_COMMIT_SHA = process.env.RELEASE_COMMIT_SHA;
const VERSION = RELEASE_COMMIT_SHA
? `0.0.0-main-${RELEASE_COMMIT_SHA.substr(0, 8)}`
: process.env.npm_package_version;
const builds = [
{
folder: 'isograph-babel-plugin',
packageName: '@isograph/babel-plugin',
},
{
folder: 'isograph-disposable-types',
packageName: '@isograph/disposable-types',
},
{
folder: 'isograph-react',
packageName: '@isograph/react',
},
{
folder: 'isograph-react-disposable-state',
packageName: '@isograph/react-disposable-state',
},
{
folder: 'isograph-reference-counted-pointer',
packageName: '@isograph/reference-counted-pointer',
},
{
folder: 'isograph-compiler',
packageName: '@isograph/compiler',
},
];
const setMainVersion = async () => {
if (!RELEASE_COMMIT_SHA) {
throw new Error('Expected the RELEASE_COMMIT_SHA env variable to be set.');
}
const packages = builds.map((build) => build.packageName);
builds.forEach((build) => {
const pkgJsonPath = path.join('.', 'libs', build.folder, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
packageJson.version = VERSION;
for (const depKind of [
'dependencies',
'devDependencies',
'peerDependencies',
]) {
const deps = packageJson[depKind];
for (const dep in deps) {
if (packages.includes(dep)) {
deps[dep] = VERSION;
}
}
}
fs.writeFileSync(
pkgJsonPath,
JSON.stringify(packageJson, null, 2) + '\n',
'utf8',
);
});
};
exports.setMainVersion = setMainVersion;