-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-versions.js
83 lines (75 loc) · 2.26 KB
/
build-versions.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* eslint-disable @typescript-eslint/no-var-requires */
const { writeFileSync } = require('fs');
const { join } = require('path');
const { lstatSync, readdirSync, readFileSync } = require('fs');
const package = require('./package.json');
const buildVersion = package.version;
const isDirectory = source => lstatSync(source).isDirectory();
const getDirectories = source =>
readdirSync(source)
.map(name => join(source, name))
.filter(isDirectory);
const repos = [];
getDirectories(__dirname).forEach(dir => {
if (dir.includes('.git')) {
return;
}
repos.push({
name: JSON.parse(readFileSync(dir + '/package.json', 'utf8')).name,
directory: dir
});
});
function changeVersion(packages, operation) {
if (packages) {
const matches = [];
for (const dep in packages) {
repos.forEach(repo => {
packages[repo.name];
if (dep === repo.name) {
packages[repo.name] = '^' + buildVersion;
matches.push({
name: repo.name,
packageVersion: packages[repo.name]
});
}
});
}
if (matches.length) {
console.log(operation);
console.log(JSON.stringify(matches, null, 1));
}
return matches;
}
}
repos.forEach(r => {
const rawFile = readFileSync(r.directory + '/package.json', 'utf8');
const package = JSON.parse(rawFile);
console.log('### ', r.name, '###');
if (process.argv[2] === '--package') {
package.version = buildVersion;
writeFileSync(
r.directory + '/package.json',
JSON.stringify(package, null, 2),
'utf8'
);
} else {
const dependencies =
changeVersion(package.dependencies, 'dependencies: ') || [];
const devDependencies =
changeVersion(package.devDependencies, 'devDependencies: ') || [];
const peerDependencies =
changeVersion(package.peerDependencies, 'peerDependencies') || [];
const matches = [...dependencies, ...devDependencies, ...peerDependencies];
if (matches.length) {
console.log('Found dependencies!');
writeFileSync(
r.directory + '/package.json',
JSON.stringify(package, null, 2),
'utf8'
);
console.log('---------------------------------------------');
} else {
console.log('No Matches found');
}
}
});