forked from module-federation/module-federation-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepotools.js
48 lines (44 loc) · 1.61 KB
/
repotools.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
const fs = require('fs');
const path = require('path');
const execSync = require('child_process').execSync;
function getDirectories(srcPath) {
return fs.readdirSync(srcPath)
.filter(file => fs.statSync(path.join(srcPath, file)).isDirectory());
}
function getPackages(dir, since) {
let packages = [];
const directories = getDirectories(dir);
directories.forEach(directory => {
if (directory !== 'node_modules' && !directory.startsWith('.')) {
const nestedDir = path.join(dir, directory);
const packageJsonPath = path.join(nestedDir, 'package.json');
if (fs.existsSync(packageJsonPath)) {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
if (since) {
const result = execSync(`git diff --name-only ${since}..HEAD -- ${nestedDir}`, { encoding: 'utf8' });
if (result) {
packages.push({
name: packageJson.name,
version: packageJson.version,
private: packageJson.private || false,
location: nestedDir
});
}
} else {
packages.push({
name: packageJson.name,
version: packageJson.version,
private: packageJson.private || false,
location: nestedDir
});
}
}
packages = packages.concat(getPackages(nestedDir, since));
}
});
return packages;
}
const since = process.argv[2] === '--since' ? process.argv[3] : null;
// const packages = getPackages('./', since); // start from current directory
// console.log(JSON.stringify(packages, null, 2));
module.exports = getPackages