forked from module-federation/module-federation-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckChangedWorkspaces.js
85 lines (82 loc) · 2.51 KB
/
checkChangedWorkspaces.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
84
85
const { execSync } = require('child_process');
const execOptions = { maxBuffer: Infinity }; // Increase maxBuffer to avoid "stdout maxBuffer length exceeded" error
const path = require('path')
const fs = require('fs')
let allPackages = process.argv[2] ? JSON.parse(process.argv[2]) : null;
let updatedPackages = process.argv[3] ? JSON.parse(process.argv[3]) : null;
if (!allPackages) {
try {
allPackages = JSON.parse(execSync('npm run list:all --silent', execOptions));
} catch (error) {
console.log(`error: ${error.message}`);
return;
}
}
if (!updatedPackages) {
try {
updatedPackages = JSON.parse(execSync('npm run list:changed --silent', execOptions));
} catch (error) {
console.log(`error: ${error.message}`);
return;
}
}
try {
if (updatedPackages && updatedPackages.includes('cypress')) {
// TODO filter for "@" added temporary to not to add packages wich are not automated and formated yet.
let newPackages = updatedPackages.map(package=>{
let pkg
if(path.resolve(package.path, '../').endsWith('module-federation-examples')) {
return package
}
try {
pkg = require(path.resolve(package.path, '../package.json'))
} catch (e) {
try {
if (!path.resolve(package.path, '../../').endsWith('module-federation-examples')) {
pkg = require(path.resolve(package.path, '../../package.json'))
}
} catch (e) {
pkg = package
}
}
if(!pkg) {
return package
}
return pkg
}).filter(p=> {
return p
}).filter(p=>p.name && !p.name.includes('cypress'))
console.log(JSON.stringify({ container: Array.from(new Set(newPackages.map(x => x.name)))}));
} else {
let newPackages = updatedPackages.map(package=>{
let pkg
if(path.resolve(package.path, '../').endsWith('module-federation-examples')) {
return package
}
try {
pkg = require(path.resolve(package.path, '../package.json'))
} catch (e) {
try {
if (!path.resolve(package.path, '../../').endsWith('module-federation-examples')) {
pkg = require(path.resolve(package.path, '../../package.json'))
}
} catch (e) {
pkg = package
}
}
if(!pkg) {
return package
}
return pkg
}).filter(p=> {
return p
})
console.log(
JSON.stringify({
container: Array.from(new Set(newPackages.map(x => x.name)))
}),
);
}
} catch (e) {
console.error(e);
}